Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
forgot modules folder, update to locker, proper @lock and @unlock
  • Loading branch information
Ferus committed Mar 16, 2012
1 parent adb5fef commit 97a03bd
Show file tree
Hide file tree
Showing 6 changed files with 379 additions and 15 deletions.
43 changes: 31 additions & 12 deletions Commands.py
Expand Up @@ -2,6 +2,7 @@

import re
import pluginLoader as pL
from Plugins import CommandLock

class Commands():
def __init__(self, nick=None, parser=None, allowed=None):
Expand All @@ -18,32 +19,36 @@ def __init__(self, nick=None, parser=None, allowed=None):
self.parser = parser
self.allowed = allowed

self.Locked = False
self.Locker = CommandLock.Locker(-1)

self.cmds = {"^@help": [self.Help, 5, False]
,"^@plugins": [self.Plugins, 5, False]
,"^@quit": [self.Quit, 0, True]
,"^@join": [self.Join, 3, True]
,"^@part": [self.Part, 3, True]
,"^@access": [self.Access, 0, True]
,"^@lock": [self.Lock, 0, True]
,"^@unlock": [self.Unlock, 0, True]
}

self.helpstrings = {
#@help alone will give a basic infostring showing how to use @help
#@help <ModuleName> will give specific info about a module.
"help" : """@help takes one argument, the name of a plugin in which you wish to get help for.
To get a list of loaded plugins, use '@plugins'
""",
"plugins" : "Notices the user with a list of plugins available. You can also '@help <PluginName>' for specific info",
"join" : "Tells {0} to join one or more channel(s). Takes channels separated by a comma with or without the leading hashtag.".format(self.nick),
"part" : "Tells {0} to part one or more channel(s). Takes channels separated by a comma with or without the leading hashtag.".format(self.nick),
"quit" : "Tells {0} to shutdown.".format(self.nick),
"access":"""Allows the owner(s) (Access level 0) to modify access levels per user/hostmask
The default level for ignore is anything above 5, but this can be changed.
add: Used to add/change access of a person. Takes 3 arguments, Nick, Host (or 'none'), and an Access Level.
del: Used to revoke access from a user. Takes 1 argument, Nick.
show: Used to print the access for a user to a channel. Takes 1 argument, Nick.
""",
"""
,"plugins" : "Notices the user with a list of plugins available. You can also '@help <PluginName>' for specific info"
,"join" : "Tells {0} to join one or more channel(s). Takes channels separated by a comma with or without the leading hashtag.".format(self.nick)
,"part" : "Tells {0} to part one or more channel(s). Takes channels separated by a comma with or without the leading hashtag.".format(self.nick)
,"quit" : "Tells {0} to shutdown.".format(self.nick)
,"access": """Allows the owner(s) (Access level 0) to modify access levels per user/hostmask
The default level for ignore is anything above 5, but this can be changed.
add: Used to add/change access of a person. Takes 3 arguments, Nick, Host (or 'none'), and an Access Level.
del: Used to revoke access from a user. Takes 1 argument, Nick.
show: Used to print the access for a user to a channel. Takes 1 argument, Nick.
"""
,"lock": "Locks all commands down to Owner access only."
,"unlock": "Unlocks all commands."
}

self.loadedplugins = []
Expand Down Expand Up @@ -159,3 +164,17 @@ def Access(self, msg, sock, users, _allowed):
except Exception, e:
sock.notice(Nick, "Format for 'access' is: `access add/del Nick Ident@host Level`")
print("* [Access] Error:\n* [Access] {0}".format(str(e)))

def Lock(self, msg, sock, users, _allowed):
if not self.Locker.Locked:
if self.Locker.Lock():
sock.say(msg[3], "Locking successful.")
else:
sock.notice(msg[0], "I'm already locked you derp.")

def Unlock(self, msg, sock, users, _allowed):
if self.Locker.Locked:
if not self.Locker.Unlock():
sock.say(msg[3], "Unlocking successful.")
else:
sock.notice(msg[0], "I'm already unlocked you derp.")
3 changes: 3 additions & 0 deletions Parser.py
Expand Up @@ -142,6 +142,9 @@ def Privmsg(self, msg):
and if they have access, execute the command. Regex based commands too. :)
'''
print(u"* [Privmsg] [{0}] <{1}> {2}".format(Location, Nick, Text))
if self.command.Locker.Locked and Nick != self.allowed.Owner[0]:
self.sock.notice(Nick, "Sorry but I'm locked bro.")
return None
for comm in self._commands: #Loop through every one.
if re.search(comm+u"(\s|$)", Text): #If we match a command
check = self.allowed.levelCheck(Nick)[1] #Start an access check
Expand Down
17 changes: 14 additions & 3 deletions Plugins/CommandLock.py
Expand Up @@ -15,6 +15,14 @@
Do_Something()
Locker.Lock()
'''

'''
Changelog:
March 15:
+ Negative integers lock forever until Unlock() is called, Zero defaults to 5.
+ Return self.Locked after calling.
'''

class Locker(object):
def __init__(self, Time=None):
self.Time = Time if Time and type(Time) == int else 5
Expand All @@ -24,9 +32,12 @@ def __init__(self, Time=None):
def Lock(self):
if not self.Locked:
self.Locked = True
t = Timer(self.Time, self.Unlock, ())
t.daemon = True
t.start()
if self.Time > 0:
t = Timer(self.Time, self.Unlock, ())
t.daemon = True
t.start()
return self.Locked

def Unlock(self):
self.Locked = False
return self.Locked

0 comments on commit 97a03bd

Please sign in to comment.