2016-07-17 07:42:17 +02:00
|
|
|
import time
|
2016-07-18 06:52:06 +02:00
|
|
|
import string
|
2016-07-17 07:42:17 +02:00
|
|
|
|
|
|
|
from pylinkirc import utils, conf
|
|
|
|
from pylinkirc.log import log
|
|
|
|
from pylinkirc.classes import Protocol, IrcUser, IrcServer
|
|
|
|
|
|
|
|
class ClientbotWrapperProtocol(Protocol):
|
|
|
|
def __init__(self, irc):
|
|
|
|
super().__init__(irc)
|
|
|
|
|
2016-07-21 08:48:18 +02:00
|
|
|
# This is just a fallback. Actual casemapping is fetched by handle_005()
|
2016-07-17 07:42:17 +02:00
|
|
|
self.casemapping = 'ascii'
|
|
|
|
|
|
|
|
self.caps = {}
|
|
|
|
|
|
|
|
# Initialize counter-based pseudo UID generators
|
|
|
|
self.uidgen = utils.PUIDGenerator('PUID')
|
|
|
|
self.sidgen = utils.PUIDGenerator('PSID')
|
|
|
|
|
2016-07-22 09:22:56 +02:00
|
|
|
# Tracks the users sent in a list of /who replies, so that users can be bursted all at once
|
|
|
|
# when ENDOFWHO is received.
|
|
|
|
self.who_received = set()
|
|
|
|
|
2016-07-18 05:59:42 +02:00
|
|
|
def _expandPUID(self, uid):
|
|
|
|
"""
|
|
|
|
Returns the real nick for the given PUID.
|
|
|
|
"""
|
|
|
|
if uid in self.irc.users:
|
|
|
|
nick = self.irc.users[uid].nick
|
|
|
|
log.debug('(%s) Mangling target PUID %s to nick %s', self.irc.name, uid, nick)
|
|
|
|
return nick
|
|
|
|
return uid
|
|
|
|
|
2016-07-18 07:34:26 +02:00
|
|
|
def _formatText(self, source, text):
|
|
|
|
"""
|
|
|
|
Formats text with the given sender as a prefix.
|
|
|
|
"""
|
2016-07-18 08:09:11 +02:00
|
|
|
if self.irc.pseudoclient and source == self.irc.pseudoclient.uid:
|
2016-07-18 07:34:26 +02:00
|
|
|
return text
|
|
|
|
else:
|
|
|
|
# TODO: configurable formatting
|
|
|
|
return '<%s> %s' % (self.irc.getFriendlyName(source), text)
|
|
|
|
|
2016-07-17 07:42:17 +02:00
|
|
|
def connect(self):
|
|
|
|
"""Initializes a connection to a server."""
|
|
|
|
ts = self.irc.start_ts
|
|
|
|
f = self.irc.send
|
|
|
|
|
|
|
|
# TODO: fetch channel/user/prefix modes from RPL_ISUPPORT.
|
|
|
|
#self.irc.prefixmodes = {'q': '~', 'a': '&', 'o': '@', 'h': '%', 'v': '+'}
|
|
|
|
|
|
|
|
# HACK: Replace the SID from the config options with our own.
|
|
|
|
old_sid = self.irc.sid
|
|
|
|
self.irc.sid = sid = self.sidgen.next_uid()
|
|
|
|
self.irc.servers[sid] = self.irc.servers[old_sid]
|
|
|
|
del self.irc.servers[old_sid]
|
|
|
|
|
|
|
|
sendpass = self.irc.serverdata.get("sendpass")
|
|
|
|
if sendpass:
|
|
|
|
f('PASS %s' % sendpass)
|
|
|
|
|
|
|
|
# This is a really gross hack to get the defined NICK/IDENT/HOST/GECOS.
|
|
|
|
# But this connection stuff is done before any of the spawnClient stuff in
|
|
|
|
# services_support fires.
|
|
|
|
f('NICK %s' % (self.irc.serverdata.get('pylink_nick') or conf.conf["bot"].get("nick", "PyLink")))
|
|
|
|
ident = self.irc.serverdata.get('pylink_ident') or conf.conf["bot"].get("ident", "pylink")
|
2016-07-21 07:02:44 +02:00
|
|
|
f('USER %s 8 * %s' % (ident, # TODO: per net realnames or hostnames aren't implemented yet.
|
|
|
|
conf.conf["bot"].get("realname", "PyLink Clientbot")))
|
2016-07-17 07:42:17 +02:00
|
|
|
|
|
|
|
def spawnClient(self, nick, ident='null', host='null', realhost=None, modes=set(),
|
|
|
|
server=None, ip='0.0.0.0', realname=None, ts=None, opertype=None,
|
|
|
|
manipulatable=False):
|
|
|
|
"""
|
|
|
|
STUB: Pretends to spawn a new client with a subset of the given options.
|
|
|
|
"""
|
|
|
|
|
2016-07-18 00:20:57 +02:00
|
|
|
server = server or self.irc.sid
|
2016-07-17 07:42:17 +02:00
|
|
|
uid = self.uidgen.next_uid()
|
|
|
|
|
|
|
|
ts = ts or int(time.time())
|
|
|
|
realname = realname or ''
|
|
|
|
log.debug('(%s) spawnClient stub called, saving nick %s as PUID %s', self.irc.name, nick, uid)
|
2016-07-22 03:13:17 +02:00
|
|
|
u = self.irc.users[uid] = IrcUser(nick, ts, uid, ident=ident, host=host, realname=realname, manipulatable=manipulatable)
|
2016-07-17 07:42:17 +02:00
|
|
|
log.debug('(%s) self.irc.users: %s', self.irc.name, self.irc.users)
|
2016-07-18 00:20:57 +02:00
|
|
|
self.irc.servers[server].users.add(uid)
|
2016-07-17 07:42:17 +02:00
|
|
|
return u
|
|
|
|
|
|
|
|
def spawnServer(self, name, sid=None, uplink=None, desc=None, endburst_delay=0):
|
|
|
|
"""
|
|
|
|
STUB: Pretends to spawn a new server with a subset of the given options.
|
|
|
|
"""
|
|
|
|
name = name.lower()
|
|
|
|
sid = self.sidgen.next_sid()
|
|
|
|
self.irc.servers[sid] = IrcServer(uplink, name)
|
|
|
|
return sid
|
|
|
|
|
2016-07-22 09:22:56 +02:00
|
|
|
def away(self, source, text):
|
|
|
|
"""STUB: sets away messages for clients internally."""
|
|
|
|
self.irc.users[source].away = text
|
|
|
|
|
2016-07-22 03:14:23 +02:00
|
|
|
def invite(self, client, target, channel):
|
|
|
|
"""Invites a user to a channel."""
|
|
|
|
self.irc.send('INVITE %s %s' % (self.irc.getFriendlyName(target), channel))
|
|
|
|
|
2016-07-18 00:20:57 +02:00
|
|
|
def join(self, client, channel):
|
|
|
|
"""STUB: Joins a user to a channel."""
|
|
|
|
channel = self.irc.toLower(channel)
|
|
|
|
|
|
|
|
self.irc.channels[channel].users.add(client)
|
|
|
|
self.irc.users[client].channels.add(channel)
|
|
|
|
|
2016-07-18 06:52:06 +02:00
|
|
|
# Only joins for the main PyLink client are actually forwarded. Others are ignored.
|
2016-07-18 08:09:11 +02:00
|
|
|
if self.irc.pseudoclient and client == self.irc.pseudoclient.uid:
|
2016-07-18 00:20:57 +02:00
|
|
|
self.irc.send('JOIN %s' % channel)
|
2016-07-22 09:22:56 +02:00
|
|
|
# Send a /who request right after
|
|
|
|
self.irc.send('WHO %s' % channel)
|
2016-07-18 00:20:57 +02:00
|
|
|
else:
|
|
|
|
log.debug('(%s) join: faking JOIN of client %s/%s to %s', self.irc.name, client,
|
|
|
|
self.irc.getFriendlyName(client), channel)
|
2016-07-17 07:42:17 +02:00
|
|
|
|
2016-07-18 07:34:26 +02:00
|
|
|
def kick(self, source, channel, target, reason=''):
|
|
|
|
"""Sends channel kicks."""
|
|
|
|
# TODO: handle kick failures and send rejoin hooks for the target
|
2016-07-18 08:09:41 +02:00
|
|
|
reason = self._formatText(source, reason)
|
2016-07-18 07:34:26 +02:00
|
|
|
self.irc.send('KICK %s %s :%s' % (channel, self._expandPUID(target), reason))
|
2016-07-22 03:03:32 +02:00
|
|
|
|
|
|
|
# Don't update our state here: wait for the IRCd to send an acknowledgement instead.
|
2016-07-18 07:34:26 +02:00
|
|
|
|
2016-07-18 05:59:42 +02:00
|
|
|
def message(self, source, target, text, notice=False):
|
|
|
|
"""Sends messages to the target."""
|
|
|
|
command = 'NOTICE' if notice else 'PRIVMSG'
|
|
|
|
target = self._expandPUID(target)
|
|
|
|
|
2016-07-18 07:34:26 +02:00
|
|
|
self.irc.send('%s %s :%s' % (command, target, self._formatText(source, text)))
|
|
|
|
|
|
|
|
def nick(self, source, newnick):
|
|
|
|
"""STUB: Sends NICK changes."""
|
2016-07-21 09:11:15 +02:00
|
|
|
if source == self.irc.pseudoclient.uid:
|
2016-07-18 07:34:26 +02:00
|
|
|
self.irc.send('NICK :%s' % (channel, self._expandPUID(target), reason))
|
|
|
|
self.irc.users[source].nick = newnick
|
2016-07-18 05:59:42 +02:00
|
|
|
|
|
|
|
def notice(self, source, target, text):
|
|
|
|
"""Sends notices to the target."""
|
2016-07-18 07:34:26 +02:00
|
|
|
# Wrap around message(), which does all the text formatting for us.
|
2016-07-18 05:59:42 +02:00
|
|
|
self.message(source, target, text, notice=True)
|
|
|
|
|
2016-07-18 05:20:49 +02:00
|
|
|
def ping(self, source=None, target=None):
|
2016-07-18 05:59:42 +02:00
|
|
|
"""
|
|
|
|
Sends PING to the uplink.
|
|
|
|
"""
|
2016-07-18 05:20:49 +02:00
|
|
|
if self.irc.uplink:
|
|
|
|
self.irc.send('PING %s' % self.irc.getFriendlyName(self.irc.uplink))
|
2016-07-17 07:42:17 +02:00
|
|
|
|
2016-07-18 06:52:06 +02:00
|
|
|
def part(self, source, channel, reason=''):
|
|
|
|
"""STUB: Parts a user from a channel."""
|
|
|
|
self.irc.channels[channel].removeuser(source)
|
|
|
|
self.irc.users[source].channels.discard(channel)
|
|
|
|
|
|
|
|
# Only parts for the main PyLink client are actually forwarded. Others are ignored.
|
2016-07-18 08:09:11 +02:00
|
|
|
if self.irc.pseudoclient and source == self.irc.pseudoclient.uid:
|
2016-07-18 06:52:06 +02:00
|
|
|
self.irc.send('PART %s :%s' % (channel, reason))
|
|
|
|
|
|
|
|
def quit(self, source, reason):
|
|
|
|
"""STUB: Quits a client."""
|
|
|
|
self.removeClient(source)
|
|
|
|
|
2016-07-18 07:34:26 +02:00
|
|
|
def sjoin(self, server, channel, users, ts=None, modes=set()):
|
|
|
|
"""STUB: bursts joins from a server."""
|
2016-07-21 07:06:09 +02:00
|
|
|
# This stub only updates the state internally with the users
|
|
|
|
# given. modes and TS are currently ignored.
|
2016-07-18 07:34:26 +02:00
|
|
|
puids = {u[-1] for u in users}
|
|
|
|
for user in puids:
|
|
|
|
self.irc.users[user].channels.add(channel)
|
|
|
|
|
|
|
|
self.irc.channels[channel].users |= puids
|
|
|
|
|
|
|
|
def squit(self, source, target, text):
|
2016-07-21 07:06:09 +02:00
|
|
|
"""STUB: SQUITs a server."""
|
|
|
|
# What this actually does is just handle the SQUIT internally: i.e.
|
|
|
|
# Removing pseudoclients and pseudoservers.
|
2016-07-22 04:11:57 +02:00
|
|
|
self._squit(source, 'CLIENTBOT_VIRTUAL_SQUIT', [target, text])
|
2016-07-18 07:34:26 +02:00
|
|
|
|
2016-07-18 08:09:57 +02:00
|
|
|
def _stub(self, *args):
|
2016-07-21 07:06:09 +02:00
|
|
|
"""Stub outgoing command function (does nothing)."""
|
2016-07-18 08:09:57 +02:00
|
|
|
return
|
2016-07-22 03:16:15 +02:00
|
|
|
kill = away = mode = topic = topicBurst = knock = updateClient = numeric = _stub
|
2016-07-18 08:09:57 +02:00
|
|
|
|
2016-07-22 03:35:57 +02:00
|
|
|
def updateClient(self, target, field, text):
|
|
|
|
"""Updates the known ident, host, or realname of a client."""
|
|
|
|
if field == 'IDENT':
|
|
|
|
self.irc.users[target].ident = text
|
|
|
|
elif field == 'HOST':
|
|
|
|
self.irc.users[target].host = text
|
|
|
|
elif field in ('REALNAME', 'GECOS'):
|
|
|
|
self.irc.users[target].realname = text
|
|
|
|
else:
|
|
|
|
raise NotImplementedError
|
|
|
|
|
2016-07-17 07:42:17 +02:00
|
|
|
def handle_events(self, data):
|
2016-07-18 07:34:26 +02:00
|
|
|
"""Event handler for the RFC1459/2812 (clientbot) protocol."""
|
2016-07-17 07:42:17 +02:00
|
|
|
data = data.split(" ")
|
2016-07-18 00:20:57 +02:00
|
|
|
try:
|
|
|
|
args = self.parsePrefixedArgs(data)
|
|
|
|
sender = args[0]
|
|
|
|
command = args[1]
|
2016-07-18 05:59:31 +02:00
|
|
|
args = args[2:]
|
2016-07-18 00:20:57 +02:00
|
|
|
|
|
|
|
except IndexError:
|
|
|
|
# Raw command without an explicit sender; assume it's being sent by our uplink.
|
|
|
|
args = self.parseArgs(data)
|
2016-07-18 05:20:49 +02:00
|
|
|
idsource = sender = self.irc.uplink
|
2016-07-18 00:20:57 +02:00
|
|
|
command = args[0]
|
|
|
|
args = args[1:]
|
2016-07-17 07:42:17 +02:00
|
|
|
else:
|
2016-07-18 00:20:57 +02:00
|
|
|
# PyLink as a services framework expects UIDs and SIDs for everythiung. Since we connect
|
|
|
|
# as a bot here, there's no explicit user introduction, so we're going to generate
|
|
|
|
# pseudo-uids and pseudo-sids as we see prefixes.
|
|
|
|
if '!' not in sender:
|
|
|
|
# Sender is a server name.
|
|
|
|
idsource = self._getSid(sender)
|
|
|
|
if idsource not in self.irc.servers:
|
|
|
|
idsource = self.spawnServer(sender)
|
|
|
|
else:
|
|
|
|
# Sender is a nick!user@host prefix. Split it into its relevant parts.
|
|
|
|
nick, ident, host = utils.splitHostmask(sender)
|
|
|
|
idsource = self.irc.nickToUid(nick)
|
|
|
|
if not idsource:
|
|
|
|
idsource = self.spawnClient(nick, ident, host, server=self.irc.uplink).uid
|
|
|
|
|
2016-07-17 07:42:17 +02:00
|
|
|
try:
|
|
|
|
func = getattr(self, 'handle_'+command.lower())
|
|
|
|
except AttributeError: # unhandled command
|
|
|
|
pass
|
|
|
|
else:
|
|
|
|
parsed_args = func(idsource, command, args)
|
|
|
|
if parsed_args is not None:
|
|
|
|
return [idsource, command, parsed_args]
|
|
|
|
|
2016-07-18 00:20:57 +02:00
|
|
|
def handle_001(self, source, command, args):
|
|
|
|
"""
|
|
|
|
Handles 001 / RPL_WELCOME.
|
|
|
|
"""
|
|
|
|
# enumerate our uplink
|
|
|
|
self.irc.uplink = source
|
|
|
|
|
2016-07-17 07:42:17 +02:00
|
|
|
def handle_005(self, source, command, args):
|
|
|
|
"""
|
|
|
|
Handles 005 / RPL_ISUPPORT.
|
|
|
|
"""
|
2016-07-21 08:48:18 +02:00
|
|
|
self.caps.update(self.parseCapabilities(args[1:-1]))
|
|
|
|
log.debug('(%s) handle_005: self.caps is %s', self.irc.name, self.caps)
|
|
|
|
|
|
|
|
if 'CHANMODES' in self.caps:
|
|
|
|
self.irc.cmodes['*A'], self.irc.cmodes['*B'], self.irc.cmodes['*C'], self.irc.cmodes['*D'] = \
|
|
|
|
self.caps['CHANMODES'].split(',')
|
|
|
|
log.debug('(%s) handle_005: cmodes: %s', self.irc.name, self.irc.cmodes)
|
|
|
|
|
|
|
|
if 'USERMODES' in self.caps:
|
|
|
|
self.irc.umodes['*A'], self.irc.umodes['*B'], self.irc.umodes['*C'], self.irc.umodes['*D'] = \
|
|
|
|
self.caps['USERMODES'].split(',')
|
|
|
|
log.debug('(%s) handle_005: umodes: %s', self.irc.name, self.irc.umodes)
|
|
|
|
|
|
|
|
self.casemapping = self.caps.get('CASEMAPPING', self.casemapping)
|
|
|
|
log.debug('(%s) handle_005: casemapping set to %s', self.irc.name, self.casemapping)
|
|
|
|
|
|
|
|
if 'PREFIX' in self.caps:
|
|
|
|
self.irc.prefixmodes = self.parsePrefixes(self.caps['PREFIX'])
|
|
|
|
log.debug('(%s) handle_005: prefix modes set to %s', self.irc.name, self.irc.prefixmodes)
|
|
|
|
|
2016-07-18 00:20:57 +02:00
|
|
|
if not self.irc.connected.is_set():
|
|
|
|
self.irc.connected.set()
|
2016-07-18 08:10:10 +02:00
|
|
|
|
|
|
|
# Run autoperform commands.
|
|
|
|
for line in self.irc.serverdata.get("autoperform", []):
|
|
|
|
self.irc.send(line)
|
|
|
|
|
2016-07-18 00:20:57 +02:00
|
|
|
return {'parse_as': 'ENDBURST'}
|
2016-07-17 07:42:17 +02:00
|
|
|
|
2016-07-18 06:52:06 +02:00
|
|
|
def handle_353(self, source, command, args):
|
|
|
|
"""
|
|
|
|
Handles 353 / RPL_NAMREPLY.
|
|
|
|
"""
|
|
|
|
# <- :charybdis.midnight.vpn 353 ice = #test :ice @GL
|
|
|
|
|
|
|
|
# Mark "@"-type channels as secret automatically, per RFC2812.
|
|
|
|
channel = self.irc.toLower(args[2])
|
|
|
|
if args[1] == '@':
|
|
|
|
self.irc.applyModes(channel, [('+s', None)])
|
|
|
|
|
|
|
|
names = set()
|
2016-07-22 03:37:50 +02:00
|
|
|
modes = set()
|
|
|
|
prefix_to_mode = {v:k for k, v in self.irc.prefixmodes.items()}
|
|
|
|
prefixes = ''.join(self.irc.prefixmodes.values())
|
|
|
|
|
2016-07-18 06:52:06 +02:00
|
|
|
for name in args[-1].split():
|
2016-07-22 03:37:50 +02:00
|
|
|
nick = name.lstrip(prefixes)
|
2016-07-18 06:52:06 +02:00
|
|
|
|
|
|
|
# Get the PUID for the given nick. If one doesn't exist, spawn
|
|
|
|
# a new virtual user. TODO: wait for WHO responses for each nick before
|
|
|
|
# spawning in order to get a real ident/host.
|
2016-07-22 03:37:50 +02:00
|
|
|
idsource = self.irc.nickToUid(nick) or self.spawnClient(nick, server=self.irc.uplink).uid
|
2016-07-18 06:52:06 +02:00
|
|
|
|
|
|
|
# Queue these virtual users to be joined if they're not already in the channel.
|
|
|
|
if idsource not in self.irc.channels[channel].users:
|
|
|
|
names.add(idsource)
|
|
|
|
self.irc.users[idsource].channels.add(channel)
|
|
|
|
|
2016-07-22 03:37:50 +02:00
|
|
|
# Process prefix modes
|
|
|
|
for char in name:
|
|
|
|
if char in self.irc.prefixmodes.values():
|
|
|
|
modes.add(('+' + prefix_to_mode[char], idsource))
|
|
|
|
else:
|
|
|
|
break
|
|
|
|
|
2016-07-18 06:52:06 +02:00
|
|
|
# Statekeeping: make sure the channel's user list is updated!
|
|
|
|
self.irc.channels[channel].users |= names
|
2016-07-22 03:37:50 +02:00
|
|
|
self.irc.applyModes(channel, modes)
|
2016-07-18 06:52:06 +02:00
|
|
|
|
|
|
|
log.debug('(%s) handle_353: adding users %s to %s', self.irc.name, names, channel)
|
2016-07-22 03:37:50 +02:00
|
|
|
log.debug('(%s) handle_353: adding modes %s to %s', self.irc.name, modes, channel)
|
2016-07-18 06:52:06 +02:00
|
|
|
|
2016-07-22 09:22:56 +02:00
|
|
|
# We send the hook for JOIN after /who data is received, to enumerate the ident, host, and
|
|
|
|
# real names of users.
|
|
|
|
|
|
|
|
def handle_352(self, source, command, args):
|
|
|
|
"""
|
|
|
|
Handles 352 / RPL_WHOREPLY.
|
|
|
|
"""
|
|
|
|
# parameter count: 0 1 2 3 4 5 6 7
|
|
|
|
# <- :charybdis.midnight.vpn 352 ice #test ~pylink 127.0.0.1 charybdis.midnight.vpn ice H+ :0 PyLink
|
|
|
|
# <- :charybdis.midnight.vpn 352 ice #test ~gl 127.0.0.1 charybdis.midnight.vpn GL H*@ :0 realname
|
|
|
|
ident = args[2]
|
|
|
|
host = args[3]
|
|
|
|
nick = args[5]
|
|
|
|
status = args[6]
|
|
|
|
# Hopcount and realname field are together. We only care about the latter.
|
|
|
|
realname = args[-1].split(' ', 1)[-1]
|
|
|
|
uid = self.irc.nickToUid(nick)
|
|
|
|
|
|
|
|
self.updateClient(uid, 'IDENT', ident)
|
|
|
|
self.updateClient(uid, 'HOST', host)
|
|
|
|
self.updateClient(uid, 'GECOS', realname)
|
|
|
|
|
|
|
|
# The status given uses the following letters: <H|G>[*][@|+]
|
|
|
|
# H means here (not marked /away)
|
|
|
|
# G means away is set (we'll have to fake a message because it's not given)
|
|
|
|
# * means IRCop.
|
|
|
|
# The rest are prefix modes. Multiple can be given by the IRCd if multiple are set
|
|
|
|
if status[0] == 'G':
|
|
|
|
self.away(uid, 'Away')
|
|
|
|
elif status[0] == 'H':
|
|
|
|
self.away(uid, '') # Unmark away status
|
|
|
|
|
|
|
|
if '*' in status: # Track IRCop status
|
|
|
|
self.irc.callHooks([uid, 'CLIENT_OPERED', {'text': 'IRC Operator'}])
|
|
|
|
#else: # TODO: track de-opers as well
|
|
|
|
|
|
|
|
self.who_received.add(uid)
|
|
|
|
|
|
|
|
def handle_315(self, source, command, args):
|
|
|
|
"""
|
|
|
|
Handles 315 / RPL_ENDOFWHO.
|
|
|
|
"""
|
|
|
|
# <- :charybdis.midnight.vpn 315 ice #test :End of /WHO list.
|
|
|
|
# Join all the users in which the last batch of /who requests were received.
|
|
|
|
users = self.who_received.copy()
|
|
|
|
self.who_received.clear()
|
|
|
|
|
|
|
|
channel = self.irc.toLower(args[1])
|
|
|
|
|
|
|
|
return {'channel': channel, 'users': users, 'modes': self.irc.channels[channel].modes,
|
2016-07-18 06:52:06 +02:00
|
|
|
'parse_as': "JOIN"}
|
|
|
|
|
|
|
|
def handle_join(self, source, command, args):
|
|
|
|
"""
|
|
|
|
Handles incoming JOINs.
|
|
|
|
"""
|
|
|
|
# <- :GL|!~GL@127.0.0.1 JOIN #whatever
|
|
|
|
channel = self.irc.toLower(args[0])
|
|
|
|
self.join(source, channel)
|
|
|
|
|
|
|
|
return {'channel': channel, 'users': [source], 'modes': self.irc.channels[channel].modes}
|
|
|
|
|
2016-07-18 07:34:26 +02:00
|
|
|
def handle_kick(self, source, command, args):
|
|
|
|
"""
|
|
|
|
Handles incoming KICKs.
|
|
|
|
"""
|
|
|
|
# <- :GL!~gl@127.0.0.1 KICK #whatever GL| :xd
|
|
|
|
channel = self.irc.toLower(args[0])
|
|
|
|
target = self.irc.nickToUid(args[1])
|
|
|
|
|
|
|
|
try:
|
|
|
|
reason = args[2]
|
|
|
|
except IndexError:
|
|
|
|
reason = ''
|
|
|
|
|
|
|
|
self.part(target, channel, reason)
|
|
|
|
return {'channel': channel, 'target': target, 'text': reason}
|
|
|
|
|
2016-07-22 04:12:05 +02:00
|
|
|
def handle_mode(self, source, command, args):
|
|
|
|
"""Handles MODE changes."""
|
|
|
|
# <- :GL!~gl@127.0.0.1 MODE #dev +v ice
|
|
|
|
# <- :ice MODE ice :+Zi
|
|
|
|
target = args[0]
|
|
|
|
if utils.isChannel(target):
|
|
|
|
target = self.irc.toLower(target)
|
|
|
|
oldobj = self.irc.channels[target].deepcopy()
|
|
|
|
else:
|
|
|
|
target = self.irc.nickToUid(target)
|
|
|
|
oldobj = None
|
|
|
|
modes = args[1:]
|
|
|
|
changedmodes = self.irc.parseModes(target, modes)
|
|
|
|
self.irc.applyModes(target, changedmodes)
|
|
|
|
|
|
|
|
return {'target': target, 'modes': changedmodes, 'oldchan': oldobj}
|
|
|
|
|
2016-07-18 07:34:26 +02:00
|
|
|
def handle_nick(self, source, command, args):
|
2016-07-22 04:12:05 +02:00
|
|
|
"""Handles NICK changes."""
|
2016-07-18 07:34:26 +02:00
|
|
|
# <- :GL|!~GL@127.0.0.1 NICK :GL_
|
|
|
|
oldnick = self.irc.users[source].nick
|
|
|
|
self.nick(source, args[0])
|
|
|
|
return {'newnick': args[0], 'oldnick': oldnick}
|
|
|
|
|
2016-07-18 06:52:06 +02:00
|
|
|
def handle_part(self, source, command, args):
|
|
|
|
"""
|
|
|
|
Handles incoming PARTs.
|
|
|
|
"""
|
|
|
|
# <- :GL|!~GL@127.0.0.1 PART #whatever
|
|
|
|
channels = list(map(self.irc.toLower, args[0].split(',')))
|
|
|
|
try:
|
|
|
|
reason = args[1]
|
|
|
|
except IndexError:
|
|
|
|
reason = ''
|
|
|
|
|
|
|
|
for channel in channels:
|
|
|
|
self.part(source, channel, reason)
|
|
|
|
|
|
|
|
return {'channels': channels, 'text': reason}
|
|
|
|
|
2016-07-18 05:20:49 +02:00
|
|
|
def handle_ping(self, source, command, args):
|
|
|
|
"""
|
|
|
|
Handles incoming PING requests.
|
|
|
|
"""
|
|
|
|
self.irc.send('PONG :%s' % args[0])
|
|
|
|
|
|
|
|
def handle_pong(self, source, command, args):
|
|
|
|
"""
|
|
|
|
Handles incoming PONG.
|
|
|
|
"""
|
|
|
|
if source == self.irc.uplink:
|
|
|
|
self.irc.lastping = time.time()
|
|
|
|
|
2016-07-18 05:59:42 +02:00
|
|
|
def handle_privmsg(self, source, command, args):
|
|
|
|
"""Handles incoming PRIVMSG/NOTICE."""
|
|
|
|
# <- :sender PRIVMSG #dev :afasfsa
|
|
|
|
# <- :sender NOTICE somenick :afasfsa
|
|
|
|
target = args[0]
|
|
|
|
|
|
|
|
# We use lowercase channels internally.
|
|
|
|
if utils.isChannel(target):
|
|
|
|
target = self.irc.toLower(target)
|
|
|
|
else:
|
|
|
|
target = self._getUid(target)
|
|
|
|
return {'target': target, 'text': args[1]}
|
|
|
|
|
2016-07-18 06:52:06 +02:00
|
|
|
def handle_quit(self, source, command, args):
|
|
|
|
"""Handles incoming QUITs."""
|
|
|
|
self.quit(source, args[0])
|
|
|
|
return {'text': args[0]}
|
|
|
|
|
2016-07-18 05:59:42 +02:00
|
|
|
handle_notice = handle_privmsg
|
2016-07-18 05:20:49 +02:00
|
|
|
|
2016-07-17 07:42:17 +02:00
|
|
|
Class = ClientbotWrapperProtocol
|