Fixed clear redundancy.
[nameless-bot.git] / nameless-bot.py
blob7b4546f2563e6f5da2cc59c89f77ea8d14f51dd0
1 import socket
3 #now it's easier to modify the bots nickname and username,
4 #just change these strings and it will update in the rest
5 #of the code where %s substitution is used
7 botnick = "botty1224"
8 botuser = "botty"
9 bottrigger = "_"
10 botchannel = "#botschool"
11 network = 'localhost'
12 port = 6664
13 irc = socket.socket ( socket.AF_INET, socket.SOCK_STREAM )
14 irc.connect ( ( network, port ) )
15 irc.send ( 'USER %s %s %s :Python IRC\r\n'%(botuser, botuser, botuser) )
16 irc.send ( 'NICK %s\r\n'%(botnick) )
17 irc.send ( 'JOIN %s\r\n'%(botchannel) )
18 irc.send ( 'PRIVMSG %s :Hello World.\r\n'%(botchannel) )
20 def say(msg):
21 irc.send('PRIVMSG %s :%s%s'% (botchannel, msg, '\r\n'))
23 while True:
24 data = irc.recv ( 4096 ).replace("\r\n", "")
25 print data
27 #THIS IF BLOCK DEALS WITH PINGS
28 if data.split()[0] == "PING":
29 irc.send ( 'PONG ' + data.split() [ 1 ] + '\r\n' )
30 print "PING SENT"
32 #PUT EVERYTHING THE BOT IS TO RESPOND TO (IN PUBLIC OR PRIVATE) WITHIN THIS BLOCK
33 if data.split()[1] == "PRIVMSG":
34 #lets define some variables to make coding more easy and fun
35 #making a bot do stuff really depends a lot on your ability
36 #to parse the incoming data, interpret it, and respond.
37 #read about split() and join(), and slicing for more infos.
38 src_nick = data.split("!")[0].replace (":", "") #nickname of person responsible for received text
39 src_username = data.split(" ")[0].split("@")[0].split("!")[1] #username of person responsible for recvd text
40 src_hostname = data.split("@")[1].split(" ")[0] #hostname of person responsible for recvd text (@irc2p)
41 msg = ":".join(data.split(":")[2:]).replace("\r\n", "") #receieved text from someone
42 msg_dest = data.split(" ")[2]#channel or person message was determined for
43 commandword = msg.split()[0]
46 #WE CAN SEPARATE OUR PUBLIC AND PRIVATE COMMANDS LIKE SO
47 #PUT PRIVATE COMMANDS YOU WANT THE BOT TO RESPOND TO IN THIS BLOCK
48 if msg_dest == botnick:
49 if msg == "hi":
50 irc.send ( 'PRIVMSG %s :hi there %s!\r\n'%(src_nick, src_nick) )
53 #PUT PUBLIC COMMANDS YOU WANT THE BOT TO RESPOND TO IN THIS BLOCK
54 elif msg_dest == botchannel:
56 #HERE ARE EXAMPLE TEMPLATES OF HOW YOU WOULD CODE A RESPONSE TO SOMETHING SPECIFIC
58 if msg == "botty who are you":
59 say ( 'I am botty, and I\'m you\'re worst nightmare')
61 #In this example, as long as anywhere in the message is said "botty is stupid" it will reply.
62 if "botty is stupid" in msg:
63 say ( '%s: NO YOU\'RE STUPID!'%(src_nick))
65 #In this example, commandword is specifically looking at the first word in the message
66 if commandword == "%sping"%(bottrigger):
67 say( '%s: PONG!\r\n'%(src_nick))
68 if "slaps botty" in msg:
69 say( '%s: This is the Trout Protection Agency. Please put the Trout Down and walk away with your hands in the air.'% (src_nick))
70 if "cheese" in msg or "cheeze" in msg:
71 if msg == "botty, do you like cheese?":
72 say ('I love it more than life itself!')
73 else:
74 say( 'WHERE!?!?!?!')
75 if commandword == "%snameless"%(bottrigger):
76 say (" /$$ ")
77 say (" | $$ ")
78 say (" /$$$$$$$ /$$$$$$ /$$$$$$/$$$$ /$$$$$$ | $$ /$$$$$$ /$$$$$$$ /$$$$$$$")
79 say ("| $$__ $$ |____ $$| $$_ $$_ $$ /$$__ $$| $$ /$$__ $$ /$$_____//$$_____/")
80 say ("| $$ \ $$ /$$$$$$$| $$ \ $$ \ $$| $$$$$$$$| $$| $$$$$$$$| $$$$$$| $$$$$$ ")
81 say ("| $$ | $$ /$$__ $$| $$ | $$ | $$| $$_____/| $$| $$_____/ \____ $$\____ $$")
82 say ("| $$ | $$| $$$$$$$| $$ | $$ | $$| $$$$$$$| $$| $$$$$$$ /$$$$$$$//$$$$$$$/")
83 say ("|__/ |__/ \_______/|__/ |__/ |__/ \_______/|__/ \_______/|_______/|_______/ ")
89 if commandword == "%ssay"%(bottrigger):
90 say("This is a say test.")
91 if commandword == "%smushroom"%(bottrigger):
92 say("\x030,1 ")
93 say("\x030,1 \x030,3 \x030,1 ")
94 say("\x030,1 \x030,3 \x030,1 \x030,3 \x030,1 ")
95 say("\x030,1 \x030,3 \x030,1 \x030,4 \x030,1 \x030,3 \x030,1 ")
96 say("\x030,1 \x030,3 \x030,1 \x030,4 \x030,1 \x030,3 \x030,1 ")
97 say("\x030,1 \x030,3 \x030,1 \x030,4 \x030,0 \x030,4 \x030,1 \x030,3 \x030,1 ")
98 say("\x030,1 \x030,3 \x030,1 \x030,4 \x030,0 \x030,4 \x030,1 \x030,3 \x030,1 ")
99 say("\x030,1 \x030,3 \x030,1 \x030,4 \x030,0 \x030,4 \x030,0 \x030,4 \x030,0 \x030,4 \x030,0 \x030,4 \x030,1 \x030,3 \x030,1 ")
100 say("\x030,1 \x030,3 \x030,1 \x030,4 \x030,0 \x030,4 \x030,0 \x030,4 \x030,0 \x030,4 \x030,0 \x030,4 \x030,0 \x030,4 \x030,1 \x030,3 \x030,1 ")
101 say("\x030,1 \x030,3 \x030,1 \x030,4 \x030,0 \x030,4 \x030,0 \x030,4 \x030,0 \x030,4 \x030,0 \x030,4 \x030,1 \x030,3 \x030,1 ")
102 say("\x030,1 \x030,3 \x030,1 \x030,4 \x030,0 \x030,4 \x030,0 \x030,4 \x030,0 \x030,4 \x030,1 \x030,3 \x030,1 ")
103 say("\x030,1 \x030,3 \x030,1 \x030,4 \x030,1 \x030,3 \x030,1 ")
104 say("\x030,1 \x030,3 \x030,1 \x030,3 \x030,1 ")
105 say("\x030,1 \x030,3 \x030,1 \x030,15 \x030,1 \x030,3 \x030,1 ")
106 say("\x030,1 \x030,3 \x030,1 \x030,14 \x030,15 \x030,0 \x030,15 \x030,14 \x030,1 \x030,3 \x030,1 ")
107 say("\x030,1 \x030,3 \x030,1 \x030,15 \x030,0 \x030,15 \x030,1 \x030,3 \x030,1 ")
108 say("\x030,1 \x030,3 \x030,1 \x030,15 \x030,1 \x030,3 \x030,1 ")
109 say("\x030,1 \x030,3 \x030,1 \x030,3 \x030,1 ")
110 say("\x030,1 \x030,3 \x030,1 ")
111 say("\x030,1 ")
117 #BELOW ARE THE REST OF YOUR COMMANDS, I DIDNT CONVERT THEM OVER TO NEW FORMAT... WILL LET YOU DO THAT ^_^
120 #if data.find ( 'botty who are you' ) != -1:
121 #irc.send ( 'PRIVMSG #botschool :I am botty, and I\'m you\'re worst nightmare\r\n')
122 #if ":".join(data.split()[3].strip(":")) == "!ping":
123 #irc.send ( 'PRIVMSG #botschool :PONG!\r\n' )
124 #if data.find ( '!botty quit' ) != -1:
125 #irc.send ( 'PRIVMSG #botschool :Fine, if you don\'t want me\r\n' )
126 #irc.send ( 'QUIT\r\n' )
127 #if data.find ( 'hi botty' ) != -1:
128 #irc.send ( 'PRIVMSG #botschool :I already said hi...\r\n' )
129 #if data.find ( 'hello botty' ) != -1:
130 #irc.send ( 'PRIVMSG #botschool :I already said hi...\r\n' )
131 #if data.find ( 'KICK' ) != -1:
132 #irc.send ( 'JOIN #botschool\r\n' )
133 #if data.find ( 'cheese' ) != -1:
134 #irc.send ( 'PRIVMSG #botschool :WHERE!!!!!!\r\n' )
135 #if data.find ( 'slaps botty' ) != -1:
136 #irc.send ( 'PRIVMSG #botschool :This is the Trout Protection Agency. Please put the Trout Down and walk away with your hands in the air.\r\n' )