예제 #1
0
파일: __init__.py 프로젝트: meskio/emma
 def trigger_history(self, cmd, param=''):
     event = Event(event="history", interface="irc",
                   identifier=self.conf['irc_id'])
     if cmd in ('start', 'stop'):
         trigger(event, (cmd, param))
     else:
         return run_event(event, (cmd, param))[0]
예제 #2
0
파일: __init__.py 프로젝트: meskio/emma
    def wikistore(self, channel):
        if not 'session' in self._[channel]:
            return
        if not 'wiki_id' in self.conf:
            return

        session = self._[channel]['session']
        self.trigger_history('stop')
        self.log(_("Store irc log on the wiki page %s") % session)

        history = self.trigger_history('get', session)
        today = time.gmtime()
        text = _("Assembly log from %(day)s/%(month)s/%(year)s\n\n") \
                 % {'day': today.tm_mday, 'month': today.tm_mon,
                    'year': today.tm_year}
        text += _("Present: ")
        text += ', '.join(set([msg['From'] for msg in history]))

        text += "\n\n<pre>\n"
        for msg in history:
            if msg['To'] != channel:
                continue
            if msg['Type'] == "ctcp":
                text += "[%s]  * %s %s\n" % (msg['Date'].strftime("%H:%M"),
                                             msg['From'], msg['Body'])
            else:
                text += "[%s] < %s> %s\n" % (msg['Date'].strftime("%H:%M"),
                                             msg['From'], msg['Body'])
        text += "</pre>"

        event = Event(event="write", interface="mediawiki",
                      identifier=self.conf['wiki_id'])
        trigger(event, (session, text))
예제 #3
0
    def wikistore(self, channel):
        if not 'session' in self._[channel]:
            return
        if not 'wiki_id' in self.conf:
            return

        session = self._[channel]['session']
        self.trigger_history('stop')
        self.log(_("Store irc log on the wiki page %s") % session)

        history = self.trigger_history('get', session)
        today = time.gmtime()
        text = _("Assembly log from %(day)s/%(month)s/%(year)s\n\n") \
                 % {'day': today.tm_mday, 'month': today.tm_mon,
                    'year': today.tm_year}
        text += _("Present: ")
        text += ', '.join(set([msg['From'] for msg in history]))

        text += "\n\n<pre>\n"
        for msg in history:
            if msg['To'] != channel:
                continue
            if msg['Type'] == "ctcp":
                text += "[%s]  * %s %s\n" % (msg['Date'].strftime("%H:%M"),
                                             msg['From'], msg['Body'])
            else:
                text += "[%s] < %s> %s\n" % (msg['Date'].strftime("%H:%M"),
                                             msg['From'], msg['Body'])
        text += "</pre>"

        event = Event(event="write",
                      interface="mediawiki",
                      identifier=self.conf['wiki_id'])
        trigger(event, (session, text))
예제 #4
0
    def cmd_handler(self, event, data):
        cmd, args = data[0]
        # Accept also untranslated help, at least this command should work
        # always :-)
        if cmd not in ('help', _('help')):
            return

        # Gather help messages from modules
        event.event = 'help'
        help_strs = set(run_event(event, args))
        help_strs -= set([""])
        if help_strs:
            if not args:
                body = _("emma is a bot for virtual assembly\n" \
                         "==================================\n" \
                         "Commands:\n")
            else:
                body = ""
            body += '\n'.join(help_strs)
        else:
            body = _("No help")

        event.event = 'send'
        to = data[1]['From']
        if event.interface == 'irc' and data[1]['To'][0] == '#':
            to = data[1]['To']
        msg = Message(body, to)
        msg['Subject'] = _("help")
        trigger(event, msg)
예제 #5
0
 def trigger_history(self, cmd, param=''):
     event = Event(event="history",
                   interface="irc",
                   identifier=self.conf['irc_id'])
     if cmd in ('start', 'stop'):
         trigger(event, (cmd, param))
     else:
         return run_event(event, (cmd, param))[0]
예제 #6
0
파일: __init__.py 프로젝트: meskio/emma
 def cmd_handler(self, event, data):
     cmd, args = data[0]
     page, text = args.split("\n", 1)
     page = page.strip()
     event_write = Event(event='write', interface='mediawiki',
                         identifier=self.conf['wiki_id'])
     self.log(_("Store '%(page)s' page on the '%(wiki)s' wiki") %
              {'page':page, 'wiki':self.conf['wiki_id']})
     trigger(event_write, (page, text))
예제 #7
0
파일: xmppclient.py 프로젝트: meskio/emma
    def _trigger_cmd(self, msg):
        s = msg['Body'].split(" ", 1)
        if len(s) == 2:
            cmd, args = s
        else:
            cmd = s[0]
            args = ""

        logging.info(_("[xmpp %(identifier)s] command received: %(cmd)s: " \
                       "%(args)s") % {'identifier': self.identifier,
                                      'cmd': cmd, 'args': args})
        cmd_event = Event(event='command', interface='xmpp', \
                          identifier=self.identifier)
        trigger(cmd_event, ((cmd, args), msg))
예제 #8
0
    def _trigger_cmd(self, args, msg):
        s = args.split(" ", 1)
        if len(s) == 2:
            cmd, args = s
        else:
            cmd = s[0]
            args = ""

        logging.info(_("[irc %(identifier)s] command received: %(cmd)s: " \
                       "%(args)s") % {'identifier': self.identifier,
                                      'cmd': cmd, 'args': args})
        cmd_event = Event(event='command', interface='irc', \
                          identifier=self.identifier)
        trigger(cmd_event, ((cmd, args), msg))
예제 #9
0
    def fetch(self):
        """
        Fetch email

        Will be run periodically fetching the email from a POP3 server.
        """
        if 'pop_user' in self.conf:
            user = self.conf['pop_user']
            passwd = self.conf['pop_pass']
        elif 'user' in self.conf:
            user = self.conf['user']
            passwd = self.conf['pass']
        else:
            self.log(_("No user defined for pop"), logging.ERROR)
            return

        self.log(
            _("fetching email %(user)s@%(host)s") % {
                'user': user,
                'host': self.conf['pop_host']
            })
        try:
            if 'pop_ssl' in self.conf and self.conf['pop_ssl'] == "yes":
                pop = poplib.POP3_SSL(self.conf['pop_host'])
            else:
                pop = poplib.POP3(self.conf['pop_host'])
            pop.user(user)
            pop.pass_(passwd)
        except:
            self.log(_("    error connecting by POP3"), logging.ERROR)
            return

        recv_event = Event(event='receive', interface='email', \
                           identifier=self.identifier)
        cmd_event = Event(event='command', interface='email', \
                          identifier=self.identifier)
        numMessages = len(pop.list()[1])
        for i in range(numMessages):
            message = Message(pop.retr(i + 1)[1])
            trigger(recv_event, message)
            for command in message.commands():
                trigger(cmd_event, (command, message))
            if self.conf['store'] == "yes":
                self.store(message)
            pop.dele(i + 1)

        pop.quit()
        self.log(_("    %s found") % numMessages)
예제 #10
0
파일: __init__.py 프로젝트: meskio/emma
    def issue(self, event, data):
        cmd, args = data[0]
        if event.interface == "email":
            group, text = args.split("\n", 1)
        else:
            group, text = args.split(" ", 1)
        self.db.insert({"group": group, "text": text})

        # Reply ack
        to = data[1]['From']
        if event.interface == 'irc' and data[1]['To'][0] == '#':
            to = data[1]['To']
        msg = Message(_("issue accepted"), to)
        event = Event(event="send", interface=event.interface,
                      identifier=event.identifier)
        trigger(event, msg)
        self.log(_("Issue accepted (%s, %s)") % (group, text))
예제 #11
0
파일: __init__.py 프로젝트: meskio/emma
    def fetch(self):
        """
        Fetch email

        Will be run periodically fetching the email from a POP3 server.
        """
        if 'pop_user' in self.conf:
            user = self.conf['pop_user']
            passwd = self.conf['pop_pass']
        elif 'user' in self.conf:
            user = self.conf['user']
            passwd = self.conf['pass']
        else:
            self.log(_("No user defined for pop"), logging.ERROR)
            return

        self.log(_("fetching email %(user)s@%(host)s")
                    % {'user': user, 'host': self.conf['pop_host']})
        try:
            if 'pop_ssl' in self.conf and self.conf['pop_ssl'] == "yes":
                pop = poplib.POP3_SSL(self.conf['pop_host'])
            else:
                pop = poplib.POP3(self.conf['pop_host'])
            pop.user(user)
            pop.pass_(passwd)
        except:
            self.log(_("    error connecting by POP3"), logging.ERROR)
            return

        recv_event = Event(event='receive', interface='email', \
                           identifier=self.identifier)
        cmd_event = Event(event='command', interface='email', \
                          identifier=self.identifier)
        numMessages = len(pop.list()[1])
        for i in range(numMessages):
            message = Message(pop.retr(i + 1)[1])
            trigger(recv_event, message)
            for command in message.commands():
                trigger(cmd_event, (command, message))
            if self.conf['store'] == "yes":
                self.store(message)
            pop.dele(i + 1)

        pop.quit()
        self.log(_("    %s found") % numMessages)
예제 #12
0
    def issue(self, event, data):
        cmd, args = data[0]
        if event.interface == "email":
            group, text = args.split("\n", 1)
        else:
            group, text = args.split(" ", 1)
        self.db.insert({"group": group, "text": text})

        # Reply ack
        to = data[1]['From']
        if event.interface == 'irc' and data[1]['To'][0] == '#':
            to = data[1]['To']
        msg = Message(_("issue accepted"), to)
        event = Event(event="send",
                      interface=event.interface,
                      identifier=event.identifier)
        trigger(event, msg)
        self.log(_("Issue accepted (%s, %s)") % (group, text))
예제 #13
0
파일: __init__.py 프로젝트: meskio/emma
 def send_ctcp(self, txt, channel):
     msg = Message(txt, channel, tpe="ctcp")
     event = Event(event="send", interface="irc",
                   identifier=self.conf['irc_id'])
     trigger(event, msg)
예제 #14
0
파일: xmppclient.py 프로젝트: meskio/emma
 def _trigger_rcv(self, msg):
     recv_event = Event(event='receive', interface='xmpp', \
                        identifier=self.identifier)
     trigger(recv_event, msg)
예제 #15
0
 def _trigger_rcv(self, msg):
     recv_event = Event(event='receive', interface='irc', \
                        identifier=self.identifier)
     trigger(recv_event, msg)
예제 #16
0
 def send_ctcp(self, txt, channel):
     msg = Message(txt, channel, tpe="ctcp")
     event = Event(event="send",
                   interface="irc",
                   identifier=self.conf['irc_id'])
     trigger(event, msg)