Advertisement
Guest User

Untitled

a guest
Jul 27th, 2017
44
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.64 KB | None | 0 0
  1. def handlePubmsg (connection, event):
  2.     opcmd = {'op':server.op,'deop':server.deop,'kick':server.kick,'ban':server.ban,'unban':server.unban} #dictionary with couples key:value where key=command and value = bound method of the object server
  3.     if event.arguments()[0][0] == "!": #if first char in the command is !
  4.         command = event.arguments()[0] #set some usefull vars
  5.         ident = irclib.nm_to_u(event.source()).lower()
  6.         chantarget = event.target()
  7.         nicktarget = command.split(" ")[1].lower()
  8.         key = command.split(" ")[0][1:].lower()
  9.         if len(command.split(" ")) == 2: #check if the command has the right sintax: !cmd target (where target is a valid target for the given command)
  10.             if opcmd.has_key(key):   #chek if the given command is present in my dictionary as a key
  11.                 ops = open("ops.txt", "r") #if so, open a file to check if the user is actually an operator, this will be improved another day
  12.                 while True:
  13.                     line = ops.readline().split('\n')[0].lower()
  14.                     if line == ident:                  
  15.                         opcmd[key](chantarget, nicktarget) #if the user is actually an operator i call the bound method passing the two needed arguments
  16.                         break
  17.                     elif line == "":
  18.                         server.privmsg(chan, "%s: you don't have enough power." % (event.source().split('!')[0]))
  19.                         break
  20.                 ops.close()
  21.             else:
  22.                 server.privmsg(chan, "%s: %s command not recognized" % (event.source().split('!')[0], command.split(" ")[0][1:]))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement