This repository has been archived by the owner on Dec 10, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathbot.py
58 lines (46 loc) · 1.65 KB
/
bot.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# -*- coding: utf-8 -*-
import time
import threading
import redis
from easyirc.client.bot import BotClient
from easyirc.const import *
from easyirc import util, settings
import settings as bot_settings
connopt = settings.connections.values()[0]
redisc = redis.Redis(db=7)
pubsub = redisc.pubsub()
for chan in connopt.autojoins:
pubsub.subscribe(chan + 'in')
listener = pubsub.listen()
class Listener(threading.Thread):
def run(self):
for item in listener:
if item['type'] == 'subscribe': continue
if item['type'] == 'message':
chan = item['channel'][:-2]
strtime, sender, message = item['data'].split(':', 2)
ircmsg = '<{sender}> {message}'.format(sender=sender, message=message)
client.privmsg(chan, ircmsg.decode('utf-8'))
bglistener = Listener()
bglistener.daemon = True
bglistener.start()
client = BotClient()
def mask(nick):
for white in bot_settings.NICK_WHITELIST:
if nick.startswith(white):
return nick.encode('utf-8')
return '*' * len(nick)
@client.events.hookmsg(PRIVMSG)
def on_message(connection, sender, target, message):
if target[0] != '#': return
identity = util.parseid(sender)
masked = mask(identity.nick)
redismsg = ':'.join((str(int(time.time())), masked, message.encode('utf-8')))
starget = target.decode('utf-8')
redisc.lpush(starget, redismsg)
redisc.publish(starget + 'out', redismsg)
starttime = str(int(time.time()))
redisc.lpush(settings.CHANNEL, starttime + ':rust-kr.org:** 연결이 재시작되었습니다 **')
client.start()
client.interactive()
client.quit(u'Keyboard Interuppt')