def reply(self, msg, is_verbose=False): """Send a reply message. All plugin responses should be via this method. The :attr:`user` is addressed by name if the response is in a channel rather than a private chat. If *is_verbose* is True, the reply is suppressed unless the bot was addressed directly, i.e. in private chat or by name in a channel. """ if self.channel == self.protocol.nickname: self.protocol.msg(nick(self.user), msg) elif self.direct or not is_verbose: self.protocol.msg(self.channel, nick(self.user) + ': ' + msg)
def account_command(self, e): nick_ = e["data"] or nick(e["user"]) account = self.get_user(nick_)["account"] if account is None: e.protocol.msg(e["reply_to"], "{} is not authenticated".format(nick_)) else: e.protocol.msg(e["reply_to"], "{} is authenticated as {}".format(nick_, account))
def account_command(self, e): nick_ = e['data'] or nick(e['user']) account = self.get_user(nick_)['account'] if account is None: e.reply('{} is not authenticated'.format(nick_)) else: e.reply('{} is authenticated as {}'.format(nick_, account))
def record_command(self, event): """Record the receipt of a new command. """ if not event['message'].startswith(self.bot.config.command_prefix): return self.record(event, nick(event['user']), event['channel'], 'command', event['message'])
def action(self, user, channel, message): self.emit_new('core.message.action', { 'channel': channel, 'user': user, 'message': message, 'is_private': channel == self.nickname, 'reply_to': nick(user) if channel == self.nickname else channel, })
def record_action(self, event): """Record the receipt of a new action. """ self.record(event, nick(event['user']), event['channel'], 'action', event['message'])
def set(self, e): """Allow a user to associate data with themselves for this channel.""" ident = self.identify_user(nick(e['user']), e['channel']) self.whoisdb.remove(ident) ident['data'] = e['data'] self.whoisdb.insert(ident)
def whois(self, e): """Look up a user by nick, and return what data they have set for themselves (or an error message if there is no data)""" nick_ = e['data'] or nick(e['user']) res = self.whois_lookup(nick_, e['channel']) if res is None: e.reply('No data for {}'.format(nick_)) else: e.reply('{}: {}'.format(nick_, str(res)))
def record_command(self, event): """Record the receipt of a new command. """ if not event['message'].startswith(self.bot.config_get('command_prefix')): return self.record(event, nick(event['user']), event['channel'], 'command', event['message'])
def whois(self, e): """Look up a user by nick, and return what data they have set for themselves (or an error message if there is no data)""" nick_ = e['data'] or nick(e['user']) ident = self.identify_user(nick_, e['channel']) user = self.whoisdb.find_one(ident) if user is None: e.protocol.msg(e['reply_to'], 'No data for {}'.format(nick_)) else: e.protocol.msg(e['reply_to'], '{}: {}'.format(nick_, user['data']))
def tell_command(self, event): """ Stores a message for a user to be delivered when the user is next in the channel. Usage:: !tell <user> <message> Example:: > TestUser [13:37] | !tell Haegin You are awesome. > Bot [13:37] | TestUser, I'll let Haegin know. If Haegin is already in the channel the bot should let the user know. :: > Bot [13:37] | TestUser, Haegin is here, you can tell them > | yourself! When Haegin next connects to the channel the bot will send him a message of the following form:: > Haegin, "You are awesome." - TestUser (at 13:37) TODO: - It should be possible to leave a long message (how long is long?). - Long messages should be announced in the channel but sent as a PM - Implement a private message feature that won't be announced in the channel - We need to handle messages which are just long enough to fit in one message when saved but too long when the citation and time is added. """ print(event.data) to_user = event.data[0] message = " ".join(event.data[1:]) from_user = nick(event.user) # TODO: this should probably do some i18n but being as the channel is # largely in the UK... time = event.datetime if (self.bot.get_plugin("users.Users").is_online(to_user)): event.reply( "{} is here, you can tell them yourself.".format(to_user)) else: msg = { 'message': message, 'from': from_user, 'to': to_user, 'time': time } self.db.messages.insert(msg) event.reply("{}, I'll let {} know.".format(from_user, to_user))
def record_message(self, event): """Record the receipt of a new message. """ # Check if this is an action if event['message'].startswith('\x01ACTION'): return # Check if this is a command if event['message'].startswith(self.bot.config.command_prefix): return self.record(event, nick(event['user']), event['channel'], 'message', event['message'])
def tell_command(self, event): """ Stores a message for a user to be delivered when the user is next in the channel. Usage:: !tell <user> <message> Example:: > TestUser [13:37] | !tell Haegin You are awesome. > Bot [13:37] | TestUser, I'll let Haegin know. If Haegin is already in the channel the bot should let the user know. :: > Bot [13:37] | TestUser, Haegin is here, you can tell them > | yourself! When Haegin next connects to the channel the bot will send him a message of the following form:: > Haegin, "You are awesome." - TestUser (at 13:37) TODO: - It should be possible to leave a long message (how long is long?). - Long messages should be announced in the channel but sent as a PM - Implement a private message feature that won't be announced in the channel - We need to handle messages which are just long enough to fit in one message when saved but too long when the citation and time is added. """ print(event.data) to_user = event.data[0] message = " ".join(event.data[1:]) from_user = nick(event.user) # TODO: this should probably do some i18n but being as the channel is # largely in the UK... time = event.datetime if (self.bot.get_plugin("users.Users").is_online(to_user)): event.reply("{} is here, you can tell them yourself." .format(to_user)) else: msg = {'message': message, 'from': from_user, 'to': to_user, 'time': time} self.db.messages.insert(msg) event.reply("{}, I'll let {} know.".format(from_user, to_user))
def record_message(self, event): """Record the receipt of a new message. """ # Check if this is an action if event['message'].startswith('\x01ACTION'): return # Check if this is a command if event['message'].startswith(self.bot.config_get('command_prefix')): return self.record(event, nick(event['user']), event['channel'], 'message', event['message'])
def irc_JOIN(self, prefix, params): """Re-implement ``JOIN`` handler to account for ``extended-join`` info. """ user = prefix nick_ = nick(user) channel, account, _ = params if nick_ == self.nickname: self.joined(channel) else: self.emit_new('core.user.identified', { 'user': user, 'account': None if account == '*' else account, }) self.emit_new('core.channel.joined', { 'channel': channel, 'user': user, })
def _channel_left(self, e): user = self._users[nick(e['user'])] user['channels'].discard(e['channel']) # Lost sight of the user, can't reliably track them any more if len(user['channels']) == 0: del self._users[nick(e['user'])]
def _channel_joined(self, e): user = self._users[nick(e['user'])] user['channels'].add(e['channel'])
def action(self, event): print '[{timestamp}][{event.channel}] * {nick} {event.message}'.format( event=event, nick=nick(event.user), timestamp=event.datetime.strftime('%Y/%m/%d %H:%M'))
def command(self, event): self.pretty_log.info( 'Command {command} fired by {nick} in channel {channel}'.format( command=(event['command'], event['data']), nick=nick(event['user']), channel=event['channel']))
def _channel_joined(self, e): user = self._users[nick(e["user"])] user["channels"].add(e["channel"])
def unset(self, e): self.whois_unset(nick(e['user']), channel=e['channel'])
def setdefault(self, e): self.whois_set(nick(e['user']), e['data'], channel=None)
def _user_identified(self, e): user = self._users[nick(e["user"])] user["account"] = e["account"]
def _user_quit(self, e): # User is gone, remove record del self._users[nick(e['user'])]
def _user_identified(self, e): user = self._users[nick(e['user'])] user['account'] = e['account']
def notice(self, event): self.pretty_log.info('[{channel}] -{nick}- {message}'.format( channel=event['channel'], nick=nick(event['user']), message=event['message']))
def action(self, event): self.pretty_log.info('[{channel}] * {nick} {message}'.format( channel=event['channel'], nick=nick(event['user']), message=event['message']))
def set(self, e): """Allow a user to associate data with themselves for this channel.""" self.whois_set(nick(e['user']), e['data'], channel=e['channel'])
def unsetdefault(self, e): self.whois_unset(nick(e['user']))
def privmsg(self, event): self.pretty_log.info('[{channel}] <{nick}> {message}'.format( channel=event['channel'], nick=nick(event['user']), message=event['message']))