-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathircbot_core.py
44 lines (39 loc) · 1.03 KB
/
ircbot_core.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
#Imports
import telnetlib
import ircbot_handler
#Variables
HOST = '' #server here
PORT = 6667
nick = "Allu2_Bot"
realname = "IrcBot by allu2"
IDENT = "allu2bot"
#Make connection to server
tn = telnetlib.Telnet(HOST,PORT)
#Send nick to irc server
tn.write("NICK %s\n" %nick)
tn.write("USER %(IDENT)s %(HOST)s Allu2:'%(realname)s'\n" % locals())
s = True
#Main loop
while True:
line = tn.read_until('\n')
c = False
#Manage Pings here
if "PING :" in line:
tn.write("PONG %s\n" %HOST)
print "PONG :%s\n" % HOST
#Reload handler if asked
if "!Reload" in line:
print "Reloading!!"
try:
reload(ircbot_handler)
c = True
#In case of errors in handler annonce emergency mode and wait till its fixed and reloaded
except:
print "Error!!"
tn.write("PRIVMSG " +'#linux '+ ":" + "Emergency mode activated, fix the bugs and reload!" + "\n\r" )
#Print all server messages for debugging observing etc.
print line
#Start up the Handler for commands :)
ircbot_handler.handler(tn,HOST,nick,realname,IDENT,line, c, s)
c = False
s = False