Пример #1
0
 def __init__(self):
     from connector.ircconnector import IRCConnector
     self.irc = IRCConnector(self.msgQueue)
     self.irc.setDaemon(True)
     self.irc.start()
Пример #2
0
class Bot():
    irc = None
    msgQueue = Queue()
    channel_list = []

    def __init__(self):
        from connector.ircconnector import IRCConnector
        self.irc = IRCConnector(self.msgQueue)
        self.irc.setDaemon(True)
        self.irc.start()

    def run(self):
        while True:
            packet = self.msgQueue.get()
            if packet['type'] == 'msg':
                msg = packet['content']
                for channel in self.channel_list:
                    self.irc.sendmsg(channel, msg)

            elif packet['type'] == 'irc':
                message = packet['content']
                print(message)
                if message.msgType == 'INVITE':
                    self.irc.joinchan(message.channel)

                elif message.msgType == 'MODE':
                    if message.msg == '+o ' + self.irc.botnick:
                        self.irc.sendmsg(message.channel, '감사합니다 :)')

                elif message.msgType == 'KICK':
                    if message.channel in self.channel_list:
                        self.channel_list.remove(message.channel)

                elif message.msgType == 'PRIVMSG':
                    if (message.msg == '!공지' and
                            message.channel not in self.channel_list):
                        self.channel_list.append(message.channel)
                        self.irc.sendmsg(message.channel, '크롤링 공지를 시작합니다')

                    elif (message.msg == '!공지해제' and
                            message.channel in self.channel_list):
                        self.channel_list.remove(message.channel)
                        self.irc.sendmsg(message.channel, '크롤링 공지를 해제합니다')
Пример #3
0
class Bot(object):
    irc = None
    msgQueue = Queue()

    def __init__(self):
        from connector.ircconnector import IRCConnector
        self.irc = IRCConnector(self.msgQueue)
        self.irc.setDaemon(True)
        self.irc.start()

    def run(self):
        while True:
            try:
                packet = self.msgQueue.get()
                if packet['type'] == 'msg':
                    msg = packet['content']
                    for channel in self.channel_list:
                        self.irc.sendmsg(channel, msg)

                elif packet['type'] == 'irc':
                    message = packet['content']
                    print(message)
                    if message.msgType == 'INVITE':
                        self.irc.joinchan(message.channel)

                    elif message.msgType == 'MODE':
                        if message.msg == '+o ' + self.irc.botnick:
                            self.irc.sendmsg(message.channel, '감사합니다 :)')

                    elif message.msgType == 'KICK':
                        pass

                    elif message.msgType == 'PRIVMSG':
                        val = functions.functionlist(message.msg)
                        if message.msg.find('!업데이트') == 0:
                            reload(functions)
                            self.irc.sendmsg(message.channel, '업데이트 완료')
                        elif val:
                            self.irc.sendmsg(message.channel, val)
                    elif message.msgType == 'NOTICE':
                        for chan in setting.chanlist:
                            self.irc.joinchan(chan)
            except Exception as err:
                with open('error.log', 'a') as f:
                    from datetime import datetime
                    f.write(
                        str(datetime.now().strftime("%Y-%m-%d %H:%M:%S")) +
                        '\n' + str(traceback.format_exc()) + '\n')
Пример #4
0
 def __init__(self):
     from connector.ircconnector import IRCConnector
     self.irc = IRCConnector(self.msgQueue)
     self.irc.setDaemon(True)
     self.irc.start()
Пример #5
0
class Bot():
    irc = None
    msgQueue = Queue()
    channel_list = []

    def __init__(self):
        from connector.ircconnector import IRCConnector
        self.irc = IRCConnector(self.msgQueue)
        self.irc.setDaemon(True)
        self.irc.start()

    def run(self):
        while True:
            packet = self.msgQueue.get()
            if packet['type'] == 'msg':
                msg = packet['content']
                for channel in self.channel_list:
                    self.irc.sendmsg(channel, msg)

            elif packet['type'] == 'irc':
                message = packet['content']
                print(message)
                if message.msgType == 'INVITE':
                    self.irc.joinchan(message.channel)

                elif message.msgType == 'MODE':
                    if message.msg == '+o ' + self.irc.botnick:
                        self.irc.sendmsg(message.channel, '감사합니다 :)')

                elif message.msgType == 'KICK':
                    if message.channel in self.channel_list:
                        self.channel_list.remove(message.channel)

                elif message.msgType == 'PRIVMSG':
                    if (message.msg == '!공지'
                            and message.channel not in self.channel_list):
                        self.channel_list.append(message.channel)
                        self.irc.sendmsg(message.channel, '크롤링 공지를 시작합니다')

                    elif (message.msg == '!공지해제'
                          and message.channel in self.channel_list):
                        self.channel_list.remove(message.channel)
                        self.irc.sendmsg(message.channel, '크롤링 공지를 해제합니다')
Пример #6
0
class Bot():
    irc = None
    msgQueue = Queue()

    def __init__(self):
        from connector.ircconnector import IRCConnector
        self.irc = IRCConnector(self.msgQueue)
        self.irc.setDaemon(True)
        self.irc.start()

    def run(self):
        while True:
            packet = self.msgQueue.get()
            if packet['type'] == 'msg':
                msg = packet['content']
                for channel in self.channel_list:
                    self.irc.sendmsg(channel, msg)

            elif packet['type'] == 'irc':
                message = packet['content']
                print(message)
                if message.msgType == 'INVITE':
                    self.irc.joinchan(message.channel)

                elif message.msgType == 'MODE':
                    if message.msg == '+o ' + self.irc.botnick:
                        self.irc.sendmsg(message.channel, '감사합니다 :)')

                elif message.msgType == 'KICK':
                    pass

                elif message.msgType == 'PRIVMSG':
                    if message.msg.find('!확률 ') == 0:
                        content = message.msg[len('!확률 '):]
                        print(content)
                        if content == '':
                            continue
                        m = hashlib.md5()
                        m.update(content.encode())
                        m.update(datetime.now().strftime("%Y%m%d").encode())
                        print(m.hexdigest())
                        prob = int(m.hexdigest(), 16) % 10000
                        print(prob)
                        self.irc.sendmsg(message.channel, content + ' = ' + str(prob / 100.0) + '%')
Пример #7
0
class Bot():
    irc = None
    msgQueue = Queue()

    def __init__(self):
        from connector.ircconnector import IRCConnector
        self.irc = IRCConnector(self.msgQueue)
        self.irc.setDaemon(True)
        self.irc.start()

    def run(self):
        while True:
            try:
                packet = self.msgQueue.get()
                if packet['type'] == 'msg':
                    msg = packet['content']
                    for channel in self.channel_list:
                        self.irc.sendmsg(channel, msg)

                elif packet['type'] == 'irc':
                    message = packet['content']
                    print(message)
                    if message.msgType == 'INVITE':
                        self.irc.joinchan(message.channel)

                    elif message.msgType == 'MODE':
                        if message.msg == '+o ' + self.irc.botnick:
                            self.irc.sendmsg(message.channel, '감사합니다 :)')

                    elif message.msgType == 'KICK':
                        pass

                    elif message.msgType == 'PRIVMSG':
                        val = functions.functionlist(message.msg)
                        if message.msg.find('!업데이트') == 0:
                            reload(functions)
                            self.irc.sendmsg(message.channel, '업데이트 완료')
                        elif val:
                            self.irc.sendmsg(message.channel, val)
            except:
                continue
Пример #8
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)
Пример #9
0
class ircBot(threading.Thread):
    irc = None
    msgQueue = Queue()
    last_id = ''
    footer = ''
    prog = re.compile(
        r'(\bhttps?://(www.|mobile.)?twitter.com/[a-zA-Z0-9_/]+/(\d+)\b)')
    log = open("log.txt", 'a')

    def __init__(self):
        self.log.write('log start at ' + str(datetime.now()) + '\n')
        super(ircBot, self).__init__()

    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)