Advertisement
Guest User

Untitled

a guest
Aug 30th, 2016
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 17.37 KB | None | 0 0
  1. # -*- coding: utf-8  -*-
  2. 2
  3.  
  4. 3 # You may read that if you created or edited the bot's commands and that you want to update it:
  5. 4 # 1) Copy your commands (not the default commands) that you've created from your old version to the new one.
  6. 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.
  7. 6
  8.  
  9. 7 import socket, time, urllib, webbrowser #Imports, do not edit unless you know Python.
  10. 8
  11.  
  12. 9 chan = "#SkyGen"
  13. 10 #What's in the inverted commas is the channel where the bot will come.
  14. 11 user_bot = "LifeBot16"
  15. 12 #There you have the bot's username (when he will connect to IRC).
  16. 13 ver = "LifeBot, variant of "
  17. 14 #This is the version-name of your bot ! After 'Variant of', add your pseudo !
  18. 15 host = "irc.freenode.net"
  19. 16 #The bot connects himself thanks to what's in the inverted commas (close to 'host').
  20. 17 port = 6667
  21. 18 #The port of IRC network.
  22. 19 restricted = True
  23. 20 #Security: some commands can only be used by certains users if True.
  24. 21 trust = ["User 1", "User 2"]
  25. 22 #The users who are able to use these commands.
  26. 23
  27.  
  28. 24 #Beginning of the connection, do not edit unless you know Python.
  29. 25 #LifeBot's version:
  30. 26 ver_LifeBot = "1.6.0"
  31. 27 lang_LifeBot = "en"
  32. 28 print(ver)
  33. 29 #Password:
  34. 30 password = raw_input("Bot's IRC password (if exists, if not let it blank) : ")
  35. 31 #Connection to IRC:
  36. 32 identify = False
  37. 33 IRC = socket.socket()
  38. 34 IRC.connect((host, port))
  39. 35 IRC.send("NICK %s\r\n" % user_bot)
  40. 36 IRC.send("USER LifeBot %s bla :%s\r\n" % (host, user_bot))
  41. 37 #Connection loop:
  42. 38 while True:
  43. 39     rep = IRC.recv(2048)
  44. 40     rep2 = rep.split()
  45. 41     print(rep)
  46. 42 #
  47. 43     try:
  48. 44         if ":Nickname is already in use." in rep and not identify:
  49. 45             user_bot = user_bot + "_"
  50. 46             IRC.send("NICK %s\r\n" % user_bot)
  51. 47         if ":End of /MOTD command." in rep and not identify:
  52. 48             IRC.send("PRIVMSG NickServ :identify %s\r\n" % password)
  53. 49             IRC.send("JOIN %s\r\n" % chan)
  54. 50             identify = True
  55. 51 #Answer to the IRC network's ping :
  56. 52         if rep2[0] == "PING":
  57. 53             IRC.send("PONG %s\r\n" % rep2[1])
  58. 54 #Answer to the bot's invitations :
  59. 55         if rep2[1] == "INVITE":
  60. 56             IRC.send("JOIN %s\r\n" % rep2[3])
  61. 57     except IndexError:
  62. 58         rep2 = ["", "", "", "", "", "", "", "", "", ""]
  63. 59 #
  64. 60     user = rep2[0].split("!")
  65. 61     user[0] = user[0].strip(":")
  66. 62     if not restricted:
  67. 63         trusted = True
  68. 64     elif identify and user[0] in trust:
  69. 65         IRC.send("PRIVMSG NickServ :info %s\r\n" % user[0])
  70. 66         IRC.settimeout(1)
  71. 67         while True:
  72. 68             try:
  73. 69                 if "Last seen  : now" in IRC.recv(2048):
  74. 70                     IRC.settimeout(None)
  75. 71                     trusted = True
  76. 72                     break
  77. 73             except socket.timeout:
  78. 74                 IRC.settimeout(None)
  79. 75                 trusted = False
  80. 76                 break
  81. 77     else:
  82. 78         trusted = False
  83. 79
  84.  
  85. 80     if rep2[1] == "PRIVMSG":
  86. 81         try:
  87. 82             if not rep2[2].startswith("#"):
  88. 83                 rep2[2] = user[0]
  89. 84 #End of the connection.
  90. 85 #Beggining of the commands. Only functionnal in PM.
  91. 86                 if rep2[3].lower() == ":!identify" and trusted:
  92. 87                     try:
  93. 88                         IRC.send("PRIVMSG NickServ :identify %s %s\r\n" % (rep2[4], rep2[5]))
  94. 89                     except IndexError:
  95. 90                         IRC.send("PRIVMSG NickServ :identify %s\r\n" % rep2[4])
  96. 91 #End of the only-functionnal-in-PM commands.
  97. 92             else: #Don't add something here.
  98. 93 #Beginning  of the non-functionnal-in-PM commands.
  99. 94 #Beginning of the syntax.
  100. 95                 if rep2[3].lower() == ":!commandtest":
  101. 96                     IRC.send("PRIVMSG %s :%s\r\n" % (rep2[2], "Text to send."))
  102. 97 #End of the syntax.
  103. 98 #Follow this syntax when you want to add a command. Need help ? Ask on #SkyGen !
  104. 99
  105.  
  106. 100                 if rep2[3].lower() == ":!ban" and trusted: #Here, we've got a command which bans a user from a chan.
  107. 101                     try:
  108. 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)
  109. 103                     except IndexError: #If we don't precise the chan (example, if we type !ban user)
  110. 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)
  111. 105
  112.  
  113. 106                 if rep2[3].lower() == ":!bing":
  114. 107                     IRC.send("PRIVMSG %s :%s\r\n" % (rep2[2], "http://www.bing.com/search?q=" + "+".join(rep2[4:])))
  115. 108
  116.  
  117. 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.
  118. 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.
  119. 111
  120.  
  121. 112                 if (rep2[3].lower() == ":!chanserv_access" or rep2[3].lower() == ":!cs_access") and trusted:
  122. 113                     try:
  123. 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.
  124. 115                     except IndexError:
  125. 116                         IRC.send("PRIVMSG ChanServ :access %s add %s %s\r\n" % (rep2[2], rep2[4], rep2[5]))
  126. 117
  127.  
  128. 118                 if (rep2[3].lower() == ":!chanserv_access_del" or rep2[3].lower() == ":!cs_access_del") and trusted:
  129. 119                     try:
  130. 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.
  131. 121                     except IndexError:
  132. 122                         IRC.send("PRIVMSG ChanServ :access %s del %s\r\n" % (rep2[2], rep2[4]))
  133. 123
  134.  
  135. 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.
  136. 125                     try:
  137. 126                         IRC.send("PRIVMSG ChanServ :akick %s add %s\r\n" % (rep2[4], rep2[5]))
  138. 127                     except IndexError:
  139. 128                         IRC.send("PRIVMSG ChanServ :akick %s add %s\r\n" % (rep2[2], rep2[4]))
  140. 129
  141.  
  142. 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.
  143. 131                     try:
  144. 132                         IRC.send("PRIVMSG ChanServ :akick %s del %s\r\n" % (rep2[4], rep2[5]))
  145. 133                     except IndexError:
  146. 134                         IRC.send("PRIVMSG ChanServ :akick %s del %s\r\n" % (rep2[2], rep2[4]))
  147. 135
  148.  
  149. 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.
  150. 137                     try:
  151. 138                         IRC.send("PRIVMSG ChanServ :deop %s %s\r\n" % (rep2[4], rep2[5]))
  152. 139                     except IndexError:
  153. 140                         IRC.send("PRIVMSG ChanServ :deop %s %s\r\n" % (rep2[2], rep2[4]))
  154. 141
  155.  
  156. 142                 if (rep2[3].lower() == ":!chanserv_devoice" or rep2[3].lower() == ":!cs_devoice") and trusted:
  157. 143                     try:
  158. 144                         IRC.send("PRIVMSG ChanServ :devoice %s %s\r\n" % (rep2[4], rep2[5]))
  159. 145                     except IndexError:
  160. 146                         IRC.send("PRIVMSG ChanServ :devoice %s %s\r\n" % (rep2[2], rep2[4]))
  161. 147
  162.  
  163. 148                 if (rep2[3].lower() == ":!chanserv_flags" or rep2[3].lower() == ":!cs_flags") and trusted:
  164. 149                     try:
  165. 150                         IRC.send("PRIVMSG ChanServ :flags %s %s %s\r\n" % (rep2[4], rep2[5], rep2[6]))
  166. 151                     except IndexError:
  167. 152                         IRC.send("PRIVMSG ChanServ :flags %s %s %s\r\n" % (rep2[2], rep2[4], rep2[5]))
  168. 153
  169.  
  170. 154                 if (rep2[3].lower() == ":!chanserv_op" or rep2[3].lower() == ":!cs_op") and trusted:
  171. 155                     try:
  172. 156                         IRC.send("PRIVMSG ChanServ :op %s %s\r\n" % (rep2[4], rep2[5]))
  173. 157                     except IndexError:
  174. 158                         IRC.send("PRIVMSG ChanServ :op %s %s\r\n" % (rep2[2], rep2[4]))
  175. 159
  176.  
  177. 160                 if (rep2[3].lower() == ":!chanserv_voice" or rep2[3].lower() == ":!cs_voice") and trusted:
  178. 161                     try:
  179. 162                         IRC.send("PRIVMSG ChanServ :voice %s %s\r\n" % (rep2[4], rep2[5]))
  180. 163                     except IndexError:
  181. 164                         IRC.send("PRIVMSG ChanServ :voice %s %s\r\n" % (rep2[2], rep2[4]))
  182. 165
  183.  
  184. 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)
  185. 167                     try:
  186. 168                         IRC.send("MODE %s -o %s\r\n" % (rep2[4], rep2[5]))
  187. 169                     except IndexError:
  188. 170                         IRC.send("MODE %s -o %s\r\n" % (rep2[2], rep2[4]))
  189. 171
  190.  
  191. 172                 if rep2[3].lower() == ":!devoice" and trusted:
  192. 173                     try:
  193. 174                         IRC.send("MODE %s -v %s\r\n" % (rep2[4], rep2[5]))
  194. 175                     except IndexError:
  195. 176                         IRC.send("MODE %s -v %s\r\n" % (rep2[2], rep2[4]))
  196. 177
  197.  
  198. 178                 if rep2[3].lower() == ":!flood":
  199. 179                     IRC.send("PRIVMSG %s :%s\r\n" % (rep2[2], "The flood is forbidden. You are incuring severe sanctions."))
  200. 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".
  201. 181
  202.  
  203. 182                 if rep2[3].lower() == ":!google":
  204. 183                     IRC.send("PRIVMSG %s :%s\r\n" % (rep2[2], "https://www.google.com/#q=" + "+".join(rep2[4:])))
  205. 184
  206.  
  207. 185                 if rep2[3].lower() == ":!help" or rep2[3].lower() == ":!aide":
  208. 186                     IRC.send("PRIVMSG %s :%s\r\n" % (rep2[2], "http://skygen.alwaysdata.net/" + lang_LifeBot + "/LifeBot/"))
  209. 187
  210.  
  211. 188                 if rep2[3].lower() == ":!ip":
  212. 189                     IRC.send("PRIVMSG %s :%s\r\n" % (rep2[2], "https://whatismyipaddress.com/ip/" + rep2[4]))
  213. 190
  214.  
  215. 191                 if rep2[3].lower() == ":!join":
  216. 192                     IRC.send("JOIN %s\r\n" % rep2[4])
  217. 193
  218.  
  219. 194                 if rep2[3].lower() == ":!kick" and trusted:
  220. 195                     if " ".join(rep2[5:]) != "":
  221. 196                         IRC.send("KICK %s %s :%s\r\n" % (rep2[2], rep2[4], " ".join(rep2[5:])))
  222. 197                     else:
  223. 198                         IRC.send("KICK %s %s\r\n" % (rep2[2], rep2[4]))
  224. 199
  225.  
  226. 200                 if rep2[3].lower() == ":!kickban" and trusted:
  227. 201                     if " ".join(rep2[5:]) != "":
  228. 202                         IRC.send("KICK %s %s :%s\r\n" % (rep2[2], rep2[4], " ".join(rep2[5:])))
  229. 203                     else:
  230. 204                         IRC.send("KICK %s %s\r\n" % (rep2[2], rep2[4]))
  231. 205                     IRC.send("MODE %s +b %s\r\n" % (rep2[2], rep2[4]))
  232. 206
  233.  
  234. 207                 if rep2[3].lower() == ":!love":
  235. 208                     IRC.send("PRIVMSG %s :%s\r\n" % (rep2[2], "I don't love you."))
  236. 209                     IRC.send("PRIVMSG %s :%s\r\n" % (rep2[2], "But no, I love you sometimes."))
  237. 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).
  238. 211
  239.  
  240. 212                 if rep2[3].lower() == ":!mode" and trusted:
  241. 213                     try:
  242. 214                         IRC.send("MODE %s %s %s\r\n" % (rep2[4], rep2[5], rep2[6]))
  243. 215                     except IndexError:
  244. 216                         IRC.send("MODE %s %s %s\r\n" % (rep2[2], rep2[4], rep2[5]))
  245. 217
  246.  
  247. 218                 if (rep2[3].lower() == ":!modechan" or rep2[3].lower() == ":!cmode") and trusted:
  248. 219                     try:
  249. 220                         IRC.send("MODE %s %s\r\n" % (rep2[4], rep2[5]))
  250. 221                     except IndexError:
  251. 222                         IRC.send("MODE %s %s\r\n" % (rep2[2], rep2[4]))
  252. 223
  253.  
  254. 224                 if rep2[3].lower() == ":!news" or rep2[3].lower() == ":!wikinews":
  255. 225                     IRC.send("PRIVMSG %s :%s\r\n" % (rep2[2], "http://" + rep2[4] + ".wikinews.org/wiki/" + "_".join(rep2[5:])))
  256. 226
  257.  
  258. 227                 if rep2[3].lower() == ":!nick" and trusted: #This command changes bot's nickname
  259. 228                     IRC.send("NICK %s\r\n" % rep2[4])
  260. 229
  261.  
  262. 230                 if rep2[3].lower() == ":!op" and trusted:
  263. 231                     try:
  264. 232                         IRC.send("MODE %s +o %s\r\n" % (rep2[4], rep2[5]))
  265. 233                     except IndexError:
  266. 234                         IRC.send("MODE %s +o %s\r\n" % (rep2[2], rep2[4]))
  267. 235
  268.  
  269. 236                 if rep2[3].lower() == ":!part" or rep2[3].lower() == ":!quit":
  270. 237                     IRC.send("PART %s\r\n" % rep2[4])
  271. 238
  272.  
  273. 239                 if rep2[3].lower() == ":!plagium":
  274. 240                     IRC.send("PRIVMSG %s :%s\r\n" % (rep2[2], "http://www.plagium.com/detecteurdeplagiat.cfm"))
  275. 241
  276.  
  277. 242                 if rep2[3].lower() == ":!quiet" and trusted:
  278. 243                     try:
  279. 244                         IRC.send("MODE %s +q %s\r\n" % (rep2[4], rep2[5]))
  280. 245                     except IndexError:
  281. 246                         IRC.send("MODE %s +q %s\r\n" % (rep2[2], rep2[4]))
  282. 247
  283.  
  284. 248                 if rep2[3].lower() == ":!trustlist": #This command show the trust users (" ".join(trust)).
  285. 249                     IRC.send("PRIVMSG %s :%s\r\n" % (rep2[2], " ".join(trust)))
  286. 250
  287.  
  288. 251                 if rep2[3].lower() == ":!unban" and trusted:
  289. 252                     try:
  290. 253                         IRC.send("MODE %s -b %s\r\n" % (rep2[4], rep2[5]))
  291. 254                     except IndexError:
  292. 255                         IRC.send("MODE %s -b %s\r\n" % (rep2[2], rep2[4]))
  293. 256
  294.  
  295. 257                 if rep2[3].lower() == ":!unquiet" and trusted:
  296. 258                     try:
  297. 259                         IRC.send("MODE %s -q %s\r\n" % (rep2[4], rep2[5]))
  298. 260                     except IndexError:
  299. 261                         IRC.send("MODE %s -q %s\r\n" % (rep2[2], rep2[4]))
  300. 262
  301.  
  302. 263                 if rep2[3].lower() == ":!version" or rep2[3].lower() == ":!ver":
  303. 264                     IRC.send("PRIVMSG %s :%s\r\n" % (rep2[2], ver + " LifeBot version : " + ver_LifeBot + " " + lang_LifeBot))
  304. 265
  305.  
  306. 266                 if rep2[3].lower() == ":!viki" or rep2[3].lower() == ":!vikidia" or rep2[3].lower() == ":!vk":
  307. 267                     IRC.send("PRIVMSG %s :%s\r\n" % (rep2[2], "http://" + rep2[4] + ".vikidia.org/wiki/" + "_".join(rep2[5:])))
  308. 268
  309.  
  310. 269                 if rep2[3].lower() == ":!voice" and trusted:
  311. 270                     try:
  312. 271                         IRC.send("MODE %s +v %s\r\n" % (rep2[4], rep2[5]))
  313. 272                     except IndexError:
  314. 273                         IRC.send("MODE %s +v %s\r\n" % (rep2[2], rep2[4]))
  315. 274
  316.  
  317. 275                 if rep2[3].lower() == ":!wmini":
  318. 276                     IRC.send("PRIVMSG %s :%s\r\n" % (rep2[2], "http://fr.wikimini.org/wiki/" + "_".join(rep2[4:])))
  319. 277
  320.  
  321. 278                 if rep2[3].lower() == ":!wp" or rep2[3].lower() == ":!wikipedia":
  322. 279                     IRC.send("PRIVMSG %s :%s\r\n" % (rep2[2], "http://" + rep2[4] + ".wikipedia.org/wiki/" + "_".join(rep2[5:])))
  323. 280 #End of non-functionnal-in-PM commands.
  324. 281 #Beginning of PM and chan functionnal commands.
  325. 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 ! :)".
  326. 283                 IRC.send("PRIVMSG %s :%s\r\n" % (rep2[2], "Thanks, you are also cool ! :)"))
  327. 284 #End of PM and chan functionnal commands.
  328. 285 #Do not edit after this line unless you know Python.
  329. 286         except IndexError:
  330. 287             IRC.send("PRIVMSG %s :%s\r\n" % (rep2[2], "You have not enter the parameters required."))
  331. 288
  332.  
  333. 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