Пример #1
0
 def __init__(self):
     from connector.ircconnector import IRCConnector
     self.irc = IRCConnector(self.msgQueue)
     self.irc.setDaemon(True)
     self.irc.start()
Пример #2
0
    def run(self):
        from connector.ircconnector import IRCConnector
        self.irc = IRCConnector(self.msgQueue)
        self.irc.start()
        for c in setting.chan_list:
            self.irc.joinchan(' '.join(c).strip())
        while True:
            packet = self.msgQueue.get()
            if packet['type'] == 'msg':
                pass
            elif packet['type'] == 'irc':
                message = packet['content']
                if message.msgType == 'INVITE':
                    self.irc.joinchan(message.channel)
                elif message.msgType == 'PRIVMSG':
                    if message.sender.find(irc_name) == 0:
                        if message.msg.find('!트윗 ') == 0:
                            content = message.msg[4:] + self.footer
                            stat = tweet(content=content)
                            if stat == None: continue
                            tweet_url = "https://twitter.com/" + screen_name + "/status/" + stat.id_str
                            self.irc.sendmsg(message.channel, tweet_url)
                            self.last_id = stat.id_str
                            self.log.write(message.msg + '\n')
                            self.log.write(tweet_url + '\n')
                            print('send tweet:', tweet_url)
                            continue
                        elif message.msg.find('!연속 ') == 0:
                            content = message.msg[4:] + self.footer
                            stat = tweet(content=content,
                                         reply_id=self.last_id)
                            if stat == None: continue
                            tweet_url = "https://twitter.com/" + screen_name + "/status/" + stat.id_str
                            self.irc.sendmsg(message.channel, tweet_url)
                            self.last_id = stat.id_str
                            self.log.write(message.msg + '\n')
                            self.log.write(tweet_url + '\n')
                            print('send tweet:', tweet_url)
                            continue
                        elif message.msg.find('!연속잇기 ') == 0:
                            content = message.msg[len('!연속잇기 '):]
                            self.last_id = content
                            self.irc.sendmsg(message.channel, content)
                            print('connect change:', content)
                        elif message.msg.find('!꼬릿말 ') == 0:
                            content = message.msg[len('!꼬릿말 '):]
                            self.footer = content
                            self.irc.sendmsg(message.channel,
                                             "꼬릿말 변경: '" + content + "'")
                            print('footer change:', content)

                    tweet_urls = self.prog.findall(message.msg)
                    print(tweet_urls)
                    for tweet_url, _, tweet_id in tweet_urls:
                        try:
                            stat = api.get_status(tweet_id)
                            tweet_string = stat.user.name + "(@" + stat.user.screen_name + "): " + stat.text
                            tweet_string = tweet_string.replace('\n', '\\n')
                            self.irc.sendmsg(message.channel, tweet_string)
                            self.log.write(tweet_string + '\n')
                            print('get tweet:', tweet_string)
                        except Exception as e:
                            self.irc.sendmsg(message.channel, "URL ERROR")
                            print('URL ERROR:', e)