Permalink
Browse files

Added channel specific values + argument to setvar() and getvar(). Ad…

…ded setchvar() and getchvar() as aliases for channel specific variables.
  • Loading branch information...
1 parent 75a1bb0 commit a531265f47526f1ad62e12d0977763ef1379f097 @omnidan committed Aug 17, 2011
Showing with 18 additions and 2 deletions.
  1. +18 −2 irc.py
View
20 irc.py
@@ -229,17 +229,33 @@ def db_findone(self, collection, dict):
def db_find(self, collection, dict):
return collection.find(dict)
- def getvar(self, variable):
+ def getchvar(self, channel, variable):
+ self.getvar(variable, channel)
+
+ def setchvar(self, channel, variable, content):
+ self.setvar(variable, content, channel)
+
+ def getvar(self, variable, channel=None):
variable = variable.lower()
+ variable = re.sub("[^0-9a-z_]", "", variable)
+ if channel != None:
+ channel = channel.lower()
+ channel = re.sub("[^0-9a-z\#-]", "", channel)
+ variable = channel + "." + variable
col = self.db_open("iforcebot_vars")
rawresult = self.db_findone(col, {"var": variable})
if rawresult != None:
return rawresult["con"]
else:
return None
- def setvar(self, variable, content):
+ def setvar(self, variable, content, channel=None):
variable = variable.lower()
+ variable = re.sub("[^0-9a-z_]", "", variable)
+ if channel != None:
+ channel = channel.lower()
+ channel = re.sub("[^0-9a-z\#-]", "", channel)
+ variable = channel + "." + variable
col = self.db_open("iforcebot_vars")
self.db_update(col, {"var": variable}, {"$set": {"con": content}})

0 comments on commit a531265

Please sign in to comment.