Advertisement
Guest User

LifeBot-en

a guest
Aug 25th, 2016
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 15.68 KB | None | 0 0
  1. # -*- 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. #Sécurity  : some commands can only be used by certains users if True.
  21. trust = ["Utilisateur 1", "Utilisateur 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-beta.1"
  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. #to the 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 ":End of /MOTD command." in rep and not identify:
  45.             IRC.send("PRIVMSG NickServ :identify %s\r\n" % password)
  46.             IRC.send("JOIN %s\r\n" % chan)
  47.             identify = True
  48. # Answer to the IRC network's ping :
  49.         if rep2[0] == "PING":
  50.             IRC.send("PONG %s\r\n" % rep2[1])
  51. # Answer to the bot's invitations :
  52.         if rep2[1] == "INVITE":
  53.             IRC.send("JOIN %s\r\n" % rep2[3])
  54.     except IndexError:
  55.         rep2 = ["", "", "", "", "", "", "", "", "", ""]
  56. #
  57.     user = rep2[0].split("!")
  58.     user[0] = user[0].strip(":")
  59.     if not restricted:
  60.         trusted = True
  61.     elif identify and user[0] in trust:
  62.         IRC.send("PRIVMSG NickServ :info %s\r\n" % user[0])
  63.         IRC.settimeout(1)
  64.         while True:
  65.             try:
  66.                 if "Last seen  : now" in IRC.recv(2048):
  67.                     IRC.settimeout(None)
  68.                     trusted = True
  69.                     break
  70.             except socket.timeout:
  71.                 IRC.settimeout(None)
  72.                 trusted = False
  73.                 break
  74.     else:
  75.         trusted = False
  76.  
  77.     if rep2[1] == "PRIVMSG":
  78.         try:
  79.             if not rep2[2].startswith("#"):
  80.                 rep2[2] = user[0]
  81. # End of the connection.
  82. # Beggining of the commands.  Only functionnal in PM.
  83.                 if rep2[3].lower() == ":!identify" and trusted:
  84.                     try:
  85.                         IRC.send("PRIVMSG NickServ :identify %s %s\r\n" % (rep2[4], rep2[5]))
  86.                     except IndexError:
  87.                         IRC.send("PRIVMSG NickServ :identify %s\r\n" % rep2[4])
  88. # End of the only-functionnal-in-PM commands.
  89.             else: #Ne rien ajouter ici.
  90. # Beginning  of the non-functionnal-in-PM commands.
  91. # Beginning of the syntax.
  92.                 if rep2[3].lower() == ":!commandtest":
  93.                     IRC.send("PRIVMSG %s :%s\r\n" % (rep2[2], "Texte à envoyer."))
  94. # End of the syntax.
  95. # Follow this syntax when you want to add a command. Need help ? Ask on #SkyGen !
  96.  
  97.                 if rep2[3].lower() == ":!ban" and trusted: #Here, we've got a command which bans a user from a chan.
  98.                     try:
  99.                         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)
  100.                     except IndexError: # If we don't precise the chan (example, if we type !ban user)
  101.                         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)
  102.  
  103.                 if rep2[3].lower() == ":!bing":
  104.                     IRC.send("PRIVMSG %s :%s\r\n" % (rep2[2], "http://www.bing.com/search?q=" + "+".join(rep2[4:])))
  105.  
  106.                 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.
  107.                     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.
  108.  
  109.                 if (rep2[3].lower() == ":!chanserv_access" or rep2[3].lower() == ":!cs_access") and trusted:
  110.                     try:
  111.                         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.
  112.                     except IndexError:
  113.                         IRC.send("PRIVMSG ChanServ :access %s add %s %s\r\n" % (rep2[2], rep2[4], rep2[5]))
  114.  
  115.                 if (rep2[3].lower() == ":!chanserv_access_del" or rep2[3].lower() == ":!cs_access_del") and trusted:
  116.                     try:
  117.                         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.
  118.                     except IndexError:
  119.                         IRC.send("PRIVMSG ChanServ :access %s del %s\r\n" % (rep2[2], rep2[4]))
  120.  
  121.                 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.
  122.                     try:
  123.                         IRC.send("PRIVMSG ChanServ :akick %s add %s\r\n" % (rep2[4], rep2[5]))
  124.                     except IndexError:
  125.                         IRC.send("PRIVMSG ChanServ :akick %s add %s\r\n" % (rep2[2], rep2[4]))
  126.  
  127.                 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.
  128.                     try:
  129.                         IRC.send("PRIVMSG ChanServ :akick %s del %s\r\n" % (rep2[4], rep2[5]))
  130.                     except IndexError:
  131.                         IRC.send("PRIVMSG ChanServ :akick %s del %s\r\n" % (rep2[2], rep2[4]))
  132.  
  133.                 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.
  134.                     try:
  135.                         IRC.send("PRIVMSG ChanServ :deop %s %s\r\n" % (rep2[4], rep2[5]))
  136.                     except IndexError:
  137.                         IRC.send("PRIVMSG ChanServ :deop %s %s\r\n" % (rep2[2], rep2[4]))
  138.  
  139.                 if (rep2[3].lower() == ":!chanserv_devoice" or rep2[3].lower() == ":!cs_devoice") and trusted:
  140.                     try:
  141.                         IRC.send("PRIVMSG ChanServ :devoice %s %s\r\n" % (rep2[4], rep2[5]))
  142.                     except IndexError:
  143.                         IRC.send("PRIVMSG ChanServ :devoice %s %s\r\n" % (rep2[2], rep2[4]))
  144.  
  145.                 if (rep2[3].lower() == ":!chanserv_flags" or rep2[3].lower() == ":!cs_flags") and trusted:
  146.                     try:
  147.                         IRC.send("PRIVMSG ChanServ :flags %s %s %s\r\n" % (rep2[4], rep2[5], rep2[6]))
  148.                     except IndexError:
  149.                         IRC.send("PRIVMSG ChanServ :flags %s %s %s\r\n" % (rep2[2], rep2[4], rep2[5]))
  150.  
  151.                 if (rep2[3].lower() == ":!chanserv_op" or rep2[3].lower() == ":!cs_op") and trusted:
  152.                     try:
  153.                         IRC.send("PRIVMSG ChanServ :op %s %s\r\n" % (rep2[4], rep2[5]))
  154.                     except IndexError:
  155.                         IRC.send("PRIVMSG ChanServ :op %s %s\r\n" % (rep2[2], rep2[4]))
  156.  
  157.                 if (rep2[3].lower() == ":!chanserv_voice" or rep2[3].lower() == ":!cs_voice") and trusted:
  158.                     try:
  159.                         IRC.send("PRIVMSG ChanServ :voice %s %s\r\n" % (rep2[4], rep2[5]))
  160.                     except IndexError:
  161.                         IRC.send("PRIVMSG ChanServ :voice %s %s\r\n" % (rep2[2], rep2[4]))
  162.  
  163.                 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)
  164.                     try:
  165.                         IRC.send("MODE %s -o %s\r\n" % (rep2[4], rep2[5]))
  166.                     except IndexError:
  167.                         IRC.send("MODE %s -o %s\r\n" % (rep2[2], rep2[4]))
  168.  
  169.                 if rep2[3].lower() == ":!devoice" and trusted:
  170.                     try:
  171.                         IRC.send("MODE %s -v %s\r\n" % (rep2[4], rep2[5]))
  172.                     except IndexError:
  173.                         IRC.send("MODE %s -v %s\r\n" % (rep2[2], rep2[4]))
  174.  
  175.                 if rep2[3].lower() == ":!flood":
  176.                     IRC.send("PRIVMSG %s :%s\r\n" % (rep2[2], "The flood is forbidden. You are incuring severe sanctions."))
  177. # 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".
  178.  
  179.                 if rep2[3].lower() == ":!google":
  180.                     IRC.send("PRIVMSG %s :%s\r\n" % (rep2[2], "https://www.google.com/#q=" + "+".join(rep2[4:])))
  181.  
  182.                 if rep2[3].lower() == ":!help" or rep2[3].lower() == ":!aide":
  183.                     IRC.send("PRIVMSG %s :%s\r\n" % (rep2[2], "http://skygen.alwaysdata.net/" + lang_LifeBot + "/LifeBot/"))
  184.  
  185.                 if rep2[3].lower() == ":!ip":
  186.                     IRC.send("PRIVMSG %s :%s\r\n" % (rep2[2], "https://whatismyipaddress.com/ip/" + rep2[4]))
  187.  
  188.                 if rep2[3].lower() == ":!join":
  189.                     IRC.send("JOIN %s\r\n" % rep2[4])
  190.  
  191.                 if rep2[3].lower() == ":!kick" and trusted:
  192.                     if " ".join(rep2[5:]) != "":
  193.                         IRC.send("KICK %s %s :%s\r\n" % (rep2[2], rep2[4], " ".join(rep2[5:])))
  194.                     else:
  195.                         IRC.send("KICK %s %s\r\n" % (rep2[2], rep2[4]))
  196.  
  197.                 if rep2[3].lower() == ":!kickban" and trusted:
  198.                     if " ".join(rep2[5:]) != "":
  199.                         IRC.send("KICK %s %s :%s\r\n" % (rep2[2], rep2[4], " ".join(rep2[5:])))
  200.                     else:
  201.                         IRC.send("KICK %s %s\r\n" % (rep2[2], rep2[4]))
  202.                     IRC.send("MODE %s +b %s\r\n" % (rep2[2], rep2[4]))
  203.  
  204.                 if rep2[3].lower() == ":!love":
  205.                     IRC.send("PRIVMSG %s :%s\r\n" % (rep2[2], "Moi aussi je t'aime...pas"))
  206.                     IRC.send("PRIVMSG %s :%s\r\n" % (rep2[2], "Mais non, je t'aime...parfois."))
  207. #Oh ! Have you seen how we make the bot answer with two distinct sentences ? If not, look at the sourcecode of "!love" (look below).
  208.  
  209.                 if rep2[3].lower() == ":!mode" and trusted:
  210.                     try:
  211.                         IRC.send("MODE %s %s %s\r\n" % (rep2[4], rep2[5], rep2[6]))
  212.                     except IndexError:
  213.                         IRC.send("MODE %s %s %s\r\n" % (rep2[2], rep2[4], rep2[5]))
  214.  
  215.                 if (rep2[3].lower() == ":!modechan" or rep2[3].lower() == ":!cmode") and trusted:
  216.                     try:
  217.                         IRC.send("MODE %s %s\r\n" % (rep2[4], rep2[5]))
  218.                     except IndexError:
  219.                         IRC.send("MODE %s %s\r\n" % (rep2[2], rep2[4]))
  220.  
  221.                 if rep2[3].lower() == ":!news" or rep2[3].lower() == ":!wikinews":
  222.                     IRC.send("PRIVMSG %s :%s\r\n" % (rep2[2], "http://" + rep2[4] + ".wikinews.org/wiki/" + "_".join(rep2[5:])))
  223.  
  224.                 if rep2[3].lower() == ":!nick" and trusted: # This command changes bot's nickname
  225.                     IRC.send("NICK %s\r\n" % rep2[4])
  226.  
  227.                 if rep2[3].lower() == ":!op" and trusted:
  228.                     try:
  229.                         IRC.send("MODE %s +o %s\r\n" % (rep2[4], rep2[5]))
  230.                     except IndexError:
  231.                         IRC.send("MODE %s +o %s\r\n" % (rep2[2], rep2[4]))
  232.  
  233.                 if rep2[3].lower() == ":!part" or rep2[3].lower() == ":!quit":
  234.                     IRC.send("PART %s\r\n" % rep2[4])
  235.  
  236.                 if rep2[3].lower() == ":!plagium":
  237.                     IRC.send("PRIVMSG %s :%s\r\n" % (rep2[2], "http://www.plagium.com/detecteurdeplagiat.cfm"))
  238.  
  239.                 if rep2[3].lower() == ":!quiet" and trusted:
  240.                     try:
  241.                         IRC.send("MODE %s +q %s\r\n" % (rep2[4], rep2[5]))
  242.                     except IndexError:
  243.                         IRC.send("MODE %s +q %s\r\n" % (rep2[2], rep2[4]))
  244.  
  245.                 if rep2[3].lower() == ":!unban" and trusted:
  246.                     try:
  247.                         IRC.send("MODE %s -b %s\r\n" % (rep2[4], rep2[5]))
  248.                     except IndexError:
  249.                         IRC.send("MODE %s -b %s\r\n" % (rep2[2], rep2[4]))
  250.  
  251.                 if rep2[3].lower() == ":!unquiet" and trusted:
  252.                     try:
  253.                         IRC.send("MODE %s -q %s\r\n" % (rep2[4], rep2[5]))
  254.                     except IndexError:
  255.                         IRC.send("MODE %s -q %s\r\n" % (rep2[2], rep2[4]))
  256.  
  257.                 if rep2[3].lower() == ":!version" or rep2[3].lower() == ":!ver":
  258.                     IRC.send("PRIVMSG %s :%s\r\n" % (rep2[2], ver + " LifeBot version : " + ver_LifeBot + " " + lang_LifeBot))
  259.  
  260.                 if rep2[3].lower() == ":!viki" or rep2[3].lower() == ":!vikidia" or rep2[3].lower() == ":!vk":
  261.                     IRC.send("PRIVMSG %s :%s\r\n" % (rep2[2], "http://" + rep2[4] + ".vikidia.org/wiki/" + "_".join(rep2[5:])))
  262.  
  263.                 if rep2[3].lower() == ":!voice" and trusted:
  264.                     try:
  265.                         IRC.send("MODE %s +v %s\r\n" % (rep2[4], rep2[5]))
  266.                     except IndexError:
  267.                         IRC.send("MODE %s +v %s\r\n" % (rep2[2], rep2[4]))
  268.  
  269.                 if rep2[3].lower() == ":!wmini":
  270.                     IRC.send("PRIVMSG %s :%s\r\n" % (rep2[2], "http://fr.wikimini.org/wiki/" + "_".join(rep2[4:])))
  271.  
  272.                 if rep2[3].lower() == ":!wp" or rep2[3].lower() == ":!wikipedia":
  273.                     IRC.send("PRIVMSG %s :%s\r\n" % (rep2[2], "http://" + rep2[4] + ".wikipedia.org/wiki/" + "_".join(rep2[5:])))
  274. # End of non-functionnal-in-PM commands.
  275. # Beginning of PM and chan functionnal commands.
  276.             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 ! :)".
  277.                 IRC.send("PRIVMSG %s :%s\r\n" % (rep2[2], "Thanks, you are also cool ! :)"))
  278. # End of PM and chan functionnal commands.
  279. #Do not edit after this line unless you know Python.
  280.         except IndexError:
  281.             IRC.send("PRIVMSG %s :%s\r\n" % (rep2[2], "Il manque des paramètres."))
  282.  
  283. # 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