コード例 #1
0
ファイル: Jhbot.py プロジェクト: Jhuni0123/Jh-bot
 def __init__(self):
     from ircconnector import IRCConnector
     self.irc = IRCConnector(self.msgQueue)
     self.irc.setDaemon(True)
     self.irc.start()
     self.exList = ExchangeCrawl()
     self.nameDic = MakeNameDic(self.exList)
     self.exDic = UpdateExDic(self.exList, self.exDic)
コード例 #2
0
ファイル: sirius.py プロジェクト: JW275/Sirius-bot
 def __init__(self):
     from ircconnector import IRCConnector
     self.irc = IRCConnector(self.msgQueue)
     self.irc.setDaemon(True)
     self.irc.start()
コード例 #3
0
ファイル: Jhbot.py プロジェクト: Jhuni0123/Jh-bot
class Bot():
    irc = None
    msgQueue = Queue()
    channel_list = []
    exList = []
    nameDic = {}
    exDic = {}
    def __init__(self):
        from ircconnector import IRCConnector
        self.irc = IRCConnector(self.msgQueue)
        self.irc.setDaemon(True)
        self.irc.start()
        self.exList = ExchangeCrawl()
        self.nameDic = MakeNameDic(self.exList)
        self.exDic = UpdateExDic(self.exList, self.exDic)
        
    def run(self):
        print('RUNNING')
        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':
                    print("%s invites to %s" % (message.sender, message.channel))
                    self.irc.joinchan(message.channel)

                elif message.msgType == 'NOTICE':
                    if message.sender == masterNick and message.channel == botnick:
                        self.irc.semdmsg('#snucse16',message.msg)
                        continue
                elif message.msgType == 'MODE':
                    if message.msg == '+o ' + botnick:
                        self.irc.sendmsg(message.channel, '>ㅅ<')
                    elif message.msg == '-o ' + botnick:
                        self.irc.sendmsg(message.channel, 'ㅇㅅㅇ..')

                elif message.msgType == 'PRIVMSG':
                    if (message.sender in botNameList):
                        continue
                    parse = re.match(r'!(\S+)\s+(.*)$',message.msg)
                    if parse:
                        command = parse.group(1)
                        contents = parse.group(2)
                        if command == '환율':
                            smsg = Exmsg(contents,self.exDic,self.nameDic)
                            self.irc.sendmsg(message.channel, smsg)
                            continue
                    
                        if command == '점수' or command == 'score':
                            sen = Sent(contents)
                            if sen == '':
                                self.irc.sendmsg(message.channel, "적절하지 않은 영단어입니다")
                                continue
                            scr = Score(sen)
                            if scr == 100:
                                self.irc.sendmsg(message.channel, "'%s'은(는) %d점짜리 입니다" % (contents,scr))
                                continue
                            else:
                                self.irc.sendmsg(message.channel, "'%s'은(는) %d점" % (contents, scr))
                                continue

                        if command == '코포':
                            smsg = CFUserInfo(contents)
                            self.irc.sendmsg(message.channel, smsg)
                            continue
                        
                    parse = re.match(r'!치킨\s+(\d+)\s*(\S*)',message.msg)
                    if parse:
                        num = int(parse.group(1))
                        etc = parse.group(2)
                        if etc == '명' or etc == '':
                            if num == 1:
                                self.irc.sendmsg(message.channel, '1인1닭은 진리입니다')
                                continue
                            elif num == 2:
                                self.irc.sendmsg(message.channel, '계산상 1마리지만 1인1닭에 따라 2마리가 적절합니다')
                                continue
                            elif num >= 573147844013817084101:
                                self.irc.sendmsg(message.channel, '필요한 치킨이 너무 많아 셀 수 없습니다')
                                continue
                            else:
                                self.irc.sendmsg(message.channel, '%d명에게는 %d마리의 치킨이 적절합니다' % (num, Chib(int(num))))
                            if num == 12117:
                                self.irc.sendmsg(message.channel, 'gs12117에게는 0.3마리의 치킨이면 충분합니다')
                            if EE(num):
                                self.irc.sendmsg(message.channel, '%d명에게는 %d마리의 치킨이 적절합니다' % (num, Chib(int(num))))
                            if Bi(num):
                                self.irc.sendmsg(message.channel, '%s명에게는 %s마리의 치킨이 적절합니다' % (Mkbi(Mkd(num)), Mkbi(Chib(int(Mkd(num))))))
                            continue

                    parse = re.match(r'!fib\s+(-?\d+)$',message.msg)
                    if parse:
                        num = int(parse.group(1))
                        if num > 256:
                            self.irc.sendmsg(message.channel, '[fib] result is too big')
                        elif num < 0:
                            self.irc.sendmsg(message.channel, '[fib] incorrect input')
                        else:
                            self.irc.sendmsg(message.channel, '[fib] %d' % fib[num])
                        continue
                    
                    parse = re.match(r'!백준\s+(\d+)$',message.msg)
                    if parse:
                        num = int(parse.group(1))
                        url = 'https://www.acmicpc.net/problem/%d' % num
                        title = BOJCrawl(url)
                        if title:
                            self.irc.sendmsg(message.channel, title + ' - ' + 'https://boj.kr/%d' % num)
                        elif title == None:
                            self.irc.sendmsg(message.channel, 'Not found')
                        elif title == False:
                            self.irc.sendmsg(message.channel, 'Timeout')
                        continue
                    
                    if message.msg == '!환율':
                        self.irc.sendmsg(message.channel, 'ex)!환율 [숫자] <통화명> [-> <통화명>]')
                        continue
                    
                    if message.msg == '!코포':
                        contestlist = CFContestList()
                        if contestlist != False:
                            if len(contestlist) == 0:
                                self.irc.sendmsg(message.channel, 'No contest yet')
                                continue
                            contestlist = sorted(contestlist, key=lambda con: con[5])
                            for i  in range(min(len(contestlist),2 if message.channel != '#Jhuni' else len(contestlist))):
                                con = contestlist[i]
                                self.irc.sendmsg(message.channel, '[%s] %s | %s | %s | %s' % (con[0],con[1], con[2],con[3],con[4]))
                            continue
                        else:
                            self.irc.sendmsg(message.channel, 'Timeout')
                            continue
                        
                        
                    if message.msg == '부스터 옵줘':
                        self.irc.sendmode(message.channel,'+o ' + message.sender)
                        continue
                    
                    isCalled = False
                    for x in callNameList:
                        if message.msg.find(x) != -1:
                            isCalled = True
                            break
                    if isCalled:
                        continue
                    
                    if message.msg.find('치킨') != -1 and message.msg.find('치킨') < message.msg.find('먹') < message.msg.find('싶'):
                        self.irc.sendmsg(message.channel, '치킨!')
                        continue
                    
                    parse = re.search(r'부(우*)스터(어*)', message.msg)
                    if parse:
                        cry1 = len(parse.group(1))
                        cry2 = len(parse.group(2))
                        self.irc.sendmsg(message.channel, '크' + ('으'*cry1 if cry1 < 10 else '으*%d' % cry1) + ('아'*cry2 if cry2 < 10 else '아*%d' % cry2) + '앙')
                        continue
                    

    def loopExCrawl(self):
        while True:
            time.sleep(30*60)
            self.exList = ExchangeCrawl()
            self.nameDic = MakeNameDic(self.exList)
            self.exDic = UpdateExDic(self.exList, self.exDic)
            
    def loopCFCrawl(self):
        RCList = InitCFChangeList('PJH0123')
        while True:
            time.sleep(10*60)
            newList = CFRatingChange('PJH0123',RCList)
            if newList:
                for i in range(max(len(newList)-2,0),len(newList)):
                    ch = newList[i]
                    RCList.append(ch['contestId'])
                    score = ch['newRating']-ch['oldRating']
                    score = chr(3) + ('12+' if score >= 0 else '07-') + str(abs(score)) + chr(3)
                    self.irc.sendmsg('#Jhuni', "[codeforeces] %s %d -> %d (%s) #%d at contest%d" % ('PJH0123', ch['oldRating'], ch['newRating'], score, ch['rank'], ch['contestId']))

    def start(self):
        threading.Thread(target = self.loopExCrawl, daemon = True).start()
        threading.Thread(target = self.loopCFCrawl, daemon = True).start()
        self.run()
コード例 #4
0
ファイル: sirius.py プロジェクト: JW275/Sirius-bot
class Bot():
    irc = None
    msgQueue = Queue()
    channel_list = ['#jwtest', '#snucse16']

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

    def run(self):
        slave = master() #추천해준 gs12117에게 감사를 표합니다
        slave.join(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' and message.sender == 'JW275':
                    self.irc.joinchan(message.channel)

                elif message.msgType == 'JOIN' and message.sender == '치즈':
                    self.irc.giveop(message.channel, message.sender)

                elif message.msgType == 'NOTICE':
                    if message.sender == 'JW275' and message.channel == botnick:
                        continue
                
                elif message.msgType == 'MODE':
                    if (message.msg == '+o ' + botnick) and (message.sender != 'JJing_e'):
                        say = op()
                        self.irc.sendmsg(message.channel, say)
                    elif message.msg == '-o ' + botnick:
                        say = deop()
                        self.irc.sendmsg(message.channel, say)

                elif (message.msgType == 'PRIVMSG') and (message.sender not in blacklist):
                    if message.msg.find('시리우스 나 주인할래') != -1:
                        slave.mkpass(self)
                    elif slave.key == 1:
                        slave.givemaster(self, message)
                    elif time.time() > slave.duetime:
                        slave.initmaster()


                    if message.msg.find('시리우스 옵줘') != -1:
                        self.irc.giveop(message.channel, message.sender)
                        say = giop()
                        self.irc.sendmsg(message.channel, say)
                    elif message.msg.find('냐아앙♡') != -1:
                        self.irc.sendmsg(message.channel, '으르릉..')
                    elif message.msg.find('참치 먹자') != -1:
                        self.irc.sendmsg(message.channel, '퉤퉷')
                    elif message.msg.find('브라이언') != -1:
                        check = random.randint(1,5)
                        if check == 1:
                            self.irc.sendmsg(message.channel, '거짓말쟁이..크르릉..')
                    
                    elif (message.msg.find('좋은아침입니다여러분') != -1) and (message.sender in slave.masterlist):
                        self.irc.sendmsg(message.channel, '헥헥! 주인님 잘자써오?')

                    elif message.msg.find('고기 먹고싶다') != -1:
                        self.irc.sendmsg(message.channel, '꼬기! 꼬기주라멍!')
                    elif message.msg.find('고양이 키우고싶다') != -1:
                        self.irc.sendmsg(message.channel, '크오아아아앙!!!!')

                    elif (message.msg.find('그치 시리우스야?') != -1) and (message.sender in slave.masterlist):
                        self.irc.sendmsg(message.channel, '멍!ฅ^•ﻌ•^ฅ')



                    parse = re.match('^시리우스\s(\S+)\s물어!$', message.msg)
                    if parse and (message.sender not in blacklist):
                        who = parse.group(1)
                        check = 0
                        for i in notlist:
                            if who.find('%s' % i) != -1:
                                check = 1
                        if check == 1:
                            self.irc.sendmsg(message.channel, 'ㅡㅅㅡ 저리가라 멍!')
                            check = 0
                        elif (who in blacklist) and (who != '치즈'):
                            say = angry()
                            self.irc.sendmsg(message.channel, say)
                        elif (who.find('1') != -1):
                            self.irc.sendmsg(message.channel, 'ㅡㅅㅡ 저리가라 멍!')
                        elif (who.find('시리우스') != -1) or (who.find('자신') != -1) or (who.find('sirius') != -1) or (who.find('너') != -1):
                            self.irc.sendmsg(message.channel, '바보새오? 꺄하하')
                        elif who.find('부스터') != -1:
                            continue
                        elif (who.find('치즈') != -1) or (who.find('고양이') != -1):
                            self.irc.sendmsg(message.channel, '냥냥이는 저리가라 멍!')
                        elif (who.find('예지') != -1):
                            self.irc.sendmsg(message.channel, '퓨터님의 여자분?')
                        elif (who.find('브랸') != -1) or (who.find('bryan') != -1) or (who.find('승현') != -1) or (who.find('조조교') != -1) or (who.find('마조') != -1):
                            self.irc.sendmsg(message.channel, '무서워오..끼이잉..')
                        else:
                            say = attack()
                            self.irc.sendmsg(message.channel, say)

                    
                    parse = re.match('^시리우스! (\S+)$', message.msg)
                    if parse:
                        act = parse.group(1)
                        if act == '공물어와!':
                            self.irc.sendmsg(message.channel, '던저쥬새오!멍!')
                            f = open("active.txt",'w')
                            f.write('on')
                            f.close()
                        elif act == '이리와!':
                            say = happy()
                            self.irc.sendmsg(message.channel, say)
                        elif act == '짖어!':
                            say = random.choice(['멍멍','왈왈'])
                            self.irc.sendmsg(message.channel, say)    


                    parse = re.match('^시리우스! 치즈 괴롭혀!$', message.msg)
                    if parse:
                        if message.sender in slave.masterlist:
                            self.irc.sendmsg(message.channel, '바보 냥이!멍!')
                            self.irc.deop(message.channel, '치즈')

                    parse = re.match('^시리우스! 치즈한테 사과해!$', message.msg)
                    if parse:
                        if message.sender in slave.masterlist:
                            self.irc.sendmsg(message.channel, 'UTェTU미아내오..쓰담쓰담..')
                            self.irc.giveop(message.channel, '치즈')


                    if message.msg.find('끙차!') != -1:
                        f = open("active.txt", 'r')
                        check = f.readline()
                        f.close()
                        if check == 'on':
                            f = open("active.txt", 'w')
                            f.write('off')
                            f.close()
                            self.irc.partchan(message.channel)
                            how = random.randint(10,30)
                            time.sleep(how)
                            self.irc.joinchan(message.channel)
                            self.irc.sendmsg(message.channel, '헥헥!ฅ^•ﻌ•^ฅ 공 여기이써오')
                        elif check == 'off':
                            continue