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
10 botchannel
= "#botschool"
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) )
21 irc
.send('PRIVMSG %s :%s%s'% (botchannel
, msg
, '\r\n'))
25 \x030,1 \x030,3 \x030,1
26 \x030,1 \x030,3 \x030,1 \x030,3 \x030,1
27 \x030,1 \x030,3 \x030,1 \x030,4 \x030,1 \x030,3 \x030,1
28 \x030,1 \x030,3 \x030,1 \x030,4 \x030,1 \x030,3 \x030,1
29 \x030,1 \x030,3 \x030,1 \x030,4 \x030,0 \x030,4 \x030,1 \x030,3 \x030,1
30 \x030,1 \x030,3 \x030,1 \x030,4 \x030,0 \x030,4 \x030,1 \x030,3 \x030,1
31 \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
32 \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
33 \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
34 \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
35 \x030,1 \x030,3 \x030,1 \x030,4 \x030,1 \x030,3 \x030,1
36 \x030,1 \x030,3 \x030,1 \x030,3 \x030,1
37 \x030,1 \x030,3 \x030,1 \x030,15 \x030,1 \x030,3 \x030,1
38 \x030,1 \x030,3 \x030,1 \x030,14 \x030,15 \x030,0 \x030,15 \x030,14 \x030,1 \x030,3 \x030,1
39 \x030,1 \x030,3 \x030,1 \x030,15 \x030,0 \x030,15 \x030,1 \x030,3 \x030,1
40 \x030,1 \x030,3 \x030,1 \x030,15 \x030,1 \x030,3 \x030,1
41 \x030,1 \x030,3 \x030,1 \x030,3 \x030,1
42 \x030,1 \x030,3 \x030,1
47 data
= irc
.recv ( 4096 ).replace("\r\n", "")
50 #THIS IF BLOCK DEALS WITH PINGS
51 if data
.split()[0] == "PING":
52 irc
.send ( 'PONG ' + data
.split() [ 1 ] + '\r\n' )
55 #PUT EVERYTHING THE BOT IS TO RESPOND TO (IN PUBLIC OR PRIVATE) WITHIN THIS BLOCK
56 if data
.split()[1] == "PRIVMSG":
57 #lets define some variables to make coding more easy and fun
58 #making a bot do stuff really depends a lot on your ability
59 #to parse the incoming data, interpret it, and respond.
60 #read about split() and join(), and slicing for more infos.
61 src_nick
= data
.split("!")[0].replace (":", "") #nickname of person responsible for received text
62 src_username
= data
.split(" ")[0].split("@")[0].split("!")[1] #username of person responsible for recvd text
63 src_hostname
= data
.split("@")[1].split(" ")[0] #hostname of person responsible for recvd text (@irc2p)
64 msg
= ":".join(data
.split(":")[2:]).replace("\r\n", "") #receieved text from someone
65 msg_dest
= data
.split(" ")[2]#channel or person message was determined for
66 commandword
= msg
.split()[0]
69 #WE CAN SEPARATE OUR PUBLIC AND PRIVATE COMMANDS LIKE SO
70 #PUT PRIVATE COMMANDS YOU WANT THE BOT TO RESPOND TO IN THIS BLOCK
71 if msg_dest
== botnick
:
73 irc
.send ( 'PRIVMSG %s :hi there %s!\r\n'%(src_nick
, src_nick
) )
76 #PUT PUBLIC COMMANDS YOU WANT THE BOT TO RESPOND TO IN THIS BLOCK
77 elif msg_dest
== botchannel
:
79 #HERE ARE EXAMPLE TEMPLATES OF HOW YOU WOULD CODE A RESPONSE TO SOMETHING SPECIFIC
81 if msg
== "botty who are you":
82 say ( 'I am botty, and I\'m you\'re worst nightmare')
84 #In this example, as long as anywhere in the message is said "botty is stupid" it will reply.
85 if "botty is stupid" in msg
:
86 say ( '%s: NO YOU\'RE STUPID!'%(src_nick))
88 #In this example, commandword is specifically looking at the first word in the message
89 if commandword
== "%sping"%(bottrigger):
90 say( '%s: PONG!\r\n'%(src_nick))
91 if "slaps botty" in msg
:
92 say( '%s: This is the Trout Protection Agency. Please put the Trout Down and walk away with your hands in the air.'% (src_nick
))
93 if "cheese" in msg
or "cheeze" in msg
:
94 if msg
== "botty, do you like cheese?":
95 say ('I love it more than life itself!')
98 if commandword
== "%snameless"%(bottrigger):
101 say (" /$$$$$$$ /$$$$$$ /$$$$$$/$$$$ /$$$$$$ | $$ /$$$$$$ /$$$$$$$ /$$$$$$$")
102 say ("| $$__ $$ |____ $$| $$_ $$_ $$ /$$__ $$| $$ /$$__ $$ /$$_____//$$_____/")
103 say ("| $$ \ $$ /$$$$$$$| $$ \ $$ \ $$| $$$$$$$$| $$| $$$$$$$$| $$$$$$| $$$$$$ ")
104 say ("| $$ | $$ /$$__ $$| $$ | $$ | $$| $$_____/| $$| $$_____/ \____ $$\____ $$")
105 say ("| $$ | $$| $$$$$$$| $$ | $$ | $$| $$$$$$$| $$| $$$$$$$ /$$$$$$$//$$$$$$$/")
106 say ("|__/ |__/ \_______/|__/ |__/ |__/ \_______/|__/ \_______/|_______/|_______/ ")
112 if commandword
== "%ssay"%(bottrigger):
113 say("This is a say test.")
114 if commandword
== "%smushroom"%(bottrigger):
116 say("\x030,1 \x030,3 \x030,1 ")
117 say("\x030,1 \x030,3 \x030,1 \x030,3 \x030,1 ")
118 say("\x030,1 \x030,3 \x030,1 \x030,4 \x030,1 \x030,3 \x030,1 ")
119 say("\x030,1 \x030,3 \x030,1 \x030,4 \x030,1 \x030,3 \x030,1 ")
120 say("\x030,1 \x030,3 \x030,1 \x030,4 \x030,0 \x030,4 \x030,1 \x030,3 \x030,1 ")
121 say("\x030,1 \x030,3 \x030,1 \x030,4 \x030,0 \x030,4 \x030,1 \x030,3 \x030,1 ")
122 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 ")
123 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 ")
124 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 ")
125 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 ")
126 say("\x030,1 \x030,3 \x030,1 \x030,4 \x030,1 \x030,3 \x030,1 ")
127 say("\x030,1 \x030,3 \x030,1 \x030,3 \x030,1 ")
128 say("\x030,1 \x030,3 \x030,1 \x030,15 \x030,1 \x030,3 \x030,1 ")
129 say("\x030,1 \x030,3 \x030,1 \x030,14 \x030,15 \x030,0 \x030,15 \x030,14 \x030,1 \x030,3 \x030,1 ")
130 say("\x030,1 \x030,3 \x030,1 \x030,15 \x030,0 \x030,15 \x030,1 \x030,3 \x030,1 ")
131 say("\x030,1 \x030,3 \x030,1 \x030,15 \x030,1 \x030,3 \x030,1 ")
132 say("\x030,1 \x030,3 \x030,1 \x030,3 \x030,1 ")
133 say("\x030,1 \x030,3 \x030,1 ")
140 #BELOW ARE THE REST OF YOUR COMMANDS, I DIDNT CONVERT THEM OVER TO NEW FORMAT... WILL LET YOU DO THAT ^_^
143 #if data.find ( 'botty who are you' ) != -1:
144 #irc.send ( 'PRIVMSG #botschool :I am botty, and I\'m you\'re worst nightmare\r\n')
145 #if ":".join(data.split()[3].strip(":")) == "!ping":
146 #irc.send ( 'PRIVMSG #botschool :PONG!\r\n' )
147 #if data.find ( '!botty quit' ) != -1:
148 #irc.send ( 'PRIVMSG #botschool :Fine, if you don\'t want me\r\n' )
149 #irc.send ( 'QUIT\r\n' )
150 #if data.find ( 'hi botty' ) != -1:
151 #irc.send ( 'PRIVMSG #botschool :I already said hi...\r\n' )
152 #if data.find ( 'hello botty' ) != -1:
153 #irc.send ( 'PRIVMSG #botschool :I already said hi...\r\n' )
154 #if data.find ( 'KICK' ) != -1:
155 #irc.send ( 'JOIN #botschool\r\n' )
156 #if data.find ( 'cheese' ) != -1:
157 #irc.send ( 'PRIVMSG #botschool :WHERE!!!!!!\r\n' )
158 #if data.find ( 'slaps botty' ) != -1:
159 #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' )