Skip to content

Instantly share code, notes, and snippets.

@Nnubes256
Created May 31, 2013 17:37
Show Gist options
  • Save Nnubes256/5686579 to your computer and use it in GitHub Desktop.
Save Nnubes256/5686579 to your computer and use it in GitHub Desktop.
Nnubes256/GuacaBot permissions system base(Python, by markveidemanis). Small bot base that I can use for make the base of the permissions system.
import socket
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect(("irc.freenode.net",6667))
user = "MasterBot"
admins = ["markveidemanis"]
grant = ["markveidemanis all"]
channel = "#mtmt"
message = "Hello!"
password = "_________________"
help = "Commands: !join, !part, !cmd, !op, !voice, !devoice, !kick, !nick, !add, !del, !addmod, !delmod, !ping, !identify, !quit, !msg, !help"
s.send("USER "+user+" "+user+" "+user+" "+user+"\n")
s.send("NICK "+user+"\n")
s.send("PRIVMSG NickServ :IDENTIFY "+user+" "+password+"\n")
#s.send("JOIN "+channel+"\n")
#s.send("PRIVMSG "+channel+" "+message+"\n")
while 1:
msg = s.recv (4096)
if printmsg == 1:
print (msg)
if msg.find("PING") != -1:
s.send("PONG "+msg.split()[1]+"\r\n")
elif msg.find ("PRIVMSG") != -1:
nick = msg.split ("!") [0].replace (":", "")
message = ":".join (msg.split(":") [2:])
target = "".join(msg.split(":")[:2]).split(' ')[-2]
if target == "PyIRC":
target = "PRIVATE"
print '(', target, ')', nick + ':', message
split = message.split()
def wordc(num):
if len(split) < num:
None
else:
return True
def auth():
if (nick+":"+split[0]) in grant:
return True
elif (nick+":all") in grant:
return True
elif nick in admins:
return True
else:
None
if split[0] == "!join" and auth() and wordc(2):
s.send("JOIN "+split[1]+"\n")
if split[0] == "!part" and auth() and wordc(2):
s.send("PART "+split[1]+"\n")
if split[0] == "!cmd" and auth():
message = message.replace("!cmd", "")
s.send(message+"\n")
if split[0] == "!op" and auth() and wordc(2):
s.send("PRIVMSG ChanServ :op "+target+" "+split[1]+"\n")
if split[0] == "!voice" and auth() and wordc(2):
s.send("PRIVMSG ChanServ :voice "+channel+" "+split[1]+"\n")
if split[0] == "!deop" and auth() and wordc(2):
s.send("PRIVMSG ChanServ :deop "+channel+" "+split[1]+"\n")
if split[0] == "!devoice" and auth() and wordc(2):
s.send("PRIVMSG ChanServ :devoice "+channel+" "+split[1]+"\n")
if split[0] == "!kick" and auth() and wordc(2):
s.send("KICK "+target+" "+split[1]+"\n")
if split[0] == "!nick" and auth() and wordc(2):
s.send("NICK "+split[1]+"\n")
if split[0] == "!add" and auth() and wordc(3):
grant.append(split[1]+":"+split[2])
s.send("PRIVMSG "+target+" "+split[1]+"\n")
if split[0] == "!del" and auth() and wordc(3):
grant.remove(split[1]+":"+split[2])
s.send("PRIVMSG "+target+" "+split[1]+"\n")
if split[0] == "!addmod" and auth() and wordc(2):
admins.append(split[1])
grant.append(nick+":all")
s.send("PRIVMSG "+target+" "+split[1]+"\n")
if split[0] == "!delmod" and auth() and wordc(2):
admins.remove(split[1])
grant.remove(nick+":all")
s.send("PRIVMSG "+target+" "+split[1]+"\n")
if split[0] == "!ping" and auth() and wordc(1):
s.send("PRIVMSG "+target+" "+"PONG"+"\n")
if split[0] == "!identify" and auth() and wordc(3):
s.send("PRIVMSG NickServ :IDENTIFY "+split[1]+" "+split[2]+"\n")
if split[0] == "!quit" and auth() and wordc(1):
s.send("QUIT"+"\n")
if split[0] == "!msg" and auth():
message = message.replace("!msg", "")
s.send("PRIVMSG "+message+"\n")
if split[0] == "!help" and auth():
s.send("PRIVMSG "+target+help+"\n")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment