Esempio n. 1
0
    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)
Esempio n. 2
0
 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))
Esempio n. 3
0
 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))
Esempio n. 4
0
 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))
Esempio n. 5
0
    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'])
Esempio n. 6
0
 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,
     })
Esempio n. 7
0
 def record_action(self, event):
     """Record the receipt of a new action.
     """
     self.record(event,
                 nick(event['user']),
                 event['channel'],
                 'action',
                 event['message'])
Esempio n. 8
0
    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)
Esempio n. 9
0
    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)))
Esempio n. 10
0
    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'])
Esempio n. 11
0
    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']))
Esempio n. 12
0
    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))
Esempio n. 13
0
    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'])
Esempio n. 14
0
    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))
Esempio n. 15
0
    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'])
Esempio n. 16
0
    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,
            })
Esempio n. 17
0
 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'])]
Esempio n. 18
0
 def _channel_joined(self, e):
     user = self._users[nick(e['user'])]
     user['channels'].add(e['channel'])
Esempio n. 19
0
 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'))
Esempio n. 20
0
 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']))
Esempio n. 21
0
 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'])]
Esempio n. 22
0
 def _channel_joined(self, e):
     user = self._users[nick(e["user"])]
     user["channels"].add(e["channel"])
Esempio n. 23
0
 def unset(self, e):
     self.whois_unset(nick(e['user']), channel=e['channel'])
Esempio n. 24
0
 def setdefault(self, e):
     self.whois_set(nick(e['user']), e['data'], channel=None)
Esempio n. 25
0
 def _user_identified(self, e):
     user = self._users[nick(e["user"])]
     user["account"] = e["account"]
Esempio n. 26
0
 def _user_quit(self, e):
     # User is gone, remove record
     del self._users[nick(e['user'])]
Esempio n. 27
0
 def _user_identified(self, e):
     user = self._users[nick(e['user'])]
     user['account'] = e['account']
Esempio n. 28
0
 def _user_identified(self, e):
     user = self._users[nick(e['user'])]
     user['account'] = e['account']
Esempio n. 29
0
 def _user_quit(self, e):
     # User is gone, remove record
     del self._users[nick(e['user'])]
Esempio n. 30
0
 def notice(self, event):
     self.pretty_log.info('[{channel}] -{nick}- {message}'.format(
         channel=event['channel'],
         nick=nick(event['user']),
         message=event['message']))
Esempio n. 31
0
 def action(self, event):
     self.pretty_log.info('[{channel}] * {nick} {message}'.format(
         channel=event['channel'],
         nick=nick(event['user']),
         message=event['message']))
Esempio n. 32
0
 def _channel_joined(self, e):
     user = self._users[nick(e['user'])]
     user['channels'].add(e['channel'])
Esempio n. 33
0
 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'])
Esempio n. 34
0
 def record_action(self, event):
     """Record the receipt of a new action.
     """
     self.record(event, nick(event['user']), event['channel'], 'action',
                 event['message'])
Esempio n. 35
0
 def unsetdefault(self, e):
     self.whois_unset(nick(e['user']))
Esempio n. 36
0
 def privmsg(self, event):
     self.pretty_log.info('[{channel}] <{nick}> {message}'.format(
         channel=event['channel'],
         nick=nick(event['user']),
         message=event['message']))