1 # Huge respects to Shinobiwan. He is a very helpful dude, and was always helpful when I needed him to be.
5 #now it's easier to modify the bots nickname and username,
6 #just change these strings and it will update in the rest
7 #of the code where %s substitution is used
12 botchannel
= "#botschool"
15 irc
= socket
.socket ( socket
.AF_INET
, socket
.SOCK_STREAM
)
16 irc
.connect ( ( network
, port
) )
17 irc
.send ( bytes('USER %s %s %s :Python IRC\r\n'%(botuser
, botuser
, botuser
), "UTF-8") )
18 irc
.send ( bytes('NICK %s\r\n'%(botnick), "UTF-8") )
19 irc
.send ( bytes('JOIN %s\r\n'%(botchannel), "UTF-8") )
20 irc
.send ( bytes('PRIVMSG %s :Hello World.\r\n'%(botchannel), "UTF-8") )
23 irc
.send(bytes('PRIVMSG %s :%s%s'% (botchannel
, msg
, '\r\n'), "UTF-8"))
27 say (" /$$$$$$$ /$$$$$$ /$$$$$$/$$$$ /$$$$$$ | $$ /$$$$$$ /$$$$$$$ /$$$$$$$")
28 say ("| $$__ $$ |____ $$| $$_ $$_ $$ /$$__ $$| $$ /$$__ $$ /$$_____//$$_____/")
29 say ("| $$ \ $$ /$$$$$$$| $$ \ $$ \ $$| $$$$$$$$| $$| $$$$$$$$| $$$$$$| $$$$$$ ")
30 say ("| $$ | $$ /$$__ $$| $$ | $$ | $$| $$_____/| $$| $$_____/ \____ $$\____ $$")
31 say ("| $$ | $$| $$$$$$$| $$ | $$ | $$| $$$$$$$| $$| $$$$$$$ /$$$$$$$//$$$$$$$/")
32 say ("|__/ |__/ \_______/|__/ |__/ |__/ \_______/|__/ \_______/|_______/|_______/ ")
36 data
= irc
.recv ( 4096 ).decode("UTF-8").replace("\r\n", "")
39 #THIS IF BLOCK DEALS WITH PINGS
40 if data
.split()[0] == "PING":
41 irc
.send ( bytes('PONG ' + data
.split() [ 1 ] + '\r\n', "UTF-8") )
44 #PUT EVERYTHING THE BOT IS TO RESPOND TO (IN PUBLIC OR PRIVATE) WITHIN THIS BLOCK
45 if data
.split()[1] == "PRIVMSG":
46 #lets define some variables to make coding more easy and fun
47 #making a bot do stuff really depends a lot on your ability
48 #to parse the incoming data, interpret it, and respond.
49 #read about split() and join(), and slicing for more infos.
50 src_nick
= data
.split("!")[0].replace (":", "") #nickname of person responsible for received text
51 src_username
= data
.split(" ")[0].split("@")[0].split("!")[1] #username of person responsible for recvd text
52 src_hostname
= data
.split("@")[1].split(" ")[0] #hostname of person responsible for recvd text (@irc2p)
53 msg
= ":".join(data
.split(":")[2:]).replace("\r\n", "") #receieved text from someone
54 msg_dest
= data
.split(" ")[2]#channel or person message was determined for
55 commandword
= msg
.split()[0]
58 #WE CAN SEPARATE OUR PUBLIC AND PRIVATE COMMANDS LIKE SO
59 #PUT PRIVATE COMMANDS YOU WANT THE BOT TO RESPOND TO IN THIS BLOCK
60 if msg_dest
== botnick
:
62 irc
.send ( bytes('PRIVMSG %s :hi there %s!\r\n'%(src_nick
, src_nick
), "UTF-8") )
65 #PUT PUBLIC COMMANDS YOU WANT THE BOT TO RESPOND TO IN THIS BLOCK
66 elif msg_dest
== botchannel
:
68 #HERE ARE EXAMPLE TEMPLATES OF HOW YOU WOULD CODE A RESPONSE TO SOMETHING SPECIFIC
70 if "botty who are you" in msg
:
71 say ( 'I am botty, and I\'m you\'re worst nightmare')
73 #In this example, as long as anywhere in the message is said "botty is stupid" it will reply.
74 if "botty is stupid" in msg
:
75 say ( '%s: NO YOU\'RE STUPID!'%(src_nick))
77 #In this example, commandword is specifically looking at the first word in the message
78 if commandword
== "%sping"%(bottrigger):
79 say( '%s: PONG!\r\n'%(src_nick))
80 if "slaps botty" in msg
:
81 say( '%s: This is the Trout Protection Agency. Please put the Trout Down and walk away with your hands in the air.'% (src_nick
))
82 if commandword
== "%sinfo"%(bottrigger):
85 say("Nameless-bot anti-copyright Schnaubelt 2012")
86 say("Python version: " + sys
.version
.replace("\n", ""))
87 if "cheese" in msg
or "cheeze" in msg
:
88 if msg
== "botty, do you like cheese?":
89 say ('I love it more than life itself!')
92 #Prints nameless in 1337 ascii art.
93 if commandword
== "%snameless"%(bottrigger):
95 if commandword
== "%ssay"%(bottrigger):
96 say("This is a say test.")
98 #prints a colored irc 1-up mushroom.
99 if commandword
== "%smushroom"%(bottrigger):
101 say("\x030,1 \x030,3 \x030,1 ")
102 say("\x030,1 \x030,3 \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,4 \x030,1 \x030,3 \x030,1 ")
105 say("\x030,1 \x030,3 \x030,1 \x030,4 \x030,0 \x030,4 \x030,1 \x030,3 \x030,1 ")
106 say("\x030,1 \x030,3 \x030,1 \x030,4 \x030,0 \x030,4 \x030,1 \x030,3 \x030,1 ")
107 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 ")
108 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 ")
109 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 ")
110 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 ")
111 say("\x030,1 \x030,3 \x030,1 \x030,4 \x030,1 \x030,3 \x030,1 ")
112 say("\x030,1 \x030,3 \x030,1 \x030,3 \x030,1 ")
113 say("\x030,1 \x030,3 \x030,1 \x030,15 \x030,1 \x030,3 \x030,1 ")
114 say("\x030,1 \x030,3 \x030,1 \x030,14 \x030,15 \x030,0 \x030,15 \x030,14 \x030,1 \x030,3 \x030,1 ")
115 say("\x030,1 \x030,3 \x030,1 \x030,15 \x030,0 \x030,15 \x030,1 \x030,3 \x030,1 ")
116 say("\x030,1 \x030,3 \x030,1 \x030,15 \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 ")