Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # -*- coding: utf-8 -*-
- # You may read that if you created or edited the bot's commands and that you want to update it :
- # 1) Copy your commands (not the default commands) that you've created from your old version to the new one.
- # 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.
- import socket, time, urllib, webbrowser #Imports, do not edit unless you know Python.
- chan = "#SkyGen"
- # What's in the inverted commas is the channel where the bot will come.
- user_bot = "LifeBot16"
- # There you have the bot's username (when he will connect to IRC).
- ver = "LifeBot, variant of"
- #This is the version-name of your bot ! After 'Variant of', add your pseudo !
- host = "irc.freenode.net"
- #The bot connects himself thanks to what's in the inverted commas (close to 'host').
- port = 6667
- #The port of IRC network.
- restricted = True
- #Sécurity : some commands can only be used by certains users if True.
- trust = ["Utilisateur 1", "Utilisateur 2"]
- # The users who are able to use these commands.
- # Beginning of the connection, do not edit unless you know Python.
- # LifeBot's version :
- ver_LifeBot = "1.6.0-beta.1"
- lang_LifeBot = "en"
- print(ver)
- # Password :
- password = raw_input("Bot's IRC password (if exists, if not let it blank) : ")
- #to the IRC :
- identify = False
- IRC = socket.socket()
- IRC.connect((host, port))
- IRC.send("NICK %s\r\n" % user_bot)
- IRC.send("USER LifeBot %s bla :%s\r\n" % (host, user_bot))
- # Connection loop:
- while True:
- rep = IRC.recv(2048)
- rep2 = rep.split()
- print(rep)
- #
- try:
- if ":End of /MOTD command." in rep and not identify:
- IRC.send("PRIVMSG NickServ :identify %s\r\n" % password)
- IRC.send("JOIN %s\r\n" % chan)
- identify = True
- # Answer to the IRC network's ping :
- if rep2[0] == "PING":
- IRC.send("PONG %s\r\n" % rep2[1])
- # Answer to the bot's invitations :
- if rep2[1] == "INVITE":
- IRC.send("JOIN %s\r\n" % rep2[3])
- except IndexError:
- rep2 = ["", "", "", "", "", "", "", "", "", ""]
- #
- user = rep2[0].split("!")
- user[0] = user[0].strip(":")
- if not restricted:
- trusted = True
- elif identify and user[0] in trust:
- IRC.send("PRIVMSG NickServ :info %s\r\n" % user[0])
- IRC.settimeout(1)
- while True:
- try:
- if "Last seen : now" in IRC.recv(2048):
- IRC.settimeout(None)
- trusted = True
- break
- except socket.timeout:
- IRC.settimeout(None)
- trusted = False
- break
- else:
- trusted = False
- if rep2[1] == "PRIVMSG":
- try:
- if not rep2[2].startswith("#"):
- rep2[2] = user[0]
- # End of the connection.
- # Beggining of the commands. Only functionnal in PM.
- if rep2[3].lower() == ":!identify" and trusted:
- try:
- IRC.send("PRIVMSG NickServ :identify %s %s\r\n" % (rep2[4], rep2[5]))
- except IndexError:
- IRC.send("PRIVMSG NickServ :identify %s\r\n" % rep2[4])
- # End of the only-functionnal-in-PM commands.
- else: #Ne rien ajouter ici.
- # Beginning of the non-functionnal-in-PM commands.
- # Beginning of the syntax.
- if rep2[3].lower() == ":!commandtest":
- IRC.send("PRIVMSG %s :%s\r\n" % (rep2[2], "Texte à envoyer."))
- # End of the syntax.
- # Follow this syntax when you want to add a command. Need help ? Ask on #SkyGen !
- if rep2[3].lower() == ":!ban" and trusted: #Here, we've got a command which bans a user from a chan.
- try:
- 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)
- except IndexError: # If we don't precise the chan (example, if we type !ban user)
- 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)
- if rep2[3].lower() == ":!bing":
- IRC.send("PRIVMSG %s :%s\r\n" % (rep2[2], "http://www.bing.com/search?q=" + "+".join(rep2[4:])))
- 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.
- 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.
- if (rep2[3].lower() == ":!chanserv_access" or rep2[3].lower() == ":!cs_access") and trusted:
- try:
- 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.
- except IndexError:
- IRC.send("PRIVMSG ChanServ :access %s add %s %s\r\n" % (rep2[2], rep2[4], rep2[5]))
- if (rep2[3].lower() == ":!chanserv_access_del" or rep2[3].lower() == ":!cs_access_del") and trusted:
- try:
- 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.
- except IndexError:
- IRC.send("PRIVMSG ChanServ :access %s del %s\r\n" % (rep2[2], rep2[4]))
- 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.
- try:
- IRC.send("PRIVMSG ChanServ :akick %s add %s\r\n" % (rep2[4], rep2[5]))
- except IndexError:
- IRC.send("PRIVMSG ChanServ :akick %s add %s\r\n" % (rep2[2], rep2[4]))
- 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.
- try:
- IRC.send("PRIVMSG ChanServ :akick %s del %s\r\n" % (rep2[4], rep2[5]))
- except IndexError:
- IRC.send("PRIVMSG ChanServ :akick %s del %s\r\n" % (rep2[2], rep2[4]))
- 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.
- try:
- IRC.send("PRIVMSG ChanServ :deop %s %s\r\n" % (rep2[4], rep2[5]))
- except IndexError:
- IRC.send("PRIVMSG ChanServ :deop %s %s\r\n" % (rep2[2], rep2[4]))
- if (rep2[3].lower() == ":!chanserv_devoice" or rep2[3].lower() == ":!cs_devoice") and trusted:
- try:
- IRC.send("PRIVMSG ChanServ :devoice %s %s\r\n" % (rep2[4], rep2[5]))
- except IndexError:
- IRC.send("PRIVMSG ChanServ :devoice %s %s\r\n" % (rep2[2], rep2[4]))
- if (rep2[3].lower() == ":!chanserv_flags" or rep2[3].lower() == ":!cs_flags") and trusted:
- try:
- IRC.send("PRIVMSG ChanServ :flags %s %s %s\r\n" % (rep2[4], rep2[5], rep2[6]))
- except IndexError:
- IRC.send("PRIVMSG ChanServ :flags %s %s %s\r\n" % (rep2[2], rep2[4], rep2[5]))
- if (rep2[3].lower() == ":!chanserv_op" or rep2[3].lower() == ":!cs_op") and trusted:
- try:
- IRC.send("PRIVMSG ChanServ :op %s %s\r\n" % (rep2[4], rep2[5]))
- except IndexError:
- IRC.send("PRIVMSG ChanServ :op %s %s\r\n" % (rep2[2], rep2[4]))
- if (rep2[3].lower() == ":!chanserv_voice" or rep2[3].lower() == ":!cs_voice") and trusted:
- try:
- IRC.send("PRIVMSG ChanServ :voice %s %s\r\n" % (rep2[4], rep2[5]))
- except IndexError:
- IRC.send("PRIVMSG ChanServ :voice %s %s\r\n" % (rep2[2], rep2[4]))
- 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)
- try:
- IRC.send("MODE %s -o %s\r\n" % (rep2[4], rep2[5]))
- except IndexError:
- IRC.send("MODE %s -o %s\r\n" % (rep2[2], rep2[4]))
- if rep2[3].lower() == ":!devoice" and trusted:
- try:
- IRC.send("MODE %s -v %s\r\n" % (rep2[4], rep2[5]))
- except IndexError:
- IRC.send("MODE %s -v %s\r\n" % (rep2[2], rep2[4]))
- if rep2[3].lower() == ":!flood":
- IRC.send("PRIVMSG %s :%s\r\n" % (rep2[2], "The flood is forbidden. You are incuring severe sanctions."))
- # 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".
- if rep2[3].lower() == ":!google":
- IRC.send("PRIVMSG %s :%s\r\n" % (rep2[2], "https://www.google.com/#q=" + "+".join(rep2[4:])))
- if rep2[3].lower() == ":!help" or rep2[3].lower() == ":!aide":
- IRC.send("PRIVMSG %s :%s\r\n" % (rep2[2], "http://skygen.alwaysdata.net/" + lang_LifeBot + "/LifeBot/"))
- if rep2[3].lower() == ":!ip":
- IRC.send("PRIVMSG %s :%s\r\n" % (rep2[2], "https://whatismyipaddress.com/ip/" + rep2[4]))
- if rep2[3].lower() == ":!join":
- IRC.send("JOIN %s\r\n" % rep2[4])
- if rep2[3].lower() == ":!kick" and trusted:
- if " ".join(rep2[5:]) != "":
- IRC.send("KICK %s %s :%s\r\n" % (rep2[2], rep2[4], " ".join(rep2[5:])))
- else:
- IRC.send("KICK %s %s\r\n" % (rep2[2], rep2[4]))
- if rep2[3].lower() == ":!kickban" and trusted:
- if " ".join(rep2[5:]) != "":
- IRC.send("KICK %s %s :%s\r\n" % (rep2[2], rep2[4], " ".join(rep2[5:])))
- else:
- IRC.send("KICK %s %s\r\n" % (rep2[2], rep2[4]))
- IRC.send("MODE %s +b %s\r\n" % (rep2[2], rep2[4]))
- if rep2[3].lower() == ":!love":
- IRC.send("PRIVMSG %s :%s\r\n" % (rep2[2], "Moi aussi je t'aime...pas"))
- IRC.send("PRIVMSG %s :%s\r\n" % (rep2[2], "Mais non, je t'aime...parfois."))
- #Oh ! Have you seen how we make the bot answer with two distinct sentences ? If not, look at the sourcecode of "!love" (look below).
- if rep2[3].lower() == ":!mode" and trusted:
- try:
- IRC.send("MODE %s %s %s\r\n" % (rep2[4], rep2[5], rep2[6]))
- except IndexError:
- IRC.send("MODE %s %s %s\r\n" % (rep2[2], rep2[4], rep2[5]))
- if (rep2[3].lower() == ":!modechan" or rep2[3].lower() == ":!cmode") and trusted:
- try:
- IRC.send("MODE %s %s\r\n" % (rep2[4], rep2[5]))
- except IndexError:
- IRC.send("MODE %s %s\r\n" % (rep2[2], rep2[4]))
- if rep2[3].lower() == ":!news" or rep2[3].lower() == ":!wikinews":
- IRC.send("PRIVMSG %s :%s\r\n" % (rep2[2], "http://" + rep2[4] + ".wikinews.org/wiki/" + "_".join(rep2[5:])))
- if rep2[3].lower() == ":!nick" and trusted: # This command changes bot's nickname
- IRC.send("NICK %s\r\n" % rep2[4])
- if rep2[3].lower() == ":!op" and trusted:
- try:
- IRC.send("MODE %s +o %s\r\n" % (rep2[4], rep2[5]))
- except IndexError:
- IRC.send("MODE %s +o %s\r\n" % (rep2[2], rep2[4]))
- if rep2[3].lower() == ":!part" or rep2[3].lower() == ":!quit":
- IRC.send("PART %s\r\n" % rep2[4])
- if rep2[3].lower() == ":!plagium":
- IRC.send("PRIVMSG %s :%s\r\n" % (rep2[2], "http://www.plagium.com/detecteurdeplagiat.cfm"))
- if rep2[3].lower() == ":!quiet" and trusted:
- try:
- IRC.send("MODE %s +q %s\r\n" % (rep2[4], rep2[5]))
- except IndexError:
- IRC.send("MODE %s +q %s\r\n" % (rep2[2], rep2[4]))
- if rep2[3].lower() == ":!unban" and trusted:
- try:
- IRC.send("MODE %s -b %s\r\n" % (rep2[4], rep2[5]))
- except IndexError:
- IRC.send("MODE %s -b %s\r\n" % (rep2[2], rep2[4]))
- if rep2[3].lower() == ":!unquiet" and trusted:
- try:
- IRC.send("MODE %s -q %s\r\n" % (rep2[4], rep2[5]))
- except IndexError:
- IRC.send("MODE %s -q %s\r\n" % (rep2[2], rep2[4]))
- if rep2[3].lower() == ":!version" or rep2[3].lower() == ":!ver":
- IRC.send("PRIVMSG %s :%s\r\n" % (rep2[2], ver + " LifeBot version : " + ver_LifeBot + " " + lang_LifeBot))
- if rep2[3].lower() == ":!viki" or rep2[3].lower() == ":!vikidia" or rep2[3].lower() == ":!vk":
- IRC.send("PRIVMSG %s :%s\r\n" % (rep2[2], "http://" + rep2[4] + ".vikidia.org/wiki/" + "_".join(rep2[5:])))
- if rep2[3].lower() == ":!voice" and trusted:
- try:
- IRC.send("MODE %s +v %s\r\n" % (rep2[4], rep2[5]))
- except IndexError:
- IRC.send("MODE %s +v %s\r\n" % (rep2[2], rep2[4]))
- if rep2[3].lower() == ":!wmini":
- IRC.send("PRIVMSG %s :%s\r\n" % (rep2[2], "http://fr.wikimini.org/wiki/" + "_".join(rep2[4:])))
- if rep2[3].lower() == ":!wp" or rep2[3].lower() == ":!wikipedia":
- IRC.send("PRIVMSG %s :%s\r\n" % (rep2[2], "http://" + rep2[4] + ".wikipedia.org/wiki/" + "_".join(rep2[5:])))
- # End of non-functionnal-in-PM commands.
- # Beginning of PM and chan functionnal commands.
- 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 ! :)".
- IRC.send("PRIVMSG %s :%s\r\n" % (rep2[2], "Thanks, you are also cool ! :)"))
- # End of PM and chan functionnal commands.
- #Do not edit after this line unless you know Python.
- except IndexError:
- IRC.send("PRIVMSG %s :%s\r\n" % (rep2[2], "Il manque des paramètres."))
- # 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