Skip to content

Commit

Permalink
Added better auth support, removed multi-channel support because it w…
Browse files Browse the repository at this point in the history
…as irritating me.
  • Loading branch information
AClockWorkLemon committed Aug 11, 2012
1 parent 578552c commit 8965eef
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 51 deletions.
32 changes: 20 additions & 12 deletions src/Main.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,6 @@
from Interface import *
from importlib import import_module

# constants are here temporarily
# maybe move to a config file in the future

class Message:
OTHER = 0
CHANNEL = 1
Expand All @@ -32,7 +29,7 @@ class Message:
def __init__(self, message=None):
if message:
prefix = ''
trailing = []
trailing = ''

if not message:
raise Exception("Empty line.")
Expand All @@ -51,10 +48,9 @@ def __init__(self, message=None):
self.command = args.pop(0)
if len(args) == 1:
self.channel = ""
self.body = " ".join(args)
else:
self.channel = args.pop(0)
self.body = " ".join(args)
self.body = trailing if trailing else " ".join(args)

#split the prefix
if '!' in prefix:
Expand Down Expand Up @@ -159,6 +155,7 @@ def run(self):
else:
# Create message object
try:
#print msg
msg_obj = Message(msg)
self.controller.incoming_message(msg_obj)
except Exception as e:#Exception as e:
Expand Down Expand Up @@ -210,15 +207,15 @@ def __init__(self, sl, gui, config):
self.sl.controller = self
self.gui.controller = self

# List of channels we are on
self.channels = [self.config['server']['channel']]

#initiate the plugin system
self.plugins = PluginHandler(self)

#initiate the buffer that the GUI will poll for updates
self.buffer = []

self.admins = []
self.ops = []
self.voiced = []


self._should_die = False
Expand Down Expand Up @@ -248,8 +245,20 @@ def outgoing_message(self, msg):
self.sl.send_message(msg)
self.buffer.append(msg) #add the message to the buffer

def is_admin(self, nick):
return True if nick in self.config['config']['admins'].split() else False
def is_admin(self, nick, announce=True):
r = True if nick in self.admins else False
if not r and announce: self.notice(nick, "Only admins can use that command")
return r

def is_op(self, nick, announce=True):
r = True if nick in self.ops or nick in self.admins else False
if not r and announce: self.notice(nick, "Only ops and admins can use that command")
return r

def is_voiced(self, nick, announce=True):
r = True if nick in self.voiced or nick in self.ops or nick in self.admins else False
if not r and announce: self.notice(nick, "Only voiced users, ops and admins can use that command")
return r

def notice(self, target, message, ctcp=''):
msg = Message()
Expand Down Expand Up @@ -305,7 +314,6 @@ def register(self, msg=None):
"Reloads all plugins. Admin only."

if msg and not self.controller.is_admin(msg.nick):
self.controller.notice(msg.nick, "You are not permitted to use this command.")
return

self.triggers = {}
Expand Down
51 changes: 51 additions & 0 deletions src/Plugins/authtools.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@

class Plugin:
def __init__(self, controller):
self.c = controller

self.op_chars = '@'
self.voice_chars = '+'

def on_incoming(self, msg):
if msg.command == '353':
nicks = msg.body.split()
for nick in nicks:
if nick[0] in self.op_chars:
self.c.ops.append(nick[1:])
elif nick[0] in self.voice_chars:
self.c.voiced.append(nick[1:])

elif msg.command == msg.MODE:
if msg.body[1] in 'vo':
mode, nick = msg.body.split()
l = self.c.ops if mode[1] == 'o' else self.c.voiced
if mode[0] == '-':
l.remove(nick)
elif mode[0] == '+':
l.append(nick)

elif msg.command == msg.NOTICE and msg.nick == "NickServ":
args = msg.body.split()
if args[2] in self.c.sl.config['config']['admins'] and args[4] == '3':
self.c.admins.append(args[0])
self.c.notice(args[0], "You have been added as an admin.")
else:
self.c.notice(args[0], "You are not an admin.")

elif msg.command == msg.NICK:
if msg.nick in self.c.admins:
self.c.admins.remove(msg.nick)
self.c.notice(msg.body, "Nickname change detected. Please reauth.")
elif msg.body in self.c.admins:
self.c.admins.remove(msg.body)
self.c.notice(msg.body, "Nickname change detected. Please reauth.")
print self.c.admins



def trigger_auth(self, msg):
"Checks with NickServ, then adds you to admins list."
if msg.nick in self.c.admins:
self.c.notice(msg.nick, "You are already an admin.")
return
self.c.privmsg("NickServ", "ACC %s *"%msg.nick)
37 changes: 0 additions & 37 deletions src/Plugins/chantools.py

This file was deleted.

4 changes: 2 additions & 2 deletions src/Plugins/uno.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ def start(self, msg):
self.timer = 2

def stop(self, msg):
if not (self.c.is_admin(msg.nick) or msg.nick == self.start_player):
if not (self.c.is_op(msg.nick, False) or msg.nick == self.start_player):
self.c.notice(msg.nick, "Only bot admins and the start player can stop a game.")
return
elif self.mode == self.INACTIVE:
Expand Down Expand Up @@ -232,7 +232,7 @@ def timer_60(self):
self._begin()

def skip(self, msg):
if not (self.c.is_admin(msg.nick) or msg.nick == self.start_player):
if not (self.c.is_op(msg.nick, False) or msg.nick == self.start_player):
self.c.notice(msg.nick, "Only bot admins and the start player can stop a game.")
return
if self.mode != self.JOINING:
Expand Down

0 comments on commit 8965eef

Please sign in to comment.