-
Notifications
You must be signed in to change notification settings - Fork 0
/
start.py
74 lines (62 loc) · 1.77 KB
/
start.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
from irc import *
from bot import *
import signal
import sys
import string
import ConfigParser
import ast
import logging
import time
config = ConfigParser.RawConfigParser()
config.read('default.cfg')
channels = config.get('base', 'channels').split(',')
chanpwd = config.get('base', 'chanpwd')
server = config.get('base', 'server')
nickname = config.get('base', 'nickname')
password = config.get('base', 'password')
port = int(config.get('base', 'port'))
placeholder = config.get('bot', 'placeholder')
replies = ast.literal_eval(config.get('bot','replies'))
print placeholder
irc = IRC()
bot = BOT(nickname,replies,placeholder)
#logger = logging.getLogger(__name__)
#logging.basicConfig(level=logging.INFO)
def signal_handler(signal, frame):
irc.quit()
sys.exit(0)
def init_logger():
timestr = time.strftime("%Y%m%d-%H%M%S")
fh = logging.FileHandler(timestr+".log")
formatter = logging.Formatter('%(asctime)s - %(levelname)s - %(message)s')
fh.setFormatter(formatter)
#logger.addHandler(fh)
#init_logger()
def Main():
signal.signal(signal.SIGINT, signal_handler)
irc.connect(server, port, chanpwd, nickname, password)
while True:
text = irc.get_text()
#logger.info(text)
isInChannel = False
channel = ''
print text
for eachChannel in channels:
if eachChannel in text:
isInChannel = True
channel = eachChannel
if "PRIVMSG" in text and isInChannel and bot.has_reply(text):
botReply = bot.reply(text)
if isinstance(botReply, list):
for eachFeed in botReply:
irc.send(channel, eachFeed.encode('utf-8').strip())
else:
irc.send(channel, botReply)
if text.find('PING') != -1:
irc.pong(text)
for eachChannel in channels:
irc.join(eachChannel,chanpwd)
#if "KICK" in text and nickname in text:
# irc.join(channel,chanpwd)
Main()
exit(0)