Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # -*- coding: utf-8 -*-
- 2
- 3 # You may read that if you created or edited the bot's commands and that you want to update it:
- 4 # 1) Copy your commands (not the default commands) that you've created from your old version to the new one.
- 5 # 2) If you have edited a default LifeBot command, delete it from the new version, then copy the old version command's code to the new version.
- 6
- 7 import socket, time, urllib, webbrowser #Imports, do not edit unless you know Python.
- 8
- 9 chan = "#SkyGen"
- 10 #What's in the inverted commas is the channel where the bot will come.
- 11 user_bot = "LifeBot16"
- 12 #There you have the bot's username (when he will connect to IRC).
- 13 ver = "LifeBot, variant of "
- 14 #This is the version-name of your bot ! After 'Variant of', add your pseudo !
- 15 host = "irc.freenode.net"
- 16 #The bot connects himself thanks to what's in the inverted commas (close to 'host').
- 17 port = 6667
- 18 #The port of IRC network.
- 19 restricted = True
- 20 #Security: some commands can only be used by certains users if True.
- 21 trust = ["User 1", "User 2"]
- 22 #The users who are able to use these commands.
- 23
- 24 #Beginning of the connection, do not edit unless you know Python.
- 25 #LifeBot's version:
- 26 ver_LifeBot = "1.6.0"
- 27 lang_LifeBot = "en"
- 28 print(ver)
- 29 #Password:
- 30 password = raw_input("Bot's IRC password (if exists, if not let it blank) : ")
- 31 #Connection to IRC:
- 32 identify = False
- 33 IRC = socket.socket()
- 34 IRC.connect((host, port))
- 35 IRC.send("NICK %s\r\n" % user_bot)
- 36 IRC.send("USER LifeBot %s bla :%s\r\n" % (host, user_bot))
- 37 #Connection loop:
- 38 while True:
- 39 rep = IRC.recv(2048)
- 40 rep2 = rep.split()
- 41 print(rep)
- 42 #
- 43 try:
- 44 if ":Nickname is already in use." in rep and not identify:
- 45 user_bot = user_bot + "_"
- 46 IRC.send("NICK %s\r\n" % user_bot)
- 47 if ":End of /MOTD command." in rep and not identify:
- 48 IRC.send("PRIVMSG NickServ :identify %s\r\n" % password)
- 49 IRC.send("JOIN %s\r\n" % chan)
- 50 identify = True
- 51 #Answer to the IRC network's ping :
- 52 if rep2[0] == "PING":
- 53 IRC.send("PONG %s\r\n" % rep2[1])
- 54 #Answer to the bot's invitations :
- 55 if rep2[1] == "INVITE":
- 56 IRC.send("JOIN %s\r\n" % rep2[3])
- 57 except IndexError:
- 58 rep2 = ["", "", "", "", "", "", "", "", "", ""]
- 59 #
- 60 user = rep2[0].split("!")
- 61 user[0] = user[0].strip(":")
- 62 if not restricted:
- 63 trusted = True
- 64 elif identify and user[0] in trust:
- 65 IRC.send("PRIVMSG NickServ :info %s\r\n" % user[0])
- 66 IRC.settimeout(1)
- 67 while True:
- 68 try:
- 69 if "Last seen : now" in IRC.recv(2048):
- 70 IRC.settimeout(None)
- 71 trusted = True
- 72 break
- 73 except socket.timeout:
- 74 IRC.settimeout(None)
- 75 trusted = False
- 76 break
- 77 else:
- 78 trusted = False
- 79
- 80 if rep2[1] == "PRIVMSG":
- 81 try:
- 82 if not rep2[2].startswith("#"):
- 83 rep2[2] = user[0]
- 84 #End of the connection.
- 85 #Beggining of the commands. Only functionnal in PM.
- 86 if rep2[3].lower() == ":!identify" and trusted:
- 87 try:
- 88 IRC.send("PRIVMSG NickServ :identify %s %s\r\n" % (rep2[4], rep2[5]))
- 89 except IndexError:
- 90 IRC.send("PRIVMSG NickServ :identify %s\r\n" % rep2[4])
- 91 #End of the only-functionnal-in-PM commands.
- 92 else: #Don't add something here.
- 93 #Beginning of the non-functionnal-in-PM commands.
- 94 #Beginning of the syntax.
- 95 if rep2[3].lower() == ":!commandtest":
- 96 IRC.send("PRIVMSG %s :%s\r\n" % (rep2[2], "Text to send."))
- 97 #End of the syntax.
- 98 #Follow this syntax when you want to add a command. Need help ? Ask on #SkyGen !
- 99
- 100 if rep2[3].lower() == ":!ban" and trusted: #Here, we've got a command which bans a user from a chan.
- 101 try:
- 102 IRC.send("MODE %s +b %s\r\n" % (rep2[4], rep2[5])) #If we type !ban ##chan user, the bots bans the user 'user' from the chan ##chan (the bot must be in the chan and must be op of the chan in order to this command works)
- 103 except IndexError: #If we don't precise the chan (example, if we type !ban user)
- 104 IRC.send("MODE %s +b %s\r\n" % (rep2[2], rep2[4])) #The bot bans the user from the chan where the command has been typed (the bot must be op of the chan for this command works)
- 105
- 106 if rep2[3].lower() == ":!bing":
- 107 IRC.send("PRIVMSG %s :%s\r\n" % (rep2[2], "http://www.bing.com/search?q=" + "+".join(rep2[4:])))
- 108
- 109 if (rep2[3].lower() == ":!chanserv" or rep2[3].lower() == ":!cs") and trusted: #In order to execute 2 commandes with the same result, you need to write (rep2[3].lower() == ":!command1" or rep2[3].lower() == ":!command2"). In order to restrict the use to trust users, you need to write 'and trusted' at the end of condition.
- 110 IRC.send("PRIVMSG ChanServ :%s\r\n" % " ".join(rep2[4:])) #This command sends a message to ChanServ, there is " ".join(rep2[4:]) qui est le message à envoyer, le or sert à déclencher une commande avec des raccourcis. Voir les commandes ChanServ.
- 111
- 112 if (rep2[3].lower() == ":!chanserv_access" or rep2[3].lower() == ":!cs_access") and trusted:
- 113 try:
- 114 IRC.send("PRIVMSG ChanServ :access %s add %s %s\r\n" % (rep2[4], rep2[5], rep2[6])) #This ChanServ command adds a user to a chan's rights group, enter /msg ChanServ help in your IRC client to see all the commands.
- 115 except IndexError:
- 116 IRC.send("PRIVMSG ChanServ :access %s add %s %s\r\n" % (rep2[2], rep2[4], rep2[5]))
- 117
- 118 if (rep2[3].lower() == ":!chanserv_access_del" or rep2[3].lower() == ":!cs_access_del") and trusted:
- 119 try:
- 120 IRC.send("PRIVMSG ChanServ :access %s del %s\r\n" % (rep2[4], rep2[5])) #This ChanServ command is the reverse of !chanserv_access, it removes the rights from a user.
- 121 except IndexError:
- 122 IRC.send("PRIVMSG ChanServ :access %s del %s\r\n" % (rep2[2], rep2[4]))
- 123
- 124 if (rep2[3].lower() == ":!chanserv_akick" or rep2[3].lower() == ":!cs_akick") and trusted: #This command sends a message to ChanServ to automatically kick and ban a user.
- 125 try:
- 126 IRC.send("PRIVMSG ChanServ :akick %s add %s\r\n" % (rep2[4], rep2[5]))
- 127 except IndexError:
- 128 IRC.send("PRIVMSG ChanServ :akick %s add %s\r\n" % (rep2[2], rep2[4]))
- 129
- 130 if (rep2[3].lower() == ":!chanserv_akick_del" or rep2[3].lower() == ":!cs_akick_del") and trusted: #This command sends a message to ChanServ to delete the automatic ban of a user.
- 131 try:
- 132 IRC.send("PRIVMSG ChanServ :akick %s del %s\r\n" % (rep2[4], rep2[5]))
- 133 except IndexError:
- 134 IRC.send("PRIVMSG ChanServ :akick %s del %s\r\n" % (rep2[2], rep2[4]))
- 135
- 136 if (rep2[3].lower() == ":!chanserv_deop" or rep2[3].lower() == ":!cs_deop") and trusted: #The !chanserv_... commands give or remove the op, voice, etc. rights of a chan user by ChanServ.
- 137 try:
- 138 IRC.send("PRIVMSG ChanServ :deop %s %s\r\n" % (rep2[4], rep2[5]))
- 139 except IndexError:
- 140 IRC.send("PRIVMSG ChanServ :deop %s %s\r\n" % (rep2[2], rep2[4]))
- 141
- 142 if (rep2[3].lower() == ":!chanserv_devoice" or rep2[3].lower() == ":!cs_devoice") and trusted:
- 143 try:
- 144 IRC.send("PRIVMSG ChanServ :devoice %s %s\r\n" % (rep2[4], rep2[5]))
- 145 except IndexError:
- 146 IRC.send("PRIVMSG ChanServ :devoice %s %s\r\n" % (rep2[2], rep2[4]))
- 147
- 148 if (rep2[3].lower() == ":!chanserv_flags" or rep2[3].lower() == ":!cs_flags") and trusted:
- 149 try:
- 150 IRC.send("PRIVMSG ChanServ :flags %s %s %s\r\n" % (rep2[4], rep2[5], rep2[6]))
- 151 except IndexError:
- 152 IRC.send("PRIVMSG ChanServ :flags %s %s %s\r\n" % (rep2[2], rep2[4], rep2[5]))
- 153
- 154 if (rep2[3].lower() == ":!chanserv_op" or rep2[3].lower() == ":!cs_op") and trusted:
- 155 try:
- 156 IRC.send("PRIVMSG ChanServ :op %s %s\r\n" % (rep2[4], rep2[5]))
- 157 except IndexError:
- 158 IRC.send("PRIVMSG ChanServ :op %s %s\r\n" % (rep2[2], rep2[4]))
- 159
- 160 if (rep2[3].lower() == ":!chanserv_voice" or rep2[3].lower() == ":!cs_voice") and trusted:
- 161 try:
- 162 IRC.send("PRIVMSG ChanServ :voice %s %s\r\n" % (rep2[4], rep2[5]))
- 163 except IndexError:
- 164 IRC.send("PRIVMSG ChanServ :voice %s %s\r\n" % (rep2[2], rep2[4]))
- 165
- 166 if rep2[3].lower() == ":!deop" and trusted: #Here, we have a command that removes the op right (-o) of a user, look at the command code : !ban (+b)
- 167 try:
- 168 IRC.send("MODE %s -o %s\r\n" % (rep2[4], rep2[5]))
- 169 except IndexError:
- 170 IRC.send("MODE %s -o %s\r\n" % (rep2[2], rep2[4]))
- 171
- 172 if rep2[3].lower() == ":!devoice" and trusted:
- 173 try:
- 174 IRC.send("MODE %s -v %s\r\n" % (rep2[4], rep2[5]))
- 175 except IndexError:
- 176 IRC.send("MODE %s -v %s\r\n" % (rep2[2], rep2[4]))
- 177
- 178 if rep2[3].lower() == ":!flood":
- 179 IRC.send("PRIVMSG %s :%s\r\n" % (rep2[2], "The flood is forbidden. You are incuring severe sanctions."))
- 180 #Between these two comments (that one and the one below), we may see a simple command. We can only execute if the bot "sees" on the chan "!flood".
- 181
- 182 if rep2[3].lower() == ":!google":
- 183 IRC.send("PRIVMSG %s :%s\r\n" % (rep2[2], "https://www.google.com/#q=" + "+".join(rep2[4:])))
- 184
- 185 if rep2[3].lower() == ":!help" or rep2[3].lower() == ":!aide":
- 186 IRC.send("PRIVMSG %s :%s\r\n" % (rep2[2], "http://skygen.alwaysdata.net/" + lang_LifeBot + "/LifeBot/"))
- 187
- 188 if rep2[3].lower() == ":!ip":
- 189 IRC.send("PRIVMSG %s :%s\r\n" % (rep2[2], "https://whatismyipaddress.com/ip/" + rep2[4]))
- 190
- 191 if rep2[3].lower() == ":!join":
- 192 IRC.send("JOIN %s\r\n" % rep2[4])
- 193
- 194 if rep2[3].lower() == ":!kick" and trusted:
- 195 if " ".join(rep2[5:]) != "":
- 196 IRC.send("KICK %s %s :%s\r\n" % (rep2[2], rep2[4], " ".join(rep2[5:])))
- 197 else:
- 198 IRC.send("KICK %s %s\r\n" % (rep2[2], rep2[4]))
- 199
- 200 if rep2[3].lower() == ":!kickban" and trusted:
- 201 if " ".join(rep2[5:]) != "":
- 202 IRC.send("KICK %s %s :%s\r\n" % (rep2[2], rep2[4], " ".join(rep2[5:])))
- 203 else:
- 204 IRC.send("KICK %s %s\r\n" % (rep2[2], rep2[4]))
- 205 IRC.send("MODE %s +b %s\r\n" % (rep2[2], rep2[4]))
- 206
- 207 if rep2[3].lower() == ":!love":
- 208 IRC.send("PRIVMSG %s :%s\r\n" % (rep2[2], "I don't love you."))
- 209 IRC.send("PRIVMSG %s :%s\r\n" % (rep2[2], "But no, I love you sometimes."))
- 210 #Oh ! Have you seen how we make the bot answer with two distinct sentences ? If not, look at the sourcecode of "!love" (look below).
- 211
- 212 if rep2[3].lower() == ":!mode" and trusted:
- 213 try:
- 214 IRC.send("MODE %s %s %s\r\n" % (rep2[4], rep2[5], rep2[6]))
- 215 except IndexError:
- 216 IRC.send("MODE %s %s %s\r\n" % (rep2[2], rep2[4], rep2[5]))
- 217
- 218 if (rep2[3].lower() == ":!modechan" or rep2[3].lower() == ":!cmode") and trusted:
- 219 try:
- 220 IRC.send("MODE %s %s\r\n" % (rep2[4], rep2[5]))
- 221 except IndexError:
- 222 IRC.send("MODE %s %s\r\n" % (rep2[2], rep2[4]))
- 223
- 224 if rep2[3].lower() == ":!news" or rep2[3].lower() == ":!wikinews":
- 225 IRC.send("PRIVMSG %s :%s\r\n" % (rep2[2], "http://" + rep2[4] + ".wikinews.org/wiki/" + "_".join(rep2[5:])))
- 226
- 227 if rep2[3].lower() == ":!nick" and trusted: #This command changes bot's nickname
- 228 IRC.send("NICK %s\r\n" % rep2[4])
- 229
- 230 if rep2[3].lower() == ":!op" and trusted:
- 231 try:
- 232 IRC.send("MODE %s +o %s\r\n" % (rep2[4], rep2[5]))
- 233 except IndexError:
- 234 IRC.send("MODE %s +o %s\r\n" % (rep2[2], rep2[4]))
- 235
- 236 if rep2[3].lower() == ":!part" or rep2[3].lower() == ":!quit":
- 237 IRC.send("PART %s\r\n" % rep2[4])
- 238
- 239 if rep2[3].lower() == ":!plagium":
- 240 IRC.send("PRIVMSG %s :%s\r\n" % (rep2[2], "http://www.plagium.com/detecteurdeplagiat.cfm"))
- 241
- 242 if rep2[3].lower() == ":!quiet" and trusted:
- 243 try:
- 244 IRC.send("MODE %s +q %s\r\n" % (rep2[4], rep2[5]))
- 245 except IndexError:
- 246 IRC.send("MODE %s +q %s\r\n" % (rep2[2], rep2[4]))
- 247
- 248 if rep2[3].lower() == ":!trustlist": #This command show the trust users (" ".join(trust)).
- 249 IRC.send("PRIVMSG %s :%s\r\n" % (rep2[2], " ".join(trust)))
- 250
- 251 if rep2[3].lower() == ":!unban" and trusted:
- 252 try:
- 253 IRC.send("MODE %s -b %s\r\n" % (rep2[4], rep2[5]))
- 254 except IndexError:
- 255 IRC.send("MODE %s -b %s\r\n" % (rep2[2], rep2[4]))
- 256
- 257 if rep2[3].lower() == ":!unquiet" and trusted:
- 258 try:
- 259 IRC.send("MODE %s -q %s\r\n" % (rep2[4], rep2[5]))
- 260 except IndexError:
- 261 IRC.send("MODE %s -q %s\r\n" % (rep2[2], rep2[4]))
- 262
- 263 if rep2[3].lower() == ":!version" or rep2[3].lower() == ":!ver":
- 264 IRC.send("PRIVMSG %s :%s\r\n" % (rep2[2], ver + " LifeBot version : " + ver_LifeBot + " " + lang_LifeBot))
- 265
- 266 if rep2[3].lower() == ":!viki" or rep2[3].lower() == ":!vikidia" or rep2[3].lower() == ":!vk":
- 267 IRC.send("PRIVMSG %s :%s\r\n" % (rep2[2], "http://" + rep2[4] + ".vikidia.org/wiki/" + "_".join(rep2[5:])))
- 268
- 269 if rep2[3].lower() == ":!voice" and trusted:
- 270 try:
- 271 IRC.send("MODE %s +v %s\r\n" % (rep2[4], rep2[5]))
- 272 except IndexError:
- 273 IRC.send("MODE %s +v %s\r\n" % (rep2[2], rep2[4]))
- 274
- 275 if rep2[3].lower() == ":!wmini":
- 276 IRC.send("PRIVMSG %s :%s\r\n" % (rep2[2], "http://fr.wikimini.org/wiki/" + "_".join(rep2[4:])))
- 277
- 278 if rep2[3].lower() == ":!wp" or rep2[3].lower() == ":!wikipedia":
- 279 IRC.send("PRIVMSG %s :%s\r\n" % (rep2[2], "http://" + rep2[4] + ".wikipedia.org/wiki/" + "_".join(rep2[5:])))
- 280 #End of non-functionnal-in-PM commands.
- 281 #Beginning of PM and chan functionnal commands.
- 282 if user_bot.lower() + " is cool" in " ".join(rep2[3:]).lower() or "he is cool " + user_bot.lower() in " ".join(rep2[3:]).lower(): # Here, the bot can answer to sentences, for example saying "LifeBot is cool" or "He is cool LifeBot", the bot will answer "Thanks, you are also cool ! :)".
- 283 IRC.send("PRIVMSG %s :%s\r\n" % (rep2[2], "Thanks, you are also cool ! :)"))
- 284 #End of PM and chan functionnal commands.
- 285 #Do not edit after this line unless you know Python.
- 286 except IndexError:
- 287 IRC.send("PRIVMSG %s :%s\r\n" % (rep2[2], "You have not enter the parameters required."))
- 288
- 289 #Don't forget testing and saving ! In case of problem, give us your variant's code on #SkyGen-help !
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement