Exemple #1
0
 def _state_event(self, entity, state, realjid=None):
     event = Event(self.name, u'state')
     event.state = state
     if entity.userhost().lower() in self.rooms:
         nick = entity.full().split('/')[1]
         event.channel = entity.userhost()
         if nick == self.parent.nick:
             event.type = u'connection'
             event.status = state == u'online' and u'joined' or u'left'
         else:
             if realjid:
                 if state == u'online':
                     self.room_users[entity.full()] = realjid.full()
                 elif state == u'offline':
                     if entity.full() in self.room_users:
                         del self.room_users[entity.full()]
                 event.sender['connection'] = realjid.full()
                 event.sender['id'] = realjid.userhost()
             else:
                 event.sender['connection'] = entity.full()
                 event.sender['id'] = event.sender['connection']
             event.sender['nick'] = nick
             event.public = True
     else:
         event.sender['connection'] = entity.full()
         event.sender['id'] = event.sender['connection'].split('/')[0]
         event.sender['nick'] = event.sender['connection'].split('@')[0]
         event.channel = entity.full()
         event.public = False
     ibid.dispatcher.dispatch(event).addCallback(self.respond)
Exemple #2
0
    def _create_event(self, type, user, channel):
        event = Event(self.factory.name, type)
        event.sender['connection'] = unicode("%s@%s" % (user.username, user.hostname), 'utf-8', 'replace')
        event.sender['nick'] = unicode(user.nickname, 'utf-8', 'replace')
        event.sender['connection'] = self._to_hex(user.user_id)
        event.sender['id'] = self._to_hex(user.fingerprint)
        if channel:
            event.channel = unicode(channel.channel_name, 'utf-8', 'replace')
        else:
            event.channel = event.sender['connection']
        event.public = True

        self.users[event.sender['connection']] = user
        self.users[event.sender['id']] = user

        return event
Exemple #3
0
    def _create_event(self, type, user, channel):
        event = Event(self.factory.name, type)
        event.sender['connection'] = unicode(
            "%s@%s" % (user.username, user.hostname), 'utf-8', 'replace')
        event.sender['nick'] = unicode(user.nickname, 'utf-8', 'replace')
        event.sender['connection'] = self._to_hex(user.user_id)
        event.sender['id'] = self._to_hex(user.fingerprint)
        if channel:
            event.channel = unicode(channel.channel_name, 'utf-8', 'replace')
        else:
            event.channel = event.sender['connection']
        event.public = True

        self.users[event.sender['connection']] = user
        self.users[event.sender['id']] = user

        return event
Exemple #4
0
 def _create_event(self, type, user):
     event = Event(self.factory.name, type)
     event.sender['connection'] = user
     event.sender['id'] = user
     event.sender['nick'] = user
     event.channel = u'$public'
     event.public = True
     return event
Exemple #5
0
    def call_later(self, delay, callable, oldevent, *args, **kw):
        "Run callable after delay seconds. Pass args and kw to it"

        event = Event(oldevent.source, u'delayed')
        event.sender = oldevent.sender
        event.channel = oldevent.channel
        event.public = oldevent.public
        return reactor.callLater(delay, threads.deferToThread, self.delayed_call, callable, event, *args, **kw)
Exemple #6
0
    def call_later(self, delay, callable, oldevent, *args, **kw):
        "Run callable after delay seconds. Pass args and kw to it"

        event = Event(oldevent.source, u'delayed')
        event.sender = oldevent.sender
        event.channel = oldevent.channel
        event.public = oldevent.public
        return reactor.callLater(delay, threads.deferToThread, self.delayed_call, callable, event, *args, **kw)
Exemple #7
0
Fichier : dc.py Projet : vhata/ibid
 def _create_event(self, type, user):
     event = Event(self.factory.name, type)
     event.sender['connection'] = user
     event.sender['id'] = user
     event.sender['nick'] = user
     event.channel = u'$public'
     event.public = True
     return event
Exemple #8
0
 def _create_event(self, type, user, channel):
     nick = user.split('!', 1)[0]
     event = Event(self.factory.name, type)
     event.sender['connection'] = user
     event.sender['id'] = nick
     event.sender['nick'] = event.sender['id']
     event.channel = channel
     event.public = True
     return event
Exemple #9
0
 def _create_event(self, type, user, channel):
     nick = user.split('!', 1)[0]
     event = Event(self.factory.name, type)
     event.sender['connection'] = user
     event.sender['id'] = nick
     event.sender['nick'] = event.sender['id']
     event.channel = channel
     event.public = True
     return event
Exemple #10
0
    def onMessage(self, message):
        self.parent.log.debug(u"Received %s message from %s: %s", message['type'], message['from'], message.body)

        if message.x and message.x.defaultUri == 'jabber:x:delay':
            self.parent.log.debug(u"Ignoring delayed message")
            return

        if self.parent.accept_domains:
            if message['from'].split('/')[0].split('@')[1] not in self.parent.accept_domains:
                self.parent.log.info(u"Ignoring message because sender is not in accept_domains")
                return

        if message.body is None:
            self.parent.log.info(u'Ignoring empty message')
            return

        event = Event(self.parent.name, u'message')
        event.message = unicode(message.body)
        event.sender['connection'] = message['from']

        if message['type'] == 'groupchat':
            if message['from'] in self.room_users:
                event.sender['connection'] = self.room_users[message['from']]
                event.sender['id'] = event.sender['connection'].split('/')[0]
            else:
                event.sender['id'] = message['from']
            if event.sender['id'] == self.parent.nick:
                return
            if '/' in message['from']:
                event.sender['nick'] = message['from'].split('/')[1]
            else:
                event.sender['nick'] = message['from']
            event.channel = message['from'].split('/')[0]
            event.public = True
        else:
            event.sender['id'] = event.sender['connection'].split('/')[0]
            event.sender['nick'] = event.sender['connection'].split('@')[0]
            event.channel = event.sender['connection']
            event.public = False
            event.addressed = True

        ibid.dispatcher.dispatch(event).addCallback(self.respond)
Exemple #11
0
 def telnet_Query(self, line):
     event = Event(self.factory.name, u'message')
     event.message = unicode(line.strip(), 'utf-8', 'replace')
     event.sender['connection'] = self.user
     event.sender['id'] = self.user
     event.sender['nick'] = event.sender['connection']
     event.channel = event.sender['connection']
     event.addressed = True
     event.public = False
     self.factory.log.debug(u"Received message from %s: %s", self.user, event.message)
     ibid.dispatcher.dispatch(event).addCallback(self.respond)
     return 'Query'
Exemple #12
0
    def make_event(self, message=None, type=u"message"):
        event = Event(self.source, type)
        event.sender["id"] = event.sender["connection"] = event.sender["nick"] = self.username
        event.identity = self.identity.id
        event.account = None
        event.addressed = not self.public
        event.public = self.public
        event.channel = u"testchan"

        if message is not None:
            event.message = unicode(message)

        return event
Exemple #13
0
 def _create_event(self, type, user_id, user_name, room_id, room_name):
     event = Event(self.factory.name, type)
     if user_id is not None:
         # user_id is an int. simplejson may have returned a str() if
         # user_name and room_name don't contain non-ASCII chars.
         user_id = unicode(user_id)
         user_name = unicode(user_name)
         event.sender['connection'] = user_id
         event.sender['id'] = user_id
         event.sender['nick'] = user_name
     event.channel = unicode(room_name)
     event.public = True
     event.source = self.factory.name
     return event
Exemple #14
0
    def make_event(self, message=None, type=u'message'):
        event = Event(self.source, type)
        event.sender['id'] = event.sender['connection'] = \
            event.sender['nick'] = self.username
        event.identity = self.identity.id
        event.account = None
        event.addressed = not self.public
        event.public = self.public
        event.channel = u'testchan'

        if message is not None:
            event.message = unicode(message)

        return event
Exemple #15
0
 def _create_event(self, type, user_id, user_name, room_id, room_name):
     event = Event(self.factory.name, type)
     if user_id is not None:
         # user_id is an int. simplejson may have returned a str() if
         # user_name and room_name don't contain non-ASCII chars.
         user_id = unicode(user_id)
         user_name = unicode(user_name)
         event.sender['connection'] = user_id
         event.sender['id'] = user_id
         event.sender['nick'] = user_name
     event.channel = unicode(room_name)
     event.public = True
     event.source = self.factory.name
     return event
Exemple #16
0
    def make_event(self, message=None, type=u'message'):
        event = Event(self.source, type)
        event.sender['id'] = event.sender['connection'] = \
            event.sender['nick'] = self.username
        event.identity = self.identity.id
        event.account = None
        event.addressed = not self.public
        event.public = self.public
        event.channel = u'testchan'

        if message is not None:
            event.message = unicode(message)

        return event
Exemple #17
0
    def signedOn(self):
        names = ibid.config.plugins['core']['names']
        if self.my_nickname not in names:
            self.factory.log.info(u'Adding "%s" to plugins.core.names', self.my_nickname)
            names.append(self.my_nickname)
            ibid.config.plugins['core']['names'] = names
            ibid.reloader.reload_config()

        event = Event(self.factory.name, u'source')
        event.status = u'connected'
        ibid.dispatcher.dispatch(event)

        event = Event(self.factory.name, u'source')
        event.channel = u'$public'
        event.status = u'joined'
        ibid.dispatcher.dispatch(event)

        self.factory.log.info(u"Signed on")
Exemple #18
0
Fichier : dc.py Projet : vhata/ibid
    def signedOn(self):
        names = ibid.config.plugins['core']['names']
        if self.my_nickname not in names:
            self.factory.log.info(u'Adding "%s" to plugins.core.names',
                                  self.my_nickname)
            names.append(self.my_nickname)
            ibid.config.plugins['core']['names'] = names
            ibid.reloader.reload_config()

        event = Event(self.factory.name, u'source')
        event.status = u'connected'
        ibid.dispatcher.dispatch(event)

        event = Event(self.factory.name, u'source')
        event.channel = u'$public'
        event.status = u'joined'
        ibid.dispatcher.dispatch(event)

        self.factory.log.info(u"Signed on")
Exemple #19
0
    def log_handler(self, event):
        self.log_event(event)

        for response in event.responses:
            if 'reply' in response and isinstance(response['reply'], basestring):
                type = 'message'
                if response.get('action', False):
                    type = 'action'
                elif response.get('notice', False):
                    type = 'notice'
                e = Event(response['source'], type)
                e.source = response['source']
                e.channel = response['target']
                e.time = datetime.utcnow()
                e.sender = {
                    'id': ibid.config['botname'],
                    'connection': ibid.config['botname'],
                    'nick': ibid.config['botname'],
                }
                e.message = response['reply']
                self.log_event(e)
Exemple #20
0
    def log_handler(self, event):
        self.log_event(event)

        for response in event.responses:
            if 'reply' in response and isinstance(response['reply'], basestring):
                type = 'message'
                if response.get('action', False):
                    type = 'action'
                elif response.get('notice', False):
                    type = 'notice'
                e = Event(response['source'], type)
                e.source = response['source']
                e.channel = response['target']
                e.time = datetime.utcnow()
                e.sender = {
                    'id': ibid.config['botname'],
                    'connection': ibid.config['botname'],
                    'nick': ibid.config['botname'],
                }
                e.message = response['reply']
                self.log_event(e)
Exemple #21
0
 def left(self, channel):
     event = Event(self.factory.name, u'source')
     event.channel = channel
     event.status = u'left'
     ibid.dispatcher.dispatch(event)
Exemple #22
0
 def joined(self, channel):
     event = Event(self.factory.name, u'source')
     event.channel = unicode(channel, 'utf-8', 'replace')
     event.status = u'joined'
     ibid.dispatcher.dispatch(event)
Exemple #23
0
 def left(self, channel):
     event = Event(self.factory.name, u'source')
     event.channel = channel
     event.status = u'left'
     ibid.dispatcher.dispatch(event)
Exemple #24
0
 def joined(self, channel):
     event = Event(self.factory.name, u'source')
     event.channel = unicode(channel, 'utf-8', 'replace')
     event.status = u'joined'
     ibid.dispatcher.dispatch(event)