Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/alkorgun/blacksmith-2.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlKorgun@gmail.com <AlKorgun@gmail.com@94c44753-77e5-68b8-8764-2ca2b8acb85e>2012-09-23 00:47:20 +0400
committerAlKorgun@gmail.com <AlKorgun@gmail.com@94c44753-77e5-68b8-8764-2ca2b8acb85e>2012-09-23 00:47:20 +0400
commit88db25c2373fffe86fa02042384a57f14289d5c7 (patch)
tree2d09d820ed27b54280356ebb71d7944b8dd492db
parent65267f5bb6afd00deb45015f51f07a6187bfc49e (diff)
!! not stable, be careful (all expansions have been rebuilt)
-rw-r--r--BlackSmith.py192
-rw-r--r--expansions/access/access.name4
-rw-r--r--expansions/access/acclist.name4
-rw-r--r--expansions/access/acclist2.name4
-rw-r--r--expansions/access/code.py336
-rw-r--r--expansions/access/gaccess.en6
-rw-r--r--expansions/access/gaccess.name4
-rw-r--r--expansions/access/gaccess.ru6
-rw-r--r--expansions/access/insc.py4
-rw-r--r--expansions/access/laccess.en6
-rw-r--r--expansions/access/laccess.name4
-rw-r--r--expansions/access/laccess.ru6
-rw-r--r--expansions/alive_keeper/code.py161
-rw-r--r--expansions/allweb/chuck.name4
-rw-r--r--expansions/allweb/code.py1135
-rw-r--r--expansions/allweb/currency.name4
-rw-r--r--expansions/allweb/gismeteo.name4
-rw-r--r--expansions/allweb/google.name4
-rw-r--r--expansions/allweb/imdb.name4
-rw-r--r--expansions/allweb/insc.py6
-rw-r--r--expansions/allweb/ithappens.name4
-rw-r--r--expansions/allweb/jc.name4
-rw-r--r--expansions/allweb/jquote.name4
-rw-r--r--expansions/allweb/kino.name4
-rw-r--r--expansions/allweb/python.name4
-rw-r--r--expansions/apocalypse/apocalypse.name4
-rw-r--r--expansions/apocalypse/code.py35
-rw-r--r--expansions/basic_control/code.py356
-rw-r--r--expansions/basic_control/exit.name4
-rw-r--r--expansions/basic_control/insc.py4
-rw-r--r--expansions/basic_control/join.name4
-rw-r--r--expansions/basic_control/leave.name4
-rw-r--r--expansions/basic_control/reconnect.name4
-rw-r--r--expansions/basic_control/rejoin.name4
-rw-r--r--expansions/basic_control/reload.name4
-rw-r--r--expansions/bot_sends/clear.name4
-rw-r--r--expansions/bot_sends/code.py266
-rw-r--r--expansions/bot_sends/insc.py4
-rw-r--r--expansions/bot_sends/invite.name4
-rw-r--r--expansions/bot_sends/more.name4
-rw-r--r--expansions/bot_sends/say.name4
-rw-r--r--expansions/bot_sends/send.name4
-rw-r--r--expansions/bot_sends/sendall.name4
-rw-r--r--expansions/bot_sends/test.name4
-rw-r--r--expansions/bot_sends/toadmin.name4
-rw-r--r--expansions/calendar/calendar.name4
-rw-r--r--expansions/calendar/code.py55
-rw-r--r--expansions/clear_stats/code.py49
-rw-r--r--expansions/config/client.name4
-rw-r--r--expansions/config/code.py412
-rw-r--r--expansions/config/config.name4
-rw-r--r--expansions/config/insc.py4
-rw-r--r--expansions/converter/code.py443
-rw-r--r--expansions/converter/convert.name4
-rw-r--r--expansions/converter/insc.py4
-rw-r--r--expansions/cron/code.py451
-rw-r--r--expansions/cron/cron.name4
-rw-r--r--expansions/cron/insc.py4
-rw-r--r--expansions/exp_control/code.py291
-rw-r--r--expansions/exp_control/command.name4
-rw-r--r--expansions/exp_control/expinfo.name4
-rw-r--r--expansions/exp_control/expload.name4
-rw-r--r--expansions/exp_control/expunload.en6
-rw-r--r--expansions/exp_control/expunload.name4
-rw-r--r--expansions/exp_control/expunload.ru6
-rw-r--r--expansions/exp_control/insc.py12
-rw-r--r--expansions/extra_control/code.py151
-rw-r--r--expansions/extra_control/private.name4
-rw-r--r--expansions/extra_control/remote.name4
-rw-r--r--expansions/game/code.py98
-rw-r--r--expansions/game/game.name4
-rw-r--r--expansions/game/insc.py12
-rw-r--r--expansions/get_iq/code.py412
-rw-r--r--expansions/get_iq/idle.name4
-rw-r--r--expansions/get_iq/insc.py4
-rw-r--r--expansions/get_iq/list.name4
-rw-r--r--expansions/get_iq/ping.name4
-rw-r--r--expansions/get_iq/pstat.en8
-rw-r--r--expansions/get_iq/pstat.name4
-rw-r--r--expansions/get_iq/pstat.ru8
-rw-r--r--expansions/get_iq/uptime.name4
-rw-r--r--expansions/get_iq/version.name4
-rw-r--r--expansions/help/code.py190
-rw-r--r--expansions/help/comacc.name4
-rw-r--r--expansions/help/commands.name4
-rw-r--r--expansions/help/help.name4
-rw-r--r--expansions/help/insc.py4
-rw-r--r--expansions/help/location.name4
-rw-r--r--expansions/info/chatslist.name4
-rw-r--r--expansions/info/code.py296
-rw-r--r--expansions/info/inmuc.name4
-rw-r--r--expansions/info/insc.py4
-rw-r--r--expansions/info/online.name4
-rw-r--r--expansions/info/search.name4
-rw-r--r--expansions/info/visitors.name4
-rw-r--r--expansions/interpreter/calc.name4
-rw-r--r--expansions/interpreter/code.py115
-rw-r--r--expansions/interpreter/eval.name4
-rw-r--r--expansions/interpreter/exec.name4
-rw-r--r--expansions/interpreter/sh.name4
-rw-r--r--expansions/muc/admin.name4
-rw-r--r--expansions/muc/ban.name4
-rw-r--r--expansions/muc/code.py740
-rw-r--r--expansions/muc/fullban.name4
-rw-r--r--expansions/muc/fullunban.name4
-rw-r--r--expansions/muc/insc.py4
-rw-r--r--expansions/muc/kick.name4
-rw-r--r--expansions/muc/member.name4
-rw-r--r--expansions/muc/moder.name4
-rw-r--r--expansions/muc/none.name4
-rw-r--r--expansions/muc/owner.name4
-rw-r--r--expansions/muc/participant.name4
-rw-r--r--expansions/muc/subject.name4
-rw-r--r--expansions/muc/visitor.name4
-rw-r--r--expansions/new_year/code.py53
-rw-r--r--expansions/new_year/new_year.name4
-rw-r--r--expansions/note/code.py206
-rw-r--r--expansions/note/insc.py4
-rw-r--r--expansions/note/note.name4
-rw-r--r--expansions/roster_ctrl/code.py160
-rw-r--r--expansions/roster_ctrl/insc.py4
-rw-r--r--expansions/roster_ctrl/roster.name4
-rw-r--r--expansions/sconf_attrs/botjid.name4
-rw-r--r--expansions/sconf_attrs/botnick.name4
-rw-r--r--expansions/sconf_attrs/botstatus.name4
-rw-r--r--expansions/sconf_attrs/code.py260
-rw-r--r--expansions/sconf_attrs/insc.py4
-rw-r--r--expansions/sconf_attrs/password.name4
-rw-r--r--expansions/sconf_attrs/prefix.name4
-rw-r--r--expansions/session_stat/botup.name4
-rw-r--r--expansions/session_stat/code.py168
-rw-r--r--expansions/session_stat/comstat.name4
-rw-r--r--expansions/session_stat/excinfo.name4
-rw-r--r--expansions/session_stat/insc.py4
-rw-r--r--expansions/session_stat/stat.name4
-rw-r--r--expansions/sheriff/code.py962
-rw-r--r--expansions/sheriff/insc.py4
-rw-r--r--expansions/sheriff/order.name4
-rw-r--r--expansions/talkers/code.py356
-rw-r--r--expansions/talkers/insc.py4
-rw-r--r--expansions/talkers/talkers.name4
-rw-r--r--expansions/turn/code.py116
-rw-r--r--expansions/turn/turn.name4
-rw-r--r--expansions/user_stats/code.py246
-rw-r--r--expansions/user_stats/here.name4
-rw-r--r--expansions/user_stats/insc.py4
-rw-r--r--expansions/user_stats/userstat.name4
-rw-r--r--librarys.zipbin84682 -> 86238 bytes
-rw-r--r--static/insc.py4
149 files changed, 4878 insertions, 4347 deletions
diff --git a/BlackSmith.py b/BlackSmith.py
index 0b34d22..90d1fa7 100644
--- a/BlackSmith.py
+++ b/BlackSmith.py
@@ -4,7 +4,7 @@
# BlackSmith's core mark.2
# BlackSmith.py
-# Code © (2010-2011) by WitcherGeralt (alkorgun@gmail.com)
+# Code © (2010-2012) by WitcherGeralt (alkorgun@gmail.com)
# imports
@@ -44,7 +44,7 @@ sys_cmds = [
"TASKKILL /PID %d /T /f", # 4
"Ver", # 5
'sh -c "%s" 2>&1' # 6
- ]
+ ]
Types = [
"chat", # 0
@@ -70,7 +70,7 @@ Types = [
"nick", # 20
"can't start new thread", # 21
"request" # 22
- ]
+ ]
AflRoles = [
"affiliation", # 0
@@ -83,14 +83,14 @@ AflRoles = [
"visitor", # 7
"participant", # 8
"moderator" # 9
- ]
+ ]
sList = [
"chat", # готов поболтать
"away", # отошел
"xa", # не беспокоить
"dnd" # недоступен
- ]
+ ]
aDesc = {
"owner": 3,
@@ -98,14 +98,14 @@ aDesc = {
"admin": 2,
"participant": 1,
"member": 1
- }
+ }
sCodesDesc = {
"301": "has-been-banned", # 0
"303": "nick-changed", # 1
"307": "has-been-kicked", # 2
"407": "members-only" # 3
- }
+ }
sCodes = sorted(sCodesDesc.keys())
@@ -124,7 +124,7 @@ eCodesDesc = {
"501": "feature-not-implemented", # 11
"503": "service-unavailable", # 12
"504": "remote-server-timeout" # 13
- }
+ }
eCodes = sorted(eCodesDesc.keys())
@@ -135,7 +135,7 @@ Features = [
xmpp.NS_URN_TIME, # 3
xmpp.NS_LAST, # 4
xmpp.NS_DISCO_INFO # 5
- ]
+ ]
aFeatures = Features + [
xmpp.NS_DISCO_ITEMS,
@@ -144,7 +144,7 @@ aFeatures = Features + [
xmpp.NS_ROSTER,
xmpp.NS_DATA,
xmpp.NS_RECEIPTS
- ]
+ ]
IsJID = compile__(".+?@\w+?\.\w+?", 32)
@@ -153,7 +153,7 @@ VarCache = {
"alive": True,
"errors": [],
"action": "# %s %s &" % (os.path.split(sys.executable)[1], BsCore)
- }
+ }
Info = {
"cmd": itypes.Number(), "sess": time.time(),
@@ -162,7 +162,7 @@ Info = {
"prs": itypes.Number(), "iq": itypes.Number(),
"errors": itypes.Number(),
"omsg": itypes.Number(), "outiq": itypes.Number()
- }
+ }
# frienly handlers
@@ -252,19 +252,19 @@ else:
# Global Names
-dynamic = "current/%s"
static = "static/%s"
-PlugsDir = "expansions"
-SvnCache = ".svn/entries"
+dynamic = "current/%s"
+ExpsDir = "expansions"
FeilDir = "feillog"
PidFile = "sessions.db"
GenCrash = "dispatcher.crash"
+SvnCache = ".svn/entries"
GenInscFile = static % ("insc.py")
GenConFile = static % ("config.ini")
ConDispFile = static % ("clients.ini")
ChatsFile = dynamic % ("chats.db")
-(BsMark, BsVer, BsRev) = (2, 24, 0)
+(BsMark, BsVer, BsRev) = (2, 26, 0)
if os.access(SvnCache, os.R_OK):
Cache = open(SvnCache).readlines()
@@ -276,7 +276,7 @@ if os.access(SvnCache, os.R_OK):
BsRev = 0
ProdName = "BlackSmith mark.%d" % (BsMark)
-ProdVer = "%d (r.%d)" % (BsVer, BsRev)
+ProdVer = "%d (r.%s)" % (BsVer, BsRev)
Caps = "http://blacksmith-2.googlecode.com/svn/"
CapsVer = "%d.%d" % (BsMark, BsVer)
FullName = "HellDev's %s CoreVer.%s (%s)" % (ProdName, ProdVer, Caps)
@@ -355,9 +355,8 @@ Handlers = {
"00si": [],
"01si": [], "02si": [],
"03si": [], "04si": []
- }
+ }
-Sequeque = iThr.Semaphore(len(InstansesDesc.keys())*15)
Sequence = iThr.Semaphore()
# call & execut Threads & handlers
@@ -375,8 +374,8 @@ def execute_handler(handler_instance, list = (), command = None):
lytic_crashlog(handler_instance, command)
def call_sfunctions(ls, list = ()):
- for handler in Handlers[ls]:
- execute_handler(handler, list)
+ for inst in Handlers[ls]:
+ execute_handler(inst, list)
def composeTimer(cors, handler, Name = False, list = (), command = None):
if not Name:
@@ -419,25 +418,35 @@ def sThread_Run(Thr, handler, command = None):
except:
lytic_crashlog(sThread_Run, command)
-def sThread(name, handler, list = (), command = None):
- with Sequeque:
- sThread_Run(composeThr(handler, name, list, command), handler, command)
+def sThread(name, inst, list = (), command = None):
+ sThread_Run(composeThr(inst, name, list, command), inst, command)
def call_efunctions(ls, list = ()):
- for handler in Handlers[ls]:
- sThread(ls, handler, list)
+ for inst in Handlers[ls]:
+ sThread(ls, inst, list)
# exceptions, register handlers & commands
class expansion(object):
- def __init__(self, object):
- self.name = object
- self.path = "%s/%s" % (PlugsDir, self.name)
+ commands, handlers = (), ()
+
+ def __init__(self, name):
+ self.name = name
+ self.path = "%s/%s" % (ExpsDir, self.name)
self.file = "%s/code.py" % (self.path)
self.isExp = os.path.isfile(self.file)
self.insc = "%s/insc.py" % (self.path)
- self.desc, self.cmds, self.ls = {}, [], []
+ self.cmds = []
+ self.desc = {}
+
+ def initialize_exp(self):
+ expansions[self.name] = (self)
+ for ls in self.commands:
+ command_handler(self, *ls)
+ for inst, ls in self.handlers:
+ self.handler_register(getattr(self, inst.func_name), ls)
+ self.AnsBase = AnsBase_temp
def dels(self, full = False):
while self.cmds:
@@ -445,10 +454,8 @@ class expansion(object):
if Cmds.has_key(cmd):
Cmds[cmd].off()
self.funcs_del()
- while self.ls:
- Name = self.ls.pop()
- if globals().has_key(Name):
- del globals()[Name]
+ self.commands = ()
+ self.handlers = ()
if full and expansions.has_key(self.name):
del expansions[self.name]
@@ -458,12 +465,12 @@ class expansion(object):
def funcs_del(self, handler = False):
- def del_(handler, ls):
+ def Del(inst, ls):
if ls == "03si":
- execute_handler(handler)
- Handler_del(ls, handler)
- list = (self.desc[ls])
- list.remove(handler)
+ execute_handler(inst)
+ self.inst_del(ls, inst)
+ list = self.desc[ls]
+ list.remove(inst)
if not list:
del self.desc[ls]
@@ -471,70 +478,64 @@ class expansion(object):
for ls, list in self.desc.items():
for inst in list:
if inst == handler:
- handler = del_(handler, ls)
+ handler = Del(inst, ls)
break
if not handler:
break
else:
for ls, list in self.desc.items():
- for handler in list:
- del_(handler, ls)
+ for inst in list:
+ Del(inst, ls)
def initialize_all(self):
for ls in sorted(self.desc.keys()):
if not (ls.endswith("si") and self.desc.has_key(ls)):
continue
- for handler in self.desc[ls]:
+ for inst in self.desc[ls]:
if ls in ("00si", "02si"):
- execute_handler(handler)
+ execute_handler(inst)
elif ls == "01si":
for conf in Chats.keys():
- execute_handler(handler, (conf,))
+ execute_handler(inst, (conf,))
- def func_add(self, ls, handler):
+ def func_add(self, ls, inst):
self.ls_add(ls)
- self.desc[ls].append(handler)
-
- def funcs_add(self, handlers):
- for handler in handlers:
- self.ls.append(handler.func_name)
+ self.desc[ls].append(inst)
def load(self):
try:
execfile(self.file, globals())
except:
- loaded = (self.name, None, exc_info())
+ result = (self.name, None, exc_info())
else:
- loaded = (self.name, True, ())
- return loaded
+ result = (self.name, True, ())
+ return result
def load_insc(self):
if os.path.isfile(self.insc):
execfile(self.insc, globals())
-def Handler_add(ls, handler):
- if handler not in Handlers[ls]:
- Handlers[ls].append(handler)
+ def inst_add(self, ls, inst):
+ if inst not in Handlers[ls]:
+ Handlers[ls].append(inst)
-def Handler_del(ls, handler):
- if handler in Handlers[ls]:
- Handlers[ls].remove(handler)
+ def inst_del(self, ls, inst):
+ if inst in Handlers[ls]:
+ Handlers[ls].remove(inst)
+
+ def handler_register(self, inst, ls):
+ Name = inst.func_name
+ for instance in Handlers[ls]:
+ if Name == instance.func_name:
+ self.inst_del(ls, instance)
+ self.inst_add(ls, inst)
+ self.func_add(ls, inst)
def expansion_register(name):
if expansions.has_key(name):
expansions[name].dels()
- else:
- expansions[name] = expansion(name)
expansions[name].load_insc()
-def handler_register(handler, ls, name):
- iname = handler.func_name
- for instance in Handlers[ls]:
- if iname == instance.func_name:
- Handlers[ls].remove(instance)
- Handler_add(ls, handler)
- expansions[name].func_add(ls, handler)
-
class Command(object):
def __init__(self, inst, name, access, help, exp):
@@ -562,7 +563,7 @@ class Command(object):
if enough_access(source[1], source[2], self.access):
if self.isAvalable and self.handler:
Info["cmd"].plus()
- sThread("command", self.handler, (ltype, source, body, disp), self.name)
+ sThread("command", self.handler, (self.exp, ltype, source, body, disp), self.name)
self.numb.plus()
source = get_source(source[1], source[2])
if source and source not in self.desc:
@@ -572,20 +573,24 @@ class Command(object):
else:
Answer(AnsBase[10], ltype, source, disp)
-def command_handler(handler, commands, access, name, pfx = True):
- if DefLANG in commands.keys():
- help = "%s/%s/%s.%s" % (PlugsDir, name, commands["EN"], DefLANG.lower())
- command = commands[DefLANG].decode("utf-8")
+def command_handler(exp_link, handler, name, access, pfx = True):
+ Path = os.path.join(ExpsDir, exp_link.name, name)
+ try:
+ commands = eval(get_file("%s.name" % Path).decode("utf-8"))
+ except:
+ commands = {}
+ if commands.has_key(DefLANG):
+ name = commands[DefLANG].decode("utf-8")
+ help = "%s.%s" % (Path, DefLANG.lower())
else:
- help = "%s/%s/%s.en" % (PlugsDir, name, commands["EN"])
- command = commands["EN"]
- if Cmds.has_key(command):
- Cmds[command].reload(handler, access, help, name)
+ help = "%s.en" % (Path)
+ if Cmds.has_key(name):
+ Cmds[name].reload(handler, access, help, exp_link)
else:
- Cmds[command] = Command(handler, command, access, help, name)
- if not pfx and command not in sCmds:
- sCmds.append(command)
- expansions[name].cmds.append(command)
+ Cmds[name] = Command(handler, name, access, help, exp_link)
+ if not pfx and name not in sCmds:
+ sCmds.append(name)
+ expansions[exp_link.name].cmds.append(name)
# Chats, Users & other
@@ -966,7 +971,7 @@ def sAttrs(stanza):
return (source, instance.lower(),
stype, resource)
-GetRole = lambda node: (str(node.getAffiliation()), str(node.getRole()))
+GetRole = lambda Node: (str(Node.getAffiliation()), str(Node.getRole()))
def xmpp_raise():
raise xmpp.NodeProcessed("continue")
@@ -1005,7 +1010,7 @@ def cat_file(filename, data, otp = "wb"):
# Crashlogs
def Dispatch_fail():
- crashfile = open(GenCrash, "a")
+ crashfile = open(GenCrash, "ab")
exc_info_(crashfile)
crashfile.close()
@@ -1046,18 +1051,21 @@ def lytic_crashlog(handler, command = None):
def load_expansions():
Print("\n\nExpansions loading...\n", color4)
- for PlugDir in os.listdir(PlugsDir):
- if (".svn") == (PlugDir) or not os.path.isdir(os.path.join(PlugsDir, PlugDir)):
+ for ExpDir in os.listdir(ExpsDir):
+ if (".svn") == (ExpDir) or not os.path.isdir(os.path.join(ExpsDir, ExpDir)):
continue
- exp = expansion(PlugDir)
+ expansions[ExpDir] = exp = expansion(ExpDir)
if exp.isExp:
- loaded = exp.load()
- if loaded[1]:
- Print("%s - successfully loaded!" % (loaded[0]), color3)
+ rslt = exp.load()
+ if rslt[1]:
+ exp = expansion_temp(ExpDir)
+ exp.initialize_exp()
+ Print("%s - successfully loaded!" % (rslt[0]), color3)
else:
exp.dels(True)
- Print("Can't load - %s!%s" % (loaded[0], "\n\t* %s: %s") % (loaded[2]), color2)
+ Print("Can't load - %s!%s" % (rslt[0], "\n\t* %s: %s") % (rslt[2]), color2)
else:
+ exp.dels(True)
Print("%s - isn't an expansion!" % (exp.name), color2)
def get_pipe(command):
diff --git a/expansions/access/access.name b/expansions/access/access.name
new file mode 100644
index 0000000..2977625
--- /dev/null
+++ b/expansions/access/access.name
@@ -0,0 +1,4 @@
+{
+ "RU": "доступ",
+ "UA": "доступ"
+} \ No newline at end of file
diff --git a/expansions/access/acclist.name b/expansions/access/acclist.name
new file mode 100644
index 0000000..c49f680
--- /dev/null
+++ b/expansions/access/acclist.name
@@ -0,0 +1,4 @@
+{
+ "RU": "доступы",
+ "UA": "доступы"
+} \ No newline at end of file
diff --git a/expansions/access/acclist2.name b/expansions/access/acclist2.name
new file mode 100644
index 0000000..a178f60
--- /dev/null
+++ b/expansions/access/acclist2.name
@@ -0,0 +1,4 @@
+{
+ "RU": "доступы*",
+ "UA": "доступы*"
+} \ No newline at end of file
diff --git a/expansions/access/code.py b/expansions/access/code.py
index 5571fbf..23739f1 100644
--- a/expansions/access/code.py
+++ b/expansions/access/code.py
@@ -1,209 +1,215 @@
# coding: utf-8
# BlackSmith mark.2
-exp_name = "access" # /code.py v.x1
-# Id: 20~1a
-# Code © (2011) by WitcherGeralt [WitcherGeralt@rocketmail.com]
+exp_name = "access" # /code.py v.x2
+# Id: 20~2b
+# Code © (2011) by WitcherGeralt [alkorgun@gmail.com]
expansion_register(exp_name)
-AccessFile = dynamic % ("access.db")
-ChatAccessFile = "access.db"
+class expansion_temp(expansion):
-def command_get_access(ltype, source, body, disp):
+ def __init__(self, name):
+ expansion.__init__(self, name)
- def get_acc(access):
- if access >= 8:
- access = "%d (BOSS)" % (access)
- elif access == 7:
- access = "7 (Chief)"
- else:
- access = str(access)
- return access
-
- if not body:
- answer = AccAnsBase[0] % get_acc(get_access(source[1], source[2]))
- elif Chats.has_key(source[1]):
- if Chats[source[1]].isHere(body):
- answer = AccAnsBase[1] % (body, get_acc(get_access(source[1], body)))
+ AccessFile = dynamic % ("access.db")
+ ChatAccessFile = "access.db"
+
+ def command_get_access(self, ltype, source, body, disp):
+
+ def get_acc(access):
+ if access >= 8:
+ access = "%d (BOSS)" % (access)
+ elif access == 7:
+ access = "7 (Chief)"
+ else:
+ access = str(access)
+ return access
+
+ if not body:
+ answer = self.AnsBase[0] % get_acc(get_access(source[1], source[2]))
+ elif Chats.has_key(source[1]):
+ if Chats[source[1]].isHere(body):
+ answer = self.AnsBase[1] % (body, get_acc(get_access(source[1], body)))
+ elif Galist.has_key(body):
+ answer = self.AnsBase[1] % (body, get_acc(Galist.get(body, 0)))
+ elif Chats[source[1]].alist.has_key(body):
+ answer = self.AnsBase[1] % (body, str(Chats[source[1]].alist.get(body, 0)))
+ else:
+ answer = self.AnsBase[2] % (body)
elif Galist.has_key(body):
- answer = AccAnsBase[1] % (body, get_acc(Galist.get(body, 0)))
- elif Chats[source[1]].alist.has_key(body):
- answer = AccAnsBase[1] % (body, str(Chats[source[1]].alist.get(body, 0)))
+ answer = self.AnsBase[1] % (body, get_acc(Galist.get(body, 0)))
else:
- answer = AccAnsBase[2] % (body)
- elif Galist.has_key(body):
- answer = AccAnsBase[1] % (body, get_acc(Galist.get(body, 0)))
- else:
- answer = AccAnsBase[2] % (body)
- Answer(answer, ltype, source, disp)
-
-def command_get_galist(ltype, source, body, disp):
- if Galist:
- list = []
- for x, y in Galist.items():
- list.append([y, x])
- list.sort()
- list.reverse()
- if ltype == Types[1]:
- Answer(AnsBase[11], ltype, source, disp)
- answer, Numb = AccAnsBase[5], itypes.Number()
- for x in list:
- answer += "%d) %s - %d\n" % (Numb.plus(), x[1], x[0])
- Msend(source[0], answer, disp)
- else:
- Answer(AccAnsBase[3], ltype, source, disp)
-
-def command_get_lalist(ltype, source, body, disp):
- if Chats.has_key(source[1]):
- if Chats[source[1]].alist:
+ answer = self.AnsBase[2] % (body)
+ Answer(answer, ltype, source, disp)
+
+ def command_get_galist(self, ltype, source, body, disp):
+ if Galist:
list = []
- for x, y in Chats[source[1]].alist.items():
+ for x, y in Galist.items():
list.append([y, x])
list.sort()
list.reverse()
if ltype == Types[1]:
Answer(AnsBase[11], ltype, source, disp)
- answer, Numb = AccAnsBase[5], itypes.Number()
+ answer, Numb = self.AnsBase[5], itypes.Number()
for x in list:
answer += "%d) %s - %d\n" % (Numb.plus(), x[1], x[0])
Msend(source[0], answer, disp)
else:
- answer = AccAnsBase[4]
- else:
- answer = AnsBase[0]
- if locals().has_key(Types[12]):
- Answer(answer, ltype, source, disp)
-
-def command_set_access(ltype, source, body, disp):
-
- def set_access(instance, access = None):
- if access != None:
- Galist[instance] = access
- else:
- del Galist[instance]
- cat_file(AccessFile, str(Galist))
- for conf in Chats.keys():
- for sUser in Chats[conf].get_users():
- if sUser.source and sUser.source == instance:
- if access == None:
- access = Chats[conf].alist.get(instance, None)
- if access != None:
- sUser.access = access
- else:
- sUser.calc_acc()
-
- if body:
- body = body.split(None, 1)
- if len(body) == 2:
- Nick = body.pop(1)
- if Chats.has_key(source[1]):
- if Chats[source[1]].isHere(Nick):
- instance = get_source(source[1], Nick)
- if not locals().has_key("instance"):
- instance = (Nick.split())[0].lower()
- if not isSource(instance):
- instance = None
- if instance:
- access = body.pop(0)
- if access == "!":
- if Galist.has_key(instance):
- set_access(instance)
- answer = AnsBase[4]
- else:
- answer = AccAnsBase[6] % (Nick)
- elif isNumber(access):
- access = int(access)
- if access in xrange(-1, 9):
- set_access(instance, access)
- answer = AnsBase[4]
- else:
- answer = AccAnsBase[7]
- else:
- answer = AnsBase[30]
+ Answer(self.AnsBase[3], ltype, source, disp)
+
+ def command_get_lalist(self, ltype, source, body, disp):
+ if Chats.has_key(source[1]):
+ if Chats[source[1]].alist:
+ list = []
+ for x, y in Chats[source[1]].alist.items():
+ list.append([y, x])
+ list.sort()
+ list.reverse()
+ if ltype == Types[1]:
+ Answer(AnsBase[11], ltype, source, disp)
+ answer, Numb = self.AnsBase[5], itypes.Number()
+ for x in list:
+ answer += "%d) %s - %d\n" % (Numb.plus(), x[1], x[0])
+ Msend(source[0], answer, disp)
else:
- answer = AccAnsBase[10] % (Nick)
+ answer = self.AnsBase[4]
else:
- answer = AnsBase[2]
- else:
- answer = AnsBase[1]
- Answer(answer, ltype, source, disp)
+ answer = AnsBase[0]
+ if locals().has_key(Types[12]):
+ Answer(answer, ltype, source, disp)
-def command_set_local_access(ltype, source, body, disp):
+ def command_set_access(self, ltype, source, body, disp):
- def set_access(conf, instance, access = None):
- if access != None:
- Chats[conf].alist[instance] = access
- else:
- del Chats[conf].alist[instance]
- cat_file(chat_file(conf, ChatAccessFile), str(Chats[conf].alist))
- for sUser in Chats[conf].get_users():
- if sUser.source and sUser.source == instance:
- if access == None:
- access = Galist.get(instance, None)
- if access != None:
- sUser.access = access
- else:
- sUser.calc_acc()
+ def set_access(self, instance, access = None):
+ if access != None:
+ Galist[instance] = access
+ else:
+ del Galist[instance]
+ cat_file(self.AccessFile, str(Galist))
+ for conf in Chats.keys():
+ for sUser in Chats[conf].get_users():
+ if sUser.source and sUser.source == instance:
+ if access == None:
+ access = Chats[conf].alist.get(instance, None)
+ if access != None:
+ sUser.access = access
+ else:
+ sUser.calc_acc()
- if Chats.has_key(source[1]):
if body:
body = body.split(None, 1)
if len(body) == 2:
Nick = body.pop(1)
- if Chats[source[1]].isHere(Nick):
- instance = get_source(source[1], Nick)
- else:
+ if Chats.has_key(source[1]):
+ if Chats[source[1]].isHere(Nick):
+ instance = get_source(source[1], Nick)
+ if not locals().has_key("instance"):
instance = (Nick.split())[0].lower()
if not isSource(instance):
instance = None
if instance:
access = body.pop(0)
if access == "!":
- if Chats[source[1]].alist.has_key(instance):
- set_access(source[1], instance)
+ if Galist.has_key(instance):
+ set_access(self, instance)
answer = AnsBase[4]
else:
- answer = AccAnsBase[6] % (Nick)
- elif not Galist.has_key(instance):
- if isNumber(access):
- access = int(access)
- if access in xrange(7):
- set_access(source[1], instance, access)
- answer = AnsBase[4]
- else:
- answer = AccAnsBase[8]
+ answer = self.AnsBase[6] % (Nick)
+ elif isNumber(access):
+ access = int(access)
+ if access in xrange(-1, 9):
+ set_access(self, instance, access)
+ answer = AnsBase[4]
else:
- answer = AnsBase[30]
+ answer = self.AnsBase[7]
else:
- answer = AccAnsBase[9] % (Nick)
+ answer = AnsBase[30]
else:
- answer = AccAnsBase[10] % (Nick)
+ answer = self.AnsBase[10] % (Nick)
else:
answer = AnsBase[2]
else:
answer = AnsBase[1]
- else:
- answer = AnsBase[0]
- Answer(answer, ltype, source, disp)
-
-def load_acclist():
- if initialize_file(AccessFile):
- Galist.update(eval(get_file(AccessFile)))
-
-def load_local_acclist(conf):
- filename = chat_file(conf, ChatAccessFile)
- if initialize_file(filename):
- Chats[conf].alist.update(eval(get_file(filename)))
-
-expansions[exp_name].funcs_add([command_get_access, command_get_galist, command_get_lalist, command_set_access, command_set_local_access, load_acclist, load_local_acclist])
-expansions[exp_name].ls.extend(["AccessFile", "ChatAccessFile", "AccAnsBase"])
-
-command_handler(command_get_access, {"RU": "доступ", "EN": "access"}, 1, exp_name)
-command_handler(command_get_galist, {"RU": "доступы", "EN": "acclist"}, 7, exp_name)
-command_handler(command_get_lalist, {"RU": "доступы*", "EN": "acclist2"}, 4, exp_name)
-command_handler(command_set_access, {"RU": "глобдоступ", "EN": "globaccess"}, 8, exp_name)
-command_handler(command_set_local_access, {"RU": "локдоступ", "EN": "locaccess"}, 6, exp_name)
-
-handler_register(load_acclist, "00si", exp_name)
-handler_register(load_local_acclist, "01si", exp_name)
+ Answer(answer, ltype, source, disp)
+
+ def command_set_local_access(self, ltype, source, body, disp):
+
+ def set_access(self, conf, instance, access = None):
+ if access != None:
+ Chats[conf].alist[instance] = access
+ else:
+ del Chats[conf].alist[instance]
+ cat_file(chat_file(conf, self.ChatAccessFile), str(Chats[conf].alist))
+ for sUser in Chats[conf].get_users():
+ if sUser.source and sUser.source == instance:
+ if access == None:
+ access = Galist.get(instance, None)
+ if access != None:
+ sUser.access = access
+ else:
+ sUser.calc_acc()
+
+ if Chats.has_key(source[1]):
+ if body:
+ body = body.split(None, 1)
+ if len(body) == 2:
+ Nick = body.pop(1)
+ if Chats[source[1]].isHere(Nick):
+ instance = get_source(source[1], Nick)
+ else:
+ instance = (Nick.split())[0].lower()
+ if not isSource(instance):
+ instance = None
+ if instance:
+ access = body.pop(0)
+ if access == "!":
+ if Chats[source[1]].alist.has_key(instance):
+ set_access(self, source[1], instance)
+ answer = AnsBase[4]
+ else:
+ answer = self.AnsBase[6] % (Nick)
+ elif not Galist.has_key(instance):
+ if isNumber(access):
+ access = int(access)
+ if access in xrange(7):
+ set_access(self, source[1], instance, access)
+ answer = AnsBase[4]
+ else:
+ answer = self.AnsBase[8]
+ else:
+ answer = AnsBase[30]
+ else:
+ answer = self.AnsBase[9] % (Nick)
+ else:
+ answer = self.AnsBase[10] % (Nick)
+ else:
+ answer = AnsBase[2]
+ else:
+ answer = AnsBase[1]
+ else:
+ answer = AnsBase[0]
+ Answer(answer, ltype, source, disp)
+
+ def load_acclist(self):
+ if initialize_file(self.AccessFile):
+ Galist.update(eval(get_file(self.AccessFile)))
+
+ def load_local_acclist(self, conf):
+ filename = chat_file(conf, self.ChatAccessFile)
+ if initialize_file(filename):
+ Chats[conf].alist.update(eval(get_file(filename)))
+
+ commands = (
+ (command_get_access, "access", 1,),
+ (command_get_galist, "acclist", 7,),
+ (command_get_lalist, "acclist2", 4,),
+ (command_set_access, "gaccess", 8,),
+ (command_set_local_access, "laccess", 6,)
+ )
+
+ handlers = (
+ (load_acclist, "00si"),
+ (load_local_acclist, "01si")
+ )
diff --git a/expansions/access/gaccess.en b/expansions/access/gaccess.en
new file mode 100644
index 0000000..c479adc
--- /dev/null
+++ b/expansions/access/gaccess.en
@@ -0,0 +1,6 @@
+bot sets global access
+gaccess [!/access] [jid/nick]
+*/gaccess 6 Obi-Wan Kenobi
+bot would set access level 6 for Obi-Wan Kenobi
+*/gaccess ! obi-wan_kenobi@jab.net
+bot would remove obi-wan_kenobi@jab.net from global access list \ No newline at end of file
diff --git a/expansions/access/gaccess.name b/expansions/access/gaccess.name
new file mode 100644
index 0000000..db911bd
--- /dev/null
+++ b/expansions/access/gaccess.name
@@ -0,0 +1,4 @@
+{
+ "RU": "гдоступ",
+ "UA": "гдоступ"
+} \ No newline at end of file
diff --git a/expansions/access/gaccess.ru b/expansions/access/gaccess.ru
new file mode 100644
index 0000000..0a4065d
--- /dev/null
+++ b/expansions/access/gaccess.ru
@@ -0,0 +1,6 @@
+бот устанавливает глобальный доступ для указанного пользователя
+гдоступ [!/доступ] [jid/nick]
+*/гдоступ 6 Оби-Ван Кеноби
+бот установит доступ 6 для Оби-Ван Кеноби
+*/гдоступ ! obi-wan_kenobi@jab.net
+бот снимет доступ с obi-wan_kenobi@jab.net \ No newline at end of file
diff --git a/expansions/access/insc.py b/expansions/access/insc.py
index f61e20e..9a07f06 100644
--- a/expansions/access/insc.py
+++ b/expansions/access/insc.py
@@ -1,7 +1,7 @@
# coding: utf-8
if DefLANG in ("RU", "UA"):
- AccAnsBase = tuple([line.decode("utf-8") for line in (
+ AnsBase_temp = tuple([line.decode("utf-8") for line in (
"Твой доступ = %s", # 0
"Доступ «%s» = %s", # 1
"На «%s» нет информации.", # 2
@@ -15,7 +15,7 @@ if DefLANG in ("RU", "UA"):
"Не могу дать доступ «%s»." # 10
)])
else:
- AccAnsBase = (
+ AnsBase_temp = (
"Your access = %s", # 0
"%s's access = %s", # 1
"I have not information about '%s'.", # 2
diff --git a/expansions/access/laccess.en b/expansions/access/laccess.en
new file mode 100644
index 0000000..a486007
--- /dev/null
+++ b/expansions/access/laccess.en
@@ -0,0 +1,6 @@
+bot sets local access
+laccess [!/access] [jid/nick]
+*/laccess 6 Obi-Wan Kenobi
+bot would set local access with level 6 for Obi-Wan Kenobi
+*/laccess ! obi-wan_kenobi@jab.net
+bot would remove obi-wan_kenobi@jab.net from local access list \ No newline at end of file
diff --git a/expansions/access/laccess.name b/expansions/access/laccess.name
new file mode 100644
index 0000000..b48bcdd
--- /dev/null
+++ b/expansions/access/laccess.name
@@ -0,0 +1,4 @@
+{
+ "RU": "локдоступ",
+ "UA": "локдоступ"
+} \ No newline at end of file
diff --git a/expansions/access/laccess.ru b/expansions/access/laccess.ru
new file mode 100644
index 0000000..c4469d5
--- /dev/null
+++ b/expansions/access/laccess.ru
@@ -0,0 +1,6 @@
+бот устанавливает локальный доступ для указанного пользователя
+локдоступ [!/доступ] [jid/nick]
+*/локдоступ 6 Оби-Ван Кеноби
+бот установит локальный доступ 6 для Оби-Ван Кеноби
+*/локдоступ ! obi-wan_kenobi@jab.net
+бот снимет доступ с obi-wan_kenobi@jab.net \ No newline at end of file
diff --git a/expansions/alive_keeper/code.py b/expansions/alive_keeper/code.py
index 4416673..d845b33 100644
--- a/expansions/alive_keeper/code.py
+++ b/expansions/alive_keeper/code.py
@@ -1,95 +1,96 @@
# coding: utf-8
# BlackSmith mark.2
-exp_name = "alive_keeper" # /code.py v.x3
-# Id: 16~3a
-# Code © (2011) by WitcherGeralt [WitcherGeralt@rocketmail.com]
+exp_name = "alive_keeper" # /code.py v.x4
+# Id: 16~4b
+# Code © (2011) by WitcherGeralt [alkorgun@gmail.com]
expansion_register(exp_name)
-def alive_keeper():
- exp_name = "alive_keeper"
+class expansion_temp(expansion):
- def alive_keeper_answer(disp, answer):
- if answer:
- Clients[get_disp(disp)].aKeeper = itypes.Number()
+ def __init__(self, name):
+ expansion.__init__(self, name)
- while VarCache["alive"]:
- time.sleep(360)
- ThrIds = iThr.ThrNames()
- for disp in Clients.keys():
- if not hasattr(Clients[disp], "aKeeper"):
- Clients[disp].aKeeper = itypes.Number()
- if Clients[disp].aKeeper._int() >= 3:
- Clients[disp].aKeeper = itypes.Number()
- ThrName = "%s%s" % (Types[13], disp)
- if ThrName in ThrIds:
- for Thr in iThr.enumerate():
- if Thr._Thread__name == ThrName:
- Thr.kill()
- try:
- composeThr(connectAndDispatch, ThrName, (disp,)).start()
- except:
- delivery(AnsBase[28] % (disp))
- elif expansions.has_key(exp_name):
- Clients[disp].aKeeper.plus()
- iq = xmpp.Iq(to = "%s/%s" % (disp, GenResource), typ = Types[10])
- iq.addChild(Types[16], {}, [], xmpp.NS_PING)
- iq.setID("Bs-i%d" % Info["outiq"].plus())
- CallForResponse(disp, iq, alive_keeper_answer)
- del iq
- else:
- raise iThr.ThrKill("exit")
- del ThrIds
+ def alive_keeper(self):
-def conf_alive_keeper():
- exp_name = "alive_keeper"
+ def alive_keeper_answer(disp, answer):
+ if answer:
+ Clients[get_disp(disp)].aKeeper = itypes.Number()
- def conf_alive_keeper_answer(disp, stanza, conf):
- if Chats.has_key(conf):
- if xmpp.isErrorNode(stanza):
- if eCodes[6] == stanza.getErrorCode():
- Chats[conf].aKeeper = itypes.Number()
- else:
- Chats[conf].aKeeper = itypes.Number()
-
- while VarCache["alive"]:
- time.sleep(360)
- ThrIds = iThr.ThrNames()
- for conf in Chats.keys():
- if not (online(Chats[conf].disp) and Chats[conf].IamHere):
- continue
- if not hasattr(Chats[conf], "aKeeper"):
- Chats[conf].aKeeper = itypes.Number()
- if Chats[conf].aKeeper._int() >= 3:
- Chats[conf].aKeeper = itypes.Number()
- TimerName = ejoinTimerName(conf)
- if TimerName not in ThrIds:
+ while VarCache["alive"]:
+ time.sleep(360)
+ ThrIds = iThr.ThrNames()
+ for disp in Clients.keys():
+ if not hasattr(Clients[disp], "aKeeper"):
+ Clients[disp].aKeeper = itypes.Number()
+ if Clients[disp].aKeeper._int() >= 3:
+ Clients[disp].aKeeper = itypes.Number()
+ ThrName = "%s%s" % (Types[13], disp)
+ if ThrName in ThrIds:
+ for Thr in iThr.enumerate():
+ if Thr._Thread__name == ThrName:
+ Thr.kill()
try:
- composeTimer(180, ejoinTimer, TimerName, (conf,)).start()
+ composeThr(connectAndDispatch, ThrName, (disp,)).start()
except:
- pass
- elif expansions.has_key(exp_name):
- Chats[conf].aKeeper.plus()
- iq = xmpp.Iq(to = "%s/%s" % (conf, get_self_nick(conf)), typ = Types[10])
- iq.addChild(Types[18], {}, [], xmpp.NS_PING)
- iq.setID("Bs-i%d" % Info["outiq"].plus())
- CallForResponse(Chats[conf].disp, iq, conf_alive_keeper_answer, {"conf": conf})
- del iq
- else:
- raise iThr.ThrKill("exit")
- del ThrIds
+ delivery(AnsBase[28] % (disp))
+ elif expansions.has_key(self.name):
+ Clients[disp].aKeeper.plus()
+ iq = xmpp.Iq(to = "%s/%s" % (disp, GenResource), typ = Types[10])
+ iq.addChild(Types[16], {}, [], xmpp.NS_PING)
+ iq.setID("Bs-i%d" % Info["outiq"].plus())
+ CallForResponse(disp, iq, alive_keeper_answer)
+ del iq
+ else:
+ raise iThr.ThrKill("exit")
+ del ThrIds
-def start_keepers():
- Name1 = alive_keeper.func_name
- Name2 = conf_alive_keeper.func_name
- for Thr in iThr.enumerate():
- ThrName = Thr._Thread__name
- if ThrName.startswith(Name1) or ThrName.startswith(Name2):
- Thr.kill()
- composeThr(alive_keeper, Name1).start()
- composeThr(conf_alive_keeper, Name2).start()
+ def conf_alive_keeper(self):
+
+ def conf_alive_keeper_answer(disp, stanza, conf):
+ if Chats.has_key(conf):
+ if xmpp.isErrorNode(stanza):
+ if eCodes[6] == stanza.getErrorCode():
+ Chats[conf].aKeeper = itypes.Number()
+ else:
+ Chats[conf].aKeeper = itypes.Number()
+
+ while VarCache["alive"]:
+ time.sleep(360)
+ ThrIds = iThr.ThrNames()
+ for conf in Chats.keys():
+ if not (online(Chats[conf].disp) and Chats[conf].IamHere):
+ continue
+ if not hasattr(Chats[conf], "aKeeper"):
+ Chats[conf].aKeeper = itypes.Number()
+ if Chats[conf].aKeeper._int() >= 3:
+ Chats[conf].aKeeper = itypes.Number()
+ TimerName = ejoinTimerName(conf)
+ if TimerName not in ThrIds:
+ try:
+ composeTimer(180, ejoinTimer, TimerName, (conf,)).start()
+ except:
+ pass
+ elif expansions.has_key(self.name):
+ Chats[conf].aKeeper.plus()
+ iq = xmpp.Iq(to = "%s/%s" % (conf, get_self_nick(conf)), typ = Types[10])
+ iq.addChild(Types[18], {}, [], xmpp.NS_PING)
+ iq.setID("Bs-i%d" % Info["outiq"].plus())
+ CallForResponse(Chats[conf].disp, iq, conf_alive_keeper_answer, {"conf": conf})
+ del iq
+ else:
+ raise iThr.ThrKill("exit")
+ del ThrIds
-expansions[exp_name].funcs_add([alive_keeper, conf_alive_keeper, start_keepers])
+ def start_keepers(self):
+ Name1 = self.alive_keeper.func_name
+ Name2 = self.conf_alive_keeper.func_name
+ for Thr in iThr.enumerate():
+ ThrName = Thr._Thread__name
+ if ThrName.startswith(Name1) or ThrName.startswith(Name2):
+ Thr.kill()
+ composeThr(self.alive_keeper, Name1).start()
+ composeThr(self.conf_alive_keeper, Name2).start()
-handler_register(start_keepers, "02si", exp_name)
+ handlers = ((start_keepers, "02si"),)
diff --git a/expansions/allweb/chuck.name b/expansions/allweb/chuck.name
new file mode 100644
index 0000000..7116f5b
--- /dev/null
+++ b/expansions/allweb/chuck.name
@@ -0,0 +1,4 @@
+{
+ "RU": "чак",
+ "UA": "чак"
+} \ No newline at end of file
diff --git a/expansions/allweb/code.py b/expansions/allweb/code.py
index 671394f..1d8e5ae 100644
--- a/expansions/allweb/code.py
+++ b/expansions/allweb/code.py
@@ -1,646 +1,641 @@
# coding: utf-8
# BlackSmith mark.2
-exp_name = "allweb" # /code.py v.x12
-# Id: 25~12a
-# Code © (2011) by WitcherGeralt [WitcherGeralt@rocketmail.com]
+exp_name = "allweb" # /code.py v.x14
+# Id: 25~14b
+# Code © (2011) by WitcherGeralt [alkorgun@gmail.com]
expansion_register(exp_name)
-import htmlentitydefs, json
+class expansion_temp(expansion):
-UserAgent = ("User-Agent", "%s/%s" % (ProdName[:10], CapsVer))
+ def __init__(self, name):
+ expansion.__init__(self, name)
-UserAgent_Moz = (UserAgent[0], "Mozilla/5.0 (X11; U; Linux i686; {0}; rv:1.7.12) Gecko/20050929".format(UserAgents.get(DefLANG, "en-US")))
+ UserAgents = UserAgents
-edefs = dict()
+ import htmlentitydefs, json
-for Name, Numb in htmlentitydefs.name2codepoint.iteritems():
- edefs[Name] = unichr(Numb)
+ UserAgent = ("User-Agent", "%s/%s" % (ProdName[:10], CapsVer))
-del Name, Numb
+ UserAgent_Moz = (UserAgent[0], "Mozilla/5.0 (Windows NT 6.1; WOW64; {0}) AppleWebKit/537.1 (KHTML, like Gecko) Chrome/21.0.1180.89 Safari/537.1".format(UserAgents.get(DefLANG, "en-US")))
-Web.Opener.addheaders = [UserAgent_Moz]
+ edefs = dict()
-REP_desc = {
- "<br>": chr(10),
- "<br />": chr(10)
- }
+ for Name, Numb in htmlentitydefs.name2codepoint.iteritems():
+ edefs[Name] = unichr(Numb)
-XML_ls = [
- ("&lt;", "<"),
- ("&gt;", ">"),
- ("&quot;", '"'),
- ("&apos;", "'"),
- ("&amp;", "&")
- ]
+ del Name, Numb
-compile_st = compile__("<[^<>]+?>")
-compile_ehtmls = compile__("&(#?[xX]?(?:[0-9a-fA-F]+|\w{1,8}));")
+ Web.Opener.addheaders = [UserAgent_Moz]
-def e_sb(co):
- co = co.groups()[0]
- if co.startswith("#"):
- if chr(120) == co[1].lower():
- Char, c06 = co[2:], 16
- else:
- Char, c06 = co[1:], 10
- try:
- Numb = int(Char, c06)
- assert (-1 < Numb < 65535)
- Char = unichr(Numb)
- except:
- Char = edefs.get(Char, "&%s;" % co)
- else:
- Char = edefs.get(co, "&%s;" % co)
- return Char
-
-def sub_ehtmls(data):
- if data.count("&"):
- data = compile_ehtmls.sub(e_sb, data)
- return data
-
-def decodeHTML(data):
- data = sub_desc(data, REP_desc)
- data = compile_st.sub("", data)
- data = sub_ehtmls(data)
- return data.strip()
-
-def command_jc(ltype, source, body, disp):
- if Chats.has_key(source[1]):
- if body:
- cName = body.lower()
- if cName.count("@conf"):
- cName = (cName.split("@conf"))[0]
- else:
- cName = (source[1].split("@conf"))[0]
- Req = Web("http://jc.jabber.ru/search.html?", [("search", cName.encode("utf-8"))])
- try:
- data = Req.get_page(UserAgent)
- except:
- answer = AllwebAnsBase[0]
- else:
- comp = compile__("<li>((?:.|\s)+?)</li>", 16)
- list = comp.findall(data)
- if list:
- Number = itypes.Number()
- ls = []
- for line in list:
- line = line.strip()
- ls.append("%d) %s" % (Number.plus(), line))
- answer = (chr(10) + decodeHTML(str.join(chr(10)*2, ls)))
- else:
- answer = AllwebAnsBase[5]
- else:
- answer = AnsBase[0]
- Answer(answer, ltype, source, disp)
+ REP_desc = {
+ "<br>": chr(10),
+ "<br />": chr(10)
+ }
+
+ XML_ls = [
+ ("&lt;", "<"),
+ ("&gt;", ">"),
+ ("&quot;", '"'),
+ ("&apos;", "'"),
+ ("&amp;", "&")
+ ]
+
+ compile_st = compile__("<[^<>]+?>")
+ compile_ehtmls = compile__("&(#?[xX]?(?:[0-9a-fA-F]+|\w{1,8}));")
-gCache = []
+ def sub_ehtmls(self, data):
+ if data.count("&"):
-def command_google(ltype, source, body, disp):
- if body:
- if (chr(42) != body):
- Req = Web("http://ajax.googleapis.com/ajax/services/search/web?", [("v", "1.0"), ("q", body.encode("utf-8"))])
+ def e_sb(co, edefs = self.edefs):
+ co = co.groups()[0]
+ if co.startswith("#"):
+ if chr(120) == co[1].lower():
+ Char, c06 = co[2:], 16
+ else:
+ Char, c06 = co[1:], 10
+ try:
+ Numb = int(Char, c06)
+ assert (-1 < Numb < 65535)
+ Char = unichr(Numb)
+ except:
+ Char = edefs.get(Char, "&%s;" % co)
+ else:
+ Char = edefs.get(co, "&%s;" % co)
+ return Char
+
+ data = self.compile_ehtmls.sub(e_sb, data)
+ return data
+
+ def decodeHTML(self, data):
+ data = sub_desc(data, self.REP_desc)
+ data = self.compile_st.sub("", data)
+ data = self.sub_ehtmls(data)
+ return data.strip()
+
+ def command_jc(self, ltype, source, body, disp):
+ if Chats.has_key(source[1]):
+ if body:
+ cName = body.lower()
+ if cName.count("@conf"):
+ cName = (cName.split("@conf"))[0]
+ else:
+ cName = (source[1].split("@conf"))[0]
+ Req = Web("http://jc.jabber.ru/search.html?", [("search", cName.encode("utf-8"))])
try:
- data = Req.get_page(UserAgent)
+ data = Req.get_page(self.UserAgent)
except:
- answer = AllwebAnsBase[0]
+ answer = self.AnsBase[0]
else:
+ comp = compile__("<li>((?:.|\s)+?)</li>", 16)
+ list = comp.findall(data)
+ if list:
+ Number = itypes.Number()
+ ls = []
+ for line in list:
+ line = line.strip()
+ ls.append("%d) %s" % (Number.plus(), line))
+ answer = (chr(10) + self.decodeHTML(str.join(chr(10)*2, ls)))
+ else:
+ answer = self.AnsBase[5]
+ else:
+ answer = AnsBase[0]
+ Answer(answer, ltype, source, disp)
+
+ gCache = []
+
+ def command_google(self, ltype, source, body, disp):
+ if body:
+ if (chr(42) != body):
+ Req = Web("http://ajax.googleapis.com/ajax/services/search/web?", [("v", "1.0"), ("q", body.encode("utf-8"))])
try:
- data = json.loads(data)
+ data = Req.get_page(self.UserAgent)
except:
- answer = AllwebAnsBase[1]
+ answer = self.AnsBase[0]
else:
- data = data.get("responseData", {"results": []})
- list = data.get("results", [])
+ try:
+ data = self.json.loads(data)
+ except:
+ answer = self.AnsBase[1]
+ else:
+ data = data.get("responseData", {"results": []})
+ list = data.get("results", [])
+ if list:
+ desc = list.pop(0)
+ ls = []
+ ls.append(desc.get("title", ""))
+ ls.append(desc.get("content", ""))
+ ls.append(desc.get("unescapedUrl", ""))
+ answer = self.decodeHTML(str.join(chr(10), ls))
+ if list:
+ source_ = get_source(source[1], source[2])
+ if source_:
+ for ls in self.gCache:
+ if ls[0] == source_:
+ self.gCache.pop(self.gCache.index(ls))
+ break
+ Numb = (len(Clients.keys())*4)
+ while len(self.gCache) >= Numb:
+ self.gCache.pop(0)
+ self.gCache.append((source_, list))
+ answer += self.AnsBase[4] % len(list)
+ else:
+ answer = self.AnsBase[5]
+ else:
+ source_ = get_source(source[1], source[2])
+ if source_:
+ list = []
+ for ls in self.gCache:
+ if ls[0] == source_:
+ list = self.gCache.pop(self.gCache.index(ls))[1]
+ break
if list:
desc = list.pop(0)
ls = []
ls.append(desc.get("title", ""))
ls.append(desc.get("content", ""))
ls.append(desc.get("unescapedUrl", ""))
- answer = decodeHTML(str.join(chr(10), ls))
+ answer = self.decodeHTML(str.join(chr(10), ls))
if list:
- source_ = get_source(source[1], source[2])
- if source_:
- for ls in gCache:
- if ls[0] == source_:
- gCache.pop(gCache.index(ls))
- break
- Numb = (len(Clients.keys())*4)
- while len(gCache) >= Numb:
- gCache.pop(0)
- gCache.append((source_, list))
- answer += AllwebAnsBase[4] % len(list)
+ self.gCache.append((source_, list))
+ answer += self.AnsBase[4] % len(list)
else:
- answer = AllwebAnsBase[5]
+ answer = self.AnsBase[2]
+ else:
+ answer = self.AnsBase[3]
else:
- source_ = get_source(source[1], source[2])
- if source_:
- list = []
- for ls in gCache:
- if ls[0] == source_:
- list = gCache.pop(gCache.index(ls))[1]
- break
- if list:
- desc = list.pop(0)
- ls = []
- ls.append(desc.get("title", ""))
- ls.append(desc.get("content", ""))
- ls.append(desc.get("unescapedUrl", ""))
- answer = decodeHTML(str.join(chr(10), ls))
+ answer = AnsBase[1]
+ Answer(answer, ltype, source, disp)
+
+ def command_kino(self, ltype, source, body, disp):
+ if body:
+ ls = body.split()
+ c1st = (ls.pop(0)).lower()
+ c3op = "СЗоР"
+ if c1st in ("top250", "топ250".decode("utf-8")):
+ if ls:
+ limit = exec_(int, (ls.pop(0),))
+ if limit <= 5:
+ limit = 5
+ else:
+ limit = None
+ Req = Web("http://www.kinopoisk.ru/level/20/")
+ try:
+ data = Req.get_page(self.UserAgent_Moz)
+ except:
+ answer = self.AnsBase[0]
+ else:
+ data = data.decode("cp1251")
+ list = get_text(data, "<tr height=25>", "</table>")
+ if list:
+ comp = compile__('<a href="/film/\d+?/" class="all">(.+?)</a>(?:.|\s)+' \
+ '?<a href="/film/\d+?/votes/" class="continue">(.+?)</a> <span.*?>(.+?)</span>', 16)
+ list = comp.findall(list)
if list:
- gCache.append((source_, list))
- answer += AllwebAnsBase[4] % len(list)
+ Number = itypes.Number()
+ ls = ["\n[#] [Name, Year] [Rating] (Votes)"]
+ for Name, Numb, Numb_ in list:
+ ls.append("%d) %s - %s (%s)" % (Number.plus(), self.sub_ehtmls(Name), Numb, sub_desc(Numb, ["&nbsp;"])))
+ if limit and limit <= Number._int():
+ break
+ if not limit or limit > 25:
+ if ltype == Types[1]:
+ Answer(AnsBase[11], ltype, source, disp)
+ Top250 = str.join(chr(10), ls)
+ Msend(source[0], Top250, disp)
+ else:
+ answer = str.join(chr(10), ls)
+ elif data.count(c3op):
+ answer = self.AnsBase[-1]
+ else:
+ answer = self.AnsBase[1]
+ elif isNumber(body):
+ Req = Web("http://m.kinopoisk.ru/movie/%s" % (body))
+ try:
+ data = Req.get_page(self.UserAgent_Moz)
+ except:
+ answer = self.AnsBase[0]
else:
- answer = AllwebAnsBase[2]
- else:
- answer = AllwebAnsBase[3]
- else:
- answer = AnsBase[1]
- Answer(answer, ltype, source, disp)
-
-def command_kino(ltype, source, body, disp):
- if body:
- ls = body.split()
- c1st = (ls.pop(0)).lower()
- c3op = "СЗоР"
- # if c1st in ("top250", "топ250".decode("utf-8")):
- # if ls:
- # limit = exec_(int, (ls.pop(0),))
- # if limit <= 5:
- # limit = 5
- # else:
- # limit = None
- # Req = Web("http://www.kinopoisk.ru/level/20/")
- # try:
- # data = Req.get_page(UserAgent_Moz)
- # except:
- # answer = AllwebAnsBase[0]
- # else:
- # data = data.decode("cp1251")
- # list = get_text(data, "<table.+?>", "</table>")
- # if list:
- # comp = compile__('<a href="/level/1/film/\d+?/" class="all">(.+?)</a>.+' \
- # '?<a href="/level/83/film/\d+?/" class="continue">(.+?)</a>.+' \
- # '?<div.+?>(.+?)</div>', 16)
- # list = comp.findall(list)
- # if list:
- # Number = itypes.Number()
- # ls = ["\n[#] [Name, Year] [Rating] (Votes)"]
- # for Name, Numb, Numb_ in list:
- # ls.append("%d) %s - %s (%s)" % (Number.plus(), sub_ehtmls(Name), Numb, sub_desc(Numb, ["&nbsp;"])))
- # if limit and limit <= Number._int():
- # break
- # if not limit or limit > 25:
- # if ltype == Types[1]:
- # Answer(AnsBase[11], ltype, source, disp)
- # Top250 = str.join(chr(10), ls)
- # Msend(source[0], Top250, disp)
- # else:
- # answer = str.join(chr(10), ls)
- # elif data.count(c3op):
- # answer = AllwebAnsBase[-1]
- # else:
- # answer = AllwebAnsBase[1]
- if isNumber(body):
- Req = Web("http://m.kinopoisk.ru/movie/%s" % (body))
- try:
- data = Req.get_page(UserAgent_Moz)
- except:
- answer = AllwebAnsBase[0]
+ data = data.decode("cp1251")
+ rslt = get_text(data, "<p class=\"title\">", "</div>")
+ if rslt:
+ rslt = self.decodeHTML(rslt)
+ ls = ["\->"]
+ for line in rslt.splitlines():
+ line = line.strip()
+ if line:
+ if line[0].islower():
+ line = "{1}{0}".format(line[1:], line[0].upper())
+ ls.append(line)
+ answer = str.join(chr(10), ls)
+ elif data.count(c3op):
+ answer = self.AnsBase[-1]
+ else:
+ answer = self.AnsBase[5]
else:
- data = data.decode("cp1251")
- relt = get_text(data, "<p class=\"title\">", "</div>")
- if relt:
- relt = decodeHTML(relt)
- ls = ["\->"]
- for line in relt.splitlines():
- line = line.strip()
- if line:
- if line[0].islower():
- line = "{1}{0}".format(line[1:], line[0].upper())
- ls.append(line)
- answer = str.join(chr(10), ls)
- elif data.count(c3op):
- answer = AllwebAnsBase[-1]
+ Req = (body if chr(42) != c1st else body[2:].strip())
+ Req = Req.encode("cp1251")
+ Req = Web("http://m.kinopoisk.ru/search/%s" % Web.One.quote_plus(Req))
+ try:
+ data = Req.get_page(self.UserAgent_Moz)
+ except:
+ answer = self.AnsBase[0]
else:
- answer = AllwebAnsBase[5]
+ data = data.decode("cp1251")
+ comp = compile__("<a href=\"http://m.kinopoisk.ru/movie/(\d+?)/\">(.+?)</a>")
+ list = comp.findall(data)
+ if list:
+ Number = itypes.Number()
+ ls = ["\n[#] [Name, Year] (#id)"]
+ for Numb, Name in list:
+ ls.append("%d) %s (#%s)" % (Number.plus(), self.sub_ehtmls(Name), Numb))
+ answer = str.join(chr(10), ls)
+ elif data.count(c3op):
+ answer = self.AnsBase[-1]
+ else:
+ answer = self.AnsBase[5]
else:
- Req = (body if chr(42) != c1st else body[2:].strip())
- Req = Req.encode("cp1251")
- Req = Web("http://m.kinopoisk.ru/search/%s" % Web.One.quote_plus(Req))
- try:
- data = Req.get_page(UserAgent_Moz)
- except:
- answer = AllwebAnsBase[0]
- else:
- data = data.decode("cp1251")
- comp = compile__("<a href=\"http://m.kinopoisk.ru/movie/(\d+?)/\">(.+?)</a>")
- list = comp.findall(data)
- if list:
- Number = itypes.Number()
- ls = ["\n[#] [Name, Year] (#id)"]
- for Numb, Name in list:
- ls.append("%d) %s (#%s)" % (Number.plus(), sub_ehtmls(Name), Numb))
- answer = str.join(chr(10), ls)
- elif data.count(c3op):
- answer = AllwebAnsBase[-1]
- else:
- answer = AllwebAnsBase[5]
- else:
- answer = AnsBase[1]
- if locals().has_key(Types[12]):
- Answer(answer, ltype, source, disp)
+ answer = AnsBase[1]
+ if locals().has_key(Types[12]):
+ Answer(answer, ltype, source, disp)
-def command_imdb(ltype, source, body, disp):
- if body:
- ls = body.split()
- c1st = (ls.pop(0)).lower()
- if c1st in ("top250", "топ250".decode("utf-8")):
- if ls:
- limit = exec_(int, (ls.pop(0),))
- if limit <= 5:
- limit = 5
- else:
- limit = None
- Req = Web("http://www.imdb.com/chart/top")
- try:
- data = Req.get_page(UserAgent_Moz)
- except:
- answer = AllwebAnsBase[0]
- else:
- list = get_text(data, '<div id="main">', "</div>")
- if list:
- comp = compile__('<td align="center">%s((?:\d+\.\d)+|\d+?)</font></td><td>%s<a href="/title/tt\d+?/">' \
- '(.+?)</a>(.+?)</font></td><td align="right">%s(.+?)</font>' \
- '</td>' % (('<font face="Arial, Helvetica, sans-serif" size="-1">',)*3), 16)
- list = comp.findall(list)
- if list:
- Number = itypes.Number()
- ls = ["\n[#] [Name, Year] [Rating] (Votes)"]
- for Numb, Name, Year, Numb_ in list:
- ls.append("%s) %s %s - %s (%s)" % (Number.plus(), sub_ehtmls(Name), Year.strip(), Numb, Numb_))
- if limit and limit <= Number._int():
- break
- if not limit or limit > 25:
- if ltype == Types[1]:
- Answer(AnsBase[11], ltype, source, disp)
- Top250 = str.join(chr(10), ls)
- Msend(source[0], Top250, disp)
- else:
- answer = str.join(chr(10), ls)
+ def command_imdb(self, ltype, source, body, disp):
+ if body:
+ ls = body.split()
+ c1st = (ls.pop(0)).lower()
+ if c1st in ("top250", "топ250".decode("utf-8")):
+ if ls:
+ limit = exec_(int, (ls.pop(0),))
+ if limit <= 5:
+ limit = 5
else:
- answer = AllwebAnsBase[1]
- elif isNumber(body):
- Req = Web("http://www.imdb.com/title/tt%s/" % (body))
- try:
- data = Req.get_page(UserAgent_Moz)
- except:
- answer = AllwebAnsBase[0]
- else:
- Name = get_text(data, '<h1 class="header" itemprop="name">', "<span>")
- if Name:
- ls = ["\->"]
- Year = get_text(data, '<a href="/year/\d+?/">', "</a>", "\d+")
- if Year:
- ls.append("%s (%s)" % (Name, Year))
+ limit = None
+ Req = Web("http://www.imdb.com/chart/top")
+ try:
+ data = Req.get_page(self.UserAgent_Moz)
+ except:
+ answer = self.AnsBase[0]
+ else:
+ list = get_text(data, '<div id="main">', "</div>")
+ if list:
+ comp = compile__('<td align="center">%s((?:\d+\.\d)+|\d+?)</font></td><td>%s<a href="/title/tt\d+?/">' \
+ '(.+?)</a>(.+?)</font></td><td align="right">%s(.+?)</font>' \
+ '</td>' % (('<font face="Arial, Helvetica, sans-serif" size="-1">',)*3), 16)
+ list = comp.findall(list)
+ if list:
+ Number = itypes.Number()
+ ls = ["\n[#] [Name, Year] [Rating] (Votes)"]
+ for Numb, Name, Year, Numb_ in list:
+ ls.append("%s) %s %s - %s (%s)" % (Number.plus(), self.sub_ehtmls(Name), Year.strip(), Numb, Numb_))
+ if limit and limit <= Number._int():
+ break
+ if not limit or limit > 25:
+ if ltype == Types[1]:
+ Answer(AnsBase[11], ltype, source, disp)
+ Top250 = str.join(chr(10), ls)
+ Msend(source[0], Top250, disp)
+ else:
+ answer = str.join(chr(10), ls)
else:
- ls.append(Name)
- desc = get_text(data, '<p itemprop="description">', "</p>")
- if desc:
- ls.append(desc)
- desc = ls.index(desc)
- Numb = get_text(data, '<span itemprop="ratingValue">', "</span>")
- UsrV = get_text(data, '<span itemprop="ratingCount">', "</span>")
- if Numb:
- if UsrV:
- Numb = "%s (Votes: %s)" % (Numb, UsrV)
- ls.append("Raiting: %s" % Numb)
- Ttls = (("Director", "\s*Director:\s*"),
- ("Stars", "\s*Stars:\s*"),
- ("Writers", "\s*Writers:\s*"), ("Writer", "\s*Writer:\s*"))
- for Title in Ttls:
- list = get_text(data, '<h4 class="inline">%s</h4>' % Title[1], "</div>")
- if list:
- comp = compile__(">(.+?)</a>")
- list = comp.findall(list)
+ answer = self.AnsBase[1]
+ elif isNumber(body):
+ Req = Web("http://www.imdb.com/title/tt%s/" % (body))
+ try:
+ data = Req.get_page(self.UserAgent_Moz)
+ except:
+ answer = self.AnsBase[0]
+ else:
+ Name = get_text(data, '<h1 class="header" itemprop="name">', "<span>")
+ if Name:
+ ls = ["\->"]
+ Year = get_text(data, '<a href="/year/\d+?/">', "</a>", "\d+")
+ if Year:
+ ls.append("%s (%s)" % (Name, Year))
+ else:
+ ls.append(Name)
+ desc = get_text(data, '<p itemprop="description">', "</p>")
+ if desc:
+ ls.append(desc)
+ desc = ls.index(desc)
+ Numb = get_text(data, '<span itemprop="ratingValue">', "</span>")
+ UsrV = get_text(data, '<span itemprop="ratingCount">', "</span>")
+ if Numb:
+ if UsrV:
+ Numb = "%s (Votes: %s)" % (Numb, UsrV)
+ ls.append("Raiting: %s" % Numb)
+ Ttls = (("Director", "\s*Director:\s*"),
+ ("Stars", "\s*Stars:\s*"),
+ ("Writers", "\s*Writers:\s*"), ("Writer", "\s*Writer:\s*"))
+ for Title in Ttls:
+ list = get_text(data, '<h4 class="inline">%s</h4>' % Title[1], "</div>")
if list:
- ls.append("%s: %s" % (Title[0], str.join(", ", list)))
- if len(ls) >= 2:
- for ln in ls:
- data = decodeHTML(ln)
- lines = []
- for line in data.splitlines():
- line = line.strip()
- if line:
- lines.append(line)
- li = ls.index(ln)
- if li == desc:
- lines.append(chr(10))
- lines.insert(0, chr(10))
- ls[li] = str.join(chr(10), lines)
- answer = str.join(chr(10), ls)
+ comp = compile__(">(.+?)</a>")
+ list = comp.findall(list)
+ if list:
+ ls.append("%s: %s" % (Title[0], str.join(", ", list)))
+ if len(ls) >= 2:
+ for ln in ls:
+ data = self.decodeHTML(ln)
+ lines = []
+ for line in data.splitlines():
+ line = line.strip()
+ if line:
+ lines.append(line)
+ li = ls.index(ln)
+ if li == desc:
+ lines.append(chr(10))
+ lines.insert(0, chr(10))
+ ls[li] = str.join(chr(10), lines)
+ answer = str.join(chr(10), ls)
+ else:
+ answer = self.AnsBase[1]
else:
- answer = AllwebAnsBase[1]
- else:
- answer = AllwebAnsBase[1]
- else:
- Req = (body if chr(42) != c1st else body[2:].strip())
- Req = Req.encode("utf-8")
- Req = Web("http://www.imdb.com/find?", [("s", "tt"), ("q", Req)])
- try:
- data = Req.get_page(UserAgent_Moz)
- except:
- answer = AllwebAnsBase[0]
+ answer = self.AnsBase[1]
else:
- list = get_text(data, "<table>", "</table>")
- if list:
- comp = compile__("/find-title-\d+?/title_.+?/images/b.gif\?link=/title/tt(\d+?)/';\">(.+?)</a> (.+?)<", 16)
- list = comp.findall(list)
- if list:
- Number = itypes.Number()
- ls = ["\n[#] [Name, Year] (#id)"]
- for Numb, Name, Year in list:
- ls.append("%d) %s %s (#%s)" % (Number.plus(), sub_ehtmls(Name), Year.strip(), Numb))
- answer = str.join(chr(10), ls)
+ Req = (body if chr(42) != c1st else body[2:].strip())
+ Req = Req.encode("utf-8")
+ Req = Web("http://www.imdb.com/find?", [("s", "tt"), ("q", Req)])
+ try:
+ data = Req.get_page(self.UserAgent_Moz)
+ except:
+ answer = self.AnsBase[0]
else:
- answer = AllwebAnsBase[5]
- else:
- answer = AnsBase[1]
- if locals().has_key(Types[12]):
- Answer(answer, ltype, source, disp)
+ list = get_text(data, "<table>", "</table>")
+ if list:
+ comp = compile__("/find-title-\d+?/title_.+?/images/b.gif\?link=/title/tt(\d+?)/';\">(.+?)</a> (.+?)<", 16)
+ list = comp.findall(list)
+ if list:
+ Number = itypes.Number()
+ ls = ["\n[#] [Name, Year] (#id)"]
+ for Numb, Name, Year in list:
+ ls.append("%d) %s %s (#%s)" % (Number.plus(), self.sub_ehtmls(Name), Year.strip(), Numb))
+ answer = str.join(chr(10), ls)
+ else:
+ answer = self.AnsBase[5]
+ else:
+ answer = AnsBase[1]
+ if locals().has_key(Types[12]):
+ Answer(answer, ltype, source, disp)
-def command_python(ltype, source, body, disp):
- Req = Web("http://python.org/")
- try:
- data = Req.get_page(UserAgent)
- except:
- answer = AllwebAnsBase[0]
- else:
- data = data.decode("koi8-r")
- data = get_text(data, "<h2 class=\"news\">", "</div>")
- if data:
- data = decodeHTML(data)
- ls = []
- for line in data.splitlines():
- if line.strip():
- ls.append(line)
- answer = str.join(chr(10), ls)
+ def command_python(self, ltype, source, body, disp):
+ Req = Web("http://python.org/")
+ try:
+ data = Req.get_page(self.UserAgent)
+ except:
+ answer = self.AnsBase[0]
else:
- answer = AllwebAnsBase[1]
- Answer(answer, ltype, source, disp)
-
-def command_currency(ltype, source, body, disp):
- if body:
- ls = body.split()
- Code = (ls.pop(0)).lower()
- if Code in ("code", "аббревиатура".decode("utf-8")):
- if ls:
- Code = (ls.pop(0)).upper()
- if Currency_desc.has_key(Code):
- answer = Currency_desc[Code].decode("utf-8")
- else:
- answer = AllwebAnsBase[1]
+ data = data.decode("koi8-r")
+ data = get_text(data, "<h2 class=\"news\">", "</div>")
+ if data:
+ data = self.decodeHTML(data)
+ ls = []
+ for line in data.splitlines():
+ if line.strip():
+ ls.append(line)
+ answer = str.join(chr(10), ls)
else:
- answer = AnsBase[2]
- elif Code in ("list", "список".decode("utf-8")):
- if ltype == Types[1]:
- Answer(AnsBase[11], ltype, source, disp)
- Curls = ["\->"] + ["%s: %s" % desc for desc in sorted(Currency_desc.items())]
- Msend(source[0], str.join(chr(10), Curls), disp)
- elif Code in ("calc", "перевести".decode("utf-8")):
- if len(ls) >= 2:
- Number = ls.pop(0)
- if isNumber(Number) and ls[0].isalpha():
- Number = int(Number)
+ answer = self.AnsBase[1]
+ Answer(answer, ltype, source, disp)
+
+ def command_currency(self, ltype, source, body, disp):
+ if body:
+ ls = body.split()
+ Code = (ls.pop(0)).lower()
+ if Code in ("code", "аббревиатура".decode("utf-8")):
+ if ls:
Code = (ls.pop(0)).upper()
- if (Code == "RUB"):
- answer = "%d %s" % (Number, Code)
- elif Currency_desc.has_key(Code):
- Req = Web("http://www.cbr.ru/scripts/XML_daily.asp")
- try:
- data = Req.get_page(UserAgent)
- except:
- answer = AllwebAnsBase[0]
- else:
- data = data.decode("cp1251")
- comp = compile__("<CharCode>%s</CharCode>\s+?<Nominal>(.+?)</Nominal>\s+?<Name>.+?</Name>\s+?<Value>(.+?)</Value>" % (Code), 16)
- data = comp.search(data)
- if data:
- No, Numb = data.groups()
- Numb = Numb.replace(chr(44), chr(46))
- No = No.replace(chr(44), chr(46))
- try:
- Numb = (Number*(float(Numb)/float(No)))
- except:
- answer = AnsBase[7]
- else:
- answer = "%.2f RUB" % (Numb)
+ if self.Currency_desc.has_key(Code):
+ answer = self.Currency_desc[Code].decode("utf-8")
+ else:
+ answer = self.AnsBase[1]
+ else:
+ answer = AnsBase[2]
+ elif Code in ("list", "список".decode("utf-8")):
+ if ltype == Types[1]:
+ Answer(AnsBase[11], ltype, source, disp)
+ Curls = ["\->"] + ["%s: %s" % desc for desc in sorted(self.Currency_desc.items())]
+ Msend(source[0], str.join(chr(10), Curls), disp)
+ elif Code in ("calc", "перевести".decode("utf-8")):
+ if len(ls) >= 2:
+ Number = ls.pop(0)
+ if isNumber(Number) and ls[0].isalpha():
+ Number = int(Number)
+ Code = (ls.pop(0)).upper()
+ if (Code == "RUB"):
+ answer = "%d %s" % (Number, Code)
+ elif self.Currency_desc.has_key(Code):
+ Req = Web("http://www.cbr.ru/scripts/XML_daily.asp")
+ try:
+ data = Req.get_page(self.UserAgent)
+ except:
+ answer = self.AnsBase[0]
else:
- answer = AllwebAnsBase[1]
+ data = data.decode("cp1251")
+ comp = compile__("<CharCode>%s</CharCode>\s+?<Nominal>(.+?)</Nominal>\s+?<Name>.+?</Name>\s+?<Value>(.+?)</Value>" % (Code), 16)
+ data = comp.search(data)
+ if data:
+ No, Numb = data.groups()
+ Numb = Numb.replace(chr(44), chr(46))
+ No = No.replace(chr(44), chr(46))
+ try:
+ Numb = (Number*(float(Numb)/float(No)))
+ except:
+ answer = AnsBase[7]
+ else:
+ answer = "%.2f RUB" % (Numb)
+ else:
+ answer = self.AnsBase[1]
+ else:
+ answer = AnsBase[2]
else:
answer = AnsBase[2]
else:
answer = AnsBase[2]
- else:
- answer = AnsBase[2]
- elif (Code != "rub") and Code.isalpha():
- Code = Code.upper()
- if Currency_desc.has_key(Code):
- Req = Web("http://www.cbr.ru/scripts/XML_daily.asp")
- try:
- data = Req.get_page(UserAgent)
- except:
- answer = AllwebAnsBase[0]
- else:
- data = data.decode("cp1251")
- comp = compile__("<CharCode>%s</CharCode>\s+?<Nominal>(.+?)</Nominal>\s+?<Name>.+?</Name>\s+?<Value>(.+?)</Value>" % (Code), 16)
- data = comp.search(data)
- if data:
- No, Numb = data.groups()
- answer = "%s/RUB - %s/%s" % (Code, No, Numb)
+ elif (Code != "rub") and Code.isalpha():
+ Code = Code.upper()
+ if self.Currency_desc.has_key(Code):
+ Req = Web("http://www.cbr.ru/scripts/XML_daily.asp")
+ try:
+ data = Req.get_page(self.UserAgent)
+ except:
+ answer = self.AnsBase[0]
else:
- answer = AllwebAnsBase[1]
+ data = data.decode("cp1251")
+ comp = compile__("<CharCode>%s</CharCode>\s+?<Nominal>(.+?)</Nominal>\s+?<Name>.+?</Name>\s+?<Value>(.+?)</Value>" % (Code), 16)
+ data = comp.search(data)
+ if data:
+ No, Numb = data.groups()
+ answer = "%s/RUB - %s/%s" % (Code, No, Numb)
+ else:
+ answer = self.AnsBase[1]
+ else:
+ answer = AnsBase[2]
else:
answer = AnsBase[2]
else:
- answer = AnsBase[2]
- else:
- Req = Web("http://www.cbr.ru/scripts/XML_daily.asp")
+ Req = Web("http://www.cbr.ru/scripts/XML_daily.asp")
+ try:
+ data = Req.get_page(self.UserAgent)
+ except:
+ answer = self.AnsBase[0]
+ else:
+ data = data.decode("cp1251")
+ comp = compile__("<CharCode>(.+?)</CharCode>\s+?<Nominal>(.+?)</Nominal>\s+?<Name>.+?</Name>\s+?<Value>(.+?)</Value>", 16)
+ list = comp.findall(data)
+ if list:
+ ls, Number = ["\->"], itypes.Number()
+ for Code, No, Numb in sorted(list):
+ ls.append("%d) %s/RUB - %s/%s" % (Number.plus(), Code, No, Numb))
+ if ltype == Types[1]:
+ Answer(AnsBase[11], ltype, source, disp)
+ Curls = str.join(chr(10), ls)
+ Msend(source[0], Curls, disp)
+ else:
+ answer = self.AnsBase[1]
+ if locals().has_key(Types[12]):
+ Answer(answer, ltype, source, disp)
+
+ def command_jquote(self, ltype, source, body, disp):
+ if body and isNumber(body):
+ Req = Web("http://jabber-quotes.ru/api/read/?id=%d" % int(body))
+ else:
+ Req = Web("http://jabber-quotes.ru/api/read/?id=random")
try:
- data = Req.get_page(UserAgent)
+ data = Req.get_page(self.UserAgent)
except:
- answer = AllwebAnsBase[0]
+ answer = self.AnsBase[0]
else:
- data = data.decode("cp1251")
- comp = compile__("<CharCode>(.+?)</CharCode>\s+?<Nominal>(.+?)</Nominal>\s+?<Name>.+?</Name>\s+?<Value>(.+?)</Value>", 16)
- list = comp.findall(data)
- if list:
- ls, Number = ["\->"], itypes.Number()
- for Code, No, Numb in sorted(list):
- ls.append("%d) %s/RUB - %s/%s" % (Number.plus(), Code, No, Numb))
- if ltype == Types[1]:
- Answer(AnsBase[11], ltype, source, disp)
- Curls = str.join(chr(10), ls)
- Msend(source[0], Curls, disp)
+ data = data.decode("utf-8")
+ comp = compile__("<id>(\d+?)</id>\s+?<author>(.+?)</author>\s+?<quote>(.+?)</quote>", 16)
+ data = comp.search(data)
+ if data:
+ Numb, Name, Quote = data.groups()
+ lt = chr(10)*3
+ answer = self.decodeHTML("Quote: #%s | by %s\n%s" % (Numb, Name, Quote))
+ while answer.count(lt):
+ answer = answer.replace(lt, lt[:2])
else:
- answer = AllwebAnsBase[1]
- if locals().has_key(Types[12]):
+ answer = self.AnsBase[1]
Answer(answer, ltype, source, disp)
-def command_jquote(ltype, source, body, disp):
- if body and isNumber(body):
- Req = Web("http://jabber-quotes.ru/api/read/?id=%d" % int(body))
- else:
- Req = Web("http://jabber-quotes.ru/api/read/?id=random")
- try:
- data = Req.get_page(UserAgent)
- except:
- answer = AllwebAnsBase[0]
- else:
- data = data.decode("utf-8")
- comp = compile__("<id>(\d+?)</id>\s+?<author>(.+?)</author>\s+?<quote>(.+?)</quote>", 16)
- data = comp.search(data)
- if data:
- Numb, Name, Quote = data.groups()
- lt = chr(10)*3
- answer = decodeHTML("Quote: #%s | by %s\n%s" % (Numb, Name, Quote))
- while answer.count(lt):
- answer = answer.replace(lt, lt[:2])
+ def command_chuck(self, ltype, source, body, disp):
+ if body and isNumber(body):
+ Req = Web("http://chucknorrisfacts.ru/quote/%d" % int(body))
else:
- answer = AllwebAnsBase[1]
- Answer(answer, ltype, source, disp)
-
-def command_chuck(ltype, source, body, disp):
- if body and isNumber(body):
- Req = Web("http://chucknorrisfacts.ru/quote/%d" % int(body))
- else:
- Req = Web("http://chucknorrisfacts.ru/random")
- try:
- data = Req.get_page(UserAgent)
- except:
- answer = AllwebAnsBase[0]
- else:
- data = data.decode("cp1251")
- comp = compile__("<a href=/quote/(\d+?)>.+?<blockquote>(.+?)</blockquote>", 16)
- data = comp.search(data)
- if data:
- answer = decodeHTML("Fact: #%s\n%s" % data.groups())
+ Req = Web("http://chucknorrisfacts.ru/random")
+ try:
+ data = Req.get_page(self.UserAgent)
+ except:
+ answer = self.AnsBase[0]
else:
- answer = AllwebAnsBase[1]
- Answer(answer, ltype, source, disp)
+ data = data.decode("cp1251")
+ comp = compile__("<a href=/quote/(\d+?)>.+?<blockquote>(.+?)</blockquote>", 16)
+ data = comp.search(data)
+ if data:
+ answer = self.decodeHTML("Fact: #%s\n%s" % data.groups())
+ else:
+ answer = self.AnsBase[1]
+ Answer(answer, ltype, source, disp)
-def command_ithappens(ltype, source, body, disp):
- if body and isNumber(body):
- Req = Web("http://ithappens.ru/story/%d" % int(body))
- else:
- Req = Web("http://ithappens.ru/random")
- try:
- data = Req.get_page(UserAgent)
- except:
- answer = AllwebAnsBase[0]
- else:
- data = data.decode("cp1251")
- data = get_text(data, "<div class=\"text\">", "</p>")
- if data:
- answer = decodeHTML(sub_desc(data, {"<p class=\"date\">": chr(32)}))
+ def command_ithappens(self, ltype, source, body, disp):
+ if body and isNumber(body):
+ Req = Web("http://ithappens.ru/story/%d" % int(body))
else:
- answer = AllwebAnsBase[1]
- Answer(answer, ltype, source, disp)
-
-def command_gismeteo(ltype, source, body, disp):
- if body:
- ls = body.split()
- Numb = ls.pop(0)
- if ls and isNumber(Numb):
- City = body[(body.find(Numb) + len(Numb) + 1):].strip()
- Numb = int(Numb)
+ Req = Web("http://ithappens.ru/random")
+ try:
+ data = Req.get_page(self.UserAgent)
+ except:
+ answer = self.AnsBase[0]
else:
- City = body
- Numb = None
- if -1 < Numb < 13 or not Numb:
- Req = Web("http://m.gismeteo.ru/citysearch/by_name/?", [("gis_search", City.encode("utf-8"))])
- try:
- data = Req.get_page(UserAgent)
- except:
- answer = AllwebAnsBase[0]
+ data = data.decode("cp1251")
+ data = get_text(data, "<div class=\"text\">", "</p>")
+ if data:
+ answer = self.decodeHTML(sub_desc(data, {"<p class=\"date\">": chr(32)}))
else:
- data = data.decode("utf-8")
- data = get_text(data, "<a href=\"/weather/", "/(1/)*?\">", "\d+")
- if data:
- if Numb != None:
- data = str.join(chr(47), [data, str(Numb) if Numb != 0 else "weekly"])
- Req = Web("http://m.gismeteo.ru/weather/%s/" % data)
- try:
- data = Req.get_page(UserAgent)
- except:
- answer = AllwebAnsBase[0]
- else:
- data = data.decode("utf-8")
- mark = get_text(data, "<th colspan=\"2\">", "</th>")
- if Numb != 0:
- comp = compile__('<tr class="tbody">\s+?<th.*?>(.+?)</th>\s+?<td.+?/></td>\s+?</tr>\s+?<tr>\s+?<td.+?>(.+?)</td>\s+?</tr>\s+?<tr class="dl">\s+?<td>&nbsp;</td>\s+?<td class="clpersp"><p>(.+?)</p></td>\s+?</tr>\s+?<tr class="dl"><td class="left">(.+?)</td><td>(.+?)</td></tr>\s+?<tr class="dl"><td class="left">(.+?)</td><td>(.+?)</td></tr>\s+?<tr class="dl bottom"><td class="left">(.+?)</td><td>(.+?)</td></tr>', 16)
- list = comp.findall(data)
- if list:
- ls = [(decodeHTML(mark) if mark else "\->")]
- for data in list:
- ls.append("{0}:\n\t{2}, {1}\n\t{3} {4}\n\t{5} {6}\n\t{7} {8}".format(*data))
- ls.append(AllwebAnsBase[-2])
- answer = decodeHTML(str.join(chr(10), ls))
- else:
- answer = AllwebAnsBase[1]
+ answer = self.AnsBase[1]
+ Answer(answer, ltype, source, disp)
+
+ def command_gismeteo(self, ltype, source, body, disp):
+ if body:
+ ls = body.split()
+ Numb = ls.pop(0)
+ if ls and isNumber(Numb):
+ City = body[(body.find(Numb) + len(Numb) + 1):].strip()
+ Numb = int(Numb)
+ else:
+ City = body
+ Numb = None
+ if -1 < Numb < 13 or not Numb:
+ Req = Web("http://m.gismeteo.ru/citysearch/by_name/?", [("gis_search", City.encode("utf-8"))])
+ try:
+ data = Req.get_page(self.UserAgent)
+ except:
+ answer = self.AnsBase[0]
+ else:
+ data = data.decode("utf-8")
+ data = get_text(data, "<a href=\"/weather/", "/(1/)*?\">", "\d+")
+ if data:
+ if Numb != None:
+ data = str.join(chr(47), [data, str(Numb) if Numb != 0 else "weekly"])
+ Req = Web("http://m.gismeteo.ru/weather/%s/" % data)
+ try:
+ data = Req.get_page(self.UserAgent)
+ except:
+ answer = self.AnsBase[0]
else:
- comp = compile__('<tr class="tbody">\s+?<td class="date" colspan="3"><a.+?>(.+?)</a></td>\s+?</tr>\s+?<tr>\s+?<td rowspan="2"><a.+?/></a></td>\s+?<td class="clpersp"><p>(.+?)</p></td>\s+?</tr>\s+?<tr>\s+?<td.+?>(.+?)</td>', 16)
- list = comp.findall(data)
- if list:
- ls = [(decodeHTML(mark) if mark else "\->")]
- for data in list:
- ls.append("%s:\n\t%s, %s" % (data))
- ls.append(AllwebAnsBase[-2])
- answer = decodeHTML(str.join(chr(10), ls))
+ data = data.decode("utf-8")
+ mark = get_text(data, "<th colspan=\"2\">", "</th>")
+ if Numb != 0:
+ comp = compile__('<tr class="tbody">\s+?<th.*?>(.+?)</th>\s+?<td.+?/></td>\s+?</tr>\s+?<tr>\s+?<td.+?>(.+?)</td>\s+?</tr>\s+?<tr class="dl">\s+?<td>&nbsp;</td>\s+?<td class="clpersp"><p>(.+?)</p></td>\s+?</tr>\s+?<tr class="dl"><td class="left">(.+?)</td><td>(.+?)</td></tr>\s+?<tr class="dl"><td class="left">(.+?)</td><td>(.+?)</td></tr>\s+?<tr class="dl bottom"><td class="left">(.+?)</td><td>(.+?)</td></tr>', 16)
+ list = comp.findall(data)
+ if list:
+ ls = [(self.decodeHTML(mark) if mark else "\->")]
+ for data in list:
+ ls.append("{0}:\n\t{2}, {1}\n\t{3} {4}\n\t{5} {6}\n\t{7} {8}".format(*data))
+ ls.append(self.AnsBase[-2])
+ answer = self.decodeHTML(str.join(chr(10), ls))
+ else:
+ answer = self.AnsBase[1]
else:
- answer = AllwebAnsBase[1]
- else:
- answer = AllwebAnsBase[5]
+ comp = compile__('<tr class="tbody">\s+?<td class="date" colspan="3"><a.+?>(.+?)</a></td>\s+?</tr>\s+?<tr>\s+?<td rowspan="2"><a.+?/></a></td>\s+?<td class="clpersp"><p>(.+?)</p></td>\s+?</tr>\s+?<tr>\s+?<td.+?>(.+?)</td>', 16)
+ list = comp.findall(data)
+ if list:
+ ls = [(self.decodeHTML(mark) if mark else "\->")]
+ for data in list:
+ ls.append("%s:\n\t%s, %s" % (data))
+ ls.append(self.AnsBase[-2])
+ answer = self.decodeHTML(str.join(chr(10), ls))
+ else:
+ answer = self.AnsBase[1]
+ else:
+ answer = self.AnsBase[5]
+ else:
+ answer = AnsBase[2]
else:
- answer = AnsBase[2]
+ answer = AnsBase[1]
+ Answer(answer, ltype, source, disp)
+
+ commands = (
+ (command_jc, "jc", 2,),
+ (command_google, "google", 2,),
+ (command_imdb, "imdb", 2,),
+ (command_python, "python", 2,)
+ )
+
+ if DefLANG in ("RU", "UA"):
+ commands = commands.__add__((
+ (command_kino, "kino", 2,),
+ (command_currency, "currency", 2,),
+ (command_jquote, "jquote", 2,),
+ (command_chuck, "chuck", 2,),
+ (command_ithappens, "ithappens", 2,),
+ (command_gismeteo, "gismeteo", 2,)
+ ))
+ Currency_desc = Currency_desc
else:
- answer = AnsBase[1]
- Answer(answer, ltype, source, disp)
-
-expansions[exp_name].funcs_add([sub_ehtmls, e_sb, decodeHTML, command_jc, command_google, command_imdb, command_python])
-expansions[exp_name].ls.extend([
- htmlentitydefs.__name__,
- json.__name__,
- "AllwebAnsBase",
- "UserAgent",
- "UserAgent_Moz",
- "edefs",
- "REP_desc",
- "XML_ls",
- "UserAgents",
- "compile_st",
- "compile_ehtmls",
- "gCache"
- ])
-
-command_handler(command_jc, {"RU": "рейтинг", "EN": "jc"}, 2, exp_name)
-command_handler(command_google, {"RU": "гугл", "EN": "google"}, 2, exp_name)
+ del command_kino, command_currency, command_jquote, command_chuck, command_ithappens, command_gismeteo
if DefLANG in ("RU", "UA"):
-
- expansions[exp_name].funcs_add([command_kino, command_currency, command_jquote, command_chuck, command_ithappens, command_gismeteo])
- expansions[exp_name].ls.extend(["Currency_desc"])
-
- command_handler(command_kino, {"RU": "кино", "EN": "kino"}, 2, exp_name)
- command_handler(command_currency, {"RU": "валюты", "EN": "currency"}, 2, exp_name)
- command_handler(command_jquote, {"RU": "цитата", "EN": "jquote"}, 2, exp_name)
- command_handler(command_chuck, {"RU": "чак", "EN": "chuck"}, 2, exp_name)
- command_handler(command_ithappens, {"RU": "ит", "EN": "ithappens"}, 2, exp_name)
- command_handler(command_gismeteo, {"RU": "погода", "EN": "gismeteo"}, 2, exp_name)
-else:
- del command_kino, command_currency, command_jquote, command_chuck, command_ithappens, command_gismeteo
-
-command_handler(command_imdb, {"RU": "imdb", "EN": "imdb"}, 2, exp_name)
-command_handler(command_python, {"RU": "питон", "EN": "python"}, 2, exp_name)
+ del Currency_desc
+del UserAgents
diff --git a/expansions/allweb/currency.name b/expansions/allweb/currency.name
new file mode 100644
index 0000000..1edb727
--- /dev/null
+++ b/expansions/allweb/currency.name
@@ -0,0 +1,4 @@
+{
+ "RU": "валюты",
+ "UA": "валюты"
+} \ No newline at end of file
diff --git a/expansions/allweb/gismeteo.name b/expansions/allweb/gismeteo.name
new file mode 100644
index 0000000..20376eb
--- /dev/null
+++ b/expansions/allweb/gismeteo.name
@@ -0,0 +1,4 @@
+{
+ "RU": "погода",
+ "UA": "погода"
+} \ No newline at end of file
diff --git a/expansions/allweb/google.name b/expansions/allweb/google.name
new file mode 100644
index 0000000..ede94f5
--- /dev/null
+++ b/expansions/allweb/google.name
@@ -0,0 +1,4 @@
+{
+ "RU": "гугл",
+ "UA": "гугл"
+} \ No newline at end of file
diff --git a/expansions/allweb/imdb.name b/expansions/allweb/imdb.name
new file mode 100644
index 0000000..94dc1ec
--- /dev/null
+++ b/expansions/allweb/imdb.name
@@ -0,0 +1,4 @@
+{
+ "RU": "imdb",
+ "UA": "imdb"
+} \ No newline at end of file
diff --git a/expansions/allweb/insc.py b/expansions/allweb/insc.py
index 43c7132..e157a94 100644
--- a/expansions/allweb/insc.py
+++ b/expansions/allweb/insc.py
@@ -4,10 +4,10 @@ UserAgents = {
"RU": "ru-RU",
"UA": "ua-UA",
"EN": "en-US"
- }
+ }
if DefLANG in ("RU", "UA"):
- AllwebAnsBase = tuple([line.decode("utf-8") for line in (
+ AnsBase_temp = tuple([line.decode("utf-8") for line in (
"Не могу получить доступ к странице.", # 0
"Проблемы с разметкой...", # 1
"Твоих запросов нет в базе.", # 2
@@ -57,7 +57,7 @@ if DefLANG in ("RU", "UA"):
"ZAR": "Южноафриканский рэнд"
}
else:
- AllwebAnsBase = (
+ AnsBase_temp = (
"No access to the page.", # 0
"Trouble with the marking...", # 1
"There are no your requests in cache.", # 2
diff --git a/expansions/allweb/ithappens.name b/expansions/allweb/ithappens.name
new file mode 100644
index 0000000..c951dda
--- /dev/null
+++ b/expansions/allweb/ithappens.name
@@ -0,0 +1,4 @@
+{
+ "RU": "ит",
+ "UA": "ит"
+} \ No newline at end of file
diff --git a/expansions/allweb/jc.name b/expansions/allweb/jc.name
new file mode 100644
index 0000000..4d566aa
--- /dev/null
+++ b/expansions/allweb/jc.name
@@ -0,0 +1,4 @@
+{
+ "RU": "рейтинг",
+ "UA": "рейтинг"
+} \ No newline at end of file
diff --git a/expansions/allweb/jquote.name b/expansions/allweb/jquote.name
new file mode 100644
index 0000000..5f76d66
--- /dev/null
+++ b/expansions/allweb/jquote.name
@@ -0,0 +1,4 @@
+{
+ "RU": "цитата",
+ "UA": "цитата"
+} \ No newline at end of file
diff --git a/expansions/allweb/kino.name b/expansions/allweb/kino.name
new file mode 100644
index 0000000..f46f546
--- /dev/null
+++ b/expansions/allweb/kino.name
@@ -0,0 +1,4 @@
+{
+ "RU": "кино",
+ "UA": "кино"
+} \ No newline at end of file
diff --git a/expansions/allweb/python.name b/expansions/allweb/python.name
new file mode 100644
index 0000000..89e1057
--- /dev/null
+++ b/expansions/allweb/python.name
@@ -0,0 +1,4 @@
+{
+ "RU": "питон",
+ "UA": "питон"
+} \ No newline at end of file
diff --git a/expansions/apocalypse/apocalypse.name b/expansions/apocalypse/apocalypse.name
new file mode 100644
index 0000000..35ee79f
--- /dev/null
+++ b/expansions/apocalypse/apocalypse.name
@@ -0,0 +1,4 @@
+{
+ "RU": "апокалипсис",
+ "UA": "апокалипсис"
+} \ No newline at end of file
diff --git a/expansions/apocalypse/code.py b/expansions/apocalypse/code.py
index 09ba22e..be946fe 100644
--- a/expansions/apocalypse/code.py
+++ b/expansions/apocalypse/code.py
@@ -1,25 +1,28 @@
# coding: utf-8
# BlackSmith mark.2
-exp_name = "apocalypse" # /code.py v.x1
-# Id: 0~1a
+exp_name = "apocalypse" # /code.py v.x2
+# Id: 0~2b
# Code © (2012) by WitcherGeralt [alkorgun@gmail.com]
expansion_register(exp_name)
-def command_apocalypse(ltype, source, body, disp):
- Time = time.gmtime()
- t1 = (356 - Time.tm_yday)
- if not t1:
- answer = "We all gonna die today!"
- elif t1 == 1:
- answer = "Tomorrow will be the doomday!"
- elif t1 < 0 or Time.tm_year != 2012:
- answer = "We must be already dead..."
- else:
- answer = "There are %d days left to the Apocalypse." % (t1)
- Answer(answer, ltype, source, disp)
+class expansion_temp(expansion):
-expansions[exp_name].funcs_add([command_apocalypse])
+ def __init__(self, name):
+ expansion.__init__(self, name)
-command_handler(command_apocalypse, {"RU": "апокалипсис", "EN": "apocalypse"}, 1, exp_name)
+ def command_apocalypse(self, ltype, source, body, disp):
+ Time = time.gmtime()
+ t1 = (356 - Time.tm_yday)
+ if not t1:
+ answer = "We all gonna die today!"
+ elif t1 == 1:
+ answer = "Tomorrow will be the doomsday!"
+ elif t1 < 0 or Time.tm_year != 2012:
+ answer = "We must be already dead..."
+ else:
+ answer = "There are %d days left to the Apocalypse." % (t1)
+ Answer(answer, ltype, source, disp)
+
+ commands = ((command_apocalypse, "apocalypse", 1,),)
diff --git a/expansions/basic_control/code.py b/expansions/basic_control/code.py
index 64cbfc0..de01e6e 100644
--- a/expansions/basic_control/code.py
+++ b/expansions/basic_control/code.py
@@ -1,200 +1,204 @@
# coding: utf-8
# BlackSmith mark.2
-exp_name = "basic_control" # /code.py v.x8
-# Id: 06~2a
-# Code © (2009-2011) by WitcherGeralt [WitcherGeralt@rocketmail.com]
+exp_name = "basic_control" # /code.py v.x9
+# Id: 06~3b
+# Code © (2009-2011) by WitcherGeralt [alkorgun@gmail.com]
expansion_register(exp_name)
-def Chat_check(conf):
- Numb = itypes.Number()
- while Chats.has_key(conf):
- if Chats[conf].IamHere != None:
- break
- time.sleep(.4)
- if Numb.plus() >= 50:
- break
+class expansion_temp(expansion):
-def command_join(ltype, source, body, disp):
- if body:
- ls = body.split()
- conf = (ls.pop(0)).lower()
- if conf.count("@conference.") and conf.count(".") >= 2:
- if not Chats.has_key(conf):
- confname = dynamic % (conf)
- if not check_nosimbols(confname):
- confname = encode_filename(confname)
- if not os.path.exists(confname):
- try:
- os.makedirs(confname, 0755)
- except:
- confname = None
- if confname:
- codename, disp_, cPref, nick = None, None, None, DefNick
- while ls:
- x = ls.pop()
- if x.startswith("1="):
- x = x.split("1=", 1)
- if len(x) == 2 and x[1]:
- x = x[1].lower()
- if Clients.has_key(x):
- disp_ = x
- elif x.startswith("2="):
- x = x.split("2=", 1)
- if len(x) == 2 and x[1]:
- if len(x[1]) <= 16:
- nick = x[1]
- elif x.startswith("3="):
- x = x.split("3=", 1)
- if len(x) == 2 and x[1]:
- if x[1] in cPrefs:
- cPref = x[1]
- elif x.startswith("4="):
- x = x.split("4=", 1)
- if len(x) == 2 and x[1]:
- codename = x[1]
- inst = get_source(source[1], source[2])
- if GodName != inst:
- delivery(ControlAnsBase[0] % (source[2], inst, conf))
- if not disp_:
- disp_ = IdleClient()
- Chats[conf] = sConf(conf, disp_, codename, cPref, nick)
- Chats[conf].load_all()
- Chats[conf].join()
- Chat_check(conf)
- if Chats.has_key(conf) and Chats[conf].IamHere:
- Msend(conf, ControlAnsBase[7] % (ProdName, source[2]), disp_)
- answer = ControlAnsBase[2] % (conf)
+ def __init__(self, name):
+ expansion.__init__(self, name)
+
+ def Chat_check(self, conf):
+ Numb = itypes.Number()
+ while Chats.has_key(conf):
+ if Chats[conf].IamHere != None:
+ break
+ time.sleep(.4)
+ if Numb.plus() >= 50:
+ break
+
+ def command_join(self, ltype, source, body, disp):
+ if body:
+ ls = body.split()
+ conf = (ls.pop(0)).lower()
+ if conf.count("@conference.") and conf.count(".") >= 2:
+ if not Chats.has_key(conf):
+ confname = dynamic % (conf)
+ if not check_nosimbols(confname):
+ confname = encode_filename(confname)
+ if not os.path.exists(confname):
+ try:
+ os.makedirs(confname, 0755)
+ except:
+ confname = None
+ if confname:
+ codename, disp_, cPref, nick = None, None, None, DefNick
+ while ls:
+ x = ls.pop()
+ if x.startswith("1="):
+ x = x.split("1=", 1)
+ if len(x) == 2 and x[1]:
+ x = x[1].lower()
+ if Clients.has_key(x):
+ disp_ = x
+ elif x.startswith("2="):
+ x = x.split("2=", 1)
+ if len(x) == 2 and x[1]:
+ if len(x[1]) <= 16:
+ nick = x[1]
+ elif x.startswith("3="):
+ x = x.split("3=", 1)
+ if len(x) == 2 and x[1]:
+ if x[1] in cPrefs:
+ cPref = x[1]
+ elif x.startswith("4="):
+ x = x.split("4=", 1)
+ if len(x) == 2 and x[1]:
+ codename = x[1]
+ inst = get_source(source[1], source[2])
+ if GodName != inst:
+ delivery(self.AnsBase[0] % (source[2], inst, conf))
+ if not disp_:
+ disp_ = IdleClient()
+ Chats[conf] = sConf(conf, disp_, codename, cPref, nick)
+ Chats[conf].load_all()
+ Chats[conf].join()
+ self.Chat_check(conf)
+ if Chats.has_key(conf) and Chats[conf].IamHere:
+ Msend(conf, self.AnsBase[7] % (ProdName, source[2]), disp_)
+ answer = self.AnsBase[2] % (conf)
+ else:
+ answer = self.AnsBase[3] % (conf)
+ time.sleep(3.6)
+ if ejoinTimerName(conf) in iThr.ThrNames():
+ answer += self.AnsBase[13]
else:
- answer = ControlAnsBase[3] % (conf)
- time.sleep(3.6)
- if ejoinTimerName(conf) in iThr.ThrNames():
- answer += ControlAnsBase[13]
+ answer = self.AnsBase[15] % (conf)
else:
- answer = ControlAnsBase[15] % (conf)
+ answer = self.AnsBase[5]
else:
- answer = ControlAnsBase[5]
+ answer = self.AnsBase[6] % (conf)
else:
- answer = ControlAnsBase[6] % (conf)
- else:
- answer = AnsBase[1]
- Answer(answer, ltype, source, disp)
+ answer = AnsBase[1]
+ Answer(answer, ltype, source, disp)
-def command_rejoin(ltype, source, body, disp):
- if body:
- conf = body.split()[0].lower()
- else:
- conf = source[1]
- if Chats.has_key(conf):
- if online(Chats[conf].disp):
- Chats[conf].leave(ControlAnsBase[8] % (source[2]))
- time.sleep(2)
- Chats[conf].join()
- Chat_check(conf)
- if Chats.has_key(conf) and Chats[conf].IamHere:
- answer = AnsBase[4]
- else:
- answer = AnsBase[7]
+ def command_rejoin(self, ltype, source, body, disp):
+ if body:
+ conf = body.split()[0].lower()
else:
- answer = ControlAnsBase[14]
- else:
- answer = AnsBase[8]
- Answer(answer, ltype, source, disp)
-
-def command_leave(ltype, source, body, disp):
- if body:
- conf = body.split()[0].lower()
- else:
- conf = source[1]
- if not body or enough_access(source[1], source[2], 7) or conf == source[1]:
+ conf = source[1]
if Chats.has_key(conf):
- source_ = get_source(source[1], source[2])
- if GodName != source_:
- delivery(ControlAnsBase[4] % (source[2], source_, conf))
- info = ControlAnsBase[9] % (source[2])
- Msend(conf, info, Chats[conf].disp)
- time.sleep(2)
- Chats[conf].full_leave(info)
- if conf != source[1]:
- answer = ControlAnsBase[10] % (conf)
+ if online(Chats[conf].disp):
+ Chats[conf].leave(self.AnsBase[8] % (source[2]))
+ time.sleep(2)
+ Chats[conf].join()
+ self.Chat_check(conf)
+ if Chats.has_key(conf) and Chats[conf].IamHere:
+ answer = AnsBase[4]
+ else:
+ answer = AnsBase[7]
+ else:
+ answer = self.AnsBase[14]
else:
answer = AnsBase[8]
- else:
- answer = AnsBase[10]
- if locals().has_key(Types[12]):
Answer(answer, ltype, source, disp)
-def command_reconnect(ltype, source, body, disp):
- if body:
- Name = body.split()[0].lower()
- else:
- Name = get_disp(disp)
- if InstansesDesc.has_key(Name):
- ThrName = "%s%s" % (Types[13], Name)
- if Clients.has_key(Name):
- ThrIds = iThr.ThrNames()
- if ThrName in ThrIds:
- for Thr in iThr.enumerate():
- if Thr._Thread__name == ThrName:
- Thr.kill()
- if online(Name):
- try:
- Clients[Name].disconnect()
- except:
- pass
- if connect_client(Name, InstansesDesc[Name])[0]:
- try:
- Try_Thr(composeThr(Dispatch_handler, ThrName, (Name,)), -1)
- except RuntimeError:
- answer = ControlAnsBase[16]
+ def command_leave(self, ltype, source, body, disp):
+ if body:
+ conf = body.split()[0].lower()
+ else:
+ conf = source[1]
+ if not body or enough_access(source[1], source[2], 7) or conf == source[1]:
+ if Chats.has_key(conf):
+ source_ = get_source(source[1], source[2])
+ if GodName != source_:
+ delivery(self.AnsBase[4] % (source[2], source_, conf))
+ info = self.AnsBase[9] % (source[2])
+ Msend(conf, info, Chats[conf].disp)
+ time.sleep(2)
+ Chats[conf].full_leave(info)
+ if conf != source[1]:
+ answer = self.AnsBase[10] % (conf)
else:
- for conf in Chats.keys():
- if Name == Chats[conf].disp:
- Chats[conf].join()
- answer = AnsBase[4]
+ answer = AnsBase[8]
else:
- answer = AnsBase[7]
- else:
- answer = ControlAnsBase[17] % (Name)
- Answer(answer, ltype, source, disp)
+ answer = AnsBase[10]
+ if locals().has_key(Types[12]):
+ Answer(answer, ltype, source, disp)
-def command_reload(ltype, source, body, disp):
- exit_desclr = ControlAnsBase[11] % (source[2])
- if body:
- exit_desclr += ControlAnsBase[1] % (body)
- for conf in Chats.keys():
- Msend(conf, exit_desclr, Chats[conf].disp)
- time.sleep(6)
- VarCache["alive"] = False
- iThr.Threads_kill()
- for disp in Clients.keys():
- if online(disp):
- sUnavailable(disp, exit_desclr)
- call_sfunctions("03si")
- Exit("\n\nRestart command...", 0, 15)
+ def command_reconnect(self, ltype, source, body, disp):
+ if body:
+ Name = body.split()[0].lower()
+ else:
+ Name = get_disp(disp)
+ if InstansesDesc.has_key(Name):
+ ThrName = "%s%s" % (Types[13], Name)
+ if Clients.has_key(Name):
+ ThrIds = iThr.ThrNames()
+ if ThrName in ThrIds:
+ for Thr in iThr.enumerate():
+ if Thr._Thread__name == ThrName:
+ Thr.kill()
+ if online(Name):
+ try:
+ Clients[Name].disconnect()
+ except:
+ pass
+ if connect_client(Name, InstansesDesc[Name])[0]:
+ try:
+ Try_Thr(composeThr(Dispatch_handler, ThrName, (Name,)), -1)
+ except RuntimeError:
+ answer = self.AnsBase[16]
+ else:
+ for conf in Chats.keys():
+ if Name == Chats[conf].disp:
+ Chats[conf].join()
+ answer = AnsBase[4]
+ else:
+ answer = AnsBase[7]
+ else:
+ answer = self.AnsBase[17] % (Name)
+ Answer(answer, ltype, source, disp)
-def command_exit(ltype, source, body, disp):
- exit_desclr = ControlAnsBase[12] % (source[2])
- if body:
- exit_desclr += ControlAnsBase[1] % (body)
- for conf in Chats.keys():
- Msend(conf, exit_desclr, Chats[conf].disp)
- time.sleep(6)
- VarCache["alive"] = False
- iThr.Threads_kill()
- for disp in Clients.keys():
- if online(disp):
- sUnavailable(disp, exit_desclr)
- call_sfunctions("03si")
- Exit("\n\nSysExit command...", 1, 15)
+ def command_reload(self, ltype, source, body, disp):
+ exit_desclr = self.AnsBase[11] % (source[2])
+ if body:
+ exit_desclr += self.AnsBase[1] % (body)
+ for conf in Chats.keys():
+ Msend(conf, exit_desclr, Chats[conf].disp)
+ time.sleep(6)
+ VarCache["alive"] = False
+ iThr.Threads_kill()
+ for disp in Clients.keys():
+ if online(disp):
+ sUnavailable(disp, exit_desclr)
+ call_sfunctions("03si")
+ Exit("\n\nRestart command...", 0, 15)
-expansions[exp_name].funcs_add([Chat_check, command_join, command_rejoin, command_leave, command_reconnect, command_reload, command_exit])
-expansions[exp_name].ls.extend(["ControlAnsBase"])
+ def command_exit(self, ltype, source, body, disp):
+ exit_desclr = self.AnsBase[12] % (source[2])
+ if body:
+ exit_desclr += self.AnsBase[1] % (body)
+ for conf in Chats.keys():
+ Msend(conf, exit_desclr, Chats[conf].disp)
+ time.sleep(6)
+ VarCache["alive"] = False
+ iThr.Threads_kill()
+ for disp in Clients.keys():
+ if online(disp):
+ sUnavailable(disp, exit_desclr)
+ call_sfunctions("03si")
+ Exit("\n\nSysExit command...", 1, 15)
-command_handler(command_join, {"RU": "джойн", "EN": "join"}, 7, exp_name)
-command_handler(command_rejoin, {"RU": "реджойн", "EN": "rejoin"}, 7, exp_name)
-command_handler(command_leave, {"RU": "выйди", "EN": "leave"}, 6, exp_name)
-command_handler(command_reconnect, {"RU": "реконнект", "EN": "reconnect"}, 8, exp_name)
-command_handler(command_reload, {"RU": "рестарт", "EN": "reload"}, 8, exp_name)
-command_handler(command_exit, {"RU": "выкл", "EN": "exit"}, 8, exp_name)
+ commands = (
+ (command_join, "join", 7,),
+ (command_rejoin, "rejoin", 7,),
+ (command_leave, "leave", 6,),
+ (command_reconnect, "reconnect", 8,),
+ (command_reload, "reload", 8,),
+ (command_exit, "exit", 8,)
+ )
diff --git a/expansions/basic_control/exit.name b/expansions/basic_control/exit.name
new file mode 100644
index 0000000..6c62134
--- /dev/null
+++ b/expansions/basic_control/exit.name
@@ -0,0 +1,4 @@
+{
+ "RU": "выкл",
+ "UA": "выкл"
+} \ No newline at end of file
diff --git a/expansions/basic_control/insc.py b/expansions/basic_control/insc.py
index e8579a2..139d198 100644
--- a/expansions/basic_control/insc.py
+++ b/expansions/basic_control/insc.py
@@ -1,7 +1,7 @@
# coding: utf-8
if DefLANG in ("RU", "UA"):
- ControlAnsBase = tuple([line.decode("utf-8") for line in (
+ AnsBase_temp = tuple([line.decode("utf-8") for line in (
"Внимание! %s (%s) загнал меня в -» '%s'", # 0
"\nПричина: %s", # 1
"Ага я зашел в -» '%s'", # 2
@@ -22,7 +22,7 @@ if DefLANG in ("RU", "UA"):
"«%s» нет в списке клиентов." # 17
)])
else:
- ControlAnsBase = (
+ AnsBase_temp = (
"Attention! %s (%s) sent me in to -> '%s'", # 0
"\nReason: %s", # 1
"I have joined -> '%s'", # 2
diff --git a/expansions/basic_control/join.name b/expansions/basic_control/join.name
new file mode 100644
index 0000000..56cf18b
--- /dev/null
+++ b/expansions/basic_control/join.name
@@ -0,0 +1,4 @@
+{
+ "RU": "джойн",
+ "UA": "джойн"
+} \ No newline at end of file
diff --git a/expansions/basic_control/leave.name b/expansions/basic_control/leave.name
new file mode 100644
index 0000000..340422c
--- /dev/null
+++ b/expansions/basic_control/leave.name
@@ -0,0 +1,4 @@
+{
+ "RU": "выйди",
+ "UA": "выйди"
+} \ No newline at end of file
diff --git a/expansions/basic_control/reconnect.name b/expansions/basic_control/reconnect.name
new file mode 100644
index 0000000..ba58f12
--- /dev/null
+++ b/expansions/basic_control/reconnect.name
@@ -0,0 +1,4 @@
+{
+ "RU": "реконнект",
+ "UA": "реконнект"
+} \ No newline at end of file
diff --git a/expansions/basic_control/rejoin.name b/expansions/basic_control/rejoin.name
new file mode 100644
index 0000000..fc75f13
--- /dev/null
+++ b/expansions/basic_control/rejoin.name
@@ -0,0 +1,4 @@
+{
+ "RU": "реджойн",
+ "UA": "реджойн"
+} \ No newline at end of file
diff --git a/expansions/basic_control/reload.name b/expansions/basic_control/reload.name
new file mode 100644
index 0000000..0acfe12
--- /dev/null
+++ b/expansions/basic_control/reload.name
@@ -0,0 +1,4 @@
+{
+ "RU": "рестарт",
+ "UA": "рестарт"
+} \ No newline at end of file
diff --git a/expansions/bot_sends/clear.name b/expansions/bot_sends/clear.name
new file mode 100644
index 0000000..73cd152
--- /dev/null
+++ b/expansions/bot_sends/clear.name
@@ -0,0 +1,4 @@
+{
+ "RU": "чисть",
+ "UA": "чисть"
+} \ No newline at end of file
diff --git a/expansions/bot_sends/code.py b/expansions/bot_sends/code.py
index 0f9525e..52632be 100644
--- a/expansions/bot_sends/code.py
+++ b/expansions/bot_sends/code.py
@@ -1,156 +1,160 @@
# coding: utf-8
# BlackSmith mark.2
-exp_name = "bot_sends" # /code.py v.x5
-# Id: 18~4a
-# Code © (2010-2011) by WitcherGeralt [WitcherGeralt@rocketmail.com]
+exp_name = "bot_sends" # /code.py v.x6
+# Id: 18~5b
+# Code © (2010-2011) by WitcherGeralt [alkorgun@gmail.com]
expansion_register(exp_name)
-def command_clear(ltype, source, body, disp):
- if Chats.has_key(source[1]):
- if ChatsAttrs[source[1]]["dirt"]:
- ChatsAttrs[source[1]]["dirt"] = None
- if ltype == Types[1]:
- s1_buckup = Chats[source[1]].state
- s2_buckup = Chats[source[1]].status
- Chats[source[1]].change_status(sList[2], BsendAnsBase[0])
- zero = xmpp.Message(to = source[1], typ = Types[1])
- for Numb in xrange(24):
- if not Chats.has_key(source[1]):
- raise SelfExc("exit")
- Sender(disp, zero); Info["omsg"].plus()
- if (Numb != 23):
- time.sleep(1.4)
- if ltype == Types[1]:
- Chats[source[1]].change_status(s1_buckup, s2_buckup)
- ChatsAttrs[source[1]]["dirt"] = True
- else:
- answer = BsendAnsBase[9]
- else:
- answer = AnsBase[0]
- if locals().has_key(Types[12]):
- Answer(answer, ltype, source, disp)
-
-def command_test(ltype, source, body, disp):
- errors = len(VarCache["errors"])
- if not errors:
- answer = BsendAnsBase[1]
- elif errors < (len(Clients.keys())*3):
- answer = BsendAnsBase[2] % (get_self_nick(source[1]), errors)
- else:
- answer = BsendAnsBase[3] % (errors)
- Answer(answer, ltype, source, disp)
-
-def command_sendall(ltype, source, body, disp):
- if body:
- for conf in Chats.keys():
- Msend(conf, BsendAnsBase[5] % (source[2], body))
- answer = AnsBase[4]
- else:
- answer = AnsBase[1]
- Answer(answer, ltype, source, disp)
+class expansion_temp(expansion):
-def command_more(ltype, source, body, disp):
- if Chats.has_key(source[1]):
- if Chats[source[1]].more:
- body = "[&&] %s" % (Chats[source[1]].more)
- Chats[source[1]].more = ""
- Msend(source[1], body, disp)
- else:
- Answer(AnsBase[0], ltype, source, disp)
+ def __init__(self, name):
+ expansion.__init__(self, name)
-def command_send(ltype, source, body, disp):
- if body:
- list = body.split()
- if len(list) >= 2:
- sTo = list[0]
- if isSource(sTo):
- conf = (sTo.split(chr(47)))[0].lower()
- if Chats.has_key(conf) or not conf.count("@conf"):
- Msend(sTo, BsendAnsBase[5] % (source[2], body[(body.find(sTo) + (len(sTo) + 1)):].strip()))
- answer = AnsBase[4]
- else:
- answer = AnsBase[8]
+ def command_clear(self, ltype, source, body, disp):
+ if Chats.has_key(source[1]):
+ if ChatsAttrs[source[1]]["dirt"]:
+ ChatsAttrs[source[1]]["dirt"] = None
+ if ltype == Types[1]:
+ s1_buckup = Chats[source[1]].state
+ s2_buckup = Chats[source[1]].status
+ Chats[source[1]].change_status(sList[2], self.AnsBase[0])
+ zero = xmpp.Message(to = source[1], typ = Types[1])
+ for Numb in xrange(24):
+ if not Chats.has_key(source[1]):
+ raise SelfExc("exit")
+ Sender(disp, zero); Info["omsg"].plus()
+ if (Numb != 23):
+ time.sleep(1.4)
+ if ltype == Types[1]:
+ Chats[source[1]].change_status(s1_buckup, s2_buckup)
+ ChatsAttrs[source[1]]["dirt"] = True
else:
- answer = BsendAnsBase[4]
+ answer = self.AnsBase[9]
else:
- answer = AnsBase[2]
- else:
- answer = AnsBase[1]
- Answer(answer, ltype, source, disp)
+ answer = AnsBase[0]
+ if locals().has_key(Types[12]):
+ Answer(answer, ltype, source, disp)
-def command_adelivery(ltype, source, body, disp):
- if body:
- if PrivLimit >= len(body):
- instance = get_source(source[1], source[2])
- delivery(BsendAnsBase[5] % ((source[2] if not instance else "%s (%s)" % (source[2], instance)), body))
+ def command_test(self, ltype, source, body, disp):
+ errors = len(VarCache["errors"])
+ if not errors:
+ answer = self.AnsBase[1]
+ elif errors < (len(Clients.keys())*3):
+ answer = self.AnsBase[2] % (get_self_nick(source[1]), errors)
+ else:
+ answer = self.AnsBase[3] % (errors)
+ Answer(answer, ltype, source, disp)
+
+ def command_sendall(self, ltype, source, body, disp):
+ if body:
+ for conf in Chats.keys():
+ Msend(conf, self.AnsBase[5] % (source[2], body))
answer = AnsBase[4]
else:
- answer = AnsBase[5]
- else:
- answer = AnsBase[1]
- Answer(answer, ltype, source, disp)
+ answer = AnsBase[1]
+ Answer(answer, ltype, source, disp)
-def command_say(ltype, source, body, disp):
- if body:
- if ConfLimit >= len(body):
- Msend(source[1], body, disp)
+ def command_more(self, ltype, source, body, disp):
+ if Chats.has_key(source[1]):
+ if Chats[source[1]].more:
+ body = "[&&] %s" % (Chats[source[1]].more)
+ Chats[source[1]].more = ""
+ Msend(source[1], body, disp)
else:
- Msend(source[1], body[:ConfLimit], disp)
- else:
- Answer(AnsBase[1], ltype, source, disp)
+ Answer(AnsBase[0], ltype, source, disp)
-def command_invite(ltype, source, body, disp):
- if Chats.has_key(source[1]):
+ def command_send(self, ltype, source, body, disp):
if body:
- timer = (726 if enough_access(source[1], source[2], 7) else (time.time() - ChatsAttrs[source[1]]["intr"]))
- if timer >= 720:
- source_, jid_ = None, (body.split()[0])
- if Chats[source[1]].isHere(body):
- if Chats[source[1]].isHereTS(body):
- Answer(BsendAnsBase[6] % (body), ltype, source, disp)
- raise iThr.ThrKill("exit")
- source_ = get_source(source[1], body)
- elif isSource(jid_):
- source_ = jid_.lower()
- if source_:
- ChatsAttrs[source[1]]["intr"] = time.time()
- invite = xmpp.Message(to = source[1])
- x = xmpp.Node("x")
- x.setNamespace(xmpp.NS_MUC_USER)
- x_child = x.addChild("invite", {"to": source_})
- x_child.setTagData("reason", source[2])
- invite.addChild(node = x)
- Info["omsg"].plus()
- Sender(disp, invite)
- answer = AnsBase[4]
+ list = body.split()
+ if len(list) >= 2:
+ sTo = list[0]
+ if isSource(sTo):
+ conf = (sTo.split(chr(47)))[0].lower()
+ if Chats.has_key(conf) or not conf.count("@conf"):
+ Msend(sTo, self.AnsBase[5] % (source[2], body[(body.find(sTo) + (len(sTo) + 1)):].strip()))
+ answer = AnsBase[4]
+ else:
+ answer = AnsBase[8]
else:
- answer = BsendAnsBase[7]
+ answer = self.AnsBase[4]
+ else:
+ answer = AnsBase[2]
+ else:
+ answer = AnsBase[1]
+ Answer(answer, ltype, source, disp)
+
+ def command_adelivery(self, ltype, source, body, disp):
+ if body:
+ if PrivLimit >= len(body):
+ instance = get_source(source[1], source[2])
+ delivery(self.AnsBase[5] % ((source[2] if not instance else "%s (%s)" % (source[2], instance)), body))
+ answer = AnsBase[4]
else:
- answer = BsendAnsBase[8] % Time2Text(720 - timer)
+ answer = AnsBase[5]
else:
answer = AnsBase[1]
- else:
- answer = AnsBase[0]
- Answer(answer, ltype, source, disp)
+ Answer(answer, ltype, source, disp)
-def init_bot_sender(conf):
- if not ChatsAttrs.has_key(conf):
- ChatsAttrs[conf] = {}
- ChatsAttrs[conf]["intr"] = 0
- ChatsAttrs[conf]["dirt"] = True
+ def command_say(self, ltype, source, body, disp):
+ if body:
+ if ConfLimit >= len(body):
+ Msend(source[1], body, disp)
+ else:
+ Msend(source[1], body[:ConfLimit], disp)
+ else:
+ Answer(AnsBase[1], ltype, source, disp)
+
+ def command_invite(self, ltype, source, body, disp):
+ if Chats.has_key(source[1]):
+ if body:
+ timer = (726 if enough_access(source[1], source[2], 7) else (time.time() - ChatsAttrs[source[1]]["intr"]))
+ if timer >= 720:
+ source_, jid_ = None, (body.split()[0])
+ if Chats[source[1]].isHere(body):
+ if Chats[source[1]].isHereTS(body):
+ Answer(self.AnsBase[6] % (body), ltype, source, disp)
+ raise iThr.ThrKill("exit")
+ source_ = get_source(source[1], body)
+ elif isSource(jid_):
+ source_ = jid_.lower()
+ if source_:
+ ChatsAttrs[source[1]]["intr"] = time.time()
+ invite = xmpp.Message(to = source[1])
+ x = xmpp.Node("x")
+ x.setNamespace(xmpp.NS_MUC_USER)
+ x_child = x.addChild("invite", {"to": source_})
+ x_child.setTagData("reason", source[2])
+ invite.addChild(node = x)
+ Info["omsg"].plus()
+ Sender(disp, invite)
+ answer = AnsBase[4]
+ else:
+ answer = self.AnsBase[7]
+ else:
+ answer = self.AnsBase[8] % Time2Text(720 - timer)
+ else:
+ answer = AnsBase[1]
+ else:
+ answer = AnsBase[0]
+ Answer(answer, ltype, source, disp)
-expansions[exp_name].funcs_add([command_clear, command_test, command_sendall, command_more, command_send, command_adelivery, command_say, command_invite, init_bot_sender])
-expansions[exp_name].ls.extend(["BsendAnsBase"])
+ def init_bot_sender(self, conf):
+ if not ChatsAttrs.has_key(conf):
+ ChatsAttrs[conf] = {}
+ ChatsAttrs[conf]["intr"] = 0
+ ChatsAttrs[conf]["dirt"] = True
-command_handler(command_clear, {"RU": "чисть", "EN": "clear"}, 3, exp_name)
-command_handler(command_test, {"RU": "тест", "EN": "test"}, 1, exp_name, False)
-command_handler(command_sendall, {"RU": "разослать", "EN": "sendall"}, 8, exp_name)
-command_handler(command_more, {"RU": "далее", "EN": "more"}, 1, exp_name)
-command_handler(command_send, {"RU": "сообщение", "EN": "send"}, 8, exp_name)
-command_handler(command_adelivery, {"RU": "суперадмину", "EN": "toadmin"}, 1, exp_name)
-command_handler(command_say, {"RU": "сказать", "EN": "say"}, 7, exp_name)
-command_handler(command_invite, {"RU": "пригласить", "EN": "invite"}, 4, exp_name)
+ commands = (
+ (command_clear, "clear", 3,),
+ (command_test, "test", 1, False),
+ (command_sendall, "sendall", 8,),
+ (command_more, "more", 1,),
+ (command_send, "send", 8,),
+ (command_adelivery, "toadmin", 1,),
+ (command_say, "say", 7,),
+ (command_invite, "invite", 4,)
+ )
-handler_register(init_bot_sender, "01si", exp_name)
+ handlers = ((init_bot_sender, "01si"),)
diff --git a/expansions/bot_sends/insc.py b/expansions/bot_sends/insc.py
index be54d3e..e5ede13 100644
--- a/expansions/bot_sends/insc.py
+++ b/expansions/bot_sends/insc.py
@@ -1,7 +1,7 @@
# coding: utf-8
if DefLANG in ("RU", "UA"):
- BsendAnsBase = tuple([line.decode("utf-8") for line in (
+ AnsBase_temp = tuple([line.decode("utf-8") for line in (
"чистка конференции...", # 0
"Всё круто, я в отличной форме! (0 ошибок)", # 1
"Бoeц %s тяжело ранен, но я ещё повоюю! (%d ошибок)", # 2
@@ -14,7 +14,7 @@ if DefLANG in ("RU", "UA"):
"Чистка итак в процессе!" # 9
)])
else:
- BsendAnsBase = (
+ AnsBase_temp = (
"cleaning conference...", # 0
"I am okay! (0 errors)", # 1
"Private %s is seriously injured, but I have the rotation! (%d errors)", # 2
diff --git a/expansions/bot_sends/invite.name b/expansions/bot_sends/invite.name
new file mode 100644
index 0000000..af4b3e9
--- /dev/null
+++ b/expansions/bot_sends/invite.name
@@ -0,0 +1,4 @@
+{
+ "RU": "пригласить",
+ "UA": "пригласить"
+} \ No newline at end of file
diff --git a/expansions/bot_sends/more.name b/expansions/bot_sends/more.name
new file mode 100644
index 0000000..3d97b7c
--- /dev/null
+++ b/expansions/bot_sends/more.name
@@ -0,0 +1,4 @@
+{
+ "RU": "далее",
+ "UA": "далее"
+} \ No newline at end of file
diff --git a/expansions/bot_sends/say.name b/expansions/bot_sends/say.name
new file mode 100644
index 0000000..e584170
--- /dev/null
+++ b/expansions/bot_sends/say.name
@@ -0,0 +1,4 @@
+{
+ "RU": "сказать",
+ "UA": "сказать"
+} \ No newline at end of file
diff --git a/expansions/bot_sends/send.name b/expansions/bot_sends/send.name
new file mode 100644
index 0000000..ec1c91d
--- /dev/null
+++ b/expansions/bot_sends/send.name
@@ -0,0 +1,4 @@
+{
+ "RU": "сообщение",
+ "UA": "сообщение"
+} \ No newline at end of file
diff --git a/expansions/bot_sends/sendall.name b/expansions/bot_sends/sendall.name
new file mode 100644
index 0000000..7594b38
--- /dev/null
+++ b/expansions/bot_sends/sendall.name
@@ -0,0 +1,4 @@
+{
+ "RU": "разослать",
+ "UA": "разослать"
+} \ No newline at end of file
diff --git a/expansions/bot_sends/test.name b/expansions/bot_sends/test.name
new file mode 100644
index 0000000..176d090
--- /dev/null
+++ b/expansions/bot_sends/test.name
@@ -0,0 +1,4 @@
+{
+ "RU": "тест",
+ "UA": "тест"
+} \ No newline at end of file
diff --git a/expansions/bot_sends/toadmin.name b/expansions/bot_sends/toadmin.name
new file mode 100644
index 0000000..49b6b98
--- /dev/null
+++ b/expansions/bot_sends/toadmin.name
@@ -0,0 +1,4 @@
+{
+ "RU": "суперадмину",
+ "UA": "суперадмину"
+} \ No newline at end of file
diff --git a/expansions/calendar/calendar.name b/expansions/calendar/calendar.name
new file mode 100644
index 0000000..e2e4048
--- /dev/null
+++ b/expansions/calendar/calendar.name
@@ -0,0 +1,4 @@
+{
+ "RU": "календарь",
+ "UA": "календарь"
+} \ No newline at end of file
diff --git a/expansions/calendar/code.py b/expansions/calendar/code.py
index 1654562..75435bb 100644
--- a/expansions/calendar/code.py
+++ b/expansions/calendar/code.py
@@ -1,35 +1,38 @@
# coding: utf-8
# BlackSmith mark.2
-exp_name = "calendar" # /code.py v.x2
-# Id: 24~2a
-# Code © (2011) by WitcherGeralt [WitcherGeralt@rocketmail.com]
+exp_name = "calendar" # /code.py v.x3
+# Id: 24~3b
+# Code © (2011) by WitcherGeralt [alkorgun@gmail.com]
expansion_register(exp_name)
-import calendar
+class expansion_temp(expansion):
-def command_calendar(ltype, source, body, disp):
- date = time.gmtime()
- y, z = 0, 0
- if body:
- body = body.split()
- x = body.pop(0)
- if isNumber(x):
- z = int(x)
- if body and isNumber(body[0]):
- y = int(body.pop(0))
- if z not in xrange(1, 13):
- y = (date.tm_year)
- z = (date.tm_mon)
- elif y <= 0:
- y = (date.tm_year)
- Ans_1 = "\nCalendar:\n*\n*\tM/Y: %s\n*\n*\t%s\n*\nCurrent Date/Time: %s"
- clndr = ((calendar.month(y, z)).strip()).splitlines()
- Ans_2 = clndr.pop(0)
- Ans_3 = "\n*\t".join(clndr)
- Answer(Ans_1 % (Ans_2, Ans_3, time.asctime(date)), ltype, source, disp)
+ def __init__(self, name):
+ expansion.__init__(self, name)
-expansions[exp_name].ls.extend([calendar.__name__, command_calendar.func_name])
+ import calendar
-command_handler(command_calendar, {"RU": "календарь", "EN": "calendar"}, 1, exp_name)
+ def command_calendar(self, ltype, source, body, disp):
+ date = time.gmtime()
+ y, z = 0, 0
+ if body:
+ body = body.split()
+ x = body.pop(0)
+ if isNumber(x):
+ z = int(x)
+ if body and isNumber(body[0]):
+ y = int(body.pop(0))
+ if z not in xrange(1, 13):
+ y = (date.tm_year)
+ z = (date.tm_mon)
+ elif y <= 0:
+ y = (date.tm_year)
+ Ans_1 = "\nCalendar:\n*\n*\tM/Y: %s\n*\n*\t%s\n*\nCurrent Date/Time: %s"
+ clndr = ((self.calendar.month(y, z)).strip()).splitlines()
+ Ans_2 = clndr.pop(0)
+ Ans_3 = "\n*\t".join(clndr)
+ Answer(Ans_1 % (Ans_2, Ans_3, time.asctime(date)), ltype, source, disp)
+
+ commands = ((command_calendar, "calendar", 1,),)
diff --git a/expansions/clear_stats/code.py b/expansions/clear_stats/code.py
index 13ee734..cda164a 100644
--- a/expansions/clear_stats/code.py
+++ b/expansions/clear_stats/code.py
@@ -1,31 +1,36 @@
# coding: utf-8
# BlackSmith mark.2
-exp_name = "clear_stats" # /code.py v.x3
-# Id: 12~3a
-# Code © (2011) by WitcherGeralt [WitcherGeralt@rocketmail.com]
+exp_name = "clear_stats" # /code.py v.x4
+# Id: 12~4b
+# Code © (2011) by WitcherGeralt [alkorgun@gmail.com]
expansion_register(exp_name)
-def join_clear(conf, nick, instance, role, stanza, disp):
- if instance:
- for obj in Chats[conf].get_users():
- if obj.source == instance and not obj.ishere and obj.nick != nick:
- if Chats[conf].isHere(obj.nick):
- Chats[conf].desc.pop(obj.nick)
+class expansion_temp(expansion):
-def exit_clear(conf, nick, sbody, scode, disp):
- instance = get_source(conf, nick)
- if instance:
- delete = False
- for obj in Chats[conf].get_users():
- if obj.source == instance and obj.ishere:
- delete = True
- break
- if delete and Chats[conf].isHere(nick):
- Chats[conf].desc.pop(nick)
+ def __init__(self, name):
+ expansion.__init__(self, name)
-expansions[exp_name].funcs_add([join_clear, exit_clear])
+ def join_clear(self, conf, nick, instance, role, stanza, disp):
+ if instance:
+ for obj in Chats[conf].get_users():
+ if obj.source == instance and not obj.ishere and obj.nick != nick:
+ if Chats[conf].isHere(obj.nick):
+ Chats[conf].desc.pop(obj.nick)
-handler_register(join_clear, "04eh", exp_name)
-handler_register(exit_clear, "05eh", exp_name)
+ def exit_clear(self, conf, nick, sbody, scode, disp):
+ instance = get_source(conf, nick)
+ if instance:
+ delete = False
+ for obj in Chats[conf].get_users():
+ if obj.source == instance and obj.ishere:
+ delete = True
+ break
+ if delete and Chats[conf].isHere(nick):
+ Chats[conf].desc.pop(nick)
+
+ handlers = (
+ (join_clear, "04eh"),
+ (exit_clear, "05eh")
+ )
diff --git a/expansions/config/client.name b/expansions/config/client.name
new file mode 100644
index 0000000..58fa5ca
--- /dev/null
+++ b/expansions/config/client.name
@@ -0,0 +1,4 @@
+{
+ "RU": "клиент",
+ "UA": "клиент"
+} \ No newline at end of file
diff --git a/expansions/config/code.py b/expansions/config/code.py
index 4db5c14..434b930 100644
--- a/expansions/config/code.py
+++ b/expansions/config/code.py
@@ -1,231 +1,235 @@
# coding: utf-8
# BlackSmith mark.2
-exp_name = "config" # /code.py v.x3
-# Id: 19~2a
-# Code © (2011) by WitcherGeralt [WitcherGeralt@rocketmail.com]
+exp_name = "config" # /code.py v.x4
+# Id: 19~3b
+# Code © (2011) by WitcherGeralt [alkorgun@gmail.com]
expansion_register(exp_name)
-def get_config(config, ecfg = str()):
- for s in config.sections():
- ecfg += "[%s]\n" % (s.upper())
- for (op, i) in config.items(s):
- ecfg += "%s = %s\n" % (op.upper(), str(i))
- return ecfg.strip()
+class expansion_temp(expansion):
-def command_config(ltype, source, body, disp):
- if body:
- ConfigDesc = {}
- for x in body.split():
- if not x.count("="):
- continue
- Name, data = x.split("=", 1)
- if not data:
- continue
- Name = Name.lower()
- for Title in GenCon.sections():
- if Name in GenCon.options(Title):
- if Name in ("chat", "incoming", "memory", "private", "port"):
- if isNumber(data):
- data = str(int(data))
- else:
- continue
- elif Name in ("tls", "getexc", "mserve"):
- if data not in (str(True), str(False)):
- continue
- elif Name in ("status", "resource"):
- data = sub_desc(data, {chr(95): chr(32)})
- if not ConfigDesc.has_key(Title):
- ConfigDesc[Title] = dict()
- ConfigDesc[Title][Name] = data
- if ConfigDesc:
- for Title in ConfigDesc.keys():
- for (Name, data) in ConfigDesc[Title].items():
- GenCon.set(Title, Name, data)
- cat_file(GenConFile, get_config(GenCon))
- list = []
- for Name in ConfigDesc.values():
- list.extend(Name.keys())
- list = [Name.upper() for Name in list]
- answer = ConfAnsBase[0] % (", ".join(list))
+ def __init__(self, name):
+ expansion.__init__(self, name)
+
+ def get_config(self, config, ecfg = str()):
+ for s in config.sections():
+ ecfg += "[%s]\n" % (s.upper())
+ for (op, i) in config.items(s):
+ ecfg += "%s = %s\n" % (op.upper(), str(i))
+ return ecfg.strip()
+
+ def command_config(self, ltype, source, body, disp):
+ if body:
+ ConfigDesc = {}
+ for x in body.split():
+ if not x.count("="):
+ continue
+ Name, data = x.split("=", 1)
+ if not data:
+ continue
+ Name = Name.lower()
+ for Title in GenCon.sections():
+ if Name in GenCon.options(Title):
+ if Name in ("chat", "incoming", "memory", "private", "port"):
+ if isNumber(data):
+ data = str(int(data))
+ else:
+ continue
+ elif Name in ("tls", "getexc", "mserve"):
+ if data not in (str(True), str(False)):
+ continue
+ elif Name in ("status", "resource"):
+ data = sub_desc(data, {chr(95): chr(32)})
+ if not ConfigDesc.has_key(Title):
+ ConfigDesc[Title] = dict()
+ ConfigDesc[Title][Name] = data
+ if ConfigDesc:
+ for Title in ConfigDesc.keys():
+ for (Name, data) in ConfigDesc[Title].items():
+ GenCon.set(Title, Name, data)
+ cat_file(GenConFile, self.get_config(GenCon))
+ list = []
+ for Name in ConfigDesc.values():
+ list.extend(Name.keys())
+ list = [Name.upper() for Name in list]
+ answer = self.AnsBase[0] % (", ".join(list))
+ else:
+ answer = self.AnsBase[1]
else:
- answer = ConfAnsBase[1]
- else:
- if ltype == Types[1]:
- Answer(AnsBase[11], ltype, source, disp)
- Msend(source[0], get_config(GenCon, ConfAnsBase[2]), disp)
- if locals().has_key(Types[12]):
- Answer(answer, ltype, source, disp)
+ if ltype == Types[1]:
+ Answer(AnsBase[11], ltype, source, disp)
+ Msend(source[0], self.get_config(GenCon, self.AnsBase[2]), disp)
+ if locals().has_key(Types[12]):
+ Answer(answer, ltype, source, disp)
-def command_cls_config(ltype, source, body, disp):
- if body:
- list = body.split()
- if len(list) >= 2:
- body = (list.pop(0)).lower()
- if body in ("del", "удалить".decode("utf-8")):
- Name = (list.pop(0)).lower()
- if InstansesDesc.has_key(Name):
- clients = Clients.keys()
- if not Clients.has_key(Name) or len(clients) >= 2:
- if Name == Gen_disp:
- clients.remove(Gen_disp)
- Gen = choice(clients)
- delivery(ConfAnsBase[6] % Gen)
- globals()["Gen_disp"], Con = Gen, client_config(GenCon, "CLIENT")[1]
- for x in ConDisp.sections():
- z = client_config(ConDisp, x)
- if Gen == z[0]:
- Con = z[1]
- ConDisp.remove_section(x)
- GenCon.set("CLIENT", "serv", Con[0])
- GenCon.set("CLIENT", "port", Con[1])
- GenCon.set("CLIENT", "host", Con[2])
- GenCon.set("CLIENT", "user", Con[3])
- GenCon.set("CLIENT", "pass", Con[4])
- cat_file(GenConFile, get_config(GenCon))
+ def command_cls_config(self, ltype, source, body, disp):
+ if body:
+ list = body.split()
+ if len(list) >= 2:
+ body = (list.pop(0)).lower()
+ if body in ("del", "удалить".decode("utf-8")):
+ Name = (list.pop(0)).lower()
+ if InstansesDesc.has_key(Name):
+ clients = Clients.keys()
+ if not Clients.has_key(Name) or len(clients) >= 2:
+ if Name == Gen_disp:
+ clients.remove(Gen_disp)
+ Gen = choice(clients)
+ delivery(self.AnsBase[6] % Gen)
+ globals()["Gen_disp"], Con = Gen, client_config(GenCon, "CLIENT")[1]
+ for x in ConDisp.sections():
+ z = client_config(ConDisp, x)
+ if Gen == z[0]:
+ Con = z[1]
+ ConDisp.remove_section(x)
+ GenCon.set("CLIENT", "serv", Con[0])
+ GenCon.set("CLIENT", "port", Con[1])
+ GenCon.set("CLIENT", "host", Con[2])
+ GenCon.set("CLIENT", "user", Con[3])
+ GenCon.set("CLIENT", "pass", Con[4])
+ cat_file(GenConFile, self.get_config(GenCon))
+ for x in ConDisp.sections():
+ if Gen == client_config(ConDisp, x)[0]:
+ ConDisp.remove_section(x)
+ if Clients.has_key(Name):
+ ThrIds = iThr.ThrNames()
+ ThrName = "%s%s" % (Types[13], Name)
+ if ThrName in ThrIds:
+ for Thr in iThr.enumerate():
+ if Thr._Thread__name == ThrName:
+ Thr.kill()
+ for conf in Chats.keys():
+ if Chats[conf].disp == Name:
+ if online(Name):
+ Msend(conf, self.AnsBase[4], Name)
+ time.sleep(0.2)
+ Chats[conf].leave(self.AnsBase[5])
+ Chats[conf].disp = IdleClient()
+ Chats[conf].save()
+ time.sleep(0.6)
+ Chats[conf].join()
+ if online(Name):
+ try:
+ Clients[Name].disconnect()
+ except:
+ pass
+ if Flood.has_key(Name):
+ del Flood[Name]
+ del InstansesDesc[Name]
for x in ConDisp.sections():
- if Gen == client_config(ConDisp, x)[0]:
+ if Name == client_config(ConDisp, x)[0]:
ConDisp.remove_section(x)
- if Clients.has_key(Name):
- ThrIds = iThr.ThrNames()
- ThrName = "%s%s" % (Types[13], Name)
- if ThrName in ThrIds:
- for Thr in iThr.enumerate():
- if Thr._Thread__name == ThrName:
- Thr.kill()
- for conf in Chats.keys():
- if Chats[conf].disp == Name:
- if online(Name):
- Msend(conf, ConfAnsBase[4], Name)
- time.sleep(0.2)
- Chats[conf].leave(ConfAnsBase[5])
- Chats[conf].disp = IdleClient()
- Chats[conf].save()
- time.sleep(0.6)
- Chats[conf].join()
- if online(Name):
- try:
- Clients[Name].disconnect()
- except:
- pass
- if Flood.has_key(Name):
- del Flood[Name]
- del InstansesDesc[Name]
- for x in ConDisp.sections():
- if Name == client_config(ConDisp, x)[0]:
- ConDisp.remove_section(x)
- cat_file(ConDispFile, get_config(ConDisp))
- if Clients.has_key(Name):
- del Clients[Name]
- answer = AnsBase[4]
+ cat_file(ConDispFile, self.get_config(ConDisp))
+ if Clients.has_key(Name):
+ del Clients[Name]
+ answer = AnsBase[4]
+ else:
+ answer = self.AnsBase[7]
else:
- answer = ConfAnsBase[7]
- else:
- answer = ConfAnsBase[11]
- elif body in ("add", "добавить".decode("utf-8")):
- if len(list) >= 3:
- host = (list.pop(0)).lower()
- user = (list.pop(0)).lower()
- code = (list.pop(0))
- if list:
- port = (list.pop(0))
- if not isNumber(port):
+ answer = self.AnsBase[11]
+ elif body in ("add", "добавить".decode("utf-8")):
+ if len(list) >= 3:
+ host = (list.pop(0)).lower()
+ user = (list.pop(0)).lower()
+ code = (list.pop(0))
+ if list:
+ port = (list.pop(0))
+ if not isNumber(port):
+ port = "5222"
+ else:
port = "5222"
- else:
- port = "5222"
- jid = "%s@%s" % (user, host)
- serv = (host)
- if list:
- serv = (list.pop(0)).lower()
- if not Clients.has_key(jid):
- if not InstansesDesc.has_key(jid):
- if connect_client(jid, (serv, port, host, user, code))[0]:
- Numb = itypes.Number()
- Name = "CLIENT%d" % (len(ConDisp.sections()) + Numb.plus())
- while ConDisp.has_section(Name):
+ jid = "%s@%s" % (user, host)
+ serv = (host)
+ if list:
+ serv = (list.pop(0)).lower()
+ if not Clients.has_key(jid):
+ if not InstansesDesc.has_key(jid):
+ if connect_client(jid, (serv, port, host, user, code))[0]:
+ Numb = itypes.Number()
Name = "CLIENT%d" % (len(ConDisp.sections()) + Numb.plus())
- ConDisp.add_section(Name)
- ConDisp.set(Name, "serv", serv)
- ConDisp.set(Name, "port", port)
- ConDisp.set(Name, "host", host)
- ConDisp.set(Name, "user", user)
- ConDisp.set(Name, "pass", code)
- Instance, desc = client_config(ConDisp, Name)
- InstansesDesc[Instance] = desc
- cat_file(ConDispFile, get_config(ConDisp))
- try:
- Try_Thr(composeThr(Dispatch_handler, "%s%s" % (Types[13], Instance), (Instance,)), -1)
- except RuntimeError:
- answer = ConfAnsBase[8]
+ while ConDisp.has_section(Name):
+ Name = "CLIENT%d" % (len(ConDisp.sections()) + Numb.plus())
+ ConDisp.add_section(Name)
+ ConDisp.set(Name, "serv", serv)
+ ConDisp.set(Name, "port", port)
+ ConDisp.set(Name, "host", host)
+ ConDisp.set(Name, "user", user)
+ ConDisp.set(Name, "pass", code)
+ Instance, desc = client_config(ConDisp, Name)
+ InstansesDesc[Instance] = desc
+ cat_file(ConDispFile, self.get_config(ConDisp))
+ try:
+ Try_Thr(composeThr(Dispatch_handler, "%s%s" % (Types[13], Instance), (Instance,)), -1)
+ except RuntimeError:
+ answer = self.AnsBase[8]
+ else:
+ for conf in Chats.keys():
+ if Instance == Chats[conf].disp:
+ Chats[conf].join()
+ answer = AnsBase[4]
else:
- for conf in Chats.keys():
- if Instance == Chats[conf].disp:
- Chats[conf].join()
- answer = AnsBase[4]
+ answer = self.AnsBase[9]
else:
- answer = ConfAnsBase[9]
+ answer = self.AnsBase[10]
else:
- answer = ConfAnsBase[10]
+ answer = self.AnsBase[10]
else:
- answer = ConfAnsBase[10]
- else:
- answer = AnsBase[2]
- elif body in ("password", "пароль".decode("utf-8")):
- Name = (list.pop(0)).lower()
- if InstansesDesc.has_key(Name):
- if list:
- code = (list.pop(0))
+ answer = AnsBase[2]
+ elif body in ("password", "пароль".decode("utf-8")):
+ Name = (list.pop(0)).lower()
+ if InstansesDesc.has_key(Name):
if list:
- if (list.pop(0)).lower() in ("set", "записать".decode("utf-8")):
- changed = True
- else:
- code, symbols = "", "%s%s%s._+(!}{#)" % (CharCase[0], CharCase[1], CharCase[2])
- for x in xrange(24):
- code += choice(symbols)
- if not locals().has_key("changed"):
- if Clients.has_key(Name):
- try:
- changed = xmpp.features.changePasswordTo(Clients[Name], code)
- except:
- changed = False
+ code = (list.pop(0))
+ if list:
+ if (list.pop(0)).lower() in ("set", "записать".decode("utf-8")):
+ changed = True
else:
- changed = False
- if changed:
- if Name == Gen_disp:
- GenCon.set("CLIENT", "pass", code)
- cat_file(GenConFile, get_config(GenCon))
+ code, symbols = "", "%s%s%s._+(!}{#)" % (CharCase[0], CharCase[1], CharCase[2])
+ for x in xrange(24):
+ code += choice(symbols)
+ if not locals().has_key("changed"):
+ if Clients.has_key(Name):
+ try:
+ changed = xmpp.features.changePasswordTo(Clients[Name], code)
+ except:
+ changed = False
+ else:
+ changed = False
+ if changed:
+ if Name == Gen_disp:
+ GenCon.set("CLIENT", "pass", code)
+ cat_file(GenConFile, self.get_config(GenCon))
+ else:
+ for x in ConDisp.sections():
+ if Name == client_config(ConDisp, x)[0]:
+ ConDisp.set(x, "pass", code)
+ cat_file(ConDispFile, self.get_config(ConDisp))
+ break
+ serv = InstansesDesc[Name][0]
+ port = InstansesDesc[Name][1]
+ host = InstansesDesc[Name][2]
+ user = InstansesDesc[Name][3]
+ InstansesDesc[Name] = (serv, port, host, user, code)
+ answer = AnsBase[4]
else:
- for x in ConDisp.sections():
- if Name == client_config(ConDisp, x)[0]:
- ConDisp.set(x, "pass", code)
- cat_file(ConDispFile, get_config(ConDisp))
- break
- serv = InstansesDesc[Name][0]
- port = InstansesDesc[Name][1]
- host = InstansesDesc[Name][2]
- user = InstansesDesc[Name][3]
- InstansesDesc[Name] = (serv, port, host, user, code)
- answer = AnsBase[4]
+ answer = AnsBase[7]
else:
- answer = AnsBase[7]
+ answer = self.AnsBase[11]
else:
- answer = ConfAnsBase[11]
+ answer = AnsBase[2]
else:
answer = AnsBase[2]
+ elif not len(ConDisp.sections()):
+ answer = self.AnsBase[3]
else:
- answer = AnsBase[2]
- elif not len(ConDisp.sections()):
- answer = ConfAnsBase[3]
- else:
- if ltype == Types[1]:
- Answer(AnsBase[11], ltype, source, disp)
- Msend(source[0], get_config(ConDisp, ConfAnsBase[2]), disp)
- if locals().has_key(Types[12]):
- Answer(answer, ltype, source)
-
-expansions[exp_name].funcs_add([get_config, command_config, command_cls_config])
-expansions[exp_name].ls.extend(["ConfAnsBase"])
+ if ltype == Types[1]:
+ Answer(AnsBase[11], ltype, source, disp)
+ Msend(source[0], self.get_config(ConDisp, self.AnsBase[2]), disp)
+ if locals().has_key(Types[12]):
+ Answer(answer, ltype, source)
-command_handler(command_config, {"RU": "конфиг", "EN": "config"}, 8, exp_name)
-command_handler(command_cls_config, {"RU": "клиент", "EN": "client"}, 8, exp_name)
+ commands = (
+ (command_config, "config", 8,),
+ (command_cls_config, "client", 8,)
+ )
diff --git a/expansions/config/config.name b/expansions/config/config.name
new file mode 100644
index 0000000..6af7210
--- /dev/null
+++ b/expansions/config/config.name
@@ -0,0 +1,4 @@
+{
+ "RU": "конфиг",
+ "UA": "конфиг"
+} \ No newline at end of file
diff --git a/expansions/config/insc.py b/expansions/config/insc.py
index 993e62a..67840ff 100644
--- a/expansions/config/insc.py
+++ b/expansions/config/insc.py
@@ -1,7 +1,7 @@
# coding: utf-8
if DefLANG in ("RU", "UA"):
- ConfAnsBase = tuple([line.decode("utf-8") for line in (
+ AnsBase_temp = tuple([line.decode("utf-8") for line in (
"Изменённые пункты: %s", # 0
"Очевидно параметры неверны.", # 1
"Настройки:\n", # 2
@@ -16,7 +16,7 @@ if DefLANG in ("RU", "UA"):
"«%s» нет в списке клиентов." # 11
)])
else:
- ConfAnsBase = (
+ AnsBase_temp = (
"Changed options: %s", # 0
"Parameters are incorrect.", # 1
"Config:\n", # 2
diff --git a/expansions/converter/code.py b/expansions/converter/code.py
index fe8fb8d..c5cfd03 100644
--- a/expansions/converter/code.py
+++ b/expansions/converter/code.py
@@ -1,236 +1,241 @@
# coding: utf-8
# BlackSmith mark.2
-exp_name = "converter" # /code.py v.x2
-# Id: 31~1a
+exp_name = "converter" # /code.py v.x3
+# Id: 31~2b
# Code © (2012) by WitcherGeralt [alkorgun@gmail.com]
expansion_register(exp_name)
-CrDesc = {
- "time": { # Время
- "year": 1.0, # Год !# Base (Базовое Значение)
- "month": 12.0, # Месяц
- "week": 52.1785714286, # Неделя
- "day": 365.25, # День
- "hour": 8766.0, # Час
- "minute": 525960.0, # Минута
- "second": 31557600.0, # Секунда
- },
- "information": { # Информация
- "bit": 1.0, # Бит !# Base
- "kbit": 9.765625e-04, # 2^10
- "mbit": 9.53674316406e-07, # 2^20
- "gbit": 9.31322574615e-10, # 2^30
- "tbit": 9.09494701773e-13, # 2^40
- "pbit": 8.881784197e-16, # 2^50
- "ebit": 8.67361737988e-19, # 2^60
- "zbit": 8.47032947254e-22, # 2^70
- "ybit": 8.27180612553e-25, # 2^80
- "byte": 0.125, # Байт
- "kbyte": 1.220703125e-04, # 2^10
- "mbyte": 1.19209289551e-07, # 2^20
- "gbyte": 1.16415321827e-10, # 2^30
- "tbyte": 1.13686837722e-13, # 2^40
- "pbyte": 1.11022302463e-16, # 2^50
- "ebyte": 1.08420217249e-19, # 2^60
- "zbyte": 1.05879118407e-22, # 2^70
- "ybyte": 1.03397576569e-25, # 2^80
- },
- "magnetics": { # Магнитное Поле
- "gauss": 1.0, # Gauss; Ггаусс (G; Гс) !# Base
- "tesla": 1e-04, # Tesla; Тесла (T; Тл)
- "ktesla": 1e-07, # 10^03
- "mtesla": 1e-10, # 10^06
- "gtesla": 1e-13, # 10^09
- "ttesla": 1e-16, # 10^12
- "ptesla": 1e-19, # 10^15
- "etesla": 1e-22, # 10^18
- "ztesla": 1e-25, # 10^21
- "ytesla": 1e-28, # 10^24
- "militesla": 1e-01, # 10^-03
- "microtesla": 1e02, # 10^-06
- "nanotesla": 1e05, # 10^-09
- "picotesla": 1e08, # 10^-12
- },
- "power": { # Мощность
- "watt": 1.0, # Watt; Ватт (W; Вт) !# Base
- "kwatt": 1e-03, # 10^03
- "mwatt": 1e-06, # 10^06
- "gwatt": 1e-09, # 10^09
- "twatt": 1e-12, # 10^12
- "hpwr": 0.0013596216173, # Horse Power; Лошадиная Сила
- },
- "radiation": { # Радиационное Излучение
- "bq": 1.0, # Becquerel; Беккерель (Bq; Бк) !# Base (Базовое Значение)
- "ci": 2.7027e-11, # Curie; Кюри (Ci; Ки)
- "rad": 1e-06, # Radiation Absorbed Dose (rad; Рад)
- },
- "temperature": { # Температура
- "c": ((lambda Numb: Numb), # °C (Celsius; Цельсий) !# Base
- (lambda Numb: Numb)),
- "f": ((lambda Numb: (Numb * 9.0 / 5.0 + 32.0)), # from Celsius to °F (Fahrenheit; Фаренгейт)
- (lambda Numb: ((Numb - 32.0) * 5.0 / 9.0))), # to Celsius
- "k": ((lambda Numb: (Numb + 273.15)), # from Celsius to K (Kelvin; Кельвин)
- (lambda Numb: (Numb - 273.15))), # to Celsius
- "r": ((lambda Numb: ((Numb + 491.67) * 9.0 / 5.0)), # from Celsius to °R (Rankine; Ранкин)
- (lambda Numb: ((Numb - 491.67) * 5.0 / 9.0))), # to Celsius
- "n": ((lambda Numb: (Numb * 33.0 / 100.0)), # from Celsius to °N (Newton; Ньютон)
- (lambda Numb: (Numb * 100.0 / 33.0))), # to Celsius
- "de": ((lambda Numb: ((100.0 - Numb) * 3.0 / 2.0)), # from Celsius to °De (Delisle; Делиль)
- (lambda Numb: (100.0 - Numb * 2.0 / 3.0))), # to Celsius
- "re": ((lambda Numb: (Numb * 4.0 / 5.0)), # from Celsius to °Re (Reaumur; Реомюр)
- (lambda Numb: (Numb * 5.0 / 4.0))), # to Celsius
- "ro": ((lambda Numb: (Numb * 21.0 / 40.0 + 7.5)), # from Celsius to °Ro (Romer; Рёмер)
- (lambda Numb: ((Numb - 7.5) * 40.0 / 21.0))), # to Celsius
- },
- "pressure": { # Давление
- "atm": 1.0, # Standard Atmosphere; Атмосферное Давление (atm; атм) !# Base
- "bar": 1.01325, # bar; бар
- "pa": 101325.0, # Pascal; Паскаль (Pa; Па)
- "torr": 760.0, # Torr; Миллиметр Ртутного Столба
- "psi": 14.696, # Pound per Square Inch; Фунт на Квадратный Дюйм
- },
- "volume": { # Объем
- "usbushel": 1.0, # U.S. Bushel; Американский Бушель !# Base
- "bushel": 0.968938622, # U.K. Bushel; Имперский Бушель
- "usgallon": 9.30917797, # U.S. Gallon; Американский Галлон
- "gallon": 7.75150897, # U.K. Gallon; Имперский Галлон
- "usquart": 37.2367119, # U.S. Quart; Американская Кварта
- "quart": 31.0060359, # U.K. Quart; Имперская Кварта
- "uspint": 74.4734238, # U.S. Pint; Американская Пинта
- "pint": 62.0120718, # U.K. Pint; Имперская Пинта
- "usounce": 1191.57478, # U.S. Ounce; Американская Унция
- "ounce": 1240.24144, # U.K. Ounce; Имперская Унция
- "oilbarrel": 0.221647095, # Oil Barrel; Нефтяной Баррель
- "drybarrel": 0.3048, # Dry Barrel; Сухой Баррель
- "fluidbarrel": 0.2955, # Fluid Barrel; Жидкий Баррель
- "litre": 35.239072, # Litre; Литр
- "mililitre": 35239.072, # MiliLitre; Милилитр
- "metre^3": 0.035239072, # Cubic Metre; Кубический Метр
- "foot^3": 1.24445608, # Cubic Foot; Кубический Фут
- "inch^3": 2150.42011, # Cubic Inch; Кубический Дюйм
- },
- "weight": { # Масса
- "g": 1.0, # Gram; Грамм !# Base
- "kg": 1e-03, # KiloGram; Килограмм
- "ton": 1e-06, # Ton; Тонна
- "oz": 0.0352739619, # Ounce; Унция
- "ozt": 0.0321507466, # Troyes Ounce; Тройская Унция
- "lb": 0.00220462262, # Pound; Фунт
- "lbt": 0.002679229, # Troyes Pound; Тройский Фунт
- "pd": 6.10482666e-05, # Russian Pood; Пуд
- "carat": 5.0, # Carat; Карат
- },
- "distance": { # Длина
- "angstrom": 1.0, # Angström; Ангстрём !# Base
- "nanometre": 1e-01, # 10^-09
- "micrometre": 1e-04, # 10^-06
- "milimetre": 1e-07, # 10^-03
- "centimetre": 1e-08, # 10^-02
- "decimetre": 1e-09, # 10^-01
- "metre": 1e-10, # Metre; Метр
- "kilometre": 1e-13, # 10^03
- "inch": 3.93700787e-09, # Inch; Дюйм
- "foot": 3.2808399e-10, # Fool; Фут
- "yard": 1.0936133e-10, # Yard; Ярд
- "mille": 6.21371192e-14, # Mile; Миля
- "league": 2.07123730667e-14, # League; Лига
- "seamile": 5.39956803e-14, # Sea Mile; Морская Миля
- "verst": 9.37382827e-14, # Verst; Верста
- "au": 6.68458712267e-22, # Astronomical Unit; Астрономическая Единица (средний радиус земной орбиты)
- "ly": 1.05700083402e-26, # Light-Year; Световой Год
- "pc": 3.24077927001e-27, # Parsec; Парсек
- },
- "speed": { # Скорость
- "km/h": 1.0, # KiloMetres per Hour; Километры в Час !# Base
- "m/s": 0.2778, # Metres per Second; Метры в Секунду
- "knot": 0.539956803, # Sea Miles per Hour; Морские Мили в Час (Knot; Узел)
- "mph": 0.621371192, # Miles per Hour; Мили в Час
- "fps": 0.911344415281, # Feet per Second; Футы в Секунду
- "ls": 9.26566930076e-10, # Light-Speed; Скорость Света
- },
- "angle": { # Угол
- "degree": 1.0, # Degree; Градус ° !# Base
- "second": 3600.0, # Arc Second; Угловая Секунда
- "minute": 60.0, # Arc Minute; Угловая Минута
- "rad": 0.0174532925, # Radians; Радиан
- "turn": 0.00277777777778, # Turn; Оборот
- "gon": 1.111111111111111, # Gradian; Градон
- },
- "square": { # Площадь
- "acre": 1.0, # Acre; Акр !# Base
- "milimetre^2": 4046856420.0, # Square MilliMetre; Квадратный Миллиметр
- "centimetre^2": 40468564.2, # Square CentiMetre; Квадратный Сантиметр
- "metre^2": 4046.85642, # Square Metre; Квадратный Метр
- "inch^2": 6272640.0, # Square Inch; Квадратный Дюйм
- "foot^2": 0.00355591837, # Square Foot; Квадратный Фут
- "mile^2": 0.0015625, # Square Mile; Квадратная Миля
- "verst^2": 0.00355591837, # Square Verst; Квадратная Верста
- "hectare": 0.404685642, # Hectare; Гектар
- "are": 40.4685642, # Are; Ар
- "barn": 4.04685642e31, # Barn; Барн
- },
- "energy": { # Энергия
- "btu": 1.0, # British Thermal Unit; Британская Термическая Единица !# Base
- "mbtu": 1000000.0, # Million British Thermal Unit; Миллион Британских Термических Единиц
- "cal": 252.164401, # Calorie; Калория
- "kcal": 0.252164401, # KiloCalorie; Килокалория
- "erg": 10550558500.0, # Erg; Эрг
- "ev": 6.58514139e20, # Electronvolt; Электронвольт
- "joule": 1055.05585, # Joule (Watt per Second); Джоуль (Ватт Секунда)
- "watt/h": 0.29307107, # Watt per Hour; Ватт Час
- "kwatt/h": 0.00029307107, # KiloWatt per Hour; Киловатт Час
- },
- }
+class expansion_temp(expansion):
-Convert = lambda Desc, Numb, Type, ToType: (CrDesc[Desc][ToType]*(Numb / CrDesc[Desc][Type]))
+ def __init__(self, name):
+ expansion.__init__(self, name)
-ConvertTemp = lambda Numb, Type, ToType, Desc = CrDesc["temperature"]: Desc[ToType][0](Desc[Type][1](Numb))
+ CrDesc = {
+ "time": { # Время
+ "year": 1.0, # Год !# Base (Базовое Значение)
+ "month": 12.0, # Месяц
+ "week": 52.1785714286, # Неделя
+ "day": 365.25, # День
+ "hour": 8766.0, # Час
+ "minute": 525960.0, # Минута
+ "second": 31557600.0, # Секунда
+ },
+ "information": { # Информация
+ "bit": 1.0, # Бит !# Base
+ "kbit": 9.765625e-04, # 2^10
+ "mbit": 9.53674316406e-07, # 2^20
+ "gbit": 9.31322574615e-10, # 2^30
+ "tbit": 9.09494701773e-13, # 2^40
+ "pbit": 8.881784197e-16, # 2^50
+ "ebit": 8.67361737988e-19, # 2^60
+ "zbit": 8.47032947254e-22, # 2^70
+ "ybit": 8.27180612553e-25, # 2^80
+ "byte": 0.125, # Байт
+ "kbyte": 1.220703125e-04, # 2^10
+ "mbyte": 1.19209289551e-07, # 2^20
+ "gbyte": 1.16415321827e-10, # 2^30
+ "tbyte": 1.13686837722e-13, # 2^40
+ "pbyte": 1.11022302463e-16, # 2^50
+ "ebyte": 1.08420217249e-19, # 2^60
+ "zbyte": 1.05879118407e-22, # 2^70
+ "ybyte": 1.03397576569e-25, # 2^80
+ },
+ "magnetics": { # Магнитное Поле
+ "gauss": 1.0, # Gauss; Ггаусс (G; Гс) !# Base
+ "tesla": 1e-04, # Tesla; Тесла (T; Тл)
+ "ktesla": 1e-07, # 10^03
+ "mtesla": 1e-10, # 10^06
+ "gtesla": 1e-13, # 10^09
+ "ttesla": 1e-16, # 10^12
+ "ptesla": 1e-19, # 10^15
+ "etesla": 1e-22, # 10^18
+ "ztesla": 1e-25, # 10^21
+ "ytesla": 1e-28, # 10^24
+ "militesla": 1e-01, # 10^-03
+ "microtesla": 1e02, # 10^-06
+ "nanotesla": 1e05, # 10^-09
+ "picotesla": 1e08, # 10^-12
+ },
+ "power": { # Мощность
+ "watt": 1.0, # Watt; Ватт (W; Вт) !# Base
+ "kwatt": 1e-03, # 10^03
+ "mwatt": 1e-06, # 10^06
+ "gwatt": 1e-09, # 10^09
+ "twatt": 1e-12, # 10^12
+ "hpwr": 0.0013596216173, # Horse Power; Лошадиная Сила
+ },
+ "radiation": { # Радиационное Излучение
+ "bq": 1.0, # Becquerel; Беккерель (Bq; Бк) !# Base (Базовое Значение)
+ "ci": 2.7027e-11, # Curie; Кюри (Ci; Ки)
+ "rad": 1e-06, # Radiation Absorbed Dose (rad; Рад)
+ },
+ "temperature": { # Температура
+ "c": ((lambda Numb: Numb), # °C (Celsius; Цельсий) !# Base
+ (lambda Numb: Numb)),
+ "f": ((lambda Numb: (Numb * 9.0 / 5.0 + 32.0)), # from Celsius to °F (Fahrenheit; Фаренгейт)
+ (lambda Numb: ((Numb - 32.0) * 5.0 / 9.0))), # to Celsius
+ "k": ((lambda Numb: (Numb + 273.15)), # from Celsius to K (Kelvin; Кельвин)
+ (lambda Numb: (Numb - 273.15))), # to Celsius
+ "r": ((lambda Numb: ((Numb + 491.67) * 9.0 / 5.0)), # from Celsius to °R (Rankine; Ранкин)
+ (lambda Numb: ((Numb - 491.67) * 5.0 / 9.0))), # to Celsius
+ "n": ((lambda Numb: (Numb * 33.0 / 100.0)), # from Celsius to °N (Newton; Ньютон)
+ (lambda Numb: (Numb * 100.0 / 33.0))), # to Celsius
+ "de": ((lambda Numb: ((100.0 - Numb) * 3.0 / 2.0)), # from Celsius to °De (Delisle; Делиль)
+ (lambda Numb: (100.0 - Numb * 2.0 / 3.0))), # to Celsius
+ "re": ((lambda Numb: (Numb * 4.0 / 5.0)), # from Celsius to °Re (Reaumur; Реомюр)
+ (lambda Numb: (Numb * 5.0 / 4.0))), # to Celsius
+ "ro": ((lambda Numb: (Numb * 21.0 / 40.0 + 7.5)), # from Celsius to °Ro (Romer; Рёмер)
+ (lambda Numb: ((Numb - 7.5) * 40.0 / 21.0))), # to Celsius
+ },
+ "pressure": { # Давление
+ "atm": 1.0, # Standard Atmosphere; Атмосферное Давление (atm; атм) !# Base
+ "bar": 1.01325, # bar; бар
+ "pa": 101325.0, # Pascal; Паскаль (Pa; Па)
+ "torr": 760.0, # Torr; Миллиметр Ртутного Столба
+ "psi": 14.696, # Pound per Square Inch; Фунт на Квадратный Дюйм
+ },
+ "volume": { # Объем
+ "usbushel": 1.0, # U.S. Bushel; Американский Бушель !# Base
+ "bushel": 0.968938622, # U.K. Bushel; Имперский Бушель
+ "usgallon": 9.30917797, # U.S. Gallon; Американский Галлон
+ "gallon": 7.75150897, # U.K. Gallon; Имперский Галлон
+ "usquart": 37.2367119, # U.S. Quart; Американская Кварта
+ "quart": 31.0060359, # U.K. Quart; Имперская Кварта
+ "uspint": 74.4734238, # U.S. Pint; Американская Пинта
+ "pint": 62.0120718, # U.K. Pint; Имперская Пинта
+ "usounce": 1191.57478, # U.S. Ounce; Американская Унция
+ "ounce": 1240.24144, # U.K. Ounce; Имперская Унция
+ "oilbarrel": 0.221647095, # Oil Barrel; Нефтяной Баррель
+ "drybarrel": 0.3048, # Dry Barrel; Сухой Баррель
+ "fluidbarrel": 0.2955, # Fluid Barrel; Жидкий Баррель
+ "litre": 35.239072, # Litre; Литр
+ "mililitre": 35239.072, # MiliLitre; Милилитр
+ "metre^3": 0.035239072, # Cubic Metre; Кубический Метр
+ "foot^3": 1.24445608, # Cubic Foot; Кубический Фут
+ "inch^3": 2150.42011, # Cubic Inch; Кубический Дюйм
+ },
+ "weight": { # Масса
+ "g": 1.0, # Gram; Грамм !# Base
+ "kg": 1e-03, # KiloGram; Килограмм
+ "ton": 1e-06, # Ton; Тонна
+ "oz": 0.0352739619, # Ounce; Унция
+ "ozt": 0.0321507466, # Troyes Ounce; Тройская Унция
+ "lb": 0.00220462262, # Pound; Фунт
+ "lbt": 0.002679229, # Troyes Pound; Тройский Фунт
+ "pd": 6.10482666e-05, # Russian Pood; Пуд
+ "carat": 5.0, # Carat; Карат
+ },
+ "distance": { # Длина
+ "angstrom": 1.0, # Angström; Ангстрём !# Base
+ "nanometre": 1e-01, # 10^-09
+ "micrometre": 1e-04, # 10^-06
+ "milimetre": 1e-07, # 10^-03
+ "centimetre": 1e-08, # 10^-02
+ "decimetre": 1e-09, # 10^-01
+ "metre": 1e-10, # Metre; Метр
+ "kilometre": 1e-13, # 10^03
+ "inch": 3.93700787e-09, # Inch; Дюйм
+ "foot": 3.2808399e-10, # Fool; Фут
+ "yard": 1.0936133e-10, # Yard; Ярд
+ "mille": 6.21371192e-14, # Mile; Миля
+ "league": 2.07123730667e-14, # League; Лига
+ "seamile": 5.39956803e-14, # Sea Mile; Морская Миля
+ "verst": 9.37382827e-14, # Verst; Верста
+ "au": 6.68458712267e-22, # Astronomical Unit; Астрономическая Единица (средний радиус земной орбиты)
+ "ly": 1.05700083402e-26, # Light-Year; Световой Год
+ "pc": 3.24077927001e-27, # Parsec; Парсек
+ },
+ "speed": { # Скорость
+ "km/h": 1.0, # KiloMetres per Hour; Километры в Час !# Base
+ "m/s": 0.2778, # Metres per Second; Метры в Секунду
+ "knot": 0.539956803, # Sea Miles per Hour; Морские Мили в Час (Knot; Узел)
+ "mph": 0.621371192, # Miles per Hour; Мили в Час
+ "fps": 0.911344415281, # Feet per Second; Футы в Секунду
+ "ls": 9.26566930076e-10, # Light-Speed; Скорость Света
+ },
+ "angle": { # Угол
+ "degree": 1.0, # Degree; Градус ° !# Base
+ "second": 3600.0, # Arc Second; Угловая Секунда
+ "minute": 60.0, # Arc Minute; Угловая Минута
+ "rad": 0.0174532925, # Radians; Радиан
+ "turn": 0.00277777777778, # Turn; Оборот
+ "gon": 1.111111111111111, # Gradian; Градон
+ },
+ "square": { # Площадь
+ "acre": 1.0, # Acre; Акр !# Base
+ "milimetre^2": 4046856420.0, # Square MilliMetre; Квадратный Миллиметр
+ "centimetre^2": 40468564.2, # Square CentiMetre; Квадратный Сантиметр
+ "metre^2": 4046.85642, # Square Metre; Квадратный Метр
+ "inch^2": 6272640.0, # Square Inch; Квадратный Дюйм
+ "foot^2": 0.00355591837, # Square Foot; Квадратный Фут
+ "mile^2": 0.0015625, # Square Mile; Квадратная Миля
+ "verst^2": 0.00355591837, # Square Verst; Квадратная Верста
+ "hectare": 0.404685642, # Hectare; Гектар
+ "are": 40.4685642, # Are; Ар
+ "barn": 4.04685642e31, # Barn; Барн
+ },
+ "energy": { # Энергия
+ "btu": 1.0, # British Thermal Unit; Британская Термическая Единица !# Base
+ "mbtu": 1000000.0, # Million British Thermal Unit; Миллион Британских Термических Единиц
+ "cal": 252.164401, # Calorie; Калория
+ "kcal": 0.252164401, # KiloCalorie; Килокалория
+ "erg": 10550558500.0, # Erg; Эрг
+ "ev": 6.58514139e20, # Electronvolt; Электронвольт
+ "joule": 1055.05585, # Joule (Watt per Second); Джоуль (Ватт Секунда)
+ "watt/h": 0.29307107, # Watt per Hour; Ватт Час
+ "kwatt/h": 0.00029307107, # KiloWatt per Hour; Киловатт Час
+ },
+ }
-def command_convert(ltype, source, body, disp):
- if body:
- ls = body.split()
- Desc = (ls.pop(0)).lower()
- if CrDesc.has_key(Desc):
- if len(ls) == 3:
- Numb = (ls.pop(0)).lower()
- if isNumber(Numb):
- Type = (ls.pop(0)).lower()
- ToType = (ls.pop(0)).lower()
- if CrDesc[Desc].has_key(Type) and CrDesc[Desc].has_key(ToType):
- if Desc == "temperature":
- answer = str(ConvertTemp(float(Numb), Type, ToType))
+ ConvertTemp = lambda self, Numb, Type, ToType, Desc = CrDesc["temperature"]: Desc[ToType][0](Desc[Type][1](Numb))
+
+ Convert = lambda self, Desc, Numb, Type, ToType: (self.CrDesc[Desc][ToType]*(Numb / self.CrDesc[Desc][Type]))
+
+ def command_convert(self, ltype, source, body, disp):
+ if body:
+ ls = body.split()
+ Desc = (ls.pop(0)).lower()
+ if self.CrDesc.has_key(Desc):
+ if len(ls) == 3:
+ Numb = (ls.pop(0)).lower()
+ if isNumber(Numb):
+ Type = (ls.pop(0)).lower()
+ ToType = (ls.pop(0)).lower()
+ if self.CrDesc[Desc].has_key(Type) and self.CrDesc[Desc].has_key(ToType):
+ if Desc == "temperature":
+ answer = str(self.ConvertTemp(float(Numb), Type, ToType))
+ else:
+ answer = str(self.Convert(Desc, float(Numb), Type, ToType))
else:
- answer = str(Convert(Desc, float(Numb), Type, ToType))
+ answer = self.AnsBase[0]
else:
- answer = ConverterAnsBase[0]
- else:
- answer = AnsBase[30]
- elif not ls:
- data = get_file(expansions["converter"].file).decode("utf-8")
- data = get_text(data, '\t"%s"\:\s{' % (Desc), '},')
- if data:
- comp = compile__('\t\t"(.+?)"\:.+?,\s+?\#\s(.+?)\n', 16)
- list = comp.findall(data)
- if list:
- ls = [Desc + ":"]
- for data in list:
- if Desc == "temperature" and "c" != data[0]:
- One, Two = data
- data = One, Two[15:].strip()
- ls.append(("%s - %s" % data).split("!#")[0].strip())
- answer = str.join(chr(10), ls)
+ answer = AnsBase[30]
+ elif not ls:
+ data = get_file(self.file).decode("utf-8")
+ data = get_text(data, '\t\t"%s"\:\s{' % (Desc), '},')
+ if data:
+ comp = compile__('\t\t\t"(.+?)"\:.+?,\s+?\#\s(.+?)\n', 16)
+ list = comp.findall(data)
+ if list:
+ ls = [Desc + ":"]
+ for data in list:
+ if Desc == "temperature" and "c" != data[0]:
+ One, Two = data
+ data = One, Two[15:].strip()
+ ls.append(("%s - %s" % data).split("!#")[0].strip())
+ answer = str.join(chr(10), ls)
+ else:
+ answer = self.AnsBase[1]
else:
- answer = ConverterAnsBase[1]
+ answer = self.AnsBase[1]
else:
- answer = ConverterAnsBase[1]
+ answer = AnsBase[2]
else:
- answer = AnsBase[2]
+ answer = self.AnsBase[2]
else:
- answer = ConverterAnsBase[2]
- else:
- answer = ", ".join(sorted(CrDesc.keys()))
- Answer(answer, ltype, source, disp)
+ answer = ", ".join(sorted(self.CrDesc.keys()))
+ Answer(answer, ltype, source, disp)
-command_handler(command_convert, {"RU": "convert", "EN": "convert"}, 2, exp_name)
+ commands = ((command_convert, "convert", 2,),)
diff --git a/expansions/converter/convert.name b/expansions/converter/convert.name
new file mode 100644
index 0000000..d55ef11
--- /dev/null
+++ b/expansions/converter/convert.name
@@ -0,0 +1,4 @@
+{
+ "RU": "convert",
+ "UA": "convert"
+} \ No newline at end of file
diff --git a/expansions/converter/insc.py b/expansions/converter/insc.py
index 10c3c4a..330387f 100644
--- a/expansions/converter/insc.py
+++ b/expansions/converter/insc.py
@@ -1,13 +1,13 @@
# coding: utf-8
if DefLANG in ("RU", "UA"):
- ConverterAnsBase = tuple([line.decode("utf-8") for line in (
+ AnsBase_temp = tuple([line.decode("utf-8") for line in (
"Неверно указана единица измерения.", # 0
"Oops...", # 1
"Неверно указана категория." # 2
)])
else:
- ConverterAnsBase = (
+ AnsBase_temp = (
"Incorrect unit.", # 0
"Oops...", # 1
"Incorrect category." # 2
diff --git a/expansions/cron/code.py b/expansions/cron/code.py
index a9cebcb..2ec085e 100644
--- a/expansions/cron/code.py
+++ b/expansions/cron/code.py
@@ -3,251 +3,260 @@
# BlackSmith mark.2
exp_name = "cron" # /code.py v.x4
# Id: 27~3a
-# Code © (2010-2011) by WitcherGeralt [WitcherGeralt@rocketmail.com]
+# Code © (2010-2011) by WitcherGeralt [alkorgun@gmail.com]
expansion_register(exp_name)
-CronFile = dynamic % ("cdesc.db")
-
-CronDesc, CronCounter = dict(), itypes.Number()
-
-def def_cron():
- exp_name = "cron"
-
- def exe_cron(command, instance, ls, repeat = ()):
- inst = get_source(ls[1][1], ls[1][2])
- if inst == instance or (not inst or not instance):
- gt = time.mktime(time.gmtime())
- rlen = len(repeat)
- if rlen == 1 and (repeat[0] >= 360):
- Answer(CronAnsBase[0] % (command), ls[0], ls[1], ls[3])
- Cmds[command].execute(*ls)
- if rlen == 2:
- seconds, repeats = (repeat)
- if repeats.reduce():
- CronDesc[CronCounter.plus()] = ((seconds + gt), (command, instance, ls, repeat))
-
- while VarCache["alive"]:
- time.sleep(2)
- if not expansions.has_key(exp_name):
- break
- Time = time.mktime(time.gmtime())
- for id, (date, ls) in CronDesc.items():
- if Time > date:
- if Cmds.has_key(ls[0]):
- sThread("command(cron)", exe_cron, ls)
- del CronDesc[id]
-
-def getDate(ls, sft, sftime = "%H:%M:%S (%d.%m.%Y)"):
- ls[5] += sft
- while ls[5] >= 60:
- ls[5] -= 60
- ls[4] += 1
- if ls[4] >= 60:
- ls[4] -= 60
- ls[3] += 1
- if ls[3] >= 24:
- ls[3] -= 24
- ls[2] += 1
- days = (0, 31, (28 if (ls[0] % 4) else 29), 31, 30, 31, 30, 31, 31, 30, 31, 30, 31)
- if ls[2] > days[ls[1]]:
- ls[2] -= days[ls[1]]
- ls[1] += 1
- if ls[1] > 12:
- ls[1] -= 12
- ls[0] += 1
- return time.strftime(sftime, time.struct_time(ls))
-
-def add_cron(disp, ls, body, Te, source, ltype, gt, answer, repeat, **ext):
- cmd = (ls.pop(0)).lower()
- if Cmds.has_key(cmd):
- if enough_access(source[1], source[2], Cmds[cmd].access):
- if ls:
- body = body[((body.lower()).find(cmd) + (len(cmd) + 1)):].strip()
- else:
- body = ""
- if 1024 >= len(body):
- Time = time.mktime(gt)
- instance = get_source(source[1], source[2])
- CronDesc[CronCounter.plus()] = ((Te + Time), (cmd, instance, (ltype, source, body, get_disp(disp)), repeat))
- cdesc_save()
+class expansion_temp(expansion):
+
+ def __init__(self, name):
+ expansion.__init__(self, name)
+
+ CronFile = dynamic % ("cdesc.db")
+
+ CronDesc, CronCounter = dict(), itypes.Number()
+
+ def def_cron(self):
+
+ def exe_cron(self, command, instance, ls, repeat = ()):
+ inst = get_source(ls[1][1], ls[1][2])
+ if inst == instance or (not inst or not instance):
+ gt = time.mktime(time.gmtime())
+ rlen = len(repeat)
+ if rlen == 1 and (repeat[0] >= 360):
+ Answer(self.AnsBase[0] % (command), ls[0], ls[1], ls[3])
+ Cmds[command].execute(*ls)
+ if rlen == 2:
+ seconds, repeats = (repeat)
+ if repeats.reduce():
+ self.CronDesc[self.CronCounter.plus()] = ((seconds + gt), (command, instance, ls, repeat))
+
+ while VarCache["alive"]:
+ time.sleep(2)
+ if not expansions.has_key(self.name):
+ break
+ Time = time.mktime(time.gmtime())
+ for id, (date, ls) in self.CronDesc.items():
+ if Time > date:
+ if Cmds.has_key(ls[0]):
+ sThread("command(cron)", exe_cron, (self,).__add__(ls))
+ del self.CronDesc[id]
+
+ def getDate(self, ls, sft, sftime = "%H:%M:%S (%d.%m.%Y)"):
+ ls[5] += sft
+ while ls[5] >= 60:
+ ls[5] -= 60
+ ls[4] += 1
+ if ls[4] >= 60:
+ ls[4] -= 60
+ ls[3] += 1
+ if ls[3] >= 24:
+ ls[3] -= 24
+ ls[2] += 1
+ days = (0, 31, (28 if (ls[0] % 4) else 29), 31, 30, 31, 30, 31, 31, 30, 31, 30, 31)
+ if ls[2] > days[ls[1]]:
+ ls[2] -= days[ls[1]]
+ ls[1] += 1
+ if ls[1] > 12:
+ ls[1] -= 12
+ ls[0] += 1
+ return time.strftime(sftime, time.struct_time(ls))
+
+ def add_cron(self, disp, ls, body, Te, source, ltype, gt, answer, repeat, **ext_):
+ cmd = (ls.pop(0)).lower()
+ if Cmds.has_key(cmd):
+ if enough_access(source[1], source[2], Cmds[cmd].access):
+ if ls:
+ body = body[((body.lower()).find(cmd) + (len(cmd) + 1)):].strip()
+ else:
+ body = ""
+ if 1024 >= len(body):
+ Time = time.mktime(gt)
+ instance = get_source(source[1], source[2])
+ self.CronDesc[self.CronCounter.plus()] = ((Te + Time), (cmd, instance, (ltype, source, body, get_disp(disp)), repeat))
+ self.cdesc_save()
+ else:
+ answer = AnsBase[5]
else:
- answer = AnsBase[5]
+ answer = AnsBase[10]
else:
- answer = AnsBase[10]
- else:
- answer = AnsBase[6]
- return answer
-
-def command_cron(ltype, source, body, disp):
- gt = time.gmtime()
- if body:
- ls = body.split()
- if len(ls) >= 2:
- Mode = (ls.pop(0)).lower()
- if Mode in ("stop", "стоп".decode("utf-8")):
- id = ls.pop(0)
- if isNumber(id):
- id = int(id)
- if CronDesc.has_key(id):
- if enough_access(source[1], source[2], 7):
- del CronDesc[id]; cdesc_save()
- answer = AnsBase[4]
- else:
- date, ls = CronDesc.get(id)
- if ls[1] == get_source(source[1], source[2]):
- del CronDesc[id]; cdesc_save()
+ answer = AnsBase[6]
+ return answer
+
+ def command_cron(self, ltype, source, body, disp):
+ gt = time.gmtime()
+ if body:
+ ls = body.split()
+ if len(ls) >= 2:
+ Mode = (ls.pop(0)).lower()
+ if Mode in ("stop", "стоп".decode("utf-8")):
+ id = ls.pop(0)
+ if isNumber(id):
+ id = int(id)
+ if self.CronDesc.has_key(id):
+ if enough_access(source[1], source[2], 7):
+ del self.CronDesc[id]; self.cdesc_save()
answer = AnsBase[4]
else:
- answer = AnsBase[10]
- else:
- answer = CronAnsBase[1] % (id)
- else:
- answer = AnsBase[30]
- elif Mode in ("cycled", "цикл".decode("utf-8")):
- if len(ls) >= 3:
- Te = ls.pop(0)
- Tr = ls.pop(0)
- if isNumber(Te) and isNumber(Tr):
- Te, Tr = int(Te), int(Tr)
- if Te <= 240 and Tr > 4:
- answer = CronAnsBase[2]
- elif 59 < Te and Te*Tr <= 4147200 or enough_access(source[1], source[2], 7):
- t_ls, repeat = [Te], (Te, itypes.Number(Tr))
- for x in xrange(1, Tr):
- t_ls.append(t_ls[-1] + Te)
- ltls = len(t_ls)
- t_ls = enumerated_list([getDate(list(gt), Tx) for Tx in t_ls[:8]])
- if ltls > 8:
- t_ls += CronAnsBase[3] % (ltls - 8)
- answer = CronAnsBase[4] % (t_ls)
- answer = add_cron(**locals())
+ date, ls = self.CronDesc.get(id)
+ if ls[1] == get_source(source[1], source[2]):
+ del self.CronDesc[id]; self.cdesc_save()
+ answer = AnsBase[4]
+ else:
+ answer = AnsBase[10]
else:
- answer = CronAnsBase[5]
+ answer = self.AnsBase[1] % (id)
else:
answer = AnsBase[30]
- else:
- answer = AnsBase[2]
- elif Mode in ("date", "дата".decode("utf-8")):
- if len(ls) >= 2:
- date = list(gt)
- Te = ls.pop(0)
- Te = Te.split("&")
- date[6], date[7], date[8] = 0, 0, 0
- Time = Te.pop(0)
- Time = Time.split(":")
- try:
- date[3] = int(Time.pop(0))
- if Time:
- date[4] = int(Time.pop(0))
- if Time:
- date[5] = int(Time.pop(0))
+ elif Mode in ("cycled", "цикл".decode("utf-8")):
+ if len(ls) >= 3:
+ Te = ls.pop(0)
+ Tr = ls.pop(0)
+ if isNumber(Te) and isNumber(Tr):
+ Te, Tr = int(Te), int(Tr)
+ if Te <= 240 and Tr > 4:
+ answer = self.AnsBase[2]
+ elif 59 < Te and Te*Tr <= 4147200 or enough_access(source[1], source[2], 7):
+ t_ls, repeat = [Te], (Te, itypes.Number(Tr))
+ for x in xrange(1, Tr):
+ t_ls.append(t_ls[-1] + Te)
+ ltls = len(t_ls)
+ t_ls = enumerated_list([self.getDate(list(gt), Tx) for Tx in t_ls[:8]])
+ if ltls > 8:
+ t_ls += self.AnsBase[3] % (ltls - 8)
+ answer = self.AnsBase[4] % (t_ls)
+ add = self.add_cron
+ del self
+ answer = add(**locals())
else:
- date[5] = 0
+ answer = self.AnsBase[5]
else:
- date[4], date[5] = 0, 0
- except:
- answer = AnsBase[2]
+ answer = AnsBase[30]
else:
- Date = (Te.pop(0) if Te else None)
- if Date:
- Date = Date.split(".")
- try:
- date[2] = int(Date.pop(0))
- if Date:
- date[1] = int(Date.pop(0))
- if Date:
- date[0] = int(Date.pop(0))
- except:
- answer = AnsBase[2]
- if not locals().has_key(Types[12]):
+ answer = AnsBase[2]
+ elif Mode in ("date", "дата".decode("utf-8")):
+ if len(ls) >= 2:
+ date = list(gt)
+ Te = ls.pop(0)
+ Te = Te.split("&")
+ date[6], date[7], date[8] = 0, 0, 0
+ Time = Te.pop(0)
+ Time = Time.split(":")
try:
- date = time.struct_time(date)
+ date[3] = int(Time.pop(0))
+ if Time:
+ date[4] = int(Time.pop(0))
+ if Time:
+ date[5] = int(Time.pop(0))
+ else:
+ date[5] = 0
+ else:
+ date[4], date[5] = 0, 0
except:
answer = AnsBase[2]
else:
- Time, Te = time.mktime(gt), time.mktime(date)
- if Te > Time:
- Te = (Te - Time)
- if 59 < Te <= 4147200 or enough_access(source[1], source[2], 7):
- repeat = (Te,)
- try:
- answer = CronAnsBase[6] % time.strftime("%H:%M:%S (%d.%m.%Y)", date)
- except ValueError:
- answer = CronAnsBase[9]
+ Date = (Te.pop(0) if Te else None)
+ if Date:
+ Date = Date.split(".")
+ try:
+ date[2] = int(Date.pop(0))
+ if Date:
+ date[1] = int(Date.pop(0))
+ if Date:
+ date[0] = int(Date.pop(0))
+ except:
+ answer = AnsBase[2]
+ if not locals().has_key(Types[12]):
+ try:
+ date = time.struct_time(date)
+ except:
+ answer = AnsBase[2]
+ else:
+ Time, Te = time.mktime(gt), time.mktime(date)
+ if Te > Time:
+ Te = (Te - Time)
+ if 59 < Te <= 4147200 or enough_access(source[1], source[2], 7):
+ repeat = (Te,)
+ try:
+ answer = self.AnsBase[6] % time.strftime("%H:%M:%S (%d.%m.%Y)", date)
+ except ValueError:
+ answer = self.AnsBase[9]
+ else:
+ add = self.add_cron
+ del self
+ answer = add(**locals())
else:
- answer = add_cron(**locals())
+ answer = self.AnsBase[5]
else:
- answer = CronAnsBase[5]
- else:
- answer = AnsBase[2]
+ answer = AnsBase[2]
+ else:
+ answer = AnsBase[2]
+ elif isNumber(Mode):
+ Te = int(Mode)
+ if 59 < Te <= 4147200 or enough_access(source[1], source[2], 7):
+ repeat = (Te,)
+ answer = self.AnsBase[6] % self.getDate(list(gt), Te)
+ add = self.add_cron
+ del self
+ answer = add(**locals())
+ else:
+ answer = self.AnsBase[5]
else:
answer = AnsBase[2]
- elif isNumber(Mode):
- Te = int(Mode)
- if 59 < Te <= 4147200 or enough_access(source[1], source[2], 7):
- repeat = (Te,)
- answer = CronAnsBase[6] % getDate(list(gt), Te)
- answer = add_cron(**locals())
- else:
- answer = CronAnsBase[5]
else:
answer = AnsBase[2]
+ elif not self.CronDesc:
+ answer = self.AnsBase[7]
else:
- answer = AnsBase[2]
- elif not CronDesc:
- answer = CronAnsBase[7]
- else:
- Te = time.mktime(gt)
- ls = []
- for id, (date, desc) in CronDesc.items():
- if date > Te:
- line = "%d (%s) [%s]" % (id, desc[0], getDate(list(gt), int(date - Te)))
- ls.append(line)
- answer = CronAnsBase[8] % enumerated_list(sorted(ls))
- Answer(answer, ltype, source, disp)
-
-def start_cron():
- Name = def_cron.func_name
- for Thr in iThr.enumerate():
- if Thr._Thread__name.startswith(Name):
- Thr.kill()
- if initialize_file(CronFile, "({}, 0)"):
- cdesc, ccnt = eval(get_file(CronFile))
- Time = time.mktime(time.gmtime())
- for id, (date, ls) in cdesc.items():
- if Time > date:
- del cdesc[id]
- elif len(ls[3]) == 2:
+ Te = time.mktime(gt)
+ ls = []
+ for id, (date, desc) in self.CronDesc.items():
+ if date > Te:
+ line = "%d (%s) [%s]" % (id, desc[0], self.getDate(list(gt), int(date - Te)))
+ ls.append(line)
+ answer = self.AnsBase[8] % enumerated_list(sorted(ls))
+ Answer(answer, ltype, source, disp)
+
+ def start_cron(self):
+ Name = self.def_cron.func_name
+ for Thr in iThr.enumerate():
+ if Thr._Thread__name.startswith(Name):
+ Thr.kill()
+ if initialize_file(self.CronFile, "({}, 0)"):
+ cdesc, ccnt = eval(get_file(self.CronFile))
+ Time = time.mktime(time.gmtime())
+ for id, (date, ls) in cdesc.items():
+ if Time > date:
+ del cdesc[id]
+ elif len(ls[3]) == 2:
+ command, instance, ls__, repeat = ls
+ seconds, repeats = repeat
+ repeat = (seconds, itypes.Number(repeats))
+ ls = (command, instance, ls__, repeat)
+ cdesc[id] = (date, ls)
+ self.CronDesc.update(cdesc)
+ self.CronCounter.__init__(ccnt)
+ composeThr(self.def_cron, Name).start()
+
+ def cdesc_save(self, conf = None):
+ if not conf:
+ cdesc = self.CronDesc.copy()
+ for id, (date, ls) in cdesc.items():
command, instance, ls__, repeat = ls
- seconds, repeats = repeat
- repeat = (seconds, itypes.Number(repeats))
+ if len(repeat) == 2:
+ seconds, repeats = repeat
+ repeat = (seconds, int(repeats))
+ ltype, source, body, disp = ls__
+ one, two, three = source
+ source = (str(one), two, three)
+ ls__ = (ltype, source, body, disp)
ls = (command, instance, ls__, repeat)
cdesc[id] = (date, ls)
- CronDesc.update(cdesc)
- CronCounter.__init__(ccnt)
- composeThr(def_cron, Name).start()
-
-def cdesc_save(conf = None):
- if not conf:
- cdesc = CronDesc.copy()
- for id, (date, ls) in cdesc.items():
- command, instance, ls__, repeat = ls
- if len(repeat) == 2:
- seconds, repeats = repeat
- repeat = (seconds, int(repeats))
- ltype, source, body, disp = ls__
- one, two, three = source
- source = (str(one), two, three)
- ls__ = (ltype, source, body, disp)
- ls = (command, instance, ls__, repeat)
- cdesc[id] = (date, ls)
- cat_file(CronFile, str((cdesc, int(CronCounter))))
-
-expansions[exp_name].funcs_add([def_cron, getDate, add_cron, command_cron, start_cron, cdesc_save])
-expansions[exp_name].ls.extend(["CronAnsBase", "CronDesc", "CronCounter"])
-
-command_handler(command_cron, {"RU": "хрон", "EN": "cron"}, 5, exp_name)
-
-handler_register(start_cron, "02si", exp_name)
-handler_register(cdesc_save, "03si", exp_name)
+ cat_file(self.CronFile, str((cdesc, int(self.CronCounter))))
+
+ commands = ((command_cron, "cron", 5,),)
+
+ handlers = (
+ (start_cron, "02si"),
+ (cdesc_save, "03si")
+ )
diff --git a/expansions/cron/cron.name b/expansions/cron/cron.name
new file mode 100644
index 0000000..56d64e8
--- /dev/null
+++ b/expansions/cron/cron.name
@@ -0,0 +1,4 @@
+{
+ "RU": "хрон",
+ "UA": "хрон"
+} \ No newline at end of file
diff --git a/expansions/cron/insc.py b/expansions/cron/insc.py
index a8ff2c3..c72093f 100644
--- a/expansions/cron/insc.py
+++ b/expansions/cron/insc.py
@@ -1,7 +1,7 @@
# coding: utf-8
if DefLANG in ("RU", "UA"):
- CronAnsBase = tuple([line.decode("utf-8") for line in (
+ AnsBase_temp = tuple([line.decode("utf-8") for line in (
"Ты просил выполнить «%s».", # 0
"Нет задания с ID'ом «%d».", # 1
"Слишком быстро и часто. (при количестве циклов большем 4х - тайм-аут должен превышать 4 минуты)", # 2
@@ -14,7 +14,7 @@ if DefLANG in ("RU", "UA"):
"Дата/Время введены некорректно." # 9
)])
else:
- CronAnsBase = (
+ AnsBase_temp = (
"You asked to execute '%s'.", # 0
"There is no task with ID '%d'.", # 1
"Too quickly and often. (when the number of cycles greater than 4 - timeout must exceed 4 minutes)", # 2
diff --git a/expansions/exp_control/code.py b/expansions/exp_control/code.py
index 6c5f00a..fa8694f 100644
--- a/expansions/exp_control/code.py
+++ b/expansions/exp_control/code.py
@@ -1,169 +1,178 @@
# coding: utf-8
# BlackSmith mark.2
-exp_name = "exp_control" # /code.py v.x4
-# Id: 09~4a
-# Code © (2011) by WitcherGeralt [WitcherGeralt@rocketmail.com]
+exp_name = "exp_control" # /code.py v.x6
+# Id: 09~6b
+# Code © (2011-2012) by WitcherGeralt [alkorgun@gmail.com]
expansion_register(exp_name)
-def command_expinfo(ltype, source, body, disp):
- get_state = lambda filename: (CexpAnsBase[1] if os.path.isfile(filename) else CexpAnsBase[2])
- if body:
- exp_name = body.lower()
- if check_nosimbols(exp_name):
- if expansions.has_key(exp_name):
- answer = CexpAnsBase[0]
+class expansion_temp(expansion):
+
+ def __init__(self, name):
+ expansion.__init__(self, name)
+
+ def command_expinfo(self, ltype, source, body, disp):
+ get_state = lambda filename: (self.AnsBase[1] if os.path.isfile(filename) else self.AnsBase[2])
+ if body:
+ exp_name = body.lower()
+ if check_nosimbols(exp_name):
+ if expansions.has_key(exp_name):
+ answer = self.AnsBase[0]
+ code_file = get_state(expansions[exp_name].file)
+ insc_file = get_state(expansions[exp_name].insc)
+ answer += "\n%s - %s - %s - %s" % (exp_name, self.AnsBase[3], code_file, insc_file)
+ if expansions[exp_name].cmds:
+ answer += self.AnsBase[4] % (", ".join(expansions[exp_name].cmds))
+ if expansions[exp_name].desc:
+ answer += self.AnsBase[5] % ("; ".join(["%s: (%s)" % (eh, ", ".join([inst.func_name for inst in ls])) for eh, ls in sorted(expansions[exp_name].desc.items())]))
+ else:
+ exp = expansion(exp_name)
+ if os.path.exists(exp.path):
+ answer = self.AnsBase[0]
+ code_file = get_state(exp.file)
+ insc_file = get_state(exp.insc)
+ answer += "\n%s - %s - %s - %s" % (exp_name, self.AnsBase[6], code_file, insc_file)
+ else:
+ answer = self.AnsBase[7]
+ else:
+ answer = self.AnsBase[7]
+ else:
+ answer, Number = self.AnsBase[8], itypes.Number()
+ for exp_name in sorted(expansions.keys()):
code_file = get_state(expansions[exp_name].file)
insc_file = get_state(expansions[exp_name].insc)
- answer += "\n%s - %s - %s - %s" % (exp_name, CexpAnsBase[3], code_file, insc_file)
- if len(expansions[exp_name].cmds):
- answer += CexpAnsBase[4] % (", ".join(expansions[exp_name].cmds))
- if len(expansions[exp_name].ls):
- answer += CexpAnsBase[5] % (", ".join(expansions[exp_name].ls))
- else:
- exp = expansion(exp_name)
- if os.path.exists(exp.path):
- answer = CexpAnsBase[0]
+ answer += "\n%d) %s - %s - %s" % (Number.plus(), exp_name, code_file, insc_file)
+ elexps = []
+ for exp_name in sorted(os.listdir(ExpsDir)):
+ if (".svn") == (exp_name) or expansions.has_key(exp_name):
+ continue
+ if os.path.isdir(os.path.join(ExpsDir, exp_name)):
+ exp = expansion(exp_name)
code_file = get_state(exp.file)
insc_file = get_state(exp.insc)
- answer += "\n%s - %s - %s - %s" % (exp_name, CexpAnsBase[6], code_file, insc_file)
- else:
- answer = CexpAnsBase[7]
- else:
- answer = CexpAnsBase[7]
- else:
- answer, Number = CexpAnsBase[8], itypes.Number()
- for exp_name in expansions.keys():
- code_file = get_state(expansions[exp_name].file)
- insc_file = get_state(expansions[exp_name].insc)
- answer += "\n%d) %s - %s - %s" % (Number.plus(), exp_name, code_file, insc_file)
- elexps = []
- for exp_name in sorted(os.listdir(PlugsDir)):
- if (".svn") == (exp_name) or expansions.has_key(exp_name):
- continue
- if os.path.isdir(os.path.join(PlugsDir, exp_name)):
- exp = expansion(exp_name)
- code_file = get_state(exp.file)
- insc_file = get_state(exp.insc)
- elexps.append("%d) %s - %s - %s" % (Number.plus(), exp_name, code_file, insc_file))
- elexps_len = len(elexps)
- if elexps_len:
- answer += CexpAnsBase[9] % (elexps_len, chr(10).join(elexps))
- Answer(answer, ltype, source, disp)
+ elexps.append("%d) %s - %s - %s" % (Number.plus(), exp_name, code_file, insc_file))
+ elexps_len = len(elexps)
+ if elexps_len:
+ answer += self.AnsBase[9] % (elexps_len, chr(10).join(elexps))
+ Answer(answer, ltype, source, disp)
-ReloadSemaphore = iThr.Semaphore()
+ ReloadSemaphore = iThr.Semaphore()
-def command_expload(ltype, source, body, disp):
- if body:
- exp_name = body.lower()
- if check_nosimbols(exp_name):
- if expansions.has_key(exp_name):
- if os.path.isfile(expansions[exp_name].file):
- with ReloadSemaphore:
- loaded = expansions[exp_name].load()
- if loaded[1]:
- expansions[exp_name].initialize_all()
- answer = CexpAnsBase[10] % (loaded[0])
- else:
- expansions[exp_name].dels(True)
- answer = CexpAnsBase[11] % (loaded[0], "\n\t* %s: %s") % (loaded[2])
- else:
- answer = CexpAnsBase[12]
- else:
- exp = expansion(exp_name)
- if exp.isExp:
- with ReloadSemaphore:
- loaded = exp.load()
- if loaded[1] and expansions.has_key(exp_name):
- expansions[exp_name].initialize_all()
- answer = CexpAnsBase[10] % (loaded[0])
- else:
- exp.dels(True)
- if loaded[2]:
- answer = CexpAnsBase[11] % (loaded[0], "\n\t* %s: %s") % (loaded[2])
+ def command_expload(self, ltype, source, body, disp):
+ if body:
+ exp_name = body.lower()
+ if check_nosimbols(exp_name):
+ if expansions.has_key(exp_name):
+ if os.path.isfile(expansions[exp_name].file):
+ with self.ReloadSemaphore:
+ rslt = expansions[exp_name].load()
+ if rslt[1]:
+ exp = expansion_temp(exp_name)
+ exp.initialize_exp()
+ exp.initialize_all()
+ answer = self.AnsBase[10] % (rslt[0])
else:
- answer = CexpAnsBase[13] % (loaded[0])
+ expansions[exp_name].dels(True)
+ answer = self.AnsBase[11] % (rslt[0], "\n\t* %s: %s") % (rslt[2])
+ else:
+ answer = self.AnsBase[12]
else:
- answer = CexpAnsBase[7]
+ expansions[exp_name] = exp = expansion(exp_name)
+ if exp.isExp:
+ with self.ReloadSemaphore:
+ rslt = exp.load()
+ if rslt[1] and expansions.has_key(exp_name):
+ exp = expansion_temp(exp_name)
+ exp.initialize_exp()
+ exp.initialize_all()
+ answer = self.AnsBase[10] % (rslt[0])
+ else:
+ exp.dels(True)
+ if rslt[2]:
+ answer = self.AnsBase[11] % (rslt[0], "\n\t* %s: %s") % (rslt[2])
+ else:
+ answer = self.AnsBase[13] % (rslt[0])
+ else:
+ exp.dels(True)
+ answer = self.AnsBase[7]
+ else:
+ answer = self.AnsBase[7]
else:
- answer = CexpAnsBase[7]
- else:
- answer = AnsBase[1]
- Answer(answer, ltype, source, disp)
+ answer = AnsBase[1]
+ Answer(answer, ltype, source, disp)
-def command_expunload(ltype, source, body, disp):
- if body:
- body = body.split()
- exp_name = (list_.pop(0)).lower()
- if expansions.has_key(exp_name):
- if body:
- handler, Name = None, body.pop(0)
- list = []
- for ls in expansions[exp_name].hnds.values():
- for instance in ls:
- inst = instance.func_name
- list.append(inst)
- if inst == Name:
- handler = instance
- break
- if handler:
- with ReloadSemaphore:
- expansions[exp_name].funcs_del(handler)
- answer = AnsBase[4]
- elif list:
- answer = CexpAnsBase[14] % (", ".join(sorted(list)))
+ def command_expunload(self, ltype, source, body, disp):
+ if body:
+ body = body.split()
+ exp_name = (list_.pop(0)).lower()
+ if expansions.has_key(exp_name):
+ if body:
+ handler, Name = None, body.pop(0)
+ list = []
+ for ls in expansions[exp_name].desc.values():
+ for instance in ls:
+ inst = instance.func_name
+ list.append(inst)
+ if inst == Name:
+ handler = instance
+ break
+ if handler:
+ with self.ReloadSemaphore:
+ expansions[exp_name].funcs_del(handler)
+ answer = AnsBase[4]
+ elif list:
+ answer = self.AnsBase[14] % (", ".join(sorted(list)))
+ else:
+ answer = self.AnsBase[15] % (exp_name)
else:
- answer = CexpAnsBase[15] % (exp_name)
+ with self.ReloadSemaphore:
+ expansions[exp_name].dels(True)
+ answer = AnsBase[4]
else:
- with ReloadSemaphore:
- expansions[exp_name].dels(True)
- answer = AnsBase[4]
+ answer = self.AnsBase[7]
else:
- answer = CexpAnsBase[7]
- else:
- answer = AnsBase[1]
- Answer(answer, ltype, source, disp)
+ answer = AnsBase[1]
+ Answer(answer, ltype, source, disp)
-def command_states(ltype, source, body, disp):
- if body:
- list_ = body.split()
- cmd = (list_.pop(0)).lower()
- if Cmds.has_key(cmd):
- if list_:
- body = (list_.pop(0)).lower()
- if body in ("off", "выкл".decode("utf-8")):
- if Cmds[cmd].isAvalable:
- if Cmds[cmd].handler:
- Cmds[cmd].isAvalable = False
- answer = AnsBase[4]
+ def command_states(self, ltype, source, body, disp):
+ if body:
+ list_ = body.split()
+ cmd = (list_.pop(0)).lower()
+ if Cmds.has_key(cmd):
+ if list_:
+ body = (list_.pop(0)).lower()
+ if body in ("off", "выкл".decode("utf-8")):
+ if Cmds[cmd].isAvalable:
+ if Cmds[cmd].handler:
+ Cmds[cmd].isAvalable = False
+ answer = AnsBase[4]
+ else:
+ answer = AnsBase[19] % (cmd)
else:
- answer = AnsBase[19] % (cmd)
- else:
- answer = CexpAnsBase[16] % (cmd)
- elif body in ("on", "вкл".decode("utf-8")):
- if not Cmds[cmd].isAvalable:
- if Cmds[cmd].handler:
- Cmds[cmd].isAvalable = True
- answer = AnsBase[4]
+ answer = self.AnsBase[16] % (cmd)
+ elif body in ("on", "вкл".decode("utf-8")):
+ if not Cmds[cmd].isAvalable:
+ if Cmds[cmd].handler:
+ Cmds[cmd].isAvalable = True
+ answer = AnsBase[4]
+ else:
+ answer = AnsBase[19] % (cmd)
else:
- answer = AnsBase[19] % (cmd)
+ answer = self.AnsBase[17] % (cmd)
else:
- answer = CexpAnsBase[17] % (cmd)
+ answer = AnsBase[2]
else:
answer = AnsBase[2]
else:
- answer = AnsBase[2]
+ answer = AnsBase[6]
else:
- answer = AnsBase[6]
- else:
- answer = AnsBase[1]
- Answer(answer, ltype, source, disp)
-
-expansions[exp_name].funcs_add([command_expinfo, command_expload, command_expunload, command_states])
-expansions[exp_name].ls.extend(["CexpAnsBase", "ReloadSemaphore"])
+ answer = AnsBase[1]
+ Answer(answer, ltype, source, disp)
-command_handler(command_expinfo, {"RU": "плагинфо", "EN": "expinfo"}, 7, exp_name)
-command_handler(command_expload, {"RU": "подгрузи", "EN": "expload"}, 8, exp_name)
-command_handler(command_expunload, {"RU": "выгрузи", "EN": "unload"}, 8, exp_name)
-command_handler(command_states, {"RU": "команда", "EN": "command"}, 8, exp_name)
+ commands = (
+ (command_expinfo, "expinfo", 7,),
+ (command_expload, "expload", 8,),
+ (command_expunload, "expunload", 8,),
+ (command_states, "command", 8,)
+ )
diff --git a/expansions/exp_control/command.name b/expansions/exp_control/command.name
new file mode 100644
index 0000000..c0c63ff
--- /dev/null
+++ b/expansions/exp_control/command.name
@@ -0,0 +1,4 @@
+{
+ "RU": "команда",
+ "UA": "команда"
+} \ No newline at end of file
diff --git a/expansions/exp_control/expinfo.name b/expansions/exp_control/expinfo.name
new file mode 100644
index 0000000..c9bd5c5
--- /dev/null
+++ b/expansions/exp_control/expinfo.name
@@ -0,0 +1,4 @@
+{
+ "RU": "плагинфо",
+ "UA": "плагинфо"
+} \ No newline at end of file
diff --git a/expansions/exp_control/expload.name b/expansions/exp_control/expload.name
new file mode 100644
index 0000000..bcf689a
--- /dev/null
+++ b/expansions/exp_control/expload.name
@@ -0,0 +1,4 @@
+{
+ "RU": "подгрузи",
+ "UA": "подгрузи"
+} \ No newline at end of file
diff --git a/expansions/exp_control/expunload.en b/expansions/exp_control/expunload.en
new file mode 100644
index 0000000..8c3a7b4
--- /dev/null
+++ b/expansions/exp_control/expunload.en
@@ -0,0 +1,6 @@
+expansions and functions unloader
+unload [expansion] (function)
+*/unload talkers
+bot would unload expansion "talkers"
+*/unload talkers calculate_talkers
+bot would unload talkers calculator (unloader should use only uers with experience) \ No newline at end of file
diff --git a/expansions/exp_control/expunload.name b/expansions/exp_control/expunload.name
new file mode 100644
index 0000000..8543011
--- /dev/null
+++ b/expansions/exp_control/expunload.name
@@ -0,0 +1,4 @@
+{
+ "RU": "выгрузи",
+ "UA": "выгрузи"
+} \ No newline at end of file
diff --git a/expansions/exp_control/expunload.ru b/expansions/exp_control/expunload.ru
new file mode 100644
index 0000000..5d22bfb
--- /dev/null
+++ b/expansions/exp_control/expunload.ru
@@ -0,0 +1,6 @@
+выгрузка плагинов и функций
+выгрузи [плагин] (функция)
+*/выгрузи talkers
+бот выгрузит плагин "talkers"
+*/выгрузи talkers calculate_talkers
+бот выгрузит функцию подсчёта болтунов (выгрузку функций следует использовать только профи) \ No newline at end of file
diff --git a/expansions/exp_control/insc.py b/expansions/exp_control/insc.py
index d3d2489..592632b 100644
--- a/expansions/exp_control/insc.py
+++ b/expansions/exp_control/insc.py
@@ -1,13 +1,13 @@
# coding: utf-8
if DefLANG in ("RU", "UA"):
- CexpAnsBase = tuple([line.decode("utf-8") for line in (
+ AnsBase_temp = tuple([line.decode("utf-8") for line in (
"\n[Название][состояние][файл кода][файл языка]", # 0
"в наличии", # 1
"отсутствует", # 2
"загружен", # 3
"\nКоманды: %s", # 4
- "\nОбъекты: %s", # 5
+ "\nФункции: %s", # 5
"не загружен", # 6
"Судя по всему нет такого плагина.", # 7
"\n[№][Название][файл кода][файл языка]", # 8
@@ -22,14 +22,14 @@ if DefLANG in ("RU", "UA"):
"Команда «%s» итак включена." # 17
)])
else:
- CexpAnsBase = (
+ AnsBase_temp = (
"\n[Name][state][code-file][lang-file]", # 0
"exists", # 1
- "", # 2
+ "not exists", # 2
"loaded", # 3
"\nCommands: %s", # 4
- "\nObjects: %s", # 5
- "", # 6
+ "\nHandlers: %s", # 5
+ "not loaded", # 6
"Also, this expansion isn't exists.", # 7
"\n[#][Name][codefile][langfile]", # 8
"\n\n## Not loaded (%d) ->\n\n%s", # 9
diff --git a/expansions/extra_control/code.py b/expansions/extra_control/code.py
index aaca546..1f65963 100644
--- a/expansions/extra_control/code.py
+++ b/expansions/extra_control/code.py
@@ -1,94 +1,99 @@
# coding: utf-8
# BlackSmith mark.2
-exp_name = "extra_control" # /code.py v.x6
-# Id: 01~4a
-# Code © (2009-2011) by WitcherGeralt [WitcherGeralt@rocketmail.com]
+exp_name = "extra_control" # /code.py v.x7
+# Id: 01~5b
+# Code © (2009-2011) by WitcherGeralt [alkorgun@gmail.com]
expansion_register(exp_name)
-def command_remote(ltype, source, body, disp):
- confs = sorted(Chats.keys())
- if body:
- ls = body.split()
- if len(ls) >= 3:
- x = (ls.pop(0)).lower()
- if x in confs:
- conf = x
- elif isNumber(x):
- Number = (int(x) - 1)
- if Number >= 0 and Number <= len(confs):
- conf = confs[Number]
+class expansion_temp(expansion):
+
+ def __init__(self, name):
+ expansion.__init__(self, name)
+
+ def command_remote(self, ltype, source, body, disp):
+ confs = sorted(Chats.keys())
+ if body:
+ ls = body.split()
+ if len(ls) >= 3:
+ x = (ls.pop(0)).lower()
+ if x in confs:
+ conf = x
+ elif isNumber(x):
+ Number = (int(x) - 1)
+ if Number >= 0 and Number <= len(confs):
+ conf = confs[Number]
+ else:
+ conf = False
else:
conf = False
- else:
- conf = False
- if conf:
- itype = (ls.pop(0)).lower()
- if itype in (Types[14], Types[0]):
- type2 = Types[1]
- elif itype in (Types[15], Types[6]):
- type2 = Types[0]
- else:
- type2 = False
- if type2:
- cmd = (ls.pop(0)).lower()
- if ls:
- body = body[((body.lower()).find(cmd) + (len(cmd) + 1)):].strip()
+ if conf:
+ itype = (ls.pop(0)).lower()
+ if itype in (Types[14], Types[0]):
+ type2 = Types[1]
+ elif itype in (Types[15], Types[6]):
+ type2 = Types[0]
else:
- body = ""
- if 1024 >= len(body):
- if Cmds.has_key(cmd):
- self = Cmds[cmd]
- if self.isAvalable and self.handler:
- Info["cmd"].plus()
- if type2 == Types[1]:
- disp_ = Chats[conf].disp
+ type2 = False
+ if type2:
+ cmd = (ls.pop(0)).lower()
+ if ls:
+ body = body[((body.lower()).find(cmd) + (len(cmd) + 1)):].strip()
+ else:
+ body = ""
+ if 1024 >= len(body):
+ if Cmds.has_key(cmd):
+ inst = Cmds[cmd]
+ if inst.isAvalable and inst.handler:
+ Info["cmd"].plus()
+ if type2 == Types[1]:
+ disp_ = Chats[conf].disp
+ else:
+ disp_ = get_disp(disp)
+ sThread("command", inst.handler, (inst.exp, type2, (source[0], conf, source[2]), body, disp_), inst.name)
+ inst.numb.plus()
+ source = get_source(source[1], source[2])
+ if source and source not in inst.desc:
+ inst.desc.append(source)
else:
- disp_ = get_disp(disp)
- sThread("command", self.handler, (type2, (source[0], conf, source[2]), body, disp_), self.name)
- self.numb.plus()
- source = get_source(source[1], source[2])
- if source and source not in self.desc:
- self.desc.append(source)
+ Answer(AnsBase[19] % (inst.name), ltype, source, disp)
else:
- Answer(AnsBase[19] % (self.name), ltype, source, disp)
+ answer = AnsBase[6]
else:
- answer = AnsBase[6]
+ answer = AnsBase[5]
else:
- answer = AnsBase[5]
+ answer = AnsBase[9]
else:
- answer = AnsBase[9]
+ answer = AnsBase[8]
else:
- answer = AnsBase[8]
+ answer = AnsBase[2]
else:
- answer = AnsBase[2]
- else:
- answer = enumerated_list(confs)
- if locals().has_key(Types[12]):
- Answer(answer, ltype, source, disp)
+ answer = enumerated_list(confs)
+ if locals().has_key(Types[12]):
+ Answer(answer, ltype, source, disp)
-def command_private(ltype, source, body, disp):
- if Chats.has_key(source[1]):
- if body:
- ls = body.split()
- cmd = (ls.pop(0)).lower()
- if Cmds.has_key(cmd):
- if ls:
- body = body[((body.lower()).find(cmd) + (len(cmd) + 1)):].strip()
+ def command_private(self, ltype, source, body, disp):
+ if Chats.has_key(source[1]):
+ if body:
+ ls = body.split()
+ cmd = (ls.pop(0)).lower()
+ if Cmds.has_key(cmd):
+ if ls:
+ body = body[((body.lower()).find(cmd) + (len(cmd) + 1)):].strip()
+ else:
+ body = ""
+ Cmds[cmd].execute(Types[0], source, body, disp)
else:
- body = ""
- Cmds[cmd].execute(Types[0], source, body, disp)
+ answer = AnsBase[6]
else:
- answer = AnsBase[6]
+ answer = AnsBase[1]
else:
- answer = AnsBase[1]
- else:
- answer = AnsBase[0]
- if locals().has_key(Types[12]):
- Answer(answer, ltype, source, disp)
-
-expansions[exp_name].funcs_add([command_remote, command_private])
+ answer = AnsBase[0]
+ if locals().has_key(Types[12]):
+ Answer(answer, ltype, source, disp)
-command_handler(command_remote, {"RU": "ремоут", "EN": "remote"}, 8, exp_name)
-command_handler(command_private, {"RU": "приват", "EN": "private"}, 1, exp_name)
+ commands = (
+ (command_remote, "remote", 8,),
+ (command_private, "private", 1,)
+ )
diff --git a/expansions/extra_control/private.name b/expansions/extra_control/private.name
new file mode 100644
index 0000000..0956105
--- /dev/null
+++ b/expansions/extra_control/private.name
@@ -0,0 +1,4 @@
+{
+ "RU": "приват",
+ "UA": "приват"
+} \ No newline at end of file
diff --git a/expansions/extra_control/remote.name b/expansions/extra_control/remote.name
new file mode 100644
index 0000000..d49490c
--- /dev/null
+++ b/expansions/extra_control/remote.name
@@ -0,0 +1,4 @@
+{
+ "RU": "ремоут",
+ "UA": "ремоут"
+} \ No newline at end of file
diff --git a/expansions/game/code.py b/expansions/game/code.py
index ffb5637..d9befd9 100644
--- a/expansions/game/code.py
+++ b/expansions/game/code.py
@@ -1,57 +1,61 @@
# coding: utf-8
# BlackSmith mark.2
-exp_name = "game" # /code.py v.x1
-# Id: 26~1a
-# Code © (2011) by WitcherGeralt [WitcherGeralt@rocketmail.com]
+exp_name = "game" # /code.py v.x2
+# Id: 26~2b
+# Code © (2011) by WitcherGeralt [alkorgun@gmail.com]
expansion_register(exp_name)
-GameDesc = {
- GameChrLS[0]: {
- GameChrLS[1]: 9,
- GameChrLS[3]: 2
- },
- GameChrLS[1]: {
- GameChrLS[2]: 0,
- GameChrLS[3]: 5
- },
- GameChrLS[2]: {
- GameChrLS[0]: 1,
- GameChrLS[4]: 7
- },
- GameChrLS[3]: {
- GameChrLS[2]: 6,
- GameChrLS[4]: 3
- },
- GameChrLS[4]: {
- GameChrLS[0]: 8,
- GameChrLS[1]: 4
- }
- }
-
-del GameChrLS
-
-def command_game(ltype, source, Char, disp):
- if Char:
- Char = Char.lower()
- if GameDesc.has_key(Char):
- Char_2 = choice(GameDesc.keys())
- Answer(Char_2, ltype, source, disp)
- time.sleep(3.2)
- if Char == Char_2:
- answer = GameAnsBase[0]
- elif GameDesc[Char_2].has_key(Char):
- answer = GameAnsBase[1] % (GameRules[GameDesc[Char_2][Char]])
+class expansion_temp(expansion):
+
+ def __init__(self, name):
+ expansion.__init__(self, name)
+
+ GameDesc = {
+ GameChrLS[0]: {
+ GameChrLS[1]: 9,
+ GameChrLS[3]: 2
+ },
+ GameChrLS[1]: {
+ GameChrLS[2]: 0,
+ GameChrLS[3]: 5
+ },
+ GameChrLS[2]: {
+ GameChrLS[0]: 1,
+ GameChrLS[4]: 7
+ },
+ GameChrLS[3]: {
+ GameChrLS[2]: 6,
+ GameChrLS[4]: 3
+ },
+ GameChrLS[4]: {
+ GameChrLS[0]: 8,
+ GameChrLS[1]: 4
+ }
+ }
+
+ GameRules = GameRules
+
+ def command_game(self, ltype, source, Char, disp):
+ if Char:
+ Char = Char.lower()
+ if self.GameDesc.has_key(Char):
+ Char_2 = choice(self.GameDesc.keys())
+ Answer(Char_2, ltype, source, disp)
+ time.sleep(3.2)
+ if Char == Char_2:
+ answer = self.AnsBase[0]
+ elif self.GameDesc[Char_2].has_key(Char):
+ answer = self.AnsBase[1] % (self.GameRules[self.GameDesc[Char_2][Char]])
+ else:
+ answer = self.AnsBase[2] % (self.GameRules[self.GameDesc[Char][Char_2]])
else:
- answer = GameAnsBase[2] % (GameRules[GameDesc[Char][Char_2]])
+ answer = AnsBase[2]
else:
- answer = AnsBase[2]
- else:
- answer = str.join(chr(10), GameRules)
- Answer(answer, ltype, source, disp)
+ answer = str.join(chr(10), self.GameRules)
+ Answer(answer, ltype, source, disp)
-expansions[exp_name].funcs_add([command_game])
-expansions[exp_name].ls.extend(["GameAnsBase", "GameRules", "GameDesc"])
+ commands = ((command_game, "game", 2,),)
-command_handler(command_game, {"RU": "игра", "EN": "game"}, 2, exp_name)
+del GameChrLS, GameRules
diff --git a/expansions/game/game.name b/expansions/game/game.name
new file mode 100644
index 0000000..df0e245
--- /dev/null
+++ b/expansions/game/game.name
@@ -0,0 +1,4 @@
+{
+ "RU": "игра",
+ "UA": "игра"
+} \ No newline at end of file
diff --git a/expansions/game/insc.py b/expansions/game/insc.py
index 21bebac..59f32da 100644
--- a/expansions/game/insc.py
+++ b/expansions/game/insc.py
@@ -1,7 +1,7 @@
# coding: utf-8
if DefLANG in ("RU", "UA"):
- GameAnsBase = tuple([line.decode("utf-8") for line in (
+ AnsBase_temp = tuple([line.decode("utf-8") for line in (
"Ничья.", # 0
"%s\n\t»» Я победил!", # 2
"%s\n\t»» Ты победил." # 3
@@ -18,7 +18,7 @@ if DefLANG in ("RU", "UA"):
"Бумага компрометирует Спока.", # 7
"Спок испаряет камень.", # 8
"Камень ломает ножницы." # 9
- )])
+ )])
GameChrLS = tuple([Char.decode("utf-8") for Char in (
"камень", # 0
@@ -26,9 +26,9 @@ if DefLANG in ("RU", "UA"):
"бумага", # 2
"ящерица", # 3
"спок" # 4
- )])
+ )])
else:
- GameAnsBase = (
+ AnsBase_temp = (
"Draw.", # 1
"%s\n\t>> I won!", # 2
"%s\n\t>> You won." # 3
@@ -45,7 +45,7 @@ else:
"Paper disproves Spock.", # 7
"Spock vaporizes rock.", # 8
"Rock crushes scissors." # 9
- )
+ )
GameChrLS = (
"rock", # 0
@@ -53,4 +53,4 @@ else:
"paper", # 2
"lizard", # 3
"spock" # 4
- ) \ No newline at end of file
+ ) \ No newline at end of file
diff --git a/expansions/get_iq/code.py b/expansions/get_iq/code.py
index aa27f51..5ac151f 100644
--- a/expansions/get_iq/code.py
+++ b/expansions/get_iq/code.py
@@ -1,233 +1,237 @@
# coding: utf-8
# BlackSmith mark.2
-exp_name = "get_iq" # /code.py v.x3
-# Id: 13~2a
-# Code © (2010-2011) by WitcherGeralt [WitcherGeralt@rocketmail.com]
+exp_name = "get_iq" # /code.py v.x4
+# Id: 13~3b
+# Code © (2010-2011) by WitcherGeralt [alkorgun@gmail.com]
expansion_register(exp_name)
-def command_ping(ltype, source, instance, disp):
- if instance:
- source_ = instance
- if Chats.has_key(source[1]) and Chats[source[1]].isHere(instance):
- if Chats[source[1]].isHereTS(instance):
- conf_nick = (source[1], instance)
- instance, source_ = "%s/%s" % conf_nick, get_source(*conf_nick)
- else:
- Answer(IqAnsBase[5] % (instance), ltype, source, disp)
- raise iThr.ThrKill("exit")
- else:
- instance, source_ = source[0], get_source(source[1], source[2])
- iq = xmpp.Iq(to = instance, typ = Types[10])
- iq.addChild(Types[16], {}, [], xmpp.NS_PING)
- iq.setID("Bs-i%d" % Info["outiq"].plus())
- CallForResponse(disp, iq, answer_ping, {"ltype": ltype, "source": source, "instance": instance, "source_": source_, "start": time.time()})
-
-PingStat = {}
-
-def answer_ping(disp, stanza, ltype, source, instance, source_, start):
- if xmpp.isResultNode(stanza):
- answer = round(time.time() - start, 3)
- if source_:
- if not PingStat.has_key(source_):
- PingStat[source_] = []
- PingStat[source_].append(answer)
- Answer(IqAnsBase[0] % str(answer), ltype, source, disp)
- else:
- iq = xmpp.Iq(to = instance, typ = Types[10])
- iq.addChild(Types[18], {}, [], xmpp.NS_VERSION)
- iq.setID("Bs-i%d" % Info["outiq"].plus())
- CallForResponse(disp, iq, answer_ping_ver, {"ltype": ltype, "source": source, "instance": instance, "source_": source_, "start": time.time()})
+class expansion_temp(expansion):
-def answer_ping_ver(disp, stanza, ltype, source, instance, source_, start):
- if xmpp.isResultNode(stanza):
- answer = round(time.time() - start, 3)
- if source_:
- if not PingStat.has_key(source_):
- PingStat[source_] = []
- PingStat[source_].append(answer)
- Name = "[None]"
- for x in stanza.getQueryChildren():
- xname = x.getName()
- if xname == "name":
- Name = x.getData()
- answer = IqAnsBase[1] % (Name, str(answer))
- else:
- answer = IqAnsBase[2]
- Answer(answer, ltype, source, disp)
-
-def command_ping_stat(ltype, source, source_, disp):
- if source_:
- if Chats.has_key(source[1]) and Chats[source[1]].isHere(source_):
- source_ = get_source(source[1], source_)
- else:
- source_ = source_.lower()
- else:
- source_ = get_source(source[1], source[2])
- if source_ and PingStat.has_key(source_):
- Number = 0.0
- for x in PingStat[source_]:
- Number += x
- len_ = len(PingStat[source_])
- max_ = max(PingStat[source_])
- min_ = min(PingStat[source_])
- if len_:
- answer = IqAnsBase[3] % (str(len_), str(min_), str(max_), str(round(Number / len_, 3)))
- else:
- answer = IqAnsBase[4]
- else:
- answer = IqAnsBase[4]
- Answer(answer, ltype, source, disp)
+ def __init__(self, name):
+ expansion.__init__(self, name)
-def command_version(ltype, source, instance, disp):
- if Chats.has_key(source[1]):
+ def command_ping(self, ltype, source, instance, disp):
if instance:
+ source_ = instance
if Chats.has_key(source[1]) and Chats[source[1]].isHere(instance):
if Chats[source[1]].isHereTS(instance):
- instance = "%s/%s" % (source[1], instance)
+ conf_nick = (source[1], instance)
+ instance, source_ = "%s/%s" % conf_nick, get_source(*conf_nick)
else:
- Answer(IqAnsBase[5] % (instance), ltype, source, disp)
+ Answer(self.AnsBase[5] % (instance), ltype, source, disp)
raise iThr.ThrKill("exit")
else:
- instance = source[0]
+ instance, source_ = source[0], get_source(source[1], source[2])
iq = xmpp.Iq(to = instance, typ = Types[10])
- iq.addChild(Types[18], {}, [], xmpp.NS_VERSION)
+ iq.addChild(Types[16], {}, [], xmpp.NS_PING)
iq.setID("Bs-i%d" % Info["outiq"].plus())
- CallForResponse(disp, iq, answer_version, {"ltype": ltype, "source": source})
- else:
- Answer(AnsBase[0], ltype, source, disp)
-
-def answer_version(disp, stanza, ltype, source):
- if xmpp.isResultNode(stanza):
- Name, Ver, Os = "[None]", "[None]", "[None]"
- for x in stanza.getQueryChildren():
- xname = x.getName()
- if xname == "name":
- Name = x.getData()
- elif xname == "version":
- Ver = x.getData()
- elif xname == "os":
- Os = x.getData()
- answer = "\nName: %s\nVer.: %s\nOS: %s" % (Name, Ver, Os)
- else:
- answer = IqAnsBase[6]
- Answer(answer, ltype, source, disp)
-
-def command_uptime(ltype, source, server, disp):
- if not server:
- server = InstansesDesc[Gen_disp][0]
- iq = xmpp.Iq(to = server, typ = Types[10])
- iq.addChild(Types[18], {}, [], xmpp.NS_LAST)
- iq.setID("Bs-i%d" % Info["outiq"].plus())
- CallForResponse(disp, iq, answer_idle, {"ltype": ltype, "source": source, "instance": server, "typ": None})
-
-def command_idle(ltype, source, instance, disp):
- if instance:
- nick = instance
- if Chats.has_key(source[1]) and Chats[source[1]].isHere(instance):
- if Chats[source[1]].isHereTS(instance):
- instance = "%s/%s" % (source[1], instance)
- else:
- answer = IqAnsBase[5] % (instance)
- if not locals().has_key(Types[12]):
+ CallForResponse(disp, iq, self.answer_ping, {"ltype": ltype, "source": source, "instance": instance, "source_": source_, "start": time.time()})
+
+ PingStat = {}
+
+ def answer_ping(self, disp, stanza, ltype, source, instance, source_, start):
+ if xmpp.isResultNode(stanza):
+ answer = round(time.time() - start, 3)
+ if source_:
+ if not self.PingStat.has_key(source_):
+ self.PingStat[source_] = []
+ self.PingStat[source_].append(answer)
+ Answer(self.AnsBase[0] % str(answer), ltype, source, disp)
+ else:
iq = xmpp.Iq(to = instance, typ = Types[10])
- iq.addChild(Types[18], {}, [], xmpp.NS_LAST)
+ iq.addChild(Types[18], {}, [], xmpp.NS_VERSION)
iq.setID("Bs-i%d" % Info["outiq"].plus())
- CallForResponse(disp, iq, answer_idle, {"ltype": ltype, "source": source, "instance": nick, "typ": True})
- else:
- answer = AnsBase[1]
- if locals().has_key(Types[12]):
+ CallForResponse(disp, iq, self.answer_ping_ver, {"ltype": ltype, "source": source, "instance": instance, "source_": source_, "start": time.time()})
+
+ def answer_ping_ver(self, disp, stanza, ltype, source, instance, source_, start):
+ if xmpp.isResultNode(stanza):
+ answer = round(time.time() - start, 3)
+ if source_:
+ if not self.PingStat.has_key(source_):
+ self.PingStat[source_] = []
+ self.PingStat[source_].append(answer)
+ Name = "[None]"
+ for x in stanza.getQueryChildren():
+ xname = x.getName()
+ if xname == "name":
+ Name = x.getData()
+ answer = self.AnsBase[1] % (Name, str(answer))
+ else:
+ answer = self.AnsBase[2]
Answer(answer, ltype, source, disp)
-def answer_idle(disp, stanza, ltype, source, instance, typ):
- if xmpp.isResultNode(stanza):
- seconds = stanza.getTagAttr(Types[18], "seconds")
- if seconds and seconds != "0" and isNumber(seconds):
- answer = (IqAnsBase[8] if typ else IqAnsBase[7]) % (instance, Time2Text(int(seconds)))
- if not locals().has_key(Types[12]):
- answer = IqAnsBase[6]
- Answer(answer, ltype, source, disp)
-
-def command_afls(ltype, source, body, disp):
-
- def get_req(body):
- afls = ("owner", "admin", "member", "outcast")
- if DefLANG in ("RU", "UA"):
- alsRU = tuple([afl.decode("utf-8") for afl in ("овнер", "админ", "мембер", "бан")])
- for afl in alsRU:
- if body.count(afl):
- return afls[alsRU.index(afl)]
- return (body if afls.count(body) else None)
-
- if Chats.has_key(source[1]):
- if body:
- list = body.split()
- body = get_req((list.pop(0)).lower())
- if body:
- Numb = 0
- if list:
- if isNumber(list[0]):
- x = int(list.pop(0))
- if x < 20:
- Numb = 20
- else:
- Numb = x
- iq = xmpp.Iq(to = source[1], typ = Types[10])
- query = xmpp.Node(Types[18])
- query.setNamespace(xmpp.NS_MUC_ADMIN)
- query.addChild("item", {AflRoles[0]: body})
- iq.addChild(node = query)
- iq.setID("Bs-i%d" % Info["outiq"].plus())
- CallForResponse(disp, iq, answer_afls, {"ltype": ltype, "source": source, "Numb": Numb})
+ def command_ping_stat(self, ltype, source, source_, disp):
+ if source_:
+ if Chats.has_key(source[1]) and Chats[source[1]].isHere(source_):
+ source_ = get_source(source[1], source_)
else:
- answer = AnsBase[2]
+ source_ = source_.lower()
else:
- answer = AnsBase[1]
- else:
- answer = AnsBase[0]
- if locals().has_key(Types[12]):
+ source_ = get_source(source[1], source[2])
+ if source_ and self.PingStat.has_key(source_):
+ Number = 0.0
+ for x in self.PingStat[source_]:
+ Number += x
+ len_ = len(self.PingStat[source_])
+ max_ = max(self.PingStat[source_])
+ min_ = min(self.PingStat[source_])
+ if len_:
+ answer = self.AnsBase[3] % (str(len_), str(min_), str(max_), str(round(Number / len_, 3)))
+ else:
+ answer = self.AnsBase[4]
+ else:
+ answer = self.AnsBase[4]
Answer(answer, ltype, source, disp)
-def answer_afls(disp, stanza, ltype, source, Numb):
- if xmpp.isResultNode(stanza):
- list = stanza.getChildren()
- if list:
- Number, answer = itypes.Number(), str()
- for child in list[0].getChildren():
- if child and child != "None":
- jid = child.getAttr("jid")
- if jid:
- if Numb and Numb <= Number._int():
- Number.plus()
- else:
- answer += "\n%d) %s" % (Number.plus(), jid)
- signature = child.getTagData("reason")
- if signature:
- answer += " [%s]" % (signature)
- if answer:
- if Numb and Numb < Number._int():
- answer += "\n...\nTotal: %s items." % (Number._str())
- Msend(source[0], answer, disp)
- if ltype == Types[1]:
- answer = AnsBase[11]
- else:
- del answer
+ def command_version(self, ltype, source, instance, disp):
+ if Chats.has_key(source[1]):
+ if instance:
+ if Chats.has_key(source[1]) and Chats[source[1]].isHere(instance):
+ if Chats[source[1]].isHereTS(instance):
+ instance = "%s/%s" % (source[1], instance)
+ else:
+ Answer(self.AnsBase[5] % (instance), ltype, source, disp)
+ raise iThr.ThrKill("exit")
else:
- answer = IqAnsBase[6]
+ instance = source[0]
+ iq = xmpp.Iq(to = instance, typ = Types[10])
+ iq.addChild(Types[18], {}, [], xmpp.NS_VERSION)
+ iq.setID("Bs-i%d" % Info["outiq"].plus())
+ CallForResponse(disp, iq, self.answer_version, {"ltype": ltype, "source": source})
+ else:
+ Answer(AnsBase[0], ltype, source, disp)
+
+ def answer_version(self, disp, stanza, ltype, source):
+ if xmpp.isResultNode(stanza):
+ Name, Ver, Os = "[None]", "[None]", "[None]"
+ for x in stanza.getQueryChildren():
+ xname = x.getName()
+ if xname == "name":
+ Name = x.getData()
+ elif xname == "version":
+ Ver = x.getData()
+ elif xname == "os":
+ Os = x.getData()
+ answer = "\nName: %s\nVer.: %s\nOS: %s" % (Name, Ver, Os)
else:
- answer = IqAnsBase[6]
- else:
- answer = IqAnsBase[6]
- if locals().has_key(Types[12]):
+ answer = self.AnsBase[6]
Answer(answer, ltype, source, disp)
-expansions[exp_name].funcs_add([command_ping, answer_ping, answer_ping_ver, command_ping_stat, command_version, answer_version, command_uptime, command_idle, answer_idle, command_afls, answer_afls])
-expansions[exp_name].ls.extend(["IqAnsBase, PingStat"])
+ def command_uptime(self, ltype, source, server, disp):
+ if not server:
+ server = InstansesDesc[Gen_disp][0]
+ iq = xmpp.Iq(to = server, typ = Types[10])
+ iq.addChild(Types[18], {}, [], xmpp.NS_LAST)
+ iq.setID("Bs-i%d" % Info["outiq"].plus())
+ CallForResponse(disp, iq, self.answer_idle, {"ltype": ltype, "source": source, "instance": server, "typ": None})
-command_handler(command_ping, {"RU": "пинг", "EN": "ping"}, 1, exp_name)
-command_handler(command_ping_stat, {"RU": "пингстат", "EN": "pingstat"}, 1, exp_name)
-command_handler(command_version, {"RU": "версия", "EN": "version"}, 1, exp_name)
-command_handler(command_uptime, {"RU": "аптайм", "EN": "uptime"}, 1, exp_name)
-command_handler(command_idle, {"RU": "жив", "EN": "idle"}, 1, exp_name)
-command_handler(command_afls, {"RU": "список", "EN": "list"}, 4, exp_name)
+ def command_idle(self, ltype, source, instance, disp):
+ if instance:
+ nick = instance
+ if Chats.has_key(source[1]) and Chats[source[1]].isHere(instance):
+ if Chats[source[1]].isHereTS(instance):
+ instance = "%s/%s" % (source[1], instance)
+ else:
+ answer = self.AnsBase[5] % (instance)
+ if not locals().has_key(Types[12]):
+ iq = xmpp.Iq(to = instance, typ = Types[10])
+ iq.addChild(Types[18], {}, [], xmpp.NS_LAST)
+ iq.setID("Bs-i%d" % Info["outiq"].plus())
+ CallForResponse(disp, iq, self.answer_idle, {"ltype": ltype, "source": source, "instance": nick, "typ": True})
+ else:
+ answer = AnsBase[1]
+ if locals().has_key(Types[12]):
+ Answer(answer, ltype, source, disp)
+
+ def answer_idle(self, disp, stanza, ltype, source, instance, typ):
+ if xmpp.isResultNode(stanza):
+ seconds = stanza.getTagAttr(Types[18], "seconds")
+ if seconds and seconds != "0" and isNumber(seconds):
+ answer = (self.AnsBase[8] if typ else self.AnsBase[7]) % (instance, Time2Text(int(seconds)))
+ if not locals().has_key(Types[12]):
+ answer = self.AnsBase[6]
+ Answer(answer, ltype, source, disp)
+
+ def command_afls(self, ltype, source, body, disp):
+
+ def get_req(body):
+ afls = ("owner", "admin", "member", "outcast")
+ if DefLANG in ("RU", "UA"):
+ alsRU = (afl.decode("utf-8") for afl in ("овнер", "админ", "мембер", "бан"))
+ for afl in alsRU:
+ if body.count(afl):
+ return afls[alsRU.index(afl)]
+ return (body if afls.count(body) else None)
+
+ if Chats.has_key(source[1]):
+ if body:
+ list = body.split()
+ body = get_req((list.pop(0)).lower())
+ if body:
+ Numb = 0
+ if list:
+ if isNumber(list[0]):
+ x = int(list.pop(0))
+ if x < 20:
+ Numb = 20
+ else:
+ Numb = x
+ iq = xmpp.Iq(to = source[1], typ = Types[10])
+ query = xmpp.Node(Types[18])
+ query.setNamespace(xmpp.NS_MUC_ADMIN)
+ query.addChild("item", {AflRoles[0]: body})
+ iq.addChild(node = query)
+ iq.setID("Bs-i%d" % Info["outiq"].plus())
+ CallForResponse(disp, iq, self.answer_afls, {"ltype": ltype, "source": source, "Numb": Numb})
+ else:
+ answer = AnsBase[2]
+ else:
+ answer = AnsBase[1]
+ else:
+ answer = AnsBase[0]
+ if locals().has_key(Types[12]):
+ Answer(answer, ltype, source, disp)
+
+ def answer_afls(self, disp, stanza, ltype, source, Numb):
+ if xmpp.isResultNode(stanza):
+ list = stanza.getChildren()
+ if list:
+ Number, answer = itypes.Number(), str()
+ for child in list[0].getChildren():
+ if child and child != "None":
+ jid = child.getAttr("jid")
+ if jid:
+ if Numb and Numb <= Number._int():
+ Number.plus()
+ else:
+ answer += "\n%d) %s" % (Number.plus(), jid)
+ signature = child.getTagData("reason")
+ if signature:
+ answer += " [%s]" % (signature)
+ if answer:
+ if Numb and Numb < Number._int():
+ answer += "\n...\nTotal: %s items." % (Number._str())
+ Msend(source[0], answer, disp)
+ if ltype == Types[1]:
+ answer = AnsBase[11]
+ else:
+ del answer
+ else:
+ answer = self.AnsBase[6]
+ else:
+ answer = self.AnsBase[6]
+ else:
+ answer = self.AnsBase[6]
+ if locals().has_key(Types[12]):
+ Answer(answer, ltype, source, disp)
+
+ commands = (
+ (command_ping, "ping", 1,),
+ (command_ping_stat, "pstat", 1,),
+ (command_version, "version", 1,),
+ (command_uptime, "uptime", 1,),
+ (command_idle, "idle", 1,),
+ (command_afls, "list", 4,)
+ )
diff --git a/expansions/get_iq/idle.name b/expansions/get_iq/idle.name
new file mode 100644
index 0000000..25fcfd2
--- /dev/null
+++ b/expansions/get_iq/idle.name
@@ -0,0 +1,4 @@
+{
+ "RU": "жив",
+ "UA": "жив"
+} \ No newline at end of file
diff --git a/expansions/get_iq/insc.py b/expansions/get_iq/insc.py
index 29eea6b..cf0fdf4 100644
--- a/expansions/get_iq/insc.py
+++ b/expansions/get_iq/insc.py
@@ -1,7 +1,7 @@
# coding: utf-8
if DefLANG in ("RU", "UA"):
- IqAnsBase = tuple([line.decode("utf-8") for line in (
+ AnsBase_temp = tuple([line.decode("utf-8") for line in (
"Понг - %s сек.", # 0
"Понга нет. Ответ на версию (%s) за %s секунд.", # 1
"Ни пинга, ни версии...", # 2
@@ -13,7 +13,7 @@ if DefLANG in ("RU", "UA"):
"Послеедняя активность «%s» - %s назад." # 8
)])
else:
- IqAnsBase = (
+ AnsBase_temp = (
"Pong - %s sec.", # 0
"No pong. Answer for version (%s) in %s sec.", # 1
"No pong, no version...", # 2
diff --git a/expansions/get_iq/list.name b/expansions/get_iq/list.name
new file mode 100644
index 0000000..118aee3
--- /dev/null
+++ b/expansions/get_iq/list.name
@@ -0,0 +1,4 @@
+{
+ "RU": "список",
+ "UA": "список"
+} \ No newline at end of file
diff --git a/expansions/get_iq/ping.name b/expansions/get_iq/ping.name
new file mode 100644
index 0000000..588895b
--- /dev/null
+++ b/expansions/get_iq/ping.name
@@ -0,0 +1,4 @@
+{
+ "RU": "пинг",
+ "UA": "пинг"
+} \ No newline at end of file
diff --git a/expansions/get_iq/pstat.en b/expansions/get_iq/pstat.en
new file mode 100644
index 0000000..7111a85
--- /dev/null
+++ b/expansions/get_iq/pstat.en
@@ -0,0 +1,8 @@
+xmpp ping statistics
+pstat (nick/jid)
+*/pstat
+bot would show your statistics
+*/pstat Dude
+bot would show Dude's statistics
+*/pstat dude@jabr.com
+bot would show the statistics of dude@jabr.com \ No newline at end of file
diff --git a/expansions/get_iq/pstat.name b/expansions/get_iq/pstat.name
new file mode 100644
index 0000000..1ee338d
--- /dev/null
+++ b/expansions/get_iq/pstat.name
@@ -0,0 +1,4 @@
+{
+ "RU": "пингстат",
+ "UA": "пингстат"
+} \ No newline at end of file
diff --git a/expansions/get_iq/pstat.ru b/expansions/get_iq/pstat.ru
new file mode 100644
index 0000000..2fc0c1c
--- /dev/null
+++ b/expansions/get_iq/pstat.ru
@@ -0,0 +1,8 @@
+статистика xmpp пинга
+пингстат (nick/jid)
+*/пингстат
+бот покажет вашу статистику
+*/пингстат Dude
+бот покажет статистику "Dude"
+*/пингстат dude@jab.ru
+бот покажет статистику "dude@jab.ru" \ No newline at end of file
diff --git a/expansions/get_iq/uptime.name b/expansions/get_iq/uptime.name
new file mode 100644
index 0000000..0c5d75b
--- /dev/null
+++ b/expansions/get_iq/uptime.name
@@ -0,0 +1,4 @@
+{
+ "RU": "аптайм",
+ "UA": "аптайм"
+} \ No newline at end of file
diff --git a/expansions/get_iq/version.name b/expansions/get_iq/version.name
new file mode 100644
index 0000000..4d8d245
--- /dev/null
+++ b/expansions/get_iq/version.name
@@ -0,0 +1,4 @@
+{
+ "RU": "версия",
+ "UA": "версия"
+} \ No newline at end of file
diff --git a/expansions/help/code.py b/expansions/help/code.py
index 02c576f..fba4ab0 100644
--- a/expansions/help/code.py
+++ b/expansions/help/code.py
@@ -1,108 +1,112 @@
# coding: utf-8
# BlackSmith mark.2
-exp_name = "help" # /code.py v.x4
-# Id: 03~1a
-# Code © (2010-2011) by WitcherGeralt [WitcherGeralt@rocketmail.com]
+exp_name = "help" # /code.py v.x5
+# Id: 03~2a
+# Code © (2010-2011) by WitcherGeralt [alkorgun@gmail.com]
expansion_register(exp_name)
-def command_location(ltype, source, body, disp):
- if body:
- command = body.lower()
- if Cmds.has_key(command):
- answer = HelpAnsBase[0] % (command, Cmds[command].exp.upper())
+class expansion_temp(expansion):
+
+ def __init__(self, name):
+ expansion.__init__(self, name)
+
+ def command_location(self, ltype, source, body, disp):
+ if body:
+ command = body.lower()
+ if Cmds.has_key(command):
+ answer = self.AnsBase[0] % (command, Cmds[command].exp.name.upper())
+ else:
+ answer = AnsBase[6]
else:
- answer = AnsBase[6]
- else:
- answer = AnsBase[1]
- Answer(answer, ltype, source, disp)
+ answer = AnsBase[1]
+ Answer(answer, ltype, source, disp)
-def command_comacc(ltype, source, body, disp):
- if body:
- command = body.lower()
- if Cmds.has_key(command):
- answer = HelpAnsBase[1] % (command, Cmds[command].access)
+ def command_comacc(self, ltype, source, body, disp):
+ if body:
+ command = body.lower()
+ if Cmds.has_key(command):
+ answer = self.AnsBase[1] % (command, Cmds[command].access)
+ else:
+ answer = AnsBase[6]
else:
- answer = AnsBase[6]
- else:
- answer = AnsBase[1]
- Answer(answer, ltype, source, disp)
+ answer = AnsBase[1]
+ Answer(answer, ltype, source, disp)
-def command_help(ltype, source, body, disp):
- if body:
- command = body.lower()
- if Cmds.has_key(command):
- if os.path.isfile(Cmds[command].help):
- help = get_file(Cmds[command].help).splitlines()
- if len(help) >= 2:
- answer = HelpAnsBase[2] % (help.pop(0), help.pop(0))
- if help:
- answer += HelpAnsBase[3]
- for line in help:
- line = line.strip()
- if line.startswith("*/"):
- Char, line = unichr(187)*3, line[2:].lstrip()
- else:
- Char = (chr(9) + chr(42))
- answer += "\n%s %s" % (Char, line)
+ def command_help(self, ltype, source, body, disp):
+ if body:
+ command = body.lower()
+ if Cmds.has_key(command):
+ if os.path.isfile(Cmds[command].help):
+ help = get_file(Cmds[command].help).splitlines()
+ if len(help) >= 2:
+ answer = self.AnsBase[2] % (help.pop(0), help.pop(0))
+ if help:
+ answer += self.AnsBase[3]
+ for line in help:
+ line = line.strip()
+ if line.startswith("*/"):
+ Char, line = unichr(187)*3, line[2:].lstrip()
+ else:
+ Char = (chr(9) + chr(42))
+ answer += "\n%s %s" % (Char, line)
+ else:
+ answer = self.AnsBase[17]
else:
- answer = HelpAnsBase[17]
+ answer = self.AnsBase[4]
else:
- answer = HelpAnsBase[4]
+ answer = AnsBase[6]
else:
- answer = AnsBase[6]
- else:
- answer = HelpAnsBase[5]
- Answer(answer, ltype, source, disp)
-
-def command_commands(ltype, source, body, disp):
- answer = HelpAnsBase[6] % (HelpAnsBase[7] % (Chats[source[1]].cPref) if (Chats.has_key(source[1]) and Chats[source[1]].cPref) else ":")
- cmds, lcmds = {}, {}
- for x in xrange(1, 9):
- lcmds[x] = itypes.Number()
- for cmd in Cmds.keys():
- access = Cmds[cmd].access
- if not cmds.has_key(access):
- cmds[access] = []
- cmds[access].append(cmd)
- for x in lcmds.keys():
- if x >= access:
- lcmds[x].plus()
- for x in cmds.keys():
- cmds[x].sort()
- if cmds.has_key(8):
- answer += HelpAnsBase[8] % (lcmds[8]._str(), ", ".join(cmds[8]))
- if cmds.has_key(7):
- answer += HelpAnsBase[9] % (lcmds[7]._str(), ", ".join(cmds[7]))
- if cmds.has_key(6):
- answer += HelpAnsBase[10] % (lcmds[6]._str(), ", ".join(cmds[6]))
- if cmds.has_key(5):
- answer += HelpAnsBase[11] % (lcmds[5]._str(), ", ".join(cmds[5]))
- if cmds.has_key(4):
- answer += HelpAnsBase[12] % (lcmds[4]._str(), ", ".join(cmds[4]))
- if cmds.has_key(3):
- answer += HelpAnsBase[13] % (lcmds[3]._str(), ", ".join(cmds[3]))
- if cmds.has_key(2):
- answer += HelpAnsBase[14] % (lcmds[2]._str(), ", ".join(cmds[2]))
- if cmds.has_key(1):
- answer += HelpAnsBase[15] % (lcmds[1]._str(), ", ".join(cmds[1]))
- access = get_access(source[1], source[2])
- if access >= 8:
- access = "%d (BOSS)" % (access)
- elif access == 7:
- access = "7 (Chief)"
- else:
- access = str(access)
- answer += HelpAnsBase[16] % (access)
- if ltype == Types[1]:
- Answer(AnsBase[11], ltype, source, disp)
- Msend(source[0], answer, disp)
+ answer = self.AnsBase[5]
+ Answer(answer, ltype, source, disp)
-expansions[exp_name].funcs_add([command_location, command_comacc, command_help, command_commands])
-expansions[exp_name].ls.extend(["HelpAnsBase"])
+ def command_commands(self, ltype, source, body, disp):
+ answer = self.AnsBase[6] % (self.AnsBase[7] % (Chats[source[1]].cPref) if (Chats.has_key(source[1]) and Chats[source[1]].cPref) else ":")
+ cmds, lcmds = {}, {}
+ for x in xrange(1, 9):
+ lcmds[x] = itypes.Number()
+ for cmd in Cmds.keys():
+ access = Cmds[cmd].access
+ if not cmds.has_key(access):
+ cmds[access] = []
+ cmds[access].append(cmd)
+ for x in lcmds.keys():
+ if x >= access:
+ lcmds[x].plus()
+ for x in cmds.keys():
+ cmds[x].sort()
+ if cmds.has_key(8):
+ answer += self.AnsBase[8] % (lcmds[8]._str(), ", ".join(cmds[8]))
+ if cmds.has_key(7):
+ answer += self.AnsBase[9] % (lcmds[7]._str(), ", ".join(cmds[7]))
+ if cmds.has_key(6):
+ answer += self.AnsBase[10] % (lcmds[6]._str(), ", ".join(cmds[6]))
+ if cmds.has_key(5):
+ answer += self.AnsBase[11] % (lcmds[5]._str(), ", ".join(cmds[5]))
+ if cmds.has_key(4):
+ answer += self.AnsBase[12] % (lcmds[4]._str(), ", ".join(cmds[4]))
+ if cmds.has_key(3):
+ answer += self.AnsBase[13] % (lcmds[3]._str(), ", ".join(cmds[3]))
+ if cmds.has_key(2):
+ answer += self.AnsBase[14] % (lcmds[2]._str(), ", ".join(cmds[2]))
+ if cmds.has_key(1):
+ answer += self.AnsBase[15] % (lcmds[1]._str(), ", ".join(cmds[1]))
+ access = get_access(source[1], source[2])
+ if access >= 8:
+ access = "%d (BOSS)" % (access)
+ elif access == 7:
+ access = "7 (Chief)"
+ else:
+ access = str(access)
+ answer += self.AnsBase[16] % (access)
+ if ltype == Types[1]:
+ Answer(AnsBase[11], ltype, source, disp)
+ Msend(source[0], answer, disp)
-command_handler(command_location, {"RU": "дислокация", "EN": "location"}, 1, exp_name)
-command_handler(command_comacc, {"RU": "комдоступ", "EN": "comacc"}, 1, exp_name)
-command_handler(command_help, {"RU": "хелп", "EN": "help"}, 1, exp_name, False)
-command_handler(command_commands, {"RU": "комлист", "EN": "commands"}, 1, exp_name, False)
+ commands = (
+ (command_location, "location", 1,),
+ (command_comacc, "comacc", 1,),
+ (command_help, "help", 1, False),
+ (command_commands, "commands", 1, False)
+ )
diff --git a/expansions/help/comacc.name b/expansions/help/comacc.name
new file mode 100644
index 0000000..2885623
--- /dev/null
+++ b/expansions/help/comacc.name
@@ -0,0 +1,4 @@
+{
+ "RU": "комдоступ",
+ "UA": "комдоступ"
+} \ No newline at end of file
diff --git a/expansions/help/commands.name b/expansions/help/commands.name
new file mode 100644
index 0000000..d6b3a3b
--- /dev/null
+++ b/expansions/help/commands.name
@@ -0,0 +1,4 @@
+{
+ "RU": "комлист",
+ "UA": "комлист"
+} \ No newline at end of file
diff --git a/expansions/help/help.name b/expansions/help/help.name
new file mode 100644
index 0000000..9d8c0a6
--- /dev/null
+++ b/expansions/help/help.name
@@ -0,0 +1,4 @@
+{
+ "RU": "хелп",
+ "UA": "хелп"
+} \ No newline at end of file
diff --git a/expansions/help/insc.py b/expansions/help/insc.py
index 1bf9b37..f38a38d 100644
--- a/expansions/help/insc.py
+++ b/expansions/help/insc.py
@@ -1,7 +1,7 @@
# coding: utf-8
if DefLANG in ("RU", "UA"):
- HelpAnsBase = tuple([line.decode("utf-8") for line in (
+ AnsBase_temp = tuple([line.decode("utf-8") for line in (
"Команда «%s» находится в плагине -» %s", # 0
"Доступ к команде «%s» - %d", # 1
"\n%s\nСинтаксис:\n»»» %s", # 2
@@ -22,7 +22,7 @@ if DefLANG in ("RU", "UA"):
"Файл со справкой повреждён!" # 17
)])
else:
- HelpAnsBase = (
+ AnsBase_temp = (
"Command '%s' located in expansion %s", # 0
"%s's access - %d", # 1
"\n%s\nSyntax:\n*** %s", # 2
diff --git a/expansions/help/location.name b/expansions/help/location.name
new file mode 100644
index 0000000..8d5f500
--- /dev/null
+++ b/expansions/help/location.name
@@ -0,0 +1,4 @@
+{
+ "RU": "дислокация",
+ "UA": "дислокация"
+} \ No newline at end of file
diff --git a/expansions/info/chatslist.name b/expansions/info/chatslist.name
new file mode 100644
index 0000000..dd94b35
--- /dev/null
+++ b/expansions/info/chatslist.name
@@ -0,0 +1,4 @@
+{
+ "RU": "чатлист",
+ "UA": "чатлист"
+} \ No newline at end of file
diff --git a/expansions/info/code.py b/expansions/info/code.py
index 2980631..b1e8568 100644
--- a/expansions/info/code.py
+++ b/expansions/info/code.py
@@ -1,171 +1,175 @@
# coding: utf-8
# BlackSmith mark.2
-exp_name = "info" # /code.py v.x4
-# Id: 11~3a
-# Code © (2010-2011) by WitcherGeralt [WitcherGeralt@rocketmail.com]
+exp_name = "info" # /code.py v.x5
+# Id: 11~4a
+# Code © (2010-2011) by WitcherGeralt [alkorgun@gmail.com]
expansion_register(exp_name)
-def command_online(ltype, source, body, disp):
- list, Numb, ThrIds = InfoAnsBase[7], itypes.Number(), iThr.ThrNames()
- for disp_ in sorted(InstansesDesc.keys()):
- connect, alive = online(disp_), str("%s%s" % (Types[13], disp_) in ThrIds)
- if not connect:
- connect = False
- list += "\n%d) %s - %s - %s" % (Numb.plus(), disp_, str(connect), alive)
- if ltype == Types[1]:
- Answer(AnsBase[11], ltype, source, disp)
- Msend(source[0], list, disp)
+class expansion_temp(expansion):
-def command_inchat(ltype, source, body, disp):
- if Chats.has_key(source[1]):
- list, Numb, acc = InfoAnsBase[8], itypes.Number(), enough_access(source[1], source[2], 4)
- owners, admins, members, none = [], [], [], []
- for nick in Chats[source[1]].sorted_users():
- if nick.ishere:
- text = nick.nick
- if acc and nick.source:
- text += " (%s)" % (nick.source)
- if nick.role[0] == AflRoles[5]:
- owners.append(text)
- elif nick.role[0] == AflRoles[4]:
- admins.append(text)
- elif nick.role[0] == AflRoles[3]:
- members.append(text)
- else:
- none.append(text)
- if owners:
- list += "\n\nOwners:"
- for x in owners:
- list += "\n%d) %s" % (Numb.plus(), x)
- if admins:
- list += "\n\nAdmins:"
- for x in admins:
- list += "\n%d) %s" % (Numb.plus(), x)
- if members:
- list += "\n\nMembers:"
- for x in members:
- list += "\n%d) %s" % (Numb.plus(), x)
- if none:
- list += "\n\nOthers:"
- for x in none:
- list += "\n%d) %s" % (Numb.plus(), x)
- if ltype == Types[1]:
- Answer(AnsBase[11], ltype, source, disp)
- Msend(source[0], list, disp)
- else:
- Answer(AnsBase[0], ltype, source, disp)
+ def __init__(self, name):
+ expansion.__init__(self, name)
-def command_conflist(ltype, source, body, disp):
- answer, Numb, admin = InfoAnsBase[5], itypes.Number(), enough_access(source[1], source[2], 7)
- for conf in sorted(Chats.keys()):
- BsNick = get_self_nick(conf)
- isModer = str(Chats[conf].isModer)
- ConfName = conf.split("@")[0]
- disp_ = (Chats[conf].disp if admin else "***")
- cPref = str(Chats[conf].cPref)
- online = itypes.Number()
- for nick in Chats[conf].get_users():
- if nick.ishere:
- online.plus()
- answer += '\n%d) %s/%s [%s] "%s" (%s) - %s' % (Numb.plus(), ConfName, BsNick, disp_, cPref, online._str(), isModer)
- if Numb._int():
+ def command_online(self, ltype, source, body, disp):
+ list, Numb, ThrIds = self.AnsBase[7], itypes.Number(), iThr.ThrNames()
+ for disp_ in sorted(InstansesDesc.keys()):
+ connect, alive = online(disp_), str("%s%s" % (Types[13], disp_) in ThrIds)
+ if not connect:
+ connect = False
+ list += "\n%d) %s - %s - %s" % (Numb.plus(), disp_, str(connect), alive)
if ltype == Types[1]:
Answer(AnsBase[11], ltype, source, disp)
- Msend(source[0], answer, disp)
- else:
- Answer(InfoAnsBase[6], ltype, source, disp)
+ Msend(source[0], list, disp)
-def command_visitors(ltype, source, body, disp):
- if Chats.has_key(source[1]):
- if body:
- Var = body.lower()
- else:
- Var = "default"
- if Var in ("today", "сегодня".decode("utf-8")):
- list = str()
- date = Yday()
- Numb = itypes.Number()
- Numb2 = itypes.Number()
+ def command_inchat(self, ltype, source, body, disp):
+ if Chats.has_key(source[1]):
+ list, Numb, acc = self.AnsBase[8], itypes.Number(), enough_access(source[1], source[2], 4)
+ owners, admins, members, none = [], [], [], []
for nick in Chats[source[1]].sorted_users():
- if not nick.ishere:
- if nick.date[1] == date:
- if nick.source:
- list += "\n%d. %s (%s)" % (Numb.plus(), nick.nick, nick.source)
- else:
- list += "\n%d. %s" % (Numb.plus(), nick.nick)
- else:
- Numb2.plus()
- if Numb._int():
- if ltype == Types[1]:
- Answer(AnsBase[11], ltype, source, disp)
- Msend(source[0], InfoAnsBase[0] % (Numb._str(), list, Numb2._str()), disp)
- else:
- Answer(InfoAnsBase[1], ltype, source, disp)
- elif Var in ("dates", "даты".decode("utf-8")):
- list = str()
- Numb = itypes.Number()
- for nick in Chats[source[1]].sorted_users():
- list += "\n%d. %s\t\t%s" % (Numb.plus(), nick.nick, nick.date[2])
+ if nick.ishere:
+ text = nick.nick
+ if acc and nick.source:
+ text += " (%s)" % (nick.source)
+ if nick.role[0] == AflRoles[5]:
+ owners.append(text)
+ elif nick.role[0] == AflRoles[4]:
+ admins.append(text)
+ elif nick.role[0] == AflRoles[3]:
+ members.append(text)
+ else:
+ none.append(text)
+ if owners:
+ list += "\n\nOwners:"
+ for x in owners:
+ list += "\n%d) %s" % (Numb.plus(), x)
+ if admins:
+ list += "\n\nAdmins:"
+ for x in admins:
+ list += "\n%d) %s" % (Numb.plus(), x)
+ if members:
+ list += "\n\nMembers:"
+ for x in members:
+ list += "\n%d) %s" % (Numb.plus(), x)
+ if none:
+ list += "\n\nOthers:"
+ for x in none:
+ list += "\n%d) %s" % (Numb.plus(), x)
if ltype == Types[1]:
Answer(AnsBase[11], ltype, source, disp)
- Msend(source[0], InfoAnsBase[2] % (Numb._str(), list), disp)
- elif Var in ("list", "лист".decode("utf-8")):
- ls = sorted(Chats[source[1]].get_nicks())
+ Msend(source[0], list, disp)
+ else:
+ Answer(AnsBase[0], ltype, source, disp)
+
+ def command_conflist(self, ltype, source, body, disp):
+ answer, Numb, admin = self.AnsBase[5], itypes.Number(), enough_access(source[1], source[2], 7)
+ for conf in sorted(Chats.keys()):
+ BsNick = get_self_nick(conf)
+ isModer = str(Chats[conf].isModer)
+ ConfName = conf.split("@")[0]
+ disp_ = (Chats[conf].disp if admin else "***")
+ cPref = str(Chats[conf].cPref)
+ online = itypes.Number()
+ for nick in Chats[conf].get_users():
+ if nick.ishere:
+ online.plus()
+ answer += '\n%d) %s/%s [%s] "%s" (%s) - %s' % (Numb.plus(), ConfName, BsNick, disp_, cPref, online._str(), isModer)
+ if Numb._int():
if ltype == Types[1]:
Answer(AnsBase[11], ltype, source, disp)
- Msend(source[0], InfoAnsBase[2] % (str(len(ls)), ", ".join(ls)), disp)
+ Msend(source[0], answer, disp)
else:
- list = str()
- Numb = itypes.Number()
- Numb2 = itypes.Number()
- for nick in Chats[source[1]].sorted_users():
- if not nick.ishere:
- if nick.source:
- list += "\n%d. %s (%s)" % (Numb.plus(), nick.nick, nick.source)
+ Answer(self.AnsBase[6], ltype, source, disp)
+
+ def command_visitors(self, ltype, source, body, disp):
+ if Chats.has_key(source[1]):
+ if body:
+ Var = body.lower()
+ else:
+ Var = "default"
+ if Var in ("today", "сегодня".decode("utf-8")):
+ list = str()
+ date = Yday()
+ Numb = itypes.Number()
+ Numb2 = itypes.Number()
+ for nick in Chats[source[1]].sorted_users():
+ if not nick.ishere:
+ if nick.date[1] == date:
+ if nick.source:
+ list += "\n%d. %s (%s)" % (Numb.plus(), nick.nick, nick.source)
+ else:
+ list += "\n%d. %s" % (Numb.plus(), nick.nick)
else:
- list += "\n%d. %s" % (Numb.plus(), nick.nick)
+ Numb2.plus()
+ if Numb._int():
+ if ltype == Types[1]:
+ Answer(AnsBase[11], ltype, source, disp)
+ Msend(source[0], self.AnsBase[0] % (Numb._str(), list, Numb2._str()), disp)
else:
- Numb2.plus()
- if Numb._int():
+ Answer(self.AnsBase[1], ltype, source, disp)
+ elif Var in ("dates", "даты".decode("utf-8")):
+ list = str()
+ Numb = itypes.Number()
+ for nick in Chats[source[1]].sorted_users():
+ list += "\n%d. %s\t\t%s" % (Numb.plus(), nick.nick, nick.date[2])
if ltype == Types[1]:
Answer(AnsBase[11], ltype, source, disp)
- Msend(source[0], InfoAnsBase[3] % (Numb._str(), list, Numb2._str()), disp)
+ Msend(source[0], self.AnsBase[2] % (Numb._str(), list), disp)
+ elif Var in ("list", "лист".decode("utf-8")):
+ ls = sorted(Chats[source[1]].get_nicks())
+ if ltype == Types[1]:
+ Answer(AnsBase[11], ltype, source, disp)
+ Msend(source[0], self.AnsBase[2] % (str(len(ls)), ", ".join(ls)), disp)
else:
- Answer(InfoAnsBase[4], ltype, source, disp)
- else:
- Answer(AnsBase[0], ltype, source, disp)
-
-def command_search(ltype, source, body, disp):
- if body:
- list, Numb, acc = str(), itypes.Number(), enough_access(source[1], source[2], 7)
- for conf in sorted(Chats.keys()):
- for nick in sorted(Chats[conf].get_nicks()):
- if Chats[conf].isHereTS(nick):
- jid = get_source(conf, nick)
- if nick.count(body) or (jid and jid.count(body)):
- list += "\n%d) %s (%s)" % (Numb.plus(), nick, conf)
- if jid and acc:
- list += " [%s]" % (jid)
- if Numb._int() >= 20:
- break
- if Numb._int():
- if ltype == Types[1]:
- Answer(AnsBase[11], ltype, source, disp)
- Msend(source[0], InfoAnsBase[9] % (Numb._str(), list), disp)
+ list = str()
+ Numb = itypes.Number()
+ Numb2 = itypes.Number()
+ for nick in Chats[source[1]].sorted_users():
+ if not nick.ishere:
+ if nick.source:
+ list += "\n%d. %s (%s)" % (Numb.plus(), nick.nick, nick.source)
+ else:
+ list += "\n%d. %s" % (Numb.plus(), nick.nick)
+ else:
+ Numb2.plus()
+ if Numb._int():
+ if ltype == Types[1]:
+ Answer(AnsBase[11], ltype, source, disp)
+ Msend(source[0], self.AnsBase[3] % (Numb._str(), list, Numb2._str()), disp)
+ else:
+ Answer(self.AnsBase[4], ltype, source, disp)
else:
- answer = InfoAnsBase[10]
- else:
- answer = AnsBase[1]
- if locals().has_key(Types[12]):
- Answer(answer, ltype, source, disp)
+ Answer(AnsBase[0], ltype, source, disp)
-expansions[exp_name].funcs_add([command_online, command_inchat, command_conflist, command_visitors, command_search])
-expansions[exp_name].ls.extend(["InfoAnsBase"])
+ def command_search(self, ltype, source, body, disp):
+ if body:
+ list, Numb, acc = str(), itypes.Number(), enough_access(source[1], source[2], 7)
+ for conf in sorted(Chats.keys()):
+ for nick in sorted(Chats[conf].get_nicks()):
+ if Chats[conf].isHereTS(nick):
+ jid = get_source(conf, nick)
+ if nick.count(body) or (jid and jid.count(body)):
+ list += "\n%d) %s (%s)" % (Numb.plus(), nick, conf)
+ if jid and acc:
+ list += " [%s]" % (jid)
+ if Numb._int() >= 20:
+ break
+ if Numb._int():
+ if ltype == Types[1]:
+ Answer(AnsBase[11], ltype, source, disp)
+ Msend(source[0], self.AnsBase[9] % (Numb._str(), list), disp)
+ else:
+ answer = self.AnsBase[10]
+ else:
+ answer = AnsBase[1]
+ if locals().has_key(Types[12]):
+ Answer(answer, ltype, source, disp)
-command_handler(command_online, {"RU": "онлайн", "EN": "online"}, 7, exp_name)
-command_handler(command_inchat, {"RU": "инмук", "EN": "inmuc"}, 2, exp_name)
-command_handler(command_conflist, {"RU": "чатлист", "EN": "chatslist"}, 5, exp_name)
-command_handler(command_visitors, {"RU": "ктобыл", "EN": "visitors"}, 4, exp_name)
-command_handler(command_search, {"RU": "где", "EN": "search"}, 2, exp_name)
+ commands = (
+ (command_online, "online", 7,),
+ (command_inchat, "inmuc", 2,),
+ (command_conflist, "chatslist", 5,),
+ (command_visitors, "visitors", 4,),
+ (command_search, "search", 2,)
+ )
diff --git a/expansions/info/inmuc.name b/expansions/info/inmuc.name
new file mode 100644
index 0000000..2339fc9
--- /dev/null
+++ b/expansions/info/inmuc.name
@@ -0,0 +1,4 @@
+{
+ "RU": "инмук",
+ "UA": "инмук"
+} \ No newline at end of file
diff --git a/expansions/info/insc.py b/expansions/info/insc.py
index 03010f6..e1af36a 100644
--- a/expansions/info/insc.py
+++ b/expansions/info/insc.py
@@ -1,7 +1,7 @@
# coding: utf-8
if DefLANG in ("RU", "UA"):
- InfoAnsBase = tuple([line.decode("utf-8") for line in (
+ AnsBase_temp = tuple([line.decode("utf-8") for line in (
"Сегодня здесь было %s юзеров:%s\n+ ещё %s досихпор здесь.", # 0
"Сегодня при мне ещё никто не выходил, все кто был досихпор здесь.", # 1
"При мне заходило %s юзеров:\n%s", # 2
@@ -15,7 +15,7 @@ if DefLANG in ("RU", "UA"):
"Не знаю." # 10
)])
else:
- InfoAnsBase = (
+ AnsBase_temp = (
"Today there were %s visitors here:%s\n+ %s are still here.", # 0
"Today when I was still nobody came, everyone who was - are still here.", # 1
"When I was still there were %s visitors here:\n%s", # 2
diff --git a/expansions/info/online.name b/expansions/info/online.name
new file mode 100644
index 0000000..48b1207
--- /dev/null
+++ b/expansions/info/online.name
@@ -0,0 +1,4 @@
+{
+ "RU": "онлайн",
+ "UA": "онлайн"
+} \ No newline at end of file
diff --git a/expansions/info/search.name b/expansions/info/search.name
new file mode 100644
index 0000000..cea0e45
--- /dev/null
+++ b/expansions/info/search.name
@@ -0,0 +1,4 @@
+{
+ "RU": "где",
+ "UA": "где"
+} \ No newline at end of file
diff --git a/expansions/info/visitors.name b/expansions/info/visitors.name
new file mode 100644
index 0000000..5a2a1ee
--- /dev/null
+++ b/expansions/info/visitors.name
@@ -0,0 +1,4 @@
+{
+ "RU": "ктобыл",
+ "UA": "ктобыл"
+} \ No newline at end of file
diff --git a/expansions/interpreter/calc.name b/expansions/interpreter/calc.name
new file mode 100644
index 0000000..f71e99f
--- /dev/null
+++ b/expansions/interpreter/calc.name
@@ -0,0 +1,4 @@
+{
+ "RU": "калк",
+ "UA": "калк"
+} \ No newline at end of file
diff --git a/expansions/interpreter/code.py b/expansions/interpreter/code.py
index cc42fbc..0b19d57 100644
--- a/expansions/interpreter/code.py
+++ b/expansions/interpreter/code.py
@@ -1,73 +1,78 @@
# coding: utf-8
# BlackSmith mark.2
-exp_name = "interpreter" # /code.py v.x6
-# Id: 04~4a
+exp_name = "interpreter" # /code.py v.x7
+# Id: 04~5b
# Code © (2002-2005) by Mike Mintz [mikemintz@gmail.com]
# Code © (2007) by Als [Als@exploit.in]
-# Code © (2009-2011) by WitcherGeralt [WitcherGeralt@rocketmail.com]
+# Code © (2009-2011) by WitcherGeralt [alkorgun@gmail.com]
expansion_register(exp_name)
-def command_eval(ltype, source, body, disp):
- if body:
- try:
- answer = UnicodeType(eval(UnicodeType(body)))
- except:
- answer = "%s - %s" % exc_info()
- else:
- answer = AnsBase[1]
- Answer(answer, ltype, source, disp)
+class expansion_temp(expansion):
-def command_exec(ltype, source, body, disp):
- if body:
- if chr(10) in body and body[-1] != chr(10):
- body += chr(10)
- answer = AnsBase[4]
- try:
- exec(UnicodeType(body), globals())
- except:
- answer = "%s - %s" % exc_info()
- else:
- answer = AnsBase[1]
- Answer(answer, ltype, source, disp)
+ def __init__(self, name):
+ expansion.__init__(self, name)
-def command_sh(ltype, source, body, disp):
- if body:
- if oSlist[1]:
- command = sys_cmds[6] % (body.encode("utf-8"))
+ def command_eval(self, ltype, source, body, disp):
+ if body:
+ try:
+ answer = UnicodeType(eval(UnicodeType(body)))
+ except:
+ answer = "%s - %s" % exc_info()
else:
- command = body.encode("cp1251")
- answer = get_pipe(command)
- if answer in ["", None]:
+ answer = AnsBase[1]
+ Answer(answer, ltype, source, disp)
+
+ def command_exec(self, ltype, source, body, disp):
+ if body:
+ if chr(10) in body and body[-1] != chr(10):
+ body += chr(10)
answer = AnsBase[4]
- else:
- answer = AnsBase[1]
- Answer(answer, ltype, source, disp)
+ try:
+ exec(UnicodeType(body), globals())
+ except:
+ answer = "%s - %s" % exc_info()
+ else:
+ answer = AnsBase[1]
+ Answer(answer, ltype, source, disp)
+
+ def command_sh(self, ltype, source, body, disp):
+ if body:
+ if oSlist[1]:
+ command = sys_cmds[6] % (body.encode("utf-8"))
+ else:
+ command = body.encode("cp1251")
+ answer = get_pipe(command)
+ if answer in ["", None]:
+ answer = AnsBase[4]
+ else:
+ answer = AnsBase[1]
+ Answer(answer, ltype, source, disp)
-def command_calc(ltype, source, body, disp):
- if body:
- if not body.count(chr(42)*2) and 32 >= len(body):
- comp = compile__("([0-9]|[\+\-\(\/\*\)\%\^\.])")
- expr = (not comp.sub("", body).strip())
- if expr:
- try:
- answer = UnicodeType(eval(body))
- except ZeroDivisionError:
- answer = "+∞".decode("utf-8")
- except:
+ def command_calc(self, ltype, source, body, disp):
+ if body:
+ if not body.count(chr(42)*2) and 32 >= len(body):
+ comp = compile__("([0-9]|[\+\-\(\/\*\)\%\^\.])")
+ expr = (not comp.sub("", body).strip())
+ if expr:
+ try:
+ answer = UnicodeType(eval(body))
+ except ZeroDivisionError:
+ answer = "+∞".decode("utf-8")
+ except:
+ answer = AnsBase[2]
+ else:
answer = AnsBase[2]
else:
answer = AnsBase[2]
else:
- answer = AnsBase[2]
- else:
- answer = AnsBase[1]
- Answer(answer, ltype, source, disp)
-
-expansions[exp_name].funcs_add([command_eval, command_exec, command_sh, command_calc])
+ answer = AnsBase[1]
+ Answer(answer, ltype, source, disp)
-command_handler(command_eval, {"RU": "eval", "EN": "eval"}, 8, exp_name)
-command_handler(command_exec, {"RU": "exec", "EN": "exec"}, 8, exp_name)
-command_handler(command_sh, {"RU": "sh", "EN": "sh"}, 8, exp_name)
-command_handler(command_calc, {"RU": "калк", "EN": "calc"}, 2, exp_name)
+ commands = (
+ (command_eval, "eval", 8,),
+ (command_exec, "exec", 8,),
+ (command_sh, "sh", 8,),
+ (command_calc, "calc", 2,)
+ )
diff --git a/expansions/interpreter/eval.name b/expansions/interpreter/eval.name
new file mode 100644
index 0000000..d649731
--- /dev/null
+++ b/expansions/interpreter/eval.name
@@ -0,0 +1,4 @@
+{
+ "RU": "eval",
+ "UA": "eval"
+} \ No newline at end of file
diff --git a/expansions/interpreter/exec.name b/expansions/interpreter/exec.name
new file mode 100644
index 0000000..95b743f
--- /dev/null
+++ b/expansions/interpreter/exec.name
@@ -0,0 +1,4 @@
+{
+ "RU": "exec",
+ "UA": "exec"
+} \ No newline at end of file
diff --git a/expansions/interpreter/sh.name b/expansions/interpreter/sh.name
new file mode 100644
index 0000000..c4c20b3
--- /dev/null
+++ b/expansions/interpreter/sh.name
@@ -0,0 +1,4 @@
+{
+ "RU": "sh",
+ "UA": "sh"
+} \ No newline at end of file
diff --git a/expansions/muc/admin.name b/expansions/muc/admin.name
new file mode 100644
index 0000000..a9e0c00
--- /dev/null
+++ b/expansions/muc/admin.name
@@ -0,0 +1,4 @@
+{
+ "RU": "админ",
+ "UA": "админ"
+} \ No newline at end of file
diff --git a/expansions/muc/ban.name b/expansions/muc/ban.name
new file mode 100644
index 0000000..166c15d
--- /dev/null
+++ b/expansions/muc/ban.name
@@ -0,0 +1,4 @@
+{
+ "RU": "бан",
+ "UA": "бан"
+} \ No newline at end of file
diff --git a/expansions/muc/code.py b/expansions/muc/code.py
index 121303b..51d1c9e 100644
--- a/expansions/muc/code.py
+++ b/expansions/muc/code.py
@@ -3,438 +3,442 @@
# BlackSmith mark.2
exp_name = "muc" # /code.py v.x7
# Id: 05~3a
-# Code © (2009-2011) by WitcherGeralt [WitcherGeralt@rocketmail.com]
+# Code © (2009-2011) by WitcherGeralt [alkorgun@gmail.com]
expansion_register(exp_name)
-def command_subject(ltype, source, body, disp):
- if Chats.has_key(source[1]):
- if body:
- if Chats[source[1]].isModer:
- Info["omsg"].plus()
- Chats[source[1]].subject(xmpp.XMLescape(body))
+class expansion_temp(expansion):
+
+ def __init__(self, name):
+ expansion.__init__(self, name)
+
+ def command_subject(self, ltype, source, body, disp):
+ if Chats.has_key(source[1]):
+ if body:
+ if Chats[source[1]].isModer:
+ Info["omsg"].plus()
+ Chats[source[1]].subject(xmpp.XMLescape(body))
+ else:
+ answer = self.AnsBase[1]
else:
- answer = MucAnsBase[1]
+ answer = AnsBase[1]
else:
- answer = AnsBase[1]
- else:
- answer = AnsBase[0]
- if locals().has_key(Types[12]):
- Answer(answer, ltype, source, disp)
+ answer = AnsBase[0]
+ if locals().has_key(Types[12]):
+ Answer(answer, ltype, source, disp)
-def command_ban(ltype, source, body, disp):
- if Chats.has_key(source[1]):
- if body:
- if Chats[source[1]].isModer:
- Lock, BsNick = False, get_self_nick(source[1])
- if getattr(Chats[source[1]].get_user(BsNick), "role", (AflRoles[5],))[0] == AflRoles[5]:
- if not enough_access(source[1], source[2], 6):
- Lock = True
- if not Lock:
- body = body.split(chr(47), 1)
- nick = body.pop(0)
- Nick = nick.strip()
- if Chats[source[1]].isHere(nick):
- jid = get_source(source[1], nick)
- elif Chats[source[1]].isHere(Nick):
- jid = get_source(source[1], Nick)
- elif nick.count(chr(46)) and not Nick.count(chr(32)):
- jid = Nick
- else:
- jid = None
- if jid and Galist.get(jid, 0) < 7 and not Clients.has_key(jid):
- if body and body[0]:
- text = "%s: %s" % (source[2], (body.pop(0)).strip())
+ def command_ban(self, ltype, source, body, disp):
+ if Chats.has_key(source[1]):
+ if body:
+ if Chats[source[1]].isModer:
+ Lock, BsNick = False, get_self_nick(source[1])
+ if getattr(Chats[source[1]].get_user(BsNick), "role", (AflRoles[5],))[0] == AflRoles[5]:
+ if not enough_access(source[1], source[2], 6):
+ Lock = True
+ if not Lock:
+ body = body.split(chr(47), 1)
+ nick = body.pop(0)
+ Nick = nick.strip()
+ if Chats[source[1]].isHere(nick):
+ jid = get_source(source[1], nick)
+ elif Chats[source[1]].isHere(Nick):
+ jid = get_source(source[1], Nick)
+ elif nick.count(chr(46)) and not Nick.count(chr(32)):
+ jid = Nick
+ else:
+ jid = None
+ if jid and Galist.get(jid, 0) < 7 and not Clients.has_key(jid):
+ if body and body[0]:
+ text = "%s: %s" % (source[2], (body.pop(0)).strip())
+ else:
+ text = "%s/%s" % (get_self_nick(source[1]), source[2])
+ Chats[source[1]].outcast(jid, text, (ltype, source))
else:
- text = "%s/%s" % (get_self_nick(source[1]), source[2])
- Chats[source[1]].outcast(jid, text, (ltype, source))
+ answer = AnsBase[7]
else:
- answer = AnsBase[7]
+ answer = self.AnsBase[0]
else:
- answer = MucAnsBase[0]
+ answer = self.AnsBase[1]
else:
- answer = MucAnsBase[1]
+ answer = AnsBase[1]
else:
- answer = AnsBase[1]
- else:
- answer = AnsBase[0]
- if locals().has_key(Types[12]):
- Answer(answer, ltype, source, disp)
+ answer = AnsBase[0]
+ if locals().has_key(Types[12]):
+ Answer(answer, ltype, source, disp)
-def command_none(ltype, source, body, disp):
- if Chats.has_key(source[1]):
- if body:
- if Chats[source[1]].isModer:
- Lock, BsNick = False, get_self_nick(source[1])
- if getattr(Chats[source[1]].get_user(BsNick), "role", (AflRoles[5],))[0] == AflRoles[5]:
- if not enough_access(source[1], source[2], 6):
- Lock = True
- if not Lock:
- body = body.split(chr(47), 1)
- nick = body.pop(0)
- Nick = nick.strip()
- if Chats[source[1]].isHere(nick):
- jid = get_source(source[1], nick)
- elif Chats[source[1]].isHere(Nick):
- jid = get_source(source[1], Nick)
- elif nick.count(chr(46)) and not Nick.count(chr(32)):
- jid = Nick
- else:
- jid = None
- if jid:
- if body and body[0]:
- text = "%s: %s" % (source[2], (body.pop(0)).strip())
+ def command_none(self, ltype, source, body, disp):
+ if Chats.has_key(source[1]):
+ if body:
+ if Chats[source[1]].isModer:
+ Lock, BsNick = False, get_self_nick(source[1])
+ if getattr(Chats[source[1]].get_user(BsNick), "role", (AflRoles[5],))[0] == AflRoles[5]:
+ if not enough_access(source[1], source[2], 6):
+ Lock = True
+ if not Lock:
+ body = body.split(chr(47), 1)
+ nick = body.pop(0)
+ Nick = nick.strip()
+ if Chats[source[1]].isHere(nick):
+ jid = get_source(source[1], nick)
+ elif Chats[source[1]].isHere(Nick):
+ jid = get_source(source[1], Nick)
+ elif nick.count(chr(46)) and not Nick.count(chr(32)):
+ jid = Nick
else:
- text = "%s/%s" % (get_self_nick(source[1]), source[2])
- Chats[source[1]].none(jid, text, (ltype, source))
+ jid = None
+ if jid:
+ if body and body[0]:
+ text = "%s: %s" % (source[2], (body.pop(0)).strip())
+ else:
+ text = "%s/%s" % (get_self_nick(source[1]), source[2])
+ Chats[source[1]].none(jid, text, (ltype, source))
+ else:
+ answer = AnsBase[7]
else:
- answer = AnsBase[7]
+ answer = self.AnsBase[0]
else:
- answer = MucAnsBase[0]
+ answer = self.AnsBase[1]
else:
- answer = MucAnsBase[1]
+ answer = AnsBase[1]
else:
- answer = AnsBase[1]
- else:
- answer = AnsBase[0]
- if locals().has_key(Types[12]):
- Answer(answer, ltype, source, disp)
+ answer = AnsBase[0]
+ if locals().has_key(Types[12]):
+ Answer(answer, ltype, source, disp)
-def command_member(ltype, source, body, disp):
- if Chats.has_key(source[1]):
- if body:
- if Chats[source[1]].isModer:
- Lock, BsNick = False, get_self_nick(source[1])
- if getattr(Chats[source[1]].get_user(BsNick), "role", (AflRoles[5],))[0] == AflRoles[5]:
- if not enough_access(source[1], source[2], 6):
- Lock = True
- if not Lock:
- body = body.split(chr(47), 1)
- nick = body.pop(0)
- Nick = nick.strip()
- if Chats[source[1]].isHere(nick):
- jid = get_source(source[1], nick)
- elif Chats[source[1]].isHere(Nick):
- jid = get_source(source[1], Nick)
- elif nick.count(chr(46)) and not Nick.count(chr(32)):
- jid = Nick
- else:
- jid = None
- if jid:
- if body and body[0]:
- text = "%s: %s" % (source[2], (body.pop(0)).strip())
+ def command_member(self, ltype, source, body, disp):
+ if Chats.has_key(source[1]):
+ if body:
+ if Chats[source[1]].isModer:
+ Lock, BsNick = False, get_self_nick(source[1])
+ if getattr(Chats[source[1]].get_user(BsNick), "role", (AflRoles[5],))[0] == AflRoles[5]:
+ if not enough_access(source[1], source[2], 6):
+ Lock = True
+ if not Lock:
+ body = body.split(chr(47), 1)
+ nick = body.pop(0)
+ Nick = nick.strip()
+ if Chats[source[1]].isHere(nick):
+ jid = get_source(source[1], nick)
+ elif Chats[source[1]].isHere(Nick):
+ jid = get_source(source[1], Nick)
+ elif nick.count(chr(46)) and not Nick.count(chr(32)):
+ jid = Nick
+ else:
+ jid = None
+ if jid:
+ if body and body[0]:
+ text = "%s: %s" % (source[2], (body.pop(0)).strip())
+ else:
+ text = "%s/%s" % (get_self_nick(source[1]), source[2])
+ Chats[source[1]].member(jid, text, (ltype, source))
else:
- text = "%s/%s" % (get_self_nick(source[1]), source[2])
- Chats[source[1]].member(jid, text, (ltype, source))
+ answer = AnsBase[7]
else:
- answer = AnsBase[7]
+ answer = self.AnsBase[0]
else:
- answer = MucAnsBase[0]
+ answer = self.AnsBase[1]
else:
- answer = MucAnsBase[1]
+ answer = AnsBase[1]
else:
- answer = AnsBase[1]
- else:
- answer = AnsBase[0]
- if locals().has_key(Types[12]):
- Answer(answer, ltype, source, disp)
+ answer = AnsBase[0]
+ if locals().has_key(Types[12]):
+ Answer(answer, ltype, source, disp)
-def command_admin(ltype, source, body, disp):
- if Chats.has_key(source[1]):
- if body:
- if Chats[source[1]].isModer:
- Lock, BsNick = False, get_self_nick(source[1])
- if getattr(Chats[source[1]].get_user(BsNick), "role", (AflRoles[5],))[0] == AflRoles[5]:
- if not enough_access(source[1], source[2], 6):
- Lock = True
- if not Lock:
- body = body.split(chr(47), 1)
- nick = body.pop(0)
- Nick = nick.strip()
- if Chats[source[1]].isHere(nick):
- jid = get_source(source[1], nick)
- elif Chats[source[1]].isHere(Nick):
- jid = get_source(source[1], Nick)
- elif nick.count(chr(46)) and not Nick.count(chr(32)):
- jid = Nick
- else:
- jid = None
- if jid:
- if body and body[0]:
- text = "%s: %s" % (source[2], (body.pop(0)).strip())
+ def command_admin(self, ltype, source, body, disp):
+ if Chats.has_key(source[1]):
+ if body:
+ if Chats[source[1]].isModer:
+ Lock, BsNick = False, get_self_nick(source[1])
+ if getattr(Chats[source[1]].get_user(BsNick), "role", (AflRoles[5],))[0] == AflRoles[5]:
+ if not enough_access(source[1], source[2], 6):
+ Lock = True
+ if not Lock:
+ body = body.split(chr(47), 1)
+ nick = body.pop(0)
+ Nick = nick.strip()
+ if Chats[source[1]].isHere(nick):
+ jid = get_source(source[1], nick)
+ elif Chats[source[1]].isHere(Nick):
+ jid = get_source(source[1], Nick)
+ elif nick.count(chr(46)) and not Nick.count(chr(32)):
+ jid = Nick
+ else:
+ jid = None
+ if jid:
+ if body and body[0]:
+ text = "%s: %s" % (source[2], (body.pop(0)).strip())
+ else:
+ text = "%s/%s" % (get_self_nick(source[1]), source[2])
+ Chats[source[1]].admin(jid, text, (ltype, source))
else:
- text = "%s/%s" % (get_self_nick(source[1]), source[2])
- Chats[source[1]].admin(jid, text, (ltype, source))
+ answer = AnsBase[7]
else:
- answer = AnsBase[7]
+ answer = self.AnsBase[0]
else:
- answer = MucAnsBase[0]
+ answer = self.AnsBase[1]
else:
- answer = MucAnsBase[1]
+ answer = AnsBase[1]
else:
- answer = AnsBase[1]
- else:
- answer = AnsBase[0]
- if locals().has_key(Types[12]):
- Answer(answer, ltype, source, disp)
+ answer = AnsBase[0]
+ if locals().has_key(Types[12]):
+ Answer(answer, ltype, source, disp)
-def command_owner(ltype, source, body, disp):
- if Chats.has_key(source[1]):
- if body:
- if Chats[source[1]].isModer:
- Lock, BsNick = False, get_self_nick(source[1])
- if getattr(Chats[source[1]].get_user(BsNick), "role", (AflRoles[5],))[0] == AflRoles[5]:
- if not enough_access(source[1], source[2], 6):
- Lock = True
- if not Lock:
- body = body.split(chr(47), 1)
- nick = body.pop(0)
- Nick = nick.strip()
- if Chats[source[1]].isHere(nick):
- jid = get_source(source[1], nick)
- elif Chats[source[1]].isHere(Nick):
- jid = get_source(source[1], Nick)
- elif nick.count(chr(46)) and not Nick.count(chr(32)):
- jid = Nick
- else:
- jid = None
- if jid:
- if body and body[0]:
- text = "%s: %s" % (source[2], (body.pop(0)).strip())
+ def command_owner(self, ltype, source, body, disp):
+ if Chats.has_key(source[1]):
+ if body:
+ if Chats[source[1]].isModer:
+ Lock, BsNick = False, get_self_nick(source[1])
+ if getattr(Chats[source[1]].get_user(BsNick), "role", (AflRoles[5],))[0] == AflRoles[5]:
+ if not enough_access(source[1], source[2], 6):
+ Lock = True
+ if not Lock:
+ body = body.split(chr(47), 1)
+ nick = body.pop(0)
+ Nick = nick.strip()
+ if Chats[source[1]].isHere(nick):
+ jid = get_source(source[1], nick)
+ elif Chats[source[1]].isHere(Nick):
+ jid = get_source(source[1], Nick)
+ elif nick.count(chr(46)) and not Nick.count(chr(32)):
+ jid = Nick
+ else:
+ jid = None
+ if jid:
+ if body and body[0]:
+ text = "%s: %s" % (source[2], (body.pop(0)).strip())
+ else:
+ text = "%s/%s" % (get_self_nick(source[1]), source[2])
+ Chats[source[1]].owner(jid, text, (ltype, source))
else:
- text = "%s/%s" % (get_self_nick(source[1]), source[2])
- Chats[source[1]].owner(jid, text, (ltype, source))
+ answer = AnsBase[7]
else:
- answer = AnsBase[7]
+ answer = self.AnsBase[0]
else:
- answer = MucAnsBase[0]
+ answer = self.AnsBase[1]
else:
- answer = MucAnsBase[1]
+ answer = AnsBase[1]
else:
- answer = AnsBase[1]
- else:
- answer = AnsBase[0]
- if locals().has_key(Types[12]):
- Answer(answer, ltype, source, disp)
+ answer = AnsBase[0]
+ if locals().has_key(Types[12]):
+ Answer(answer, ltype, source, disp)
-def command_kick(ltype, source, body, disp):
- if Chats.has_key(source[1]):
- if body:
- if Chats[source[1]].isModer:
- Lock, BsNick = False, get_self_nick(source[1])
- if getattr(Chats[source[1]].get_user(BsNick), "role", (AflRoles[5],))[0] == AflRoles[5]:
- if not enough_access(source[1], source[2], 6):
- Lock = True
- if not Lock:
- body = body.split(chr(47), 1)
- nick = body.pop(0)
- Nick = nick.strip()
- if Chats[source[1]].isHere(nick):
- pass
- elif Chats[source[1]].isHere(Nick):
- nick = Nick
- else:
- nick = None
- jid = get_source(source[1], nick)
- if nick and jid and Galist.get(jid, 0) < 7 and jid != get_disp(disp):
- if body and body[0]:
- text = "%s: %s" % (source[2], (body.pop(0)).strip())
+ def command_kick(self, ltype, source, body, disp):
+ if Chats.has_key(source[1]):
+ if body:
+ if Chats[source[1]].isModer:
+ Lock, BsNick = False, get_self_nick(source[1])
+ if getattr(Chats[source[1]].get_user(BsNick), "role", (AflRoles[5],))[0] == AflRoles[5]:
+ if not enough_access(source[1], source[2], 6):
+ Lock = True
+ if not Lock:
+ body = body.split(chr(47), 1)
+ nick = body.pop(0)
+ Nick = nick.strip()
+ if Chats[source[1]].isHere(nick):
+ pass
+ elif Chats[source[1]].isHere(Nick):
+ nick = Nick
else:
- text = "%s/%s" % (get_self_nick(source[1]), source[2])
- Chats[source[1]].kick(nick, text, (ltype, source))
+ nick = None
+ jid = get_source(source[1], nick)
+ if nick and jid and Galist.get(jid, 0) < 7 and jid != get_disp(disp):
+ if body and body[0]:
+ text = "%s: %s" % (source[2], (body.pop(0)).strip())
+ else:
+ text = "%s/%s" % (get_self_nick(source[1]), source[2])
+ Chats[source[1]].kick(nick, text, (ltype, source))
+ else:
+ answer = AnsBase[7]
else:
- answer = AnsBase[7]
+ answer = self.AnsBase[0]
else:
- answer = MucAnsBase[0]
+ answer = self.AnsBase[1]
else:
- answer = MucAnsBase[1]
+ answer = AnsBase[1]
else:
- answer = AnsBase[1]
- else:
- answer = AnsBase[0]
- if locals().has_key(Types[12]):
- Answer(answer, ltype, source, disp)
+ answer = AnsBase[0]
+ if locals().has_key(Types[12]):
+ Answer(answer, ltype, source, disp)
-def command_visitor(ltype, source, body, disp):
- if Chats.has_key(source[1]):
- if body:
- if Chats[source[1]].isModer:
- Lock, BsNick = False, get_self_nick(source[1])
- if getattr(Chats[source[1]].get_user(BsNick), "role", (AflRoles[5],))[0] == AflRoles[5]:
- if not enough_access(source[1], source[2], 6):
- Lock = True
- if not Lock:
- body = body.split(chr(47), 1)
- nick = body.pop(0)
- Nick = nick.strip()
- if Chats[source[1]].isHere(nick):
- pass
- elif Chats[source[1]].isHere(Nick):
- nick = Nick
- else:
- nick = None
- jid = get_source(source[1], nick)
- if nick and jid and Galist.get(jid, 0) < 7:
- if body and body[0]:
- text = "%s: %s" % (source[2], (body.pop(0)).strip())
+ def command_visitor(self, ltype, source, body, disp):
+ if Chats.has_key(source[1]):
+ if body:
+ if Chats[source[1]].isModer:
+ Lock, BsNick = False, get_self_nick(source[1])
+ if getattr(Chats[source[1]].get_user(BsNick), "role", (AflRoles[5],))[0] == AflRoles[5]:
+ if not enough_access(source[1], source[2], 6):
+ Lock = True
+ if not Lock:
+ body = body.split(chr(47), 1)
+ nick = body.pop(0)
+ Nick = nick.strip()
+ if Chats[source[1]].isHere(nick):
+ pass
+ elif Chats[source[1]].isHere(Nick):
+ nick = Nick
+ else:
+ nick = None
+ jid = get_source(source[1], nick)
+ if nick and jid and Galist.get(jid, 0) < 7:
+ if body and body[0]:
+ text = "%s: %s" % (source[2], (body.pop(0)).strip())
+ else:
+ text = "%s/%s" % (get_self_nick(source[1]), source[2])
+ Chats[source[1]].visitor(nick, text, (ltype, source))
else:
- text = "%s/%s" % (get_self_nick(source[1]), source[2])
- Chats[source[1]].visitor(nick, text, (ltype, source))
+ answer = AnsBase[7]
else:
- answer = AnsBase[7]
+ answer = self.AnsBase[0]
else:
- answer = MucAnsBase[0]
+ answer = self.AnsBase[1]
else:
- answer = MucAnsBase[1]
+ answer = AnsBase[1]
else:
- answer = AnsBase[1]
- else:
- answer = AnsBase[0]
- if locals().has_key(Types[12]):
- Answer(answer, ltype, source, disp)
+ answer = AnsBase[0]
+ if locals().has_key(Types[12]):
+ Answer(answer, ltype, source, disp)
-def command_participant(ltype, source, body, disp):
- if Chats.has_key(source[1]):
- if body:
- if Chats[source[1]].isModer:
- Lock, BsNick = False, get_self_nick(source[1])
- if getattr(Chats[source[1]].get_user(BsNick), "role", (AflRoles[5],))[0] == AflRoles[5]:
- if not enough_access(source[1], source[2], 6):
- Lock = True
- if not Lock:
- body = body.split(chr(47), 1)
- nick = body.pop(0)
- Nick = nick.strip()
- if Chats[source[1]].isHere(nick):
- pass
- elif Chats[source[1]].isHere(Nick):
- nick = Nick
- else:
- nick = None
- if nick:
- if body and body[0]:
- text = "%s: %s" % (source[2], (body.pop(0)).strip())
+ def command_participant(self, ltype, source, body, disp):
+ if Chats.has_key(source[1]):
+ if body:
+ if Chats[source[1]].isModer:
+ Lock, BsNick = False, get_self_nick(source[1])
+ if getattr(Chats[source[1]].get_user(BsNick), "role", (AflRoles[5],))[0] == AflRoles[5]:
+ if not enough_access(source[1], source[2], 6):
+ Lock = True
+ if not Lock:
+ body = body.split(chr(47), 1)
+ nick = body.pop(0)
+ Nick = nick.strip()
+ if Chats[source[1]].isHere(nick):
+ pass
+ elif Chats[source[1]].isHere(Nick):
+ nick = Nick
+ else:
+ nick = None
+ if nick:
+ if body and body[0]:
+ text = "%s: %s" % (source[2], (body.pop(0)).strip())
+ else:
+ text = "%s/%s" % (get_self_nick(source[1]), source[2])
+ Chats[source[1]].participant(nick, text, (ltype, source))
else:
- text = "%s/%s" % (get_self_nick(source[1]), source[2])
- Chats[source[1]].participant(nick, text, (ltype, source))
+ answer = AnsBase[7]
else:
- answer = AnsBase[7]
+ answer = self.AnsBase[0]
else:
- answer = MucAnsBase[0]
+ answer = self.AnsBase[1]
else:
- answer = MucAnsBase[1]
+ answer = AnsBase[1]
else:
- answer = AnsBase[1]
- else:
- answer = AnsBase[0]
- if locals().has_key(Types[12]):
- Answer(answer, ltype, source, disp)
+ answer = AnsBase[0]
+ if locals().has_key(Types[12]):
+ Answer(answer, ltype, source, disp)
-def command_moder(ltype, source, body, disp):
- if Chats.has_key(source[1]):
- if body:
- if Chats[source[1]].isModer:
- Lock, BsNick = False, get_self_nick(source[1])
- if getattr(Chats[source[1]].get_user(BsNick), "role", (AflRoles[5],))[0] == AflRoles[5]:
- if not enough_access(source[1], source[2], 6):
- Lock = True
- if not Lock:
- body = body.split(chr(47), 1)
- nick = body.pop(0)
- Nick = nick.strip()
- if Chats[source[1]].isHere(nick):
- pass
- elif Chats[source[1]].isHere(Nick):
- nick = Nick
- else:
- nick = None
- if nick:
- if body and body[0]:
- text = "%s: %s" % (source[2], (body.pop(0)).strip())
+ def command_moder(self, ltype, source, body, disp):
+ if Chats.has_key(source[1]):
+ if body:
+ if Chats[source[1]].isModer:
+ Lock, BsNick = False, get_self_nick(source[1])
+ if getattr(Chats[source[1]].get_user(BsNick), "role", (AflRoles[5],))[0] == AflRoles[5]:
+ if not enough_access(source[1], source[2], 6):
+ Lock = True
+ if not Lock:
+ body = body.split(chr(47), 1)
+ nick = body.pop(0)
+ Nick = nick.strip()
+ if Chats[source[1]].isHere(nick):
+ pass
+ elif Chats[source[1]].isHere(Nick):
+ nick = Nick
+ else:
+ nick = None
+ if nick:
+ if body and body[0]:
+ text = "%s: %s" % (source[2], (body.pop(0)).strip())
+ else:
+ text = "%s/%s" % (get_self_nick(source[1]), source[2])
+ Chats[source[1]].moder(nick, text, (ltype, source))
else:
- text = "%s/%s" % (get_self_nick(source[1]), source[2])
- Chats[source[1]].moder(nick, text, (ltype, source))
+ answer = AnsBase[7]
else:
- answer = AnsBase[7]
+ answer = self.AnsBase[0]
else:
- answer = MucAnsBase[0]
+ answer = self.AnsBase[1]
else:
- answer = MucAnsBase[1]
+ answer = AnsBase[1]
else:
- answer = AnsBase[1]
- else:
- answer = AnsBase[0]
- if locals().has_key(Types[12]):
- Answer(answer, ltype, source, disp)
+ answer = AnsBase[0]
+ if locals().has_key(Types[12]):
+ Answer(answer, ltype, source, disp)
-def command_fullban(ltype, source, body, disp):
- if Chats.has_key(source[1]):
- if body:
- body = body.split(chr(47), 1)
- nick = body.pop(0)
- Nick = nick.strip()
- if Chats[source[1]].isHere(nick):
- jid = get_source(source[1], nick)
- elif Chats[source[1]].isHere(Nick):
- jid = get_source(source[1], Nick)
- elif nick.count(chr(46)) and not Nick.count(chr(32)):
- jid = Nick
- else:
- jid = None
- if jid and Galist.get(jid, 0) < 7 and not Clients.has_key(jid):
- if body and body[0]:
- text = "%s: %s" % (source[2], (body.pop(0)).strip())
+ def command_fullban(self, ltype, source, body, disp):
+ if Chats.has_key(source[1]):
+ if body:
+ body = body.split(chr(47), 1)
+ nick = body.pop(0)
+ Nick = nick.strip()
+ if Chats[source[1]].isHere(nick):
+ jid = get_source(source[1], nick)
+ elif Chats[source[1]].isHere(Nick):
+ jid = get_source(source[1], Nick)
+ elif nick.count(chr(46)) and not Nick.count(chr(32)):
+ jid = Nick
else:
- text = "%s/%s" % (get_self_nick(source[1]), source[2])
- for conf in Chats.keys():
- Chats[conf].outcast(jid, text)
- answer = AnsBase[4]
+ jid = None
+ if jid and Galist.get(jid, 0) < 7 and not Clients.has_key(jid):
+ if body and body[0]:
+ text = "%s: %s" % (source[2], (body.pop(0)).strip())
+ else:
+ text = "%s/%s" % (get_self_nick(source[1]), source[2])
+ for conf in Chats.keys():
+ Chats[conf].outcast(jid, text)
+ answer = AnsBase[4]
+ else:
+ answer = AnsBase[7]
else:
- answer = AnsBase[7]
+ answer = AnsBase[1]
else:
- answer = AnsBase[1]
- else:
- answer = AnsBase[0]
- Answer(answer, ltype, source, disp)
+ answer = AnsBase[0]
+ Answer(answer, ltype, source, disp)
-def command_fullunban(ltype, source, body, disp):
- if Chats.has_key(source[1]):
- if body:
- body = body.split(chr(47), 1)
- nick = body.pop(0)
- Nick = nick.strip()
- if Chats[source[1]].isHere(nick):
- jid = get_source(source[1], nick)
- elif Chats[source[1]].isHere(Nick):
- jid = get_source(source[1], Nick)
- elif nick.count(chr(46)) and not Nick.count(chr(32)):
- jid = Nick
- else:
- jid = None
- if jid:
- for conf in Chats.keys():
- Chats[conf].none(jid)
- answer = AnsBase[4]
+ def command_fullunban(self, ltype, source, body, disp):
+ if Chats.has_key(source[1]):
+ if body:
+ body = body.split(chr(47), 1)
+ nick = body.pop(0)
+ Nick = nick.strip()
+ if Chats[source[1]].isHere(nick):
+ jid = get_source(source[1], nick)
+ elif Chats[source[1]].isHere(Nick):
+ jid = get_source(source[1], Nick)
+ elif nick.count(chr(46)) and not Nick.count(chr(32)):
+ jid = Nick
+ else:
+ jid = None
+ if jid:
+ for conf in Chats.keys():
+ Chats[conf].none(jid)
+ answer = AnsBase[4]
+ else:
+ answer = AnsBase[7]
else:
- answer = AnsBase[7]
+ answer = AnsBase[1]
else:
- answer = AnsBase[1]
- else:
- answer = AnsBase[0]
- Answer(answer, ltype, source, disp)
-
-expansions[exp_name].funcs_add([command_ban, command_none, command_member, command_admin, command_owner, command_kick, command_visitor, command_participant, command_moder, command_fullban, command_fullunban])
-expansions[exp_name].ls.extend(["MucAnsBase"])
+ answer = AnsBase[0]
+ Answer(answer, ltype, source, disp)
-command_handler(command_subject, {"RU": "топик", "EN": "subject"}, 3, exp_name)
-command_handler(command_ban, {"RU": "бан", "EN": "ban"}, 5, exp_name)
-command_handler(command_none, {"RU": "никто", "EN": "none"}, 5, exp_name)
-command_handler(command_member, {"RU": "мембер", "EN": "member"}, 5, exp_name)
-command_handler(command_admin, {"RU": "админ", "EN": "admin"}, 6, exp_name)
-command_handler(command_owner, {"RU": "овнер", "EN": "owner"}, 6, exp_name)
-command_handler(command_kick, {"RU": "кик", "EN": "kick"}, 3, exp_name)
-command_handler(command_visitor, {"RU": "визитор", "EN": "visitor"}, 3, exp_name)
-command_handler(command_participant, {"RU": "участник", "EN": "participant"}, 3, exp_name)
-command_handler(command_moder, {"RU": "модер", "EN": "moder"}, 5, exp_name)
-command_handler(command_fullban, {"RU": "фулбан", "EN": "fullban"}, 7, exp_name)
-command_handler(command_fullunban, {"RU": "фулунбан", "EN": "fullunban"}, 7, exp_name)
+ commands = (
+ (command_subject, "subject", 3,),
+ (command_ban, "ban", 5,),
+ (command_none, "none", 5,),
+ (command_member, "member", 5,),
+ (command_admin, "admin", 6,),
+ (command_owner, "owner", 6,),
+ (command_kick, "kick", 3,),
+ (command_visitor, "visitor", 3,),
+ (command_participant, "participant", 3,),
+ (command_moder, "moder", 5,),
+ (command_fullban, "fullban", 7,),
+ (command_fullunban, "fullunban", 7,)
+ )
diff --git a/expansions/muc/fullban.name b/expansions/muc/fullban.name
new file mode 100644
index 0000000..b326776
--- /dev/null
+++ b/expansions/muc/fullban.name
@@ -0,0 +1,4 @@
+{
+ "RU": "фулбан",
+ "UA": "фулбан"
+} \ No newline at end of file
diff --git a/expansions/muc/fullunban.name b/expansions/muc/fullunban.name
new file mode 100644
index 0000000..6b00d2b
--- /dev/null
+++ b/expansions/muc/fullunban.name
@@ -0,0 +1,4 @@
+{
+ "RU": "фулунбан",
+ "UA": "фулунбан"
+} \ No newline at end of file
diff --git a/expansions/muc/insc.py b/expansions/muc/insc.py
index 1cbb40a..4b44ae1 100644
--- a/expansions/muc/insc.py
+++ b/expansions/muc/insc.py
@@ -1,12 +1,12 @@
# coding: utf-8
if DefLANG in ("RU", "UA"):
- MucAnsBase = tuple([line.decode("utf-8") for line in (
+ AnsBase_temp = tuple([line.decode("utf-8") for line in (
"Протоколы безопасности конференции запрещают мне выполнить твою команду.", # 0
"Дай админа/модера, потом поговорим." # 1
)])
else:
- MucAnsBase = (
+ AnsBase_temp = (
"Security protocols are prohibits this action.", # 0
"I must to be admin/moder to do this." # 1
) \ No newline at end of file
diff --git a/expansions/muc/kick.name b/expansions/muc/kick.name
new file mode 100644
index 0000000..2b5ac7e
--- /dev/null
+++ b/expansions/muc/kick.name
@@ -0,0 +1,4 @@
+{
+ "RU": "кик",
+ "UA": "кик"
+} \ No newline at end of file
diff --git a/expansions/muc/member.name b/expansions/muc/member.name
new file mode 100644
index 0000000..7cd3d94
--- /dev/null
+++ b/expansions/muc/member.name
@@ -0,0 +1,4 @@
+{
+ "RU": "мембер",
+ "UA": "мембер"
+} \ No newline at end of file
diff --git a/expansions/muc/moder.name b/expansions/muc/moder.name
new file mode 100644
index 0000000..d1689b6
--- /dev/null
+++ b/expansions/muc/moder.name
@@ -0,0 +1,4 @@
+{
+ "RU": "модер",
+ "UA": "модер"
+} \ No newline at end of file
diff --git a/expansions/muc/none.name b/expansions/muc/none.name
new file mode 100644
index 0000000..d0d27a8
--- /dev/null
+++ b/expansions/muc/none.name
@@ -0,0 +1,4 @@
+{
+ "RU": "никто",
+ "UA": "никто"
+} \ No newline at end of file
diff --git a/expansions/muc/owner.name b/expansions/muc/owner.name
new file mode 100644
index 0000000..b2bcf0e
--- /dev/null
+++ b/expansions/muc/owner.name
@@ -0,0 +1,4 @@
+{
+ "RU": "овнер",
+ "UA": "овнер"
+} \ No newline at end of file
diff --git a/expansions/muc/participant.name b/expansions/muc/participant.name
new file mode 100644
index 0000000..1be575d
--- /dev/null
+++ b/expansions/muc/participant.name
@@ -0,0 +1,4 @@
+{
+ "RU": "участник",
+ "UA": "участник"
+} \ No newline at end of file
diff --git a/expansions/muc/subject.name b/expansions/muc/subject.name
new file mode 100644
index 0000000..ea798ed
--- /dev/null
+++ b/expansions/muc/subject.name
@@ -0,0 +1,4 @@
+{
+ "RU": "топик",
+ "UA": "топик"
+} \ No newline at end of file
diff --git a/expansions/muc/visitor.name b/expansions/muc/visitor.name
new file mode 100644
index 0000000..55fe6f0
--- /dev/null
+++ b/expansions/muc/visitor.name
@@ -0,0 +1,4 @@
+{
+ "RU": "визитор",
+ "UA": "визитор"
+} \ No newline at end of file
diff --git a/expansions/new_year/code.py b/expansions/new_year/code.py
index d35ecf9..424c964 100644
--- a/expansions/new_year/code.py
+++ b/expansions/new_year/code.py
@@ -1,33 +1,36 @@
# coding: utf-8
# BlackSmith mark.2
-exp_name = "new_year" # /code.py v.x3
-# Id: 02~2a
-# Code © (2010-2011) by WitcherGeralt [WitcherGeralt@rocketmail.com]
+exp_name = "new_year" # /code.py v.x4
+# Id: 02~3b
+# Code © (2010-2011) by WitcherGeralt [alkorgun@gmail.com]
expansion_register(exp_name)
-def command_new_year(ltype, source, body, disp):
- list = ["Until the New Year (UTC) left:"]
- Time = time.gmtime()
- dr = lambda Numb: (Numb, ("s" if Numb >= 2 else ""))
- t0 = (365 if (Time.tm_year%4) else 366)
- t1 = (t0 - Time.tm_yday)
- t2 = (23 - Time.tm_hour)
- t3 = (59 - Time.tm_min)
- t4 = (59 - Time.tm_sec)
- if t1:
- list.append("%d Day%s" % dr(t1))
- if t2:
- list.append("%d Hour%s" % dr(t2))
- if t3:
- list.append("%d Minute%s" % dr(t3))
- if t4:
- list.append("%d Second%s" % dr(t4))
- if len(list) == 1:
- list = ["Happy New Year!"]
- Answer(str.join(chr(32), list), ltype, source, disp)
+class expansion_temp(expansion):
-expansions[exp_name].funcs_add([command_new_year])
+ def __init__(self, name):
+ expansion.__init__(self, name)
-command_handler(command_new_year, {"RU": "нг", "EN": "new_year"}, 1, exp_name)
+ def command_new_year(self, ltype, source, body, disp):
+ list = ["Until the New Year (UTC) left:"]
+ Time = time.gmtime()
+ dr = lambda Numb: (Numb, ("s" if Numb >= 2 else ""))
+ t0 = (365 if (Time.tm_year%4) else 366)
+ t1 = (t0 - Time.tm_yday)
+ t2 = (23 - Time.tm_hour)
+ t3 = (59 - Time.tm_min)
+ t4 = (59 - Time.tm_sec)
+ if t1:
+ list.append("%d Day%s" % dr(t1))
+ if t2:
+ list.append("%d Hour%s" % dr(t2))
+ if t3:
+ list.append("%d Minute%s" % dr(t3))
+ if t4:
+ list.append("%d Second%s" % dr(t4))
+ if len(list) == 1:
+ list = ["Happy New Year!"]
+ Answer(str.join(chr(32), list), ltype, source, disp)
+
+ commands = ((command_new_year, "new_year", 1,),)
diff --git a/expansions/new_year/new_year.name b/expansions/new_year/new_year.name
new file mode 100644
index 0000000..3fbf35d
--- /dev/null
+++ b/expansions/new_year/new_year.name
@@ -0,0 +1,4 @@
+{
+ "RU": "нг",
+ "UA": "нг"
+} \ No newline at end of file
diff --git a/expansions/note/code.py b/expansions/note/code.py
index 476f771..f3cb661 100644
--- a/expansions/note/code.py
+++ b/expansions/note/code.py
@@ -1,125 +1,125 @@
# coding: utf-8
# BlackSmith mark.2
-exp_name = "note" # /code.py v.x4
-# Id: 22~3a
-# Code © (2010-2011) by WitcherGeralt [WitcherGeralt@rocketmail.com]
+exp_name = "note" # /code.py v.x5
+# Id: 22~4b
+# Code © (2010-2011) by WitcherGeralt [alkorgun@gmail.com]
expansion_register(exp_name)
-NoteFile = dynamic % ("notepad.db")
+class expansion_temp(expansion):
-def command_note(ltype, source, body, disp):
- source_ = get_source(source[1], source[2])
- if source_:
- if body:
- list_ = body.split()
- x = (list_.pop(0)).lower()
- if x in ("clear", "чисть".decode("utf-8")):
- with database(NoteFile) as db:
- db("select * from note where jid=?", (source_,))
- db_desc = db.fetchone()
- if db_desc:
- db("delete from note where jid=?", (source_,))
- db.commit()
- answer = AnsBase[4]
- else:
- answer = NoteAnsBase[0]
- elif list_:
- if x == "+":
- body = body[2:].lstrip()
- if len(body) <= 512:
- date = strTime(local = False)
- with database(NoteFile) as db:
- db("select * from note where jid=?", (source_,))
- db_desc = db.fetchone()
- if db_desc:
- Numb, Added = itypes.Number(), False
- for line in db_desc:
- if not line:
- db("update note set line_%s=? where jid=?" % (Numb._str()), ("[%s] %s" % (date, body), source_))
- db.commit()
- Added = True
- break
- Numb.plus()
- if Added:
- answer = NoteAnsBase[7] % (Numb._str())
- else:
- answer = NoteAnsBase[3]
- else:
- db("insert into note values (%s)" % (",".join(["?" for x in xrange(17)])), (source_, "[%s] %s" % (date, body), "", "", "", "", "", "", "", "", "", "", "", "", "", "", ""))
- db.commit()
- answer = AnsBase[4]
- else:
- answer = NoteAnsBase[1]
- elif x in ("-", "*"):
- Numb = list_.pop(0)
- if isNumber(Numb):
- Numb = int(Numb)
- if Numb in xrange(1, 17):
- with database(NoteFile) as db:
+ def __init__(self, name):
+ expansion.__init__(self, name)
+
+ NoteFile = dynamic % ("notepad.db")
+
+ def command_note(self, ltype, source, body, disp):
+ source_ = get_source(source[1], source[2])
+ if source_:
+ if body:
+ list_ = body.split()
+ x = (list_.pop(0)).lower()
+ if x in ("clear", "чисть".decode("utf-8")):
+ with database(self.NoteFile) as db:
+ db("select * from note where jid=?", (source_,))
+ db_desc = db.fetchone()
+ if db_desc:
+ db("delete from note where jid=?", (source_,))
+ db.commit()
+ answer = AnsBase[4]
+ else:
+ answer = self.AnsBase[0]
+ elif list_:
+ if x == "+":
+ body = body[2:].lstrip()
+ if len(body) <= 512:
+ date = strTime(local = False)
+ with database(self.NoteFile) as db:
db("select * from note where jid=?", (source_,))
db_desc = db.fetchone()
if db_desc:
- if x == "*":
- if db_desc[Numb]:
- answer = db_desc[Numb]
- else:
- answer = NoteAnsBase[5]
- elif not db_desc[Numb]:
- answer = NoteAnsBase[8]
+ Numb = itypes.Number()
+ for line in db_desc:
+ if not line:
+ db("update note set line_%s=? where jid=?" % (Numb._str()), ("[%s] %s" % (date, body), source_))
+ db.commit()
+ answer = self.AnsBase[7] % (Numb._str())
+ break
+ Numb.plus()
else:
- db("update note set line_%d=? where jid=?" % (Numb), ("", source_))
- db.commit()
- answer = AnsBase[4]
+ answer = self.AnsBase[3]
else:
- answer = NoteAnsBase[0]
+ db("insert into note values (%s)" % (",".join(["?" for x in xrange(17)])), (source_, "[%s] %s" % (date, body), "", "", "", "", "", "", "", "", "", "", "", "", "", "", ""))
+ db.commit()
+ answer = AnsBase[4]
else:
- answer = NoteAnsBase[4]
+ answer = self.AnsBase[1]
+ elif x in ("-", "*"):
+ Numb = list_.pop(0)
+ if isNumber(Numb):
+ Numb = int(Numb)
+ if Numb in xrange(1, 17):
+ with database(self.NoteFile) as db:
+ db("select * from note where jid=?", (source_,))
+ db_desc = db.fetchone()
+ if db_desc:
+ if x == "*":
+ if db_desc[Numb]:
+ answer = db_desc[Numb]
+ else:
+ answer = self.AnsBase[5]
+ elif not db_desc[Numb]:
+ answer = self.AnsBase[8]
+ else:
+ db("update note set line_%d=? where jid=?" % (Numb), ("", source_))
+ db.commit()
+ answer = AnsBase[4]
+ else:
+ answer = self.AnsBase[0]
+ else:
+ answer = self.AnsBase[4]
+ else:
+ answer = AnsBase[30]
else:
- answer = AnsBase[30]
+ answer = AnsBase[2]
else:
answer = AnsBase[2]
else:
- answer = AnsBase[2]
- else:
- with database(NoteFile) as db:
- db("select * from note where jid=?", (source_,))
- db_desc = db.fetchone()
- if db_desc:
- Notes, Numb = str(), itypes.Number()
- for line in db_desc:
- if not Numb._int():
+ with database(self.NoteFile) as db:
+ db("select * from note where jid=?", (source_,))
+ db_desc = db.fetchone()
+ if db_desc:
+ Notes, Numb = str(), itypes.Number()
+ for line in db_desc:
+ if not Numb._int():
+ Numb.plus()
+ continue
+ if line:
+ Notes += "\nLine[%s] %s" % (Numb._str(), line)
Numb.plus()
- continue
- if line:
- Notes += "\nLine[%s] %s" % (Numb._str(), line)
- Numb.plus()
- if Notes:
- Notes = (NoteAnsBase[6] % (Notes))
- if ltype == Types[1]:
- Answer(AnsBase[11], ltype, source, disp)
- Msend(source[0], Notes, disp)
+ if Notes:
+ Notes = (self.AnsBase[6] % (Notes))
+ if ltype == Types[1]:
+ Answer(AnsBase[11], ltype, source, disp)
+ Msend(source[0], Notes, disp)
+ else:
+ db("delete from note where jid=?", (source_,))
+ db.commit()
+ answer = self.AnsBase[0]
else:
- db("delete from note where jid=?", (source_,))
- db.commit()
- answer = NoteAnsBase[0]
- else:
- answer = NoteAnsBase[0]
- else:
- answer = NoteAnsBase[2]
- if locals().has_key(Types[12]):
- Answer(answer, ltype, source, disp)
-
-def init_note_file():
- if not os.path.isfile(NoteFile):
- with database(NoteFile) as db:
- db("create table note (jid text, %s)" % (", ".join(["line_%s text" % (Numb) for Numb in xrange(1, 17)])))
- db.commit()
+ answer = self.AnsBase[0]
+ else:
+ answer = self.AnsBase[2]
+ if locals().has_key(Types[12]):
+ Answer(answer, ltype, source, disp)
-expansions[exp_name].funcs_add([command_note, init_note_file])
-expansions[exp_name].ls.extend(["NoteAnsBase", "NoteFile"])
+ def init_note_file(self):
+ if not os.path.isfile(self.NoteFile):
+ with database(self.NoteFile) as db:
+ db("create table note (jid text, %s)" % (", ".join(["line_%s text" % (Numb) for Numb in xrange(1, 17)])))
+ db.commit()
-command_handler(command_note, {"RU": "блокнот", "EN": "note"}, 2, exp_name)
+ commands = ((command_note, "note", 2,),)
-handler_register(init_note_file, "00si", exp_name)
+ handlers = ((init_note_file, "00si"),)
diff --git a/expansions/note/insc.py b/expansions/note/insc.py
index ce0cc4a..f4976a0 100644
--- a/expansions/note/insc.py
+++ b/expansions/note/insc.py
@@ -1,7 +1,7 @@
# coding: utf-8
if DefLANG in ("RU", "UA"):
- NoteAnsBase = tuple([line.decode("utf-8") for line in (
+ AnsBase_temp = tuple([line.decode("utf-8") for line in (
"У тебя нет записей в блокноте.", # 0
"Длинна одной записи не должна превышать 512 символов.", # 1
"Не получится. Твой jid мне не известен.", # 2
@@ -13,7 +13,7 @@ if DefLANG in ("RU", "UA"):
"Эта строка итак пуста." # 8
)])
else:
- NoteAnsBase = (
+ AnsBase_temp = (
"Your note is empty.", # 0
"Length of one line can't be more than 512 symbols.", # 1
"No chance. I don't know your jid.", # 2
diff --git a/expansions/note/note.name b/expansions/note/note.name
new file mode 100644
index 0000000..b11e2ef
--- /dev/null
+++ b/expansions/note/note.name
@@ -0,0 +1,4 @@
+{
+ "RU": "блокнот",
+ "UA": "блокнот"
+} \ No newline at end of file
diff --git a/expansions/roster_ctrl/code.py b/expansions/roster_ctrl/code.py
index e0b54f8..37f8ae0 100644
--- a/expansions/roster_ctrl/code.py
+++ b/expansions/roster_ctrl/code.py
@@ -1,101 +1,105 @@
# coding: utf-8
# BlackSmith mark.2
-exp_name = "roster_ctrl" # /code.py v.x1
-# Id: 23~1a
-# Code © (2011) by WitcherGeralt [WitcherGeralt@rocketmail.com]
+exp_name = "roster_ctrl" # /code.py v.x2
+# Id: 23~2b
+# Code © (2011) by WitcherGeralt [alkorgun@gmail.com]
expansion_register(exp_name)
-RosterFile = dynamic % ("roster.db")
+class expansion_temp(expansion):
-def command_roster(ltype, source, body, disp):
- cls = sorted(Clients.keys())
- if body:
- list = body.split()
- x = (list.pop(0)).lower()
- if x in cls:
- cl_name = x
- elif isNumber(x):
- Number = (int(x) - 1)
- if Number >= 0 and Number <= len(cls):
- cl_name = cls[Number]
+ def __init__(self, name):
+ expansion.__init__(self, name)
+
+ RosterFile = dynamic % ("roster.db")
+
+ def command_roster(self, ltype, source, body, disp):
+ cls = sorted(Clients.keys())
+ if body:
+ list = body.split()
+ x = (list.pop(0)).lower()
+ if x in cls:
+ cl_name = x
+ elif isNumber(x):
+ Number = (int(x) - 1)
+ if Number >= 0 and Number <= len(cls):
+ cl_name = cls[Number]
+ else:
+ cl_name = False
else:
cl_name = False
- else:
- cl_name = False
- if cl_name:
- if list:
- body = list.pop(0)
+ if cl_name:
if list:
- jid = (list.pop(0)).lower()
- if jid.count("."):
- if body == "+":
- Clients[cl_name].Roster.Authorize(jid)
- Clients[cl_name].Roster.Subscribe(jid)
- if list:
- Tabe = ("admin", "админ".decode("utf-8"))
- Nick = list.pop(0)
- if list and Tabe.count(list[0].lower()):
- Clients[cl_name].Roster.setItem(jid, Nick, ["Admins"])
+ body = list.pop(0)
+ if list:
+ jid = (list.pop(0)).lower()
+ if jid.count("."):
+ if body == "+":
+ Clients[cl_name].Roster.Authorize(jid)
+ Clients[cl_name].Roster.Subscribe(jid)
+ if list:
+ Tabe = ("admin", "админ".decode("utf-8"))
+ Nick = list.pop(0)
+ if list and Tabe.count(list[0].lower()):
+ Clients[cl_name].Roster.setItem(jid, Nick, ["Admins"])
+ else:
+ Clients[cl_name].Roster.setItem(jid, Nick, ["Users"])
else:
- Clients[cl_name].Roster.setItem(jid, Nick, ["Users"])
- else:
- Clients[cl_name].Roster.setItem(jid, (jid.split("@"))[0], ["Users"])
- answer = AnsBase[4]
- elif body == "-":
- if jid in Clients[cl_name].Roster.keys():
- Clients[cl_name].Roster.Unauthorize(jid)
- Clients[cl_name].Roster.Unsubscribe(jid)
- Clients[cl_name].Roster.delItem(jid)
+ Clients[cl_name].Roster.setItem(jid, (jid.split("@"))[0], ["Users"])
answer = AnsBase[4]
+ elif body == "-":
+ if jid in Clients[cl_name].Roster.keys():
+ Clients[cl_name].Roster.Unauthorize(jid)
+ Clients[cl_name].Roster.Unsubscribe(jid)
+ Clients[cl_name].Roster.delItem(jid)
+ answer = AnsBase[4]
+ else:
+ answer = self.AnsBase[0]
else:
- answer = RosterAnsBase[0]
+ answer = AnsBase[2]
else:
answer = AnsBase[2]
else:
answer = AnsBase[2]
else:
- answer = AnsBase[2]
+ Rdsp = getattr(Clients[cl_name], "Roster")
+ if Rdsp:
+ jids = Rdsp.keys()
+ for jx in jids:
+ if jx.count("@conference."):
+ jids.remove(jx)
+ if Rdsp and jids:
+ # Numb = itypes.Number()
+ # answer = "[#] [JID] [Nick] (Group)"
+ # Gpoups = []
+ # for jx in jids:
+ # Name = Rdsp.getName(jx)
+ # Grps = Rdsp.getGroups(jx)
+ # if Grps:
+ #
+ # else:
+ #
+ # if Groups:
+ # answer += "\n%d) %s - %s (%s)" % (Numb.plus(), Name, Groups[0])
+ # else:
+ # answer += "\n%d) %s - %s" % (Numb.plus(), Name)
+ answer = enumerated_list(sorted(jids))
+ else:
+ answer = self.AnsBase[1]
else:
- Rdsp = getattr(Clients[cl_name], "Roster")
- if Rdsp:
- jids = Rdsp.keys()
- for jx in jids:
- if jx.count("@conference."):
- jids.remove(jx)
- if Rdsp and jids:
-# Numb = itypes.Number()
-# answer = "[#] [JID] [Nick] (Group)"
-# Gpoups = []
-# for jx in jids:
-# Name = Rdsp.getName(jx)
-# Grps = Rdsp.getGroups(jx)
-# if Grps:
-#
-# else:
-#
-# if Groups:
-# answer += "\n%d) %s - %s (%s)" % (Numb.plus(), Name, Groups[0])
-# else:
-# answer += "\n%d) %s - %s" % (Numb.plus(), Name)
- answer = enumerated_list(sorted(jids))
- else:
- answer = RosterAnsBase[1]
+ answer = self.AnsBase[2]
else:
- answer = RosterAnsBase[2]
- else:
- answer = enumerated_list(cls)
- Answer(answer, ltype, source, disp)
-
-def init_roster_state():
- if initialize_file(RosterFile, str(True)):
- Roster["on"] = eval(get_file(RosterFile))
+ answer = enumerated_list(cls)
+ Answer(answer, ltype, source, disp)
-expansions[exp_name].funcs_add([command_roster, init_roster_state])
-expansions[exp_name].ls.extend(["RosterAnsBase", "RosterFile"])
+ def init_roster_state(self):
+ if initialize_file(self.RosterFile, str(True)):
+ Roster["on"] = eval(get_file(self.RosterFile))
-command_handler(command_roster, {"RU": "ростер", "EN": "roster"}, 7, exp_name)
-#command_handler(command_roster_state, {"RU": "ростер*", "EN": "roster2"}, 7, exp_name)
+ commands = (
+ (command_roster, "roster", 7,),
+# (command_roster_state, "roster2", 7,)
+ )
-#handler_register(init_roster_state, "00si", exp_name)
+# handlers = ((init_roster_state, "00si"),)
diff --git a/expansions/roster_ctrl/insc.py b/expansions/roster_ctrl/insc.py
index c6ab154..84da513 100644
--- a/expansions/roster_ctrl/insc.py
+++ b/expansions/roster_ctrl/insc.py
@@ -1,13 +1,13 @@
# coding: utf-8
if DefLANG in ("RU", "UA"):
- RosterAnsBase = tuple([line.decode("utf-8") for line in (
+ AnsBase_temp = tuple([line.decode("utf-8") for line in (
"Такого jid'а нет в ростере этого клиента.", # 0
"Ростер пуст.", # 1
"У меня нет такого jid'а." # 2
)])
else:
- RosterAnsBase = (
+ AnsBase_temp = (
"This jid isn't in that client's roster.", # 0
"Roster is empty.", # 1
"It isn't my jid." # 2
diff --git a/expansions/roster_ctrl/roster.name b/expansions/roster_ctrl/roster.name
new file mode 100644
index 0000000..a400156
--- /dev/null
+++ b/expansions/roster_ctrl/roster.name
@@ -0,0 +1,4 @@
+{
+ "RU": "ростер",
+ "UA": "ростер"
+} \ No newline at end of file
diff --git a/expansions/sconf_attrs/botjid.name b/expansions/sconf_attrs/botjid.name
new file mode 100644
index 0000000..fe583b0
--- /dev/null
+++ b/expansions/sconf_attrs/botjid.name
@@ -0,0 +1,4 @@
+{
+ "RU": "ботжид",
+ "UA": "ботжид"
+} \ No newline at end of file
diff --git a/expansions/sconf_attrs/botnick.name b/expansions/sconf_attrs/botnick.name
new file mode 100644
index 0000000..aa0b24e
--- /dev/null
+++ b/expansions/sconf_attrs/botnick.name
@@ -0,0 +1,4 @@
+{
+ "RU": "ботник",
+ "UA": "ботник"
+} \ No newline at end of file
diff --git a/expansions/sconf_attrs/botstatus.name b/expansions/sconf_attrs/botstatus.name
new file mode 100644
index 0000000..419bebb
--- /dev/null
+++ b/expansions/sconf_attrs/botstatus.name
@@ -0,0 +1,4 @@
+{
+ "RU": "ботстатус",
+ "UA": "ботстатус"
+} \ No newline at end of file
diff --git a/expansions/sconf_attrs/code.py b/expansions/sconf_attrs/code.py
index bcdda8b..6dfa322 100644
--- a/expansions/sconf_attrs/code.py
+++ b/expansions/sconf_attrs/code.py
@@ -1,159 +1,163 @@
# coding: utf-8
# BlackSmith mark.2
-exp_name = "sconf_attrs" # /code.py v.x3
-# Id: 07~2a
-# Code © (2010-2011) by WitcherGeralt [WitcherGeralt@rocketmail.com]
+exp_name = "sconf_attrs" # /code.py v.x4
+# Id: 07~3b
+# Code © (2010-2011) by WitcherGeralt [alkorgun@gmail.com]
expansion_register(exp_name)
-def command_redisp(ltype, source, body, disp):
- body = body.split()
- if len(body) >= 1:
- disp_ = (body.pop(0)).lower()
- if Clients.has_key(disp_):
- if body:
- conf = (body.pop(0)).lower()
- else:
- conf = source[1]
- if Chats.has_key(conf):
- if Chats[conf].disp != disp_:
- if online(disp_):
- Chats[conf].leave(CstatAnsBase[3])
- Chats[conf].disp = disp_
- Chats[conf].save()
- time.sleep(0.6)
- Chats[conf].join()
- if conf == source[1]:
- disp = disp_
- answer = AnsBase[4]
+class expansion_temp(expansion):
+
+ def __init__(self, name):
+ expansion.__init__(self, name)
+
+ def command_redisp(self, ltype, source, body, disp):
+ body = body.split()
+ if len(body) >= 1:
+ disp_ = (body.pop(0)).lower()
+ if Clients.has_key(disp_):
+ if body:
+ conf = (body.pop(0)).lower()
+ else:
+ conf = source[1]
+ if Chats.has_key(conf):
+ if Chats[conf].disp != disp_:
+ if online(disp_):
+ Chats[conf].leave(self.AnsBase[3])
+ Chats[conf].disp = disp_
+ Chats[conf].save()
+ time.sleep(0.6)
+ Chats[conf].join()
+ if conf == source[1]:
+ disp = disp_
+ answer = AnsBase[4]
+ else:
+ answer = self.AnsBase[0] % (disp_)
else:
- answer = CstatAnsBase[0] % (disp_)
+ answer = self.AnsBase[1] % (disp_)
else:
- answer = CstatAnsBase[1] % (disp_)
+ answer = AnsBase[8]
else:
- answer = AnsBase[8]
+ answer = self.AnsBase[2] % (disp_)
else:
- answer = CstatAnsBase[2] % (disp_)
- else:
- answer = AnsBase[2]
- Answer(answer, ltype, source, disp)
+ answer = AnsBase[2]
+ Answer(answer, ltype, source, disp)
-def command_botnick(ltype, source, body, disp):
- if Chats.has_key(source[1]):
- if body:
- Nick = sub_desc(body, [(chr(32), chr(95)), chr(10), chr(13), chr(9)]).strip()
- if len(Nick) <= 16:
- Chats[source[1]].nick = xmpp.XMLescape(Nick)
- Chats[source[1]].save()
- Chats[source[1]].join()
- answer = CstatAnsBase[4] % (Nick)
+ def command_botnick(self, ltype, source, body, disp):
+ if Chats.has_key(source[1]):
+ if body:
+ Nick = sub_desc(body, [(chr(32), chr(95)), chr(10), chr(13), chr(9)]).strip()
+ if len(Nick) <= 16:
+ Chats[source[1]].nick = xmpp.XMLescape(Nick)
+ Chats[source[1]].save()
+ Chats[source[1]].join()
+ answer = self.AnsBase[4] % (Nick)
+ else:
+ answer = self.AnsBase[5]
else:
- answer = CstatAnsBase[5]
+ answer = AnsBase[1]
else:
- answer = AnsBase[1]
- else:
- answer = AnsBase[0]
- Answer(answer, ltype, source, disp)
+ answer = AnsBase[0]
+ Answer(answer, ltype, source, disp)
-def command_prefix(ltype, source, body, disp):
- if Chats.has_key(source[1]):
- if body:
- if enough_access(source[1], source[2], 6):
- body = body.lower()
- if body in ("del", "убрать".decode("utf-8")):
- if Chats[source[1]].cPref:
- Chats[source[1]].cPref = None
- Chats[source[1]].save()
- answer = CstatAnsBase[6]
- else:
- answer = CstatAnsBase[7]
- elif body in cPrefs:
- if Chats[source[1]].cPref != body:
- Chats[source[1]].cPref = body
- Chats[source[1]].save()
- answer = CstatAnsBase[8] % (body)
+ def command_prefix(self, ltype, source, body, disp):
+ if Chats.has_key(source[1]):
+ if body:
+ if enough_access(source[1], source[2], 6):
+ body = body.lower()
+ if body in ("del", "убрать".decode("utf-8")):
+ if Chats[source[1]].cPref:
+ Chats[source[1]].cPref = None
+ Chats[source[1]].save()
+ answer = self.AnsBase[6]
+ else:
+ answer = self.AnsBase[7]
+ elif body in cPrefs:
+ if Chats[source[1]].cPref != body:
+ Chats[source[1]].cPref = body
+ Chats[source[1]].save()
+ answer = self.AnsBase[8] % (body)
+ else:
+ answer = self.AnsBase[9] % (body)
else:
- answer = CstatAnsBase[9] % (body)
+ answer = self.AnsBase[10] % (", ".join(cPrefs))
else:
- answer = CstatAnsBase[10] % (", ".join(cPrefs))
+ answer = AnsBase[10]
+ elif Chats[source[1]].cPref:
+ answer = self.AnsBase[11] % (Chats[source[1]].cPref)
else:
- answer = AnsBase[10]
- elif Chats[source[1]].cPref:
- answer = CstatAnsBase[11] % (Chats[source[1]].cPref)
+ answer = self.AnsBase[12]
else:
- answer = CstatAnsBase[12]
- else:
- answer = AnsBase[0]
- Answer(answer, ltype, source, disp)
+ answer = AnsBase[0]
+ Answer(answer, ltype, source, disp)
-StatusDesc = {"чат".decode("utf-8"): 0, "ушел".decode("utf-8"): 1, "нет".decode("utf-8"): 2, "занят".decode("utf-8"): 3}
+ StatusDesc = {"чат".decode("utf-8"): 0, "ушел".decode("utf-8"): 1, "нет".decode("utf-8"): 2, "занят".decode("utf-8"): 3}
-ChatStatus = "status.db"
+ ChatStatus = "status.db"
-def command_status(ltype, source, body, disp):
- if body:
- list = body.split(None, 2)
- if len(list) == 3:
- state = list[1].lower()
- if StatusDesc.has_key(state):
- state = sList[StatusDesc[state]]
- if state in sList:
- chat = list[0].lower()
- status = list[2].strip()
- body = "%s|%s" % (state, status)
- if chat in ("everywhere", "везде".decode("utf-8")):
- for conf in Chats.keys():
- Chats[conf].change_status(state, status)
- cat_file(chat_file(conf, ChatStatus), body)
- answer = AnsBase[4]
- elif chat in ("here", "здесь".decode("utf-8")):
- if Chats.has_key(source[1]):
- Chats[source[1]].change_status(state, status)
- cat_file(chat_file(source[1], ChatStatus), body)
+ def command_status(self, ltype, source, body, disp):
+ if body:
+ list = body.split(None, 2)
+ if len(list) == 3:
+ state = list[1].lower()
+ if self.StatusDesc.has_key(state):
+ state = sList[self.StatusDesc[state]]
+ if state in sList:
+ chat = list[0].lower()
+ status = list[2].strip()
+ body = "%s|%s" % (state, status)
+ if chat in ("everywhere", "везде".decode("utf-8")):
+ for conf in Chats.keys():
+ Chats[conf].change_status(state, status)
+ cat_file(chat_file(conf, self.ChatStatus), body)
+ answer = AnsBase[4]
+ elif chat in ("here", "здесь".decode("utf-8")):
+ if Chats.has_key(source[1]):
+ Chats[source[1]].change_status(state, status)
+ cat_file(chat_file(source[1], self.ChatStatus), body)
+ answer = AnsBase[4]
+ else:
+ answer = AnsBase[0]
+ elif Chats.has_key(chat):
+ Chats[chat].change_status(state, status)
+ cat_file(chat_file(chat, self.ChatStatus), body)
answer = AnsBase[4]
else:
- answer = AnsBase[0]
- elif Chats.has_key(chat):
- Chats[chat].change_status(state, status)
- cat_file(chat_file(chat, ChatStatus), body)
- answer = AnsBase[4]
+ answer = AnsBase[8]
else:
- answer = AnsBase[8]
+ answer = self.AnsBase[13] % (state)
else:
- answer = CstatAnsBase[13] % (state)
+ answer = AnsBase[2]
else:
- answer = AnsBase[2]
- else:
- answer = AnsBase[1]
- Answer(answer, ltype, source, disp)
+ answer = AnsBase[1]
+ Answer(answer, ltype, source, disp)
-def command_password(ltype, source, body, disp):
- if Chats.has_key(source[1]):
- if body:
- if body in ("none", "нет".decode("utf-8")):
- body = None
- Chats[source[1]].code = body
- Chats[source[1]].save()
- answer = AnsBase[4]
+ def command_password(self, ltype, source, body, disp):
+ if Chats.has_key(source[1]):
+ if body:
+ if body in ("none", "нет".decode("utf-8")):
+ body = None
+ Chats[source[1]].code = body
+ Chats[source[1]].save()
+ answer = AnsBase[4]
+ else:
+ answer = str(Chats[source[1]].code)
else:
- answer = str(Chats[source[1]].code)
- else:
- answer = AnsBase[0]
- Answer(answer, ltype, source, disp)
-
-def load_status(conf):
- filename = chat_file(conf, ChatStatus)
- if initialize_file(filename, "%s|%s" % (sList[0], DefStatus)):
- Chats[conf].set_status(*get_file(filename).split("|", 1))
+ answer = AnsBase[0]
+ Answer(answer, ltype, source, disp)
-expansions[exp_name].funcs_add([command_redisp, command_botnick, command_prefix, command_status, command_password, load_status])
-expansions[exp_name].ls.extend(["CstatAnsBase, StatusDesc, ChatStatus"])
+ def load_status(self, conf):
+ filename = chat_file(conf, self.ChatStatus)
+ if initialize_file(filename, "%s|%s" % (sList[0], DefStatus)):
+ Chats[conf].set_status(*get_file(filename).split("|", 1))
-command_handler(command_redisp, {"RU": "ботжид", "EN": "botjid"}, 7, exp_name)
-command_handler(command_botnick, {"RU": "ботник", "EN": "botnick"}, 6, exp_name)
-command_handler(command_status, {"RU": "ботстатус", "EN": "botstatus"}, 7, exp_name)
-command_handler(command_password, {"RU": "пароль", "EN": "password"}, 6, exp_name)
-command_handler(command_prefix, {"RU": "префикс", "EN": "prefix"}, 1, exp_name, False)
+ commands = (
+ (command_redisp, "botjid", 7,),
+ (command_botnick, "botnick", 6,),
+ (command_status, "botstatus", 7,),
+ (command_password, "password", 6,),
+ (command_prefix, "prefix", 1, False)
+ )
-handler_register(load_status, "01si", exp_name)
+ handlers = ((load_status, "01si"),)
diff --git a/expansions/sconf_attrs/insc.py b/expansions/sconf_attrs/insc.py
index 9457409..013ace3 100644
--- a/expansions/sconf_attrs/insc.py
+++ b/expansions/sconf_attrs/insc.py
@@ -1,7 +1,7 @@
# coding: utf-8
if DefLANG in ("RU", "UA"):
- CstatAnsBase = tuple([line.decode("utf-8") for line in (
+ AnsBase_temp = tuple([line.decode("utf-8") for line in (
"Сдаётся мне '%s' сейчас оффлайн.", # 0
"Сдаётся мне '%s' итак закреплён за этой конфой.", # 1
"'%s' нет среди доступных клиентов!", # 2
@@ -18,7 +18,7 @@ if DefLANG in ("RU", "UA"):
"Статус '%s' мне неизвестен." # 13
)])
else:
- CstatAnsBase = (
+ AnsBase_temp = (
"I can't, because '%s' is offline.", # 0
"'%s' is alredy owned by this conferense.", # 1
"'%s' not in available clients.", # 2
diff --git a/expansions/sconf_attrs/password.name b/expansions/sconf_attrs/password.name
new file mode 100644
index 0000000..0183ae2
--- /dev/null
+++ b/expansions/sconf_attrs/password.name
@@ -0,0 +1,4 @@
+{
+ "RU": "пароль",
+ "UA": "пароль"
+} \ No newline at end of file
diff --git a/expansions/sconf_attrs/prefix.name b/expansions/sconf_attrs/prefix.name
new file mode 100644
index 0000000..2706f27
--- /dev/null
+++ b/expansions/sconf_attrs/prefix.name
@@ -0,0 +1,4 @@
+{
+ "RU": "префикс",
+ "UA": "префикс"
+} \ No newline at end of file
diff --git a/expansions/session_stat/botup.name b/expansions/session_stat/botup.name
new file mode 100644
index 0000000..6ce7452
--- /dev/null
+++ b/expansions/session_stat/botup.name
@@ -0,0 +1,4 @@
+{
+ "RU": "ботап",
+ "UA": "ботап"
+} \ No newline at end of file
diff --git a/expansions/session_stat/code.py b/expansions/session_stat/code.py
index 7ff54f4..1dbff2b 100644
--- a/expansions/session_stat/code.py
+++ b/expansions/session_stat/code.py
@@ -1,95 +1,99 @@
# coding: utf-8
# BlackSmith mark.2
-exp_name = "session_stat" # /code.py v.x4
-# Id: 10~2a
-# Code © (2010-2011) by WitcherGeralt [WitcherGeralt@rocketmail.com]
+exp_name = "session_stat" # /code.py v.x5
+# Id: 10~3b
+# Code © (2010-2011) by WitcherGeralt [alkorgun@gmail.com]
expansion_register(exp_name)
-def command_exc_info(ltype, source, body, disp):
- if body:
- if isNumber(body):
- Number = (int(body) - 1)
- if Number in xrange(len(VarCache["errors"])):
- try:
- exc = VarCache["errors"][Number]
- if oSlist[0]:
- exc = exc.decode("cp1251")
- exc = "%s" % (exc)
- if ltype == Types[1]:
- Answer(AnsBase[11], ltype, source, disp)
- Msend(source[0], exc, disp)
- except:
- answer = SstatAnsBase[20]
+class expansion_temp(expansion):
+
+ def __init__(self, name):
+ expansion.__init__(self, name)
+
+ def command_exc_info(self, ltype, source, body, disp):
+ if body:
+ if isNumber(body):
+ Number = (int(body) - 1)
+ if Number in xrange(len(VarCache["errors"])):
+ try:
+ exc = VarCache["errors"][Number]
+ if oSlist[0]:
+ exc = exc.decode("cp1251")
+ exc = "%s" % (exc)
+ if ltype == Types[1]:
+ Answer(AnsBase[11], ltype, source, disp)
+ Msend(source[0], exc, disp)
+ except:
+ answer = self.SstatAnsBase[20]
+ else:
+ answer = self.SstatAnsBase[21] % (body)
else:
- answer = SstatAnsBase[21] % (body)
+ answer = AnsBase[30]
else:
- answer = AnsBase[30]
- else:
- answer = SstatAnsBase[22] % len(VarCache["errors"])
- if locals().has_key(Types[12]):
- Answer(answer, ltype, source, disp)
+ answer = self.SstatAnsBase[22] % len(VarCache["errors"])
+ if locals().has_key(Types[12]):
+ Answer(answer, ltype, source, disp)
-def command_botup(ltype, source, body, disp):
- NowTime = time.time()
- answer = SstatAnsBase[15] % (Time2Text(NowTime - Info["up"]))
- if Info["alls"]:
- answer += SstatAnsBase[16] % (Time2Text(NowTime - Info["sess"]), str(len(Info["alls"])), ", ".join(sorted(Info["alls"])))
- elif not oSlist[0]:
- answer += SstatAnsBase[17]
- Answer(answer, ltype, source, disp)
+ def command_botup(self, ltype, source, body, disp):
+ NowTime = time.time()
+ answer = self.SstatAnsBase[15] % (Time2Text(NowTime - Info["up"]))
+ if Info["alls"]:
+ answer += self.SstatAnsBase[16] % (Time2Text(NowTime - Info["sess"]), str(len(Info["alls"])), ", ".join(sorted(Info["alls"])))
+ elif not oSlist[0]:
+ answer += self.SstatAnsBase[17]
+ Answer(answer, ltype, source, disp)
-def command_session(ltype, source, body, disp):
- NowTime = time.time()
- answer = SstatAnsBase[0] % (BsPid)
- answer += SstatAnsBase[1] % (Time2Text(NowTime - Info["up"]))
- if len(Info["alls"]):
- answer += SstatAnsBase[2] % (Time2Text(NowTime - Info["sess"]))
- answer += SstatAnsBase[7] % len(Chats.keys())
- answer += SstatAnsBase[3] % (Info["msg"]._str())
- answer += SstatAnsBase[4] % (Info["cmd"]._str())
- answer += SstatAnsBase[5] % (Info["prs"]._str(), Info["iq"]._str())
- answer += SstatAnsBase[6] % (Info["omsg"]._str(), Info["outiq"]._str())
- Number = itypes.Number()
- for conf in Chats.keys():
- Number.plus(len(Chats[conf].get_nicks()))
- answer += SstatAnsBase[8] % (int(Number))
- answer += SstatAnsBase[10] % (len(VarCache["errors"]), Info["errors"]._str())
- answer += SstatAnsBase[11] % (Info["cfw"]._str())
- answer += SstatAnsBase[12] % (iThr.Counter._str(), len(iThr.enumerate()))
- answer += SstatAnsBase[13] % os.times()[0]
- Number = calculate()
- if Number:
- answer += SstatAnsBase[14] % str(round(float(Number) / 1024, 3))
- Answer(answer, ltype, source, disp)
+ def command_session(self, ltype, source, body, disp):
+ NowTime = time.time()
+ answer = self.SstatAnsBase[0] % (BsPid)
+ answer += self.SstatAnsBase[1] % (Time2Text(NowTime - Info["up"]))
+ if len(Info["alls"]):
+ answer += self.SstatAnsBase[2] % (Time2Text(NowTime - Info["sess"]))
+ answer += self.SstatAnsBase[7] % len(Chats.keys())
+ answer += self.SstatAnsBase[3] % (Info["msg"]._str())
+ answer += self.SstatAnsBase[4] % (Info["cmd"]._str())
+ answer += self.SstatAnsBase[5] % (Info["prs"]._str(), Info["iq"]._str())
+ answer += self.SstatAnsBase[6] % (Info["omsg"]._str(), Info["outiq"]._str())
+ Number = itypes.Number()
+ for conf in Chats.keys():
+ Number.plus(len(Chats[conf].get_nicks()))
+ answer += self.SstatAnsBase[8] % (int(Number))
+ answer += self.SstatAnsBase[10] % (len(VarCache["errors"]), Info["errors"]._str())
+ answer += self.SstatAnsBase[11] % (Info["cfw"]._str())
+ answer += self.SstatAnsBase[12] % (iThr.Counter._str(), len(iThr.enumerate()))
+ answer += self.SstatAnsBase[13] % os.times()[0]
+ Number = calculate()
+ if Number:
+ answer += self.SstatAnsBase[14] % str(round(float(Number) / 1024, 3))
+ Answer(answer, ltype, source, disp)
-def command_stat(ltype, source, body, disp):
- if body:
- x = body.lower()
- if x in Cmds.keys():
- answer = SstatAnsBase[18] % (x, Cmds[x].numb._str(), len(Cmds[x].desc))
+ def command_stat(self, ltype, source, body, disp):
+ if body:
+ x = body.lower()
+ if x in Cmds.keys():
+ answer = self.SstatAnsBase[18] % (x, Cmds[x].numb._str(), len(Cmds[x].desc))
+ else:
+ answer = AnsBase[6]
else:
- answer = AnsBase[6]
- else:
- list = []
- for x in Cmds.values():
- x_len = x.numb._int()
- if x_len:
- list.append((x_len, len(x.desc), x.name))
- list.sort()
- list.reverse()
- answer, Numb = SstatAnsBase[19], itypes.Number()
- for x, y, z in list:
- answer += "\n%s. %s - %d (%d)" % (Numb.plus(), z, x, y)
- if Numb._int() >= 20:
- break
- Answer(answer, ltype, source, disp)
-
-expansions[exp_name].funcs_add([command_exc_info, command_botup, command_session, command_stat])
-expansions[exp_name].ls.extend(["SstatAnsBase"])
+ list = []
+ for x in Cmds.values():
+ x_len = x.numb._int()
+ if x_len:
+ list.append((x_len, len(x.desc), x.name))
+ list.sort()
+ list.reverse()
+ answer, Numb = self.SstatAnsBase[19], itypes.Number()
+ for x, y, z in list:
+ answer += "\n%s. %s - %d (%d)" % (Numb.plus(), z, x, y)
+ if Numb._int() >= 20:
+ break
+ Answer(answer, ltype, source, disp)
-command_handler(command_exc_info, {"RU": "ошибка", "EN": "excinfo"}, 8, exp_name)
-command_handler(command_botup, {"RU": "ботап", "EN": "botup"}, 1, exp_name)
-command_handler(command_session, {"RU": "стат", "EN": "stat"}, 1, exp_name)
-command_handler(command_stat, {"RU": "комстат", "EN": "comstat"}, 1, exp_name)
+ commands = (
+ (command_exc_info, "excinfo", 8,),
+ (command_botup, "botup", 1,),
+ (command_session, "stat", 1,),
+ (command_stat, "comstat", 1,)
+ )
diff --git a/expansions/session_stat/comstat.name b/expansions/session_stat/comstat.name
new file mode 100644
index 0000000..7c6c0ca
--- /dev/null
+++ b/expansions/session_stat/comstat.name
@@ -0,0 +1,4 @@
+{
+ "RU": "комстат",
+ "UA": "комстат"
+} \ No newline at end of file
diff --git a/expansions/session_stat/excinfo.name b/expansions/session_stat/excinfo.name
new file mode 100644
index 0000000..60f985a
--- /dev/null
+++ b/expansions/session_stat/excinfo.name
@@ -0,0 +1,4 @@
+{
+ "RU": "ошибка",
+ "UA": "ошибка"
+} \ No newline at end of file
diff --git a/expansions/session_stat/insc.py b/expansions/session_stat/insc.py
index a830b81..989cad0 100644
--- a/expansions/session_stat/insc.py
+++ b/expansions/session_stat/insc.py
@@ -1,7 +1,7 @@
# coding: utf-8
if DefLANG in ("RU", "UA"):
- SstatAnsBase = tuple([line.decode("utf-8") for line in (
+ AnsBase_temp = tuple([line.decode("utf-8") for line in (
"\n*// Статистика работы (Pid: %d):", # 0
"\n-//- Время работы %s", # 1
"\n-//- Последняя сессия %s", # 2
@@ -27,7 +27,7 @@ if DefLANG in ("RU", "UA"):
"Всего произошло %d ошибок." # 22
)])
else:
- SstatAnsBase = (
+ AnsBase_temp = (
"\n*// Session statistics (Pid: %d):", # 0
"\n-//- Bot uptime %s", # 1
"\n-//- Last working set %s", # 2
diff --git a/expansions/session_stat/stat.name b/expansions/session_stat/stat.name
new file mode 100644
index 0000000..d410933
--- /dev/null
+++ b/expansions/session_stat/stat.name
@@ -0,0 +1,4 @@
+{
+ "RU": "стат",
+ "UA": "стат"
+} \ No newline at end of file
diff --git a/expansions/sheriff/code.py b/expansions/sheriff/code.py
index a8904c8..adca226 100644
--- a/expansions/sheriff/code.py
+++ b/expansions/sheriff/code.py
@@ -3,535 +3,539 @@
# BlackSmith mark.2
exp_name = "sheriff" # /code.py v.x5
# Id: 15~3a
-# Code © (2011) by WitcherGeralt [WitcherGeralt@rocketmail.com]
+# Code © (2011) by WitcherGeralt [alkorgun@gmail.com]
expansion_register(exp_name)
-GoodServers = ["jabber.ru", "xmpp.ru", "jabbers.ru", "xmpps.ru", "talkonaut.com", "jabber.org", "gtalk.com", "gmail.com", "jabberon.ru", "gajim.org", "jabbrik.ru", "worldskynet.net", "qip.ru", "blackfishka.ru", "ya.ru"]
+class expansion_temp(expansion):
-if DefLANG != "RU":
- GoodServers += ["jabber.com", "xmpp.com", "jabber.uk", "jabber.co.uk", "jabberworld.net"]
+ def __init__(self, name):
+ expansion.__init__(self, name)
-LawsFile = "laws.db"
+ GoodServers = ["jabber.ru", "xmpp.ru", "jabbers.ru", "xmpps.ru", "talkonaut.com", "jabber.org", "gtalk.com", "gmail.com", "jabberon.ru", "gajim.org", "jabbrik.ru", "worldskynet.net", "qip.ru", "blackfishka.ru", "ya.ru"]
-Federal_Jail, Antiwipe = {}, {}
+ if (DefLANG != "RU"):
+ GoodServers += ["jabber.com", "xmpp.com", "jabber.uk", "jabber.co.uk", "jabberworld.net"]
-class rUser:
+ LawsFile = "laws.db"
- def __init__(self):
- self.devoice = 0
- self.prdates = [time.time()]
- self.msdates = []
- self.offenses = 0
- self.verif = False
- self.kicks = itypes.Number()
- self.vakey = ""
- self.vnumb = itypes.Number()
+ Federal_Jail, Antiwipe = {}, {}
- def Autenticated(self):
- self.verif = True
- self.vakey = ""
- delattr(self, "vnumb")
+ class rUser:
- def leaved(self):
- self.msdates = []
- self.vakey = ""
+ def __init__(self):
+ self.devoice = 0
+ self.prdates = [time.time()]
+ self.msdates = []
+ self.offenses = 0
+ self.verif = False
+ self.kicks = itypes.Number()
+ self.vakey = ""
+ self.vnumb = itypes.Number()
- def SetDevoice(self):
- self.devoice = time.time()
+ def Autenticated(self):
+ self.verif = True
+ self.vakey = ""
+ delattr(self, "vnumb")
- GetDevoice = lambda self: (time.time() - self.devoice)
+ def leaved(self):
+ self.msdates = []
+ self.vakey = ""
- def addPrTime(self):
- self.prdates.append(time.time())
+ def SetDevoice(self):
+ self.devoice = time.time()
- def addMsTime(self):
- self.msdates.append(time.time())
+ GetDevoice = lambda self: (time.time() - self.devoice)
-def command_order(ltype, source, body, disp):
+ def addPrTime(self):
+ self.prdates.append(time.time())
- def change_cfg(conf, Name, mode):
- if mode in ("on", "1", "вкл".decode("utf-8")):
- ChatsAttrs[conf]["laws"][Name] = True
- answer = AnsBase[4]
- elif mode in ("off", "0", "выкл".decode("utf-8")):
- ChatsAttrs[conf]["laws"][Name] = False
- answer = AnsBase[4]
- else:
- answer = AnsBase[2]
- return answer
-
- def alt_change_cfg(conf, Name, mode, drange):
- if isNumber(mode):
- mode = int(mode)
- if mode in xrange(*drange):
- ChatsAttrs[conf]["laws"][Name] = mode
+ def addMsTime(self):
+ self.msdates.append(time.time())
+
+ def command_order(self, ltype, source, body, disp):
+
+ def change_cfg(conf, Name, mode):
+ if mode in ("on", "1", "вкл".decode("utf-8")):
+ ChatsAttrs[conf]["laws"][Name] = True
+ answer = AnsBase[4]
+ elif mode in ("off", "0", "выкл".decode("utf-8")):
+ ChatsAttrs[conf]["laws"][Name] = False
answer = AnsBase[4]
else:
answer = AnsBase[2]
- else:
- answer = AnsBase[30]
- return answer
-
- if Chats.has_key(source[1]):
- if body:
- ls = (body.lower()).split()
- Name = ls.pop(0)
- if ls:
- mode = ls.pop(0)
- if Name in ("servers", "сервера".decode("utf-8")):
- if ls:
- jid = ls.pop(0)
- if jid.count(chr(46)):
- if mode in ("add", "+"):
- if jid not in (GoodServers + ChatsAttrs[source[1]]["laws"]["list"]):
- ChatsAttrs[source[1]]["laws"]["list"].append(jid)
- answer = AnsBase[4]
- else:
- answer = SheriffAnsBase[34]
- elif mode in ("del", "-"):
- if ChatsAttrs[source[1]]["laws"]["list"].count(jid):
- ChatsAttrs[source[1]]["laws"]["list"].remove(jid)
- answer = AnsBase[4]
+ return answer
+
+ def alt_change_cfg(conf, Name, mode, drange):
+ if isNumber(mode):
+ mode = int(mode)
+ if mode in xrange(*drange):
+ ChatsAttrs[conf]["laws"][Name] = mode
+ answer = AnsBase[4]
+ else:
+ answer = AnsBase[2]
+ else:
+ answer = AnsBase[30]
+ return answer
+
+ if Chats.has_key(source[1]):
+ if body:
+ ls = (body.lower()).split()
+ Name = ls.pop(0)
+ if ls:
+ mode = ls.pop(0)
+ if Name in ("servers", "сервера".decode("utf-8")):
+ if ls:
+ jid = ls.pop(0)
+ if jid.count(chr(46)):
+ if mode in ("add", "+"):
+ if jid not in (self.GoodServers + ChatsAttrs[source[1]]["laws"]["list"]):
+ ChatsAttrs[source[1]]["laws"]["list"].append(jid)
+ answer = AnsBase[4]
+ else:
+ answer = self.AnsBase[34]
+ elif mode in ("del", "-"):
+ if ChatsAttrs[source[1]]["laws"]["list"].count(jid):
+ ChatsAttrs[source[1]]["laws"]["list"].remove(jid)
+ answer = AnsBase[4]
+ else:
+ answer = self.AnsBase[35]
else:
- answer = SheriffAnsBase[35]
+ answer = AnsBase[2]
else:
- answer = AnsBase[2]
+ answer = self.AnsBase[36]
else:
- answer = SheriffAnsBase[36]
+ answer = AnsBase[2]
+ elif Name in ("awipe", "антивайп".decode("utf-8")):
+ answer = change_cfg(source[1], "awipe", mode)
+ elif Name in ("aspace", "антиспэйс".decode("utf-8")):
+ answer = change_cfg(source[1], "space", mode)
+ elif Name in ("sparta", "спарта".decode("utf-8")):
+ answer = change_cfg(source[1], "sparta", mode)
+ elif Name in ("verif", "авторизация".decode("utf-8")):
+ answer = change_cfg(source[1], "verif", mode)
+ elif Name in ("atiser", "антиреклама".decode("utf-8")):
+ answer = change_cfg(source[1], "tiser", mode)
+ elif Name in ("aobscene", "антимат".decode("utf-8")):
+ answer = change_cfg(source[1], "obscene", mode)
+ elif Name in ("acaps", "антикапс".decode("utf-8")):
+ answer = change_cfg(source[1], "lower", mode)
+ elif Name in ("lnick", "никлен".decode("utf-8")):
+ answer = alt_change_cfg(source[1], "lnick", mode, (12, 33))
+ elif Name in ("aban", "автобан".decode("utf-8")):
+ answer = alt_change_cfg(source[1], "aban", mode, (2, 7))
+ elif Name in ("loyalty", "лояльность".decode("utf-8")):
+ answer = alt_change_cfg(source[1], "loyalty", mode, (1, 6))
+ elif Name in ("devoice", "девойс".decode("utf-8")):
+ answer = alt_change_cfg(source[1], "dtime", mode, (60, 361))
+ elif Name in ("msglen", "мсглен".decode("utf-8")):
+ answer = alt_change_cfg(source[1], "len", mode, (512, 2049))
+ elif Name in ("prslen", "прзлен".decode("utf-8")):
+ answer = alt_change_cfg(source[1], "prlen", mode, (128, 513))
else:
answer = AnsBase[2]
- elif Name in ("awipe", "антивайп".decode("utf-8")):
- answer = change_cfg(source[1], "awipe", mode)
- elif Name in ("aspace", "антиспэйс".decode("utf-8")):
- answer = change_cfg(source[1], "space", mode)
- elif Name in ("sparta", "спарта".decode("utf-8")):
- answer = change_cfg(source[1], "sparta", mode)
- elif Name in ("verif", "авторизация".decode("utf-8")):
- answer = change_cfg(source[1], "verif", mode)
- elif Name in ("atiser", "антиреклама".decode("utf-8")):
- answer = change_cfg(source[1], "tiser", mode)
- elif Name in ("aobscene", "антимат".decode("utf-8")):
- answer = change_cfg(source[1], "obscene", mode)
- elif Name in ("acaps", "антикапс".decode("utf-8")):
- answer = change_cfg(source[1], "lower", mode)
- elif Name in ("lnick", "никлен".decode("utf-8")):
- answer = alt_change_cfg(source[1], "lnick", mode, (12, 33))
- elif Name in ("aban", "автобан".decode("utf-8")):
- answer = alt_change_cfg(source[1], "aban", mode, (2, 7))
- elif Name in ("loyalty", "лояльность".decode("utf-8")):
- answer = alt_change_cfg(source[1], "loyalty", mode, (1, 6))
- elif Name in ("devoice", "девойс".decode("utf-8")):
- answer = alt_change_cfg(source[1], "dtime", mode, (60, 361))
- elif Name in ("msglen", "мсглен".decode("utf-8")):
- answer = alt_change_cfg(source[1], "len", mode, (512, 2049))
- elif Name in ("prslen", "прзлен".decode("utf-8")):
- answer = alt_change_cfg(source[1], "prlen", mode, (128, 513))
+ if answer == AnsBase[4]:
+ cat_file(chat_file(source[1], self.LawsFile), str(ChatsAttrs[source[1]]["laws"]))
+ elif Name in ("servers", "сервера".decode("utf-8")):
+ answer = "\nDefault:\n%s" % enumerated_list(sorted(self.GoodServers))
+ if ChatsAttrs[source[1]]["laws"]["list"]:
+ answer += "\n\nDefined:\n%s" % enumerated_list(sorted(ChatsAttrs[source[1]]["laws"]["list"]))
else:
answer = AnsBase[2]
- if answer == AnsBase[4]:
- cat_file(chat_file(source[1], LawsFile), str(ChatsAttrs[source[1]]["laws"]))
- elif Name in ("servers", "сервера".decode("utf-8")):
- answer = "\nDefault:\n%s" % enumerated_list(sorted(GoodServers))
- if ChatsAttrs[source[1]]["laws"]["list"]:
- answer += "\n\nDefined:\n%s" % enumerated_list(sorted(ChatsAttrs[source[1]]["laws"]["list"]))
else:
- answer = AnsBase[2]
+ answer = self.AnsBase[24]
+ if ChatsAttrs[source[1]]["laws"]["space"]:
+ answer += self.AnsBase[25][:-1]
+ else:
+ answer += self.AnsBase[26][:-1]
+ answer += self.AnsBase[27] % (ChatsAttrs[source[1]]["laws"]["lnick"])
+ if ChatsAttrs[source[1]]["laws"]["awipe"]:
+ answer += self.AnsBase[25]
+ else:
+ answer += self.AnsBase[26]
+ answer += self.AnsBase[28] % (ChatsAttrs[source[1]]["laws"]["aban"])
+ if ChatsAttrs[source[1]]["laws"]["verif"]:
+ answer += self.AnsBase[25]
+ else:
+ answer += self.AnsBase[26]
+ answer += self.AnsBase[29] % (ChatsAttrs[source[1]]["laws"]["loyalty"])
+ if ChatsAttrs[source[1]]["laws"]["tiser"]:
+ answer += self.AnsBase[25]
+ else:
+ answer += self.AnsBase[26]
+ answer += self.AnsBase[30] % (ChatsAttrs[source[1]]["laws"]["dtime"])
+ if ChatsAttrs[source[1]]["laws"]["obscene"]:
+ answer += self.AnsBase[25][:-1]
+ else:
+ answer += self.AnsBase[26][:-1]
+ answer += self.AnsBase[31] % (ChatsAttrs[source[1]]["laws"]["len"])
+ if ChatsAttrs[source[1]]["laws"]["lower"]:
+ answer += self.AnsBase[25][:-1]
+ else:
+ answer += self.AnsBase[26][:-1]
+ answer += self.AnsBase[32] % (ChatsAttrs[source[1]]["laws"]["prlen"])
+ if ChatsAttrs[source[1]]["laws"]["sparta"]:
+ answer += self.AnsBase[25][:-1]
+ else:
+ answer += self.AnsBase[26][:-1]
else:
- answer = SheriffAnsBase[24]
- if ChatsAttrs[source[1]]["laws"]["space"]:
- answer += SheriffAnsBase[25][:-1]
- else:
- answer += SheriffAnsBase[26][:-1]
- answer += SheriffAnsBase[27] % (ChatsAttrs[source[1]]["laws"]["lnick"])
- if ChatsAttrs[source[1]]["laws"]["awipe"]:
- answer += SheriffAnsBase[25]
- else:
- answer += SheriffAnsBase[26]
- answer += SheriffAnsBase[28] % (ChatsAttrs[source[1]]["laws"]["aban"])
- if ChatsAttrs[source[1]]["laws"]["verif"]:
- answer += SheriffAnsBase[25]
- else:
- answer += SheriffAnsBase[26]
- answer += SheriffAnsBase[29] % (ChatsAttrs[source[1]]["laws"]["loyalty"])
- if ChatsAttrs[source[1]]["laws"]["tiser"]:
- answer += SheriffAnsBase[25]
- else:
- answer += SheriffAnsBase[26]
- answer += SheriffAnsBase[30] % (ChatsAttrs[source[1]]["laws"]["dtime"])
- if ChatsAttrs[source[1]]["laws"]["obscene"]:
- answer += SheriffAnsBase[25][:-1]
- else:
- answer += SheriffAnsBase[26][:-1]
- answer += SheriffAnsBase[31] % (ChatsAttrs[source[1]]["laws"]["len"])
- if ChatsAttrs[source[1]]["laws"]["lower"]:
- answer += SheriffAnsBase[25][:-1]
- else:
- answer += SheriffAnsBase[26][:-1]
- answer += SheriffAnsBase[32] % (ChatsAttrs[source[1]]["laws"]["prlen"])
- if ChatsAttrs[source[1]]["laws"]["sparta"]:
- answer += SheriffAnsBase[25][:-1]
- else:
- answer += SheriffAnsBase[26][:-1]
- else:
- answer = AnsBase[0]
- Answer(answer, ltype, source, disp)
-
-def spesial_kick(conf, nick, text):
- Chats[conf].kick(nick, "%s: %s" % (get_self_nick(conf), text))
- raise iThr.ThrKill("exit")
-
-def sheriffs_loyalty(conf):
- access = loy = ChatsAttrs[conf]["laws"]["loyalty"]
- if access > 2:
- access = 2
- return (loy, access)
-
-def tiser_checker(body):
- body = body.lower()
- c1, c2 = 0, 0
- for dkey in ("@", "conf", "ence"):
- if body.count(dkey):
- c1 += 1
- for dkey in ("http", "//", "www"):
- if body.count(dkey):
- c2 += 1
- if c1 == 3 or c2 > 1:
- return True
- return False
-
-def obscene_checker(body):
- body = " %s " % body.lower()
- for dkey in SheriffAnsBase[33].split(chr(47)):
- if body.count(dkey):
+ answer = AnsBase[0]
+ Answer(answer, ltype, source, disp)
+
+ def spesial_kick(self, conf, nick, text):
+ Chats[conf].kick(nick, "%s: %s" % (get_self_nick(conf), text))
+ raise iThr.ThrKill("exit")
+
+ def sheriffs_loyalty(self, conf):
+ access = loy = ChatsAttrs[conf]["laws"]["loyalty"]
+ if access > 2:
+ access = 2
+ return (loy, access)
+
+ def tiser_checker(self, body):
+ body = body.lower()
+ c1, c2 = 0, 0
+ for dkey in ("@", "conf", "ence"):
+ if body.count(dkey):
+ c1 += 1
+ for dkey in ("http", "//", "www"):
+ if body.count(dkey):
+ c2 += 1
+ if c1 == 3 or c2 > 1:
return True
- return False
-
-def lower_checker(conf, body):
- Numb, body = 0, sub_desc(body, [chr(32), chr(10), chr(13), chr(9)] + Chats[conf].get_nicks()).strip()
- for char in list(body):
- if char.isupper():
- Numb += 1
- if Numb > 12 and Numb > (len(body) / 3):
- return True
- return False
-
-def check_nick(conf, nick):
-
- def nick_checker(conf, nick):
- nick = nick.lower()
- for dkey in ("%s", "%d", "%i", "%f"):
- if nick.count(dkey):
+ return False
+
+ def obscene_checker(self, body):
+ body = " %s " % body.lower()
+ for dkey in self.AnsBase[33].split(chr(47)):
+ if body.count(dkey):
return True
- nick = nick.split()[0]
- if nick in Cmds.keys():
+ return False
+
+ def lower_checker(self, conf, body):
+ Numb, body = 0, sub_desc(body, [chr(32), chr(10), chr(13), chr(9)] + Chats[conf].get_nicks()).strip()
+ for char in list(body):
+ if char.isupper():
+ Numb += 1
+ if Numb > 12 and Numb > (len(body) / 3):
return True
- if Chats[conf].cPref and nick.startswith(Chats[conf].cPref):
- if nick[1:] in Cmds.keys():
- return True
return False
- if (nick.strip()):
- if len(nick) > ChatsAttrs[conf]["laws"]["lnick"]:
- spesial_kick(conf, nick, SheriffAnsBase[0] % (ChatsAttrs[conf]["laws"]["lnick"]))
- if nick_checker(conf, nick):
- spesial_kick(conf, nick, SheriffAnsBase[1])
- if ChatsAttrs[conf]["laws"]["space"]:
- if len(nick) != len(nick.strip()):
- spesial_kick(conf, nick, SheriffAnsBase[2])
- if ChatsAttrs[conf]["laws"]["obscene"]:
- if obscene_checker(nick):
- spesial_kick(conf, nick, SheriffAnsBase[3])
-
-def sheriff_set(ltype, source, source_, access, loyalty, body, disp):
- if access <= loyalty:
- prisoner = Federal_Jail[source[1]].get(source_)
- if prisoner:
- prisoner.offenses += 1
- if prisoner.offenses in (1, 2):
- Answer(body, ltype, source, disp)
- raise iThr.ThrKill("exit")
- elif prisoner.offenses == 3:
- Chats[source[1]].visitor(source[2], "%s: %s" % (get_self_nick(source[1]), body))
- prisoner.SetDevoice()
- Msend(source[0], SheriffAnsBase[16] % (body, ChatsAttrs[source[1]]["laws"]["dtime"]), disp)
- raise iThr.ThrKill("exit")
+ def check_nick(self, conf, nick):
+
+ def nick_checker(conf, nick):
+ nick = nick.lower()
+ for dkey in ("%s", "%d", "%i", "%f"):
+ if nick.count(dkey):
+ return True
+ nick = nick.split()[0]
+ if nick in Cmds.keys():
+ return True
+ if Chats[conf].cPref and nick.startswith(Chats[conf].cPref):
+ if nick[1:] in Cmds.keys():
+ return True
+ return False
+
+ if (nick.strip()):
+ if len(nick) > ChatsAttrs[conf]["laws"]["lnick"]:
+ self.spesial_kick(conf, nick, self.AnsBase[0] % (ChatsAttrs[conf]["laws"]["lnick"]))
+ if nick_checker(conf, nick):
+ self.spesial_kick(conf, nick, self.AnsBase[1])
+ if ChatsAttrs[conf]["laws"]["space"]:
+ if len(nick) != len(nick.strip()):
+ self.spesial_kick(conf, nick, self.AnsBase[2])
+ if ChatsAttrs[conf]["laws"]["obscene"]:
+ if self.obscene_checker(nick):
+ self.spesial_kick(conf, nick, self.AnsBase[3])
+
+ def sheriff_set(self, ltype, source, source_, access, loyalty, body, disp):
+ if access <= loyalty:
+ prisoner = self.Federal_Jail[source[1]].get(source_)
+ if prisoner:
+ prisoner.offenses += 1
+ if prisoner.offenses in (1, 2):
+ Answer(body, ltype, source, disp)
+ raise iThr.ThrKill("exit")
+ elif prisoner.offenses == 3:
+ Chats[source[1]].visitor(source[2], "%s: %s" % (get_self_nick(source[1]), body))
+ prisoner.SetDevoice()
+ Msend(source[0], self.AnsBase[16] % (body, ChatsAttrs[source[1]]["laws"]["dtime"]), disp)
+ raise iThr.ThrKill("exit")
+ else:
+ prisoner.SetDevoice()
+ self.spesial_kick(source[1], source[2], body)
else:
- prisoner.SetDevoice()
- spesial_kick(source[1], source[2], body)
+ self.spesial_kick(source[1], source[2], body)
else:
- spesial_kick(source[1], source[2], body)
- else:
- Answer(body, ltype, source, disp)
- raise iThr.ThrKill("exit")
-
-def Security_01eh(stanza, isConf, ltype, source, body, isToBs, disp):
- if isConf and source[2] and Chats[source[1]].isModer:
- source_ = get_source(source[1], source[2])
- if source_:
- loyalty, access = sheriffs_loyalty(source[1]), get_access(source[1], source[2])
- if access <= loyalty[0]:
- prisoner = Federal_Jail[source[1]].get(source_)
- if prisoner:
- prisoner.addMsTime()
- if ChatsAttrs[source[1]]["laws"]["tiser"]:
- if tiser_checker(body):
- if access <= loyalty[1]:
- if prisoner:
- prisoner.SetDevoice()
- spesial_kick(source[1], source[2], SheriffAnsBase[4])
+ Answer(body, ltype, source, disp)
+ raise iThr.ThrKill("exit")
+
+ def Security_01eh(self, stanza, isConf, ltype, source, body, isToBs, disp):
+ if isConf and source[2] and Chats[source[1]].isModer:
+ source_ = get_source(source[1], source[2])
+ if source_:
+ loyalty, access = self.sheriffs_loyalty(source[1]), get_access(source[1], source[2])
+ if access <= loyalty[0]:
+ prisoner = self.Federal_Jail[source[1]].get(source_)
+ if prisoner:
+ prisoner.addMsTime()
+ if ChatsAttrs[source[1]]["laws"]["tiser"]:
+ if self.tiser_checker(body):
+ if access <= loyalty[1]:
+ if prisoner:
+ prisoner.SetDevoice()
+ self.spesial_kick(source[1], source[2], self.AnsBase[4])
+ else:
+ Answer(self.AnsBase[4], ltype, source, disp)
+ raise iThr.ThrKill("exit")
+ if ChatsAttrs[source[1]]["laws"]["verif"]:
+ if access < 2 and prisoner.vakey and ltype == Types[0]:
+ if prisoner.vakey == body.lower():
+ prisoner.Autenticated()
+ Chats[source[1]].participant(source[2], self.AnsBase[20] % get_self_nick(source[1]))
+ Msend(source[0], self.AnsBase[21], disp)
+ elif prisoner.vnumb.plus() >= 3:
+ prisoner.vnumb = itypes.Number()
+ self.spesial_kick(source[1], source[2], self.AnsBase[22])
+ else:
+ Msend(source[0], self.AnsBase[23], disp)
+ raise iThr.ThrKill("exit")
+ list = getattr(prisoner, "msdates")
+ if len(list) >= 4:
+ if (list[-1] - list[0]) <= 6:
+ prisoner.msdates = [list.pop()]
+ prisoner.SetDevoice()
+ self.spesial_kick(source[1], source[2], self.AnsBase[15])
else:
- Answer(SheriffAnsBase[4], ltype, source, disp)
- raise iThr.ThrKill("exit")
- if ChatsAttrs[source[1]]["laws"]["verif"]:
- if access < 2 and prisoner.vakey and ltype == Types[0]:
- if prisoner.vakey == body.lower():
- prisoner.Autenticated()
- Chats[source[1]].participant(source[2], SheriffAnsBase[20] % get_self_nick(source[1]))
- Msend(source[0], SheriffAnsBase[21], disp)
- elif prisoner.vnumb.plus() >= 3:
- prisoner.vnumb = itypes.Number()
- spesial_kick(source[1], source[2], SheriffAnsBase[22])
+ prisoner.msdates.pop(0)
+ del list
+ if ltype == Types[1]:
+ if ChatsAttrs[source[1]]["laws"]["obscene"]:
+ if self.obscene_checker(body):
+ self.sheriff_set(ltype, source, source_, access, loyalty[1], self.AnsBase[5], disp)
+ if ChatsAttrs[source[1]]["laws"]["len"]:
+ if len(body) > ChatsAttrs[source[1]]["laws"]["len"]:
+ self.sheriff_set(ltype, source, source_, access, loyalty[1], self.AnsBase[6], disp)
+ if ChatsAttrs[source[1]]["laws"]["lower"]:
+ if self.lower_checker(source[1], body):
+ self.sheriff_set(ltype, source, source_, access, loyalty[1], self.AnsBase[7], disp)
+
+ def AwipeClear(self, conf, list):
+ if Chats.has_key(conf):
+ self.Antiwipe[conf]["clear"] = []
+ for sUser in Chats[conf].get_users():
+ if sUser.source in list:
+ if not sUser.ishere:
+ if Chats[conf].isHere(sUser.nick):
+ del Chats[conf].desc[sUser.nick]
+ if self.Federal_Jail[conf].has_key(sUser.source):
+ del self.Federal_Jail[conf][sUser.source]
+ for source_ in list:
+ Chats[conf].none(source_); time.sleep(0.4)
+
+ def get_server(self, source, state = 0):
+ At = chr(64)
+ if source.count(At):
+ source = source.split(At)[1]
+ if state:
+ source = source.split(chr(46), 1)[1]
+ return source
+
+ GoodServers__ = lambda self, conf: (self.GoodServers + ChatsAttrs[conf]["laws"]["list"] + [self.get_server(conf, True)])
+
+ def check_wipe(self, conf, nick, role, inst):
+ if role == AflRoles[2]:
+ BsNick = get_self_nick(conf)
+ if ChatsAttrs[conf]["laws"]["sparta"]:
+ jid = self.get_server(inst)
+ if jid not in self.GoodServers__(conf):
+ Reason = ("%s: This is SPARTA!!" % BsNick)
+ Chats[conf].outcast(jid, Reason); Chats[conf].kick(nick, Reason)
+ elif ChatsAttrs[conf]["laws"]["awipe"]:
+ NowTime = time.time()
+ if (NowTime - Chats[conf].sdate) >= 60:
+ difference = (NowTime - self.Antiwipe[conf]["ltime"])
+ if difference > 360 and self.Antiwipe[conf]["clear"]:
+ sThread(self.AwipeClear.func_name, self.AwipeClear, (conf, self.Antiwipe[conf]["clear"],))
+ if difference > 15:
+ self.Antiwipe[conf]["ltime"] = NowTime
+ self.Antiwipe[conf]["jids"] = [inst]
+ else:
+ self.Antiwipe[conf]["jids"].append(inst)
+ joined = self.Antiwipe[conf]["jids"]
+ Numb = len(joined)
+ if Numb >= 3:
+ self.Antiwipe[conf]["ltime"] = NowTime
+ jid = self.get_server(inst)
+ if jid == self.get_server(joined[Numb - 2]) and jid == self.get_server(joined[Numb - 3]):
+ if jid not in self.GoodServers__(conf):
+ ls = []
+ for sUser in Chats[conf].get_users():
+ if sUser.source and sUser.ishere:
+ if sUser.nick != BsNick and sUser.role[0] == AflRoles[2]:
+ if jid == self.get_server(sUser.source):
+ if self.Federal_Jail[conf].has_key(sUser.source):
+ if not self.Federal_Jail[conf][sUser.source].verif:
+ ls.append(sUser)
+ Chats[conf].outcast(jid, self.AnsBase[12] % (BsNick))
+ if ls:
+ for sUser in ls:
+ Chats[conf].kick(sUser.nick, self.AnsBase[12] % (BsNick))
+ else:
+ for sUser in Chats[conf].get_users():
+ if sUser.source and sUser.ishere:
+ if sUser.nick != BsNick and sUser.role[0] == AflRoles[2]:
+ if jid == self.get_server(sUser.source):
+ if self.Federal_Jail[conf].has_key(sUser.source):
+ if not self.Federal_Jail[conf][sUser.source].verif:
+ self.Antiwipe[conf]["clear"].append(sUser.source)
+ Chats[conf].outcast(sUser.source, self.AnsBase[12] % (BsNick))
else:
- Msend(source[0], SheriffAnsBase[23], disp)
+ self.Antiwipe[conf]["clear"].append(inst)
+ Chats[conf].outcast(inst, self.AnsBase[12] % (BsNick))
raise iThr.ThrKill("exit")
- list = getattr(prisoner, "msdates")
- if len(list) >= 4:
- if (list[-1] - list[0]) <= 6:
- prisoner.msdates = [list.pop()]
- prisoner.SetDevoice()
- spesial_kick(source[1], source[2], SheriffAnsBase[15])
- else:
- prisoner.msdates.pop(0)
- del list
- if ltype == Types[1]:
- if ChatsAttrs[source[1]]["laws"]["obscene"]:
- if obscene_checker(body):
- sheriff_set(ltype, source, source_, access, loyalty[1], SheriffAnsBase[5], disp)
- if ChatsAttrs[source[1]]["laws"]["len"]:
- if len(body) > ChatsAttrs[source[1]]["laws"]["len"]:
- sheriff_set(ltype, source, source_, access, loyalty[1], SheriffAnsBase[6], disp)
- if ChatsAttrs[source[1]]["laws"]["lower"]:
- if lower_checker(source[1], body):
- sheriff_set(ltype, source, source_, access, loyalty[1], SheriffAnsBase[7], disp)
-
-def AwipeClear(conf, list):
- if Chats.has_key(conf):
- Antiwipe[conf]["clear"] = []
- for sUser in Chats[conf].get_users():
- if sUser.source in list:
- if not sUser.ishere:
- if Chats[conf].isHere(sUser.nick):
- del Chats[conf].desc[sUser.nick]
- if Federal_Jail[conf].has_key(sUser.source):
- del Federal_Jail[conf][sUser.source]
- for source_ in list:
- Chats[conf].none(source_); time.sleep(0.4)
-
-def get_server(source, state = 0):
- At = chr(64)
- if source.count(At):
- source = source.split(At)[1]
- if state:
- source = source.split(chr(46), 1)[1]
- return source
-
-GoodServers__ = lambda conf: (GoodServers + ChatsAttrs[conf]["laws"]["list"] + [get_server(conf, True)])
-
-def check_wipe(conf, nick, role, inst):
- if role == AflRoles[2]:
- BsNick = get_self_nick(conf)
- if ChatsAttrs[conf]["laws"]["sparta"]:
- jid = get_server(inst)
- if jid not in GoodServers__(conf):
- Reason = ("%s: This is SPARTA!!" % BsNick)
- Chats[conf].outcast(jid, Reason); Chats[conf].kick(nick, Reason)
- elif ChatsAttrs[conf]["laws"]["awipe"]:
- NowTime = time.time()
- if (NowTime - Chats[conf].sdate) >= 60:
- difference = (NowTime - Antiwipe[conf]["ltime"])
- if difference > 360 and Antiwipe[conf]["clear"]:
- sThread(AwipeClear.func_name, AwipeClear, (conf, Antiwipe[conf]["clear"],))
- if difference > 15:
- Antiwipe[conf]["ltime"] = NowTime
- Antiwipe[conf]["jids"] = [inst]
- else:
- Antiwipe[conf]["jids"].append(inst)
- joined = Antiwipe[conf]["jids"]
- Numb = len(joined)
- if Numb >= 3:
- Antiwipe[conf]["ltime"] = NowTime
- jid = get_server(inst)
- if jid == get_server(joined[Numb - 2]) and jid == get_server(joined[Numb - 3]):
- if jid not in GoodServers__(conf):
- ls = []
- for sUser in Chats[conf].get_users():
- if sUser.source and sUser.ishere:
- if sUser.nick != BsNick and sUser.role[0] == AflRoles[2]:
- if jid == get_server(sUser.source):
- if Federal_Jail[conf].has_key(sUser.source):
- if not Federal_Jail[conf][sUser.source].verif:
- ls.append(sUser)
- Chats[conf].outcast(jid, SheriffAnsBase[12] % (BsNick))
- if ls:
- for sUser in ls:
- Chats[conf].kick(sUser.nick, SheriffAnsBase[12] % (BsNick))
- else:
- for sUser in Chats[conf].get_users():
- if sUser.source and sUser.ishere:
- if sUser.nick != BsNick and sUser.role[0] == AflRoles[2]:
- if jid == get_server(sUser.source):
- if Federal_Jail[conf].has_key(sUser.source):
- if not Federal_Jail[conf][sUser.source].verif:
- Antiwipe[conf]["clear"].append(sUser.source)
- Chats[conf].outcast(sUser.source, SheriffAnsBase[12] % (BsNick))
+
+ def Security_04eh(self, conf, nick, source_, role, stanza, disp):
+ if source_ and nick != get_self_nick(conf):
+ access = get_access(conf, nick)
+ if access <= self.sheriffs_loyalty(conf)[1]:
+ prisoner = self.Federal_Jail[conf].get(source_)
+ if prisoner:
+ prisoner.addPrTime()
+ if prisoner.devoice:
+ eTime = prisoner.GetDevoice()
+ if (eTime < ChatsAttrs[conf]["laws"]["dtime"]):
+ Chats[conf].visitor(nick, self.AnsBase[11] % get_self_nick(conf))
+ Msend("%s/%s" % (conf, nick), self.AnsBase[14] % Time2Text(ChatsAttrs[conf]["laws"]["dtime"] - eTime), disp)
else:
- Antiwipe[conf]["clear"].append(inst)
- Chats[conf].outcast(inst, SheriffAnsBase[12] % (BsNick))
- raise iThr.ThrKill("exit")
-
-def Security_04eh(conf, nick, source_, role, stanza, disp):
- if source_ and nick != get_self_nick(conf):
- access = get_access(conf, nick)
- if access <= sheriffs_loyalty(conf)[1]:
- prisoner = Federal_Jail[conf].get(source_)
- if prisoner:
- prisoner.addPrTime()
- if prisoner.devoice:
- eTime = prisoner.GetDevoice()
- if (eTime < ChatsAttrs[conf]["laws"]["dtime"]):
- Chats[conf].visitor(nick, SheriffAnsBase[11] % get_self_nick(conf))
- Msend("%s/%s" % (conf, nick), SheriffAnsBase[14] % Time2Text(ChatsAttrs[conf]["laws"]["dtime"] - eTime), disp)
- else:
- prisoner.devoice = 0
- else:
- Federal_Jail[conf][source_] = prisoner = rUser()
- if not prisoner.verif and access >= 2:
- prisoner.Autenticated()
- check_wipe(conf, nick, role[0], source_)
- check_nick(conf, nick)
- if ChatsAttrs[conf]["laws"]["verif"] and access < 2 and AflRoles[2] == role[0]:
- if not prisoner.verif and not prisoner.devoice:
- Chats[conf].visitor(nick, SheriffAnsBase[17] % get_self_nick(conf))
- ques = choice(SheriffAnsBase[19].splitlines())
- ques = ques.split(chr(124), 1)
- prisoner.vakey = (ques[1].strip()).lower()
- Msend("%s/%s" % (conf, nick), SheriffAnsBase[18] % (ques[0].strip()), disp)
- del ques
- list = getattr(prisoner, "prdates")
- if len(list) >= 4:
- if (list[-1] - list[0]) <= 10:
- prisoner.prdates = [list.pop()]
- spesial_kick(conf, nick, SheriffAnsBase[13])
- else:
- prisoner.prdates.pop(0)
- del list
- status = stanza.getStatus()
- if status:
- if ChatsAttrs[conf]["laws"]["tiser"]:
- if tiser_checker(status):
- spesial_kick(conf, nick, SheriffAnsBase[4])
- if ChatsAttrs[conf]["laws"]["obscene"]:
- if obscene_checker(status):
- spesial_kick(conf, nick, SheriffAnsBase[8])
- if ChatsAttrs[conf]["laws"]["prlen"]:
- if len(status) > ChatsAttrs[conf]["laws"]["prlen"]:
- spesial_kick(conf, nick, SheriffAnsBase[9])
-
-def Security_05eh(conf, nick, sbody, scode, disp):
- if nick != get_self_nick(conf):
- source_ = get_source(conf, nick)
- if source_:
- prisoner = Federal_Jail[conf].get(source_)
- if prisoner:
- if not Chats[conf].isModer or scode in (sCodes[0], sCodes[3]):
- del Federal_Jail[conf][source_]
+ prisoner.devoice = 0
else:
- prisoner.leaved()
- if scode == sCodes[2] and prisoner.kicks.plus() >= ChatsAttrs[conf]["laws"]["aban"]:
- if ChatsAttrs[conf]["laws"]["aban"]:
- del Federal_Jail[conf][source_]
- Chats[conf].outcast(source_, SheriffAnsBase[10] % (get_self_nick(conf), ChatsAttrs[conf]["laws"]["aban"]))
-
-def Security_06eh(conf, old_nick, nick, disp):
- if nick != get_self_nick(conf) and Chats[conf].isModer:
- sUser = Chats[conf].get_user(nick)
- if getattr(sUser, "source", 0):
- prisoner = Federal_Jail[conf].get(sUser.source)
- if prisoner:
- prisoner.addPrTime()
- check_wipe(conf, nick, sUser.role[0], sUser.source)
- check_nick(conf, nick)
+ self.Federal_Jail[conf][source_] = prisoner = self.rUser()
+ if not prisoner.verif and access >= 2:
+ prisoner.Autenticated()
+ self.check_wipe(conf, nick, role[0], source_)
+ self.check_nick(conf, nick)
+ if ChatsAttrs[conf]["laws"]["verif"] and access < 2 and AflRoles[2] == role[0]:
+ if not prisoner.verif and not prisoner.devoice:
+ Chats[conf].visitor(nick, self.AnsBase[17] % get_self_nick(conf))
+ ques = choice(self.AnsBase[19].splitlines())
+ ques = ques.split(chr(124), 1)
+ prisoner.vakey = (ques[1].strip()).lower()
+ Msend("%s/%s" % (conf, nick), self.AnsBase[18] % (ques[0].strip()), disp)
+ del ques
list = getattr(prisoner, "prdates")
if len(list) >= 4:
if (list[-1] - list[0]) <= 10:
prisoner.prdates = [list.pop()]
- spesial_kick(conf, nick, SheriffAnsBase[13])
- else:
- prisoner.prdates.pop(0)
-
-def Security_07eh(conf, nick, role, disp):
- if nick != get_self_nick(conf):
- sUser = Chats[conf].get_user(nick)
- if getattr(sUser, "source", 0):
- prisoner = ((sUser.access <= sheriffs_loyalty(conf)[1]) and Chats[conf].isModer)
- if Federal_Jail[conf].has_key(sUser.source):
- if not prisoner:
- del Federal_Jail[conf][sUser.source]
- elif prisoner:
- Federal_Jail[conf][sUser.source] = rUser()
-
-def Security_08eh(conf, nick, stanza, disp):
- if nick != get_self_nick(conf) and Chats[conf].isModer:
- source_ = get_source(conf, nick)
- if source_:
- prisoner = Federal_Jail[conf].get(source_)
- if prisoner:
- prisoner.addPrTime()
- list = getattr(prisoner, "prdates")
- if len(list) >= 4:
- if (list[-1] - list[0]) <= 10:
- prisoner.prdates = [list.pop()]
- spesial_kick(conf, nick, SheriffAnsBase[13])
+ self.spesial_kick(conf, nick, self.AnsBase[13])
else:
prisoner.prdates.pop(0)
del list
status = stanza.getStatus()
if status:
if ChatsAttrs[conf]["laws"]["tiser"]:
- if tiser_checker(status):
- spesial_kick(conf, nick, SheriffAnsBase[4])
+ if self.tiser_checker(status):
+ self.spesial_kick(conf, nick, self.AnsBase[4])
if ChatsAttrs[conf]["laws"]["obscene"]:
- if obscene_checker(status):
- spesial_kick(conf, nick, SheriffAnsBase[8])
+ if self.obscene_checker(status):
+ self.spesial_kick(conf, nick, self.AnsBase[8])
if ChatsAttrs[conf]["laws"]["prlen"]:
if len(status) > ChatsAttrs[conf]["laws"]["prlen"]:
- spesial_kick(conf, nick, SheriffAnsBase[9])
-
-def Security_01si(conf):
- Federal_Jail[conf] = {}
- Antiwipe[conf] = {"ltime": 0, "jids": [], "clear": []}
- if not ChatsAttrs.has_key(conf):
- ChatsAttrs[conf] = {}
- ChatsAttrs[conf]["laws"] = {"awipe": True, "space": True, "verif": False, "tiser": True, "obscene": False, "lower": False, "sparta": False, "list": [], "dtime": 180, "loyalty": 1, "aban": 3, "prlen": 256, "lnick": 24, "len": 1024}
- Name = chat_file(conf, LawsFile)
- if initialize_file(Name, str(ChatsAttrs[conf]["laws"])):
- ChatsAttrs[conf]["laws"] = eval(get_file(Name))
-
-def Security_04si(conf):
- del Federal_Jail[conf]
- del Antiwipe[conf]
-
-expansions[exp_name].funcs_add([command_order, spesial_kick, sheriffs_loyalty, tiser_checker, obscene_checker, lower_checker, check_nick, sheriff_set, AwipeClear, get_server, check_wipe, Security_01eh, Security_04eh, Security_05eh, Security_06eh, Security_07eh, Security_08eh, Security_01si, Security_04si])
-expansions[exp_name].ls.extend(["SheriffAnsBase", "GoodServers", "LawsFile", "Federal_Jail", "Antiwipe", rUser.__name__, "GoodServers__"])
-
-command_handler(command_order, {"RU": "ордер", "EN": "order"}, 6, exp_name)
-
-handler_register(Security_01si, "01si", exp_name)
-handler_register(Security_04si, "04si", exp_name)
-handler_register(Security_01eh, "01eh", exp_name)
-handler_register(Security_04eh, "04eh", exp_name)
-handler_register(Security_05eh, "05eh", exp_name)
-handler_register(Security_06eh, "06eh", exp_name)
-handler_register(Security_07eh, "07eh", exp_name)
-handler_register(Security_08eh, "08eh", exp_name)
+ self.spesial_kick(conf, nick, self.AnsBase[9])
+
+ def Security_05eh(self, conf, nick, sbody, scode, disp):
+ if nick != get_self_nick(conf):
+ source_ = get_source(conf, nick)
+ if source_:
+ prisoner = self.Federal_Jail[conf].get(source_)
+ if prisoner:
+ if not Chats[conf].isModer or scode in (sCodes[0], sCodes[3]):
+ del self.Federal_Jail[conf][source_]
+ else:
+ prisoner.leaved()
+ if scode == sCodes[2] and prisoner.kicks.plus() >= ChatsAttrs[conf]["laws"]["aban"]:
+ if ChatsAttrs[conf]["laws"]["aban"]:
+ del self.Federal_Jail[conf][source_]
+ Chats[conf].outcast(source_, self.AnsBase[10] % (get_self_nick(conf), ChatsAttrs[conf]["laws"]["aban"]))
+
+ def Security_06eh(self, conf, old_nick, nick, disp):
+ if nick != get_self_nick(conf) and Chats[conf].isModer:
+ sUser = Chats[conf].get_user(nick)
+ if getattr(sUser, "source", 0):
+ prisoner = self.Federal_Jail[conf].get(sUser.source)
+ if prisoner:
+ prisoner.addPrTime()
+ self.check_wipe(conf, nick, sUser.role[0], sUser.source)
+ self.check_nick(conf, nick)
+ list = getattr(prisoner, "prdates")
+ if len(list) >= 4:
+ if (list[-1] - list[0]) <= 10:
+ prisoner.prdates = [list.pop()]
+ self.spesial_kick(conf, nick, self.AnsBase[13])
+ else:
+ prisoner.prdates.pop(0)
+
+ def Security_07eh(self, conf, nick, role, disp):
+ if nick != get_self_nick(conf):
+ sUser = Chats[conf].get_user(nick)
+ if getattr(sUser, "source", 0):
+ prisoner = ((sUser.access <= self.sheriffs_loyalty(conf)[1]) and Chats[conf].isModer)
+ if self.Federal_Jail[conf].has_key(sUser.source):
+ if not prisoner:
+ del self.Federal_Jail[conf][sUser.source]
+ elif prisoner:
+ self.Federal_Jail[conf][sUser.source] = self.rUser()
+
+ def Security_08eh(self, conf, nick, stanza, disp):
+ if nick != get_self_nick(conf) and Chats[conf].isModer:
+ source_ = get_source(conf, nick)
+ if source_:
+ prisoner = self.Federal_Jail[conf].get(source_)
+ if prisoner:
+ prisoner.addPrTime()
+ list = getattr(prisoner, "prdates")
+ if len(list) >= 4:
+ if (list[-1] - list[0]) <= 10:
+ prisoner.prdates = [list.pop()]
+ self.spesial_kick(conf, nick, self.AnsBase[13])
+ else:
+ prisoner.prdates.pop(0)
+ del list
+ status = stanza.getStatus()
+ if status:
+ if ChatsAttrs[conf]["laws"]["tiser"]:
+ if self.tiser_checker(status):
+ self.spesial_kick(conf, nick, self.AnsBase[4])
+ if ChatsAttrs[conf]["laws"]["obscene"]:
+ if self.obscene_checker(status):
+ self.spesial_kick(conf, nick, self.AnsBase[8])
+ if ChatsAttrs[conf]["laws"]["prlen"]:
+ if len(status) > ChatsAttrs[conf]["laws"]["prlen"]:
+ self.spesial_kick(conf, nick, self.AnsBase[9])
+
+ def Security_01si(self, conf):
+ self.Federal_Jail[conf] = {}
+ self.Antiwipe[conf] = {"ltime": 0, "jids": [], "clear": []}
+ if not ChatsAttrs.has_key(conf):
+ ChatsAttrs[conf] = {}
+ ChatsAttrs[conf]["laws"] = {"awipe": True, "space": True, "verif": False, "tiser": True, "obscene": False, "lower": False, "sparta": False, "list": [], "dtime": 180, "loyalty": 1, "aban": 3, "prlen": 256, "lnick": 24, "len": 1024}
+ Name = chat_file(conf, self.LawsFile)
+ if initialize_file(Name, str(ChatsAttrs[conf]["laws"])):
+ ChatsAttrs[conf]["laws"] = eval(get_file(Name))
+
+ def Security_04si(self, conf):
+ del self.Federal_Jail[conf]
+ del self.Antiwipe[conf]
+
+ commands = ((command_order, "order", 6,),)
+
+ handlers = (
+ (Security_01si, "01si"),
+ (Security_04si, "04si"),
+ (Security_01eh, "01eh"),
+ (Security_04eh, "04eh"),
+ (Security_05eh, "05eh"),
+ (Security_06eh, "06eh"),
+ (Security_07eh, "07eh"),
+ (Security_08eh, "08eh")
+ )
diff --git a/expansions/sheriff/insc.py b/expansions/sheriff/insc.py
index 3d3d2c5..acac4c1 100644
--- a/expansions/sheriff/insc.py
+++ b/expansions/sheriff/insc.py
@@ -1,7 +1,7 @@
# coding: utf-8
if DefLANG in ("RU", "UA"):
- SheriffAnsBase = tuple([line.decode("utf-8") for line in (
+ AnsBase_temp = tuple([line.decode("utf-8") for line in (
"слишком длинный ник. (%d - предел)", # 0
"запрещённый ник.", # 1
"пробелы по краям ников - запрещены.", # 2
@@ -50,7 +50,7 @@ if DefLANG in ("RU", "UA"):
"это не сервер" # 36
)])
else:
- SheriffAnsBase = (
+ AnsBase_temp = (
"too long nickname. (%d - limit)", # 0
"forbidden nickname.", # 1
"spaces at the edges of nicknames - forbidden.", # 2
diff --git a/expansions/sheriff/order.name b/expansions/sheriff/order.name
new file mode 100644
index 0000000..132ccd9
--- /dev/null
+++ b/expansions/sheriff/order.name
@@ -0,0 +1,4 @@
+{
+ "RU": "ордер",
+ "UA": "ордер"
+} \ No newline at end of file
diff --git a/expansions/talkers/code.py b/expansions/talkers/code.py
index 28918dd..86820a1 100644
--- a/expansions/talkers/code.py
+++ b/expansions/talkers/code.py
@@ -1,213 +1,217 @@
# coding: utf-8
# BlackSmith mark.2
-exp_name = "talkers" # /code.py v.x3
-# Id: 14~2a
-# Code © (2010-2011) by WitcherGeralt [WitcherGeralt@rocketmail.com]
+exp_name = "talkers" # /code.py v.x4
+# Id: 14~3b
+# Code © (2010-2011) by WitcherGeralt [alkorgun@gmail.com]
expansion_register(exp_name)
-TalkersFile = "talkers.db"
-
-TalkersDesc = {}
-
-def command_talkers(ltype, source, body, disp):
- if Chats.has_key(source[1]):
- if body:
- list_ = body.split()
- if len(list_) >= 2:
- a1 = (list_.pop(0)).lower()
- a2 = body[((body.lower()).find(a1) + (len(a1) + 1)):].strip()
- if a1 in ("top", "топ".decode("utf-8")):
- if a2 in ("local", "локальный".decode("utf-8")):
- filename = cefile(chat_file(source[1], TalkersFile))
- with TalkersDesc[source[1]]:
- with database(filename) as db:
- db("select * from talkers order by -msgs")
- db_desc = db.fetchmany(10)
- if db_desc:
- answer, Numb = TalkersAnsBase[0], itypes.Number()
- for x in db_desc:
- answer += "\n%d. %s\t\t%d\t%d\t%s" % (Numb.plus(), x[1], x[2], x[3], str(round((float(x[3]) / x[2]), 1)))
- else:
- answer = TalkersAnsBase[1]
- elif a2 in ("global", "глобальный".decode("utf-8")):
- Glob_dbs = {}
- for conf in Chats.keys():
- filename = cefile(chat_file(conf, TalkersFile))
- with TalkersDesc[conf]:
- with database(filename) as db:
- db("select * from talkers order by -msgs")
- db_desc = db.fetchmany(99)
- for x in db_desc:
- if Glob_dbs.has_key(x[0]):
- Glob_dbs[x[0]][2] += x[2]
- Glob_dbs[x[0]][3] += x[3]
- else:
- Glob_dbs[x[0]] = list(x)
- if Glob_dbs:
- Top_list = []
- for x, y in Glob_dbs.items():
- Top_list.append([y[2], y[3], y[1]])
- del Glob_dbs
- answer, Numb = TalkersAnsBase[0], itypes.Number()
- Top_list.sort()
- Top_list.reverse()
- for x in Top_list:
- answer += "\n%d. %s\t\t%d\t%d\t%s" % (Numb.plus(), x[2], x[0], x[1], str(round((float(x[1]) / x[0]), 1)))
- if Numb._int() >= 20:
- break
- else:
- answer = TalkersAnsBase[1]
- else:
- answer = AnsBase[2]
- elif a1 in ("global", "глобальный".decode("utf-8")):
+class expansion_temp(expansion):
+
+ def __init__(self, name):
+ expansion.__init__(self, name)
+
+ TalkersFile = "talkers.db"
+
+ TalkersDesc = {}
- def get_talker_stat(source_):
- x, y = 0, 0
- for conf in Chats.keys():
- filename = cefile(chat_file(conf, TalkersFile))
- with TalkersDesc[conf]:
+ def command_talkers(self, ltype, source, body, disp):
+ if Chats.has_key(source[1]):
+ if body:
+ list_ = body.split()
+ if len(list_) >= 2:
+ a1 = (list_.pop(0)).lower()
+ a2 = body[((body.lower()).find(a1) + (len(a1) + 1)):].strip()
+ if a1 in ("top", "топ".decode("utf-8")):
+ if a2 in ("local", "локальный".decode("utf-8")):
+ filename = cefile(chat_file(source[1], self.TalkersFile))
+ with self.TalkersDesc[source[1]]:
with database(filename) as db:
- db("select * from talkers where jid=?", (source_,))
- db_desc = db.fetchone()
+ db("select * from talkers order by -msgs")
+ db_desc = db.fetchmany(10)
if db_desc:
- x += db_desc[2]
- y += db_desc[3]
- if x:
- answer = TalkersAnsBase[2] % (x, y, str(round((float(y) / x), 1)))
- else:
- answer = TalkersAnsBase[1]
- return answer
-
- if a2 in ("mine", "мой".decode("utf-8")):
- source_ = get_source(source[1], source[2])
- if source_:
- answer = get_talker_stat(source_)
- else:
- answer = TalkersAnsBase[1]
- else:
- if Chats[source[1]].isHere(a2):
- source_ = get_source(source[1], a2)
- else:
- source_ = (list_.pop(0)).lower()
- if not isSource(source_):
- source_ = None
- if source_:
- answer = get_talker_stat(source_)
- else:
+ answer, Numb = self.AnsBase[0], itypes.Number()
+ for x in db_desc:
+ answer += "\n%d. %s\t\t%d\t%d\t%s" % (Numb.plus(), x[1], x[2], x[3], str(round((float(x[3]) / x[2]), 1)))
+ else:
+ answer = self.AnsBase[1]
+ elif a2 in ("global", "глобальный".decode("utf-8")):
Glob_dbs = {}
for conf in Chats.keys():
- filename = cefile(chat_file(conf, TalkersFile))
- with TalkersDesc[conf]:
+ filename = cefile(chat_file(conf, self.TalkersFile))
+ with self.TalkersDesc[conf]:
with database(filename) as db:
- db("select * from talkers where (jid like ? or lastnick like ?) order by -msgs", (a2, a2))
- db_desc = db.fetchmany(10)
+ db("select * from talkers order by -msgs")
+ db_desc = db.fetchmany(99)
for x in db_desc:
if Glob_dbs.has_key(x[0]):
Glob_dbs[x[0]][2] += x[2]
Glob_dbs[x[0]][3] += x[3]
else:
- Glob_dbs[x[0]] = x
+ Glob_dbs[x[0]] = list(x)
if Glob_dbs:
- Usr_list = []
+ Top_list = []
for x, y in Glob_dbs.items():
- Usr_list.append([y[2], y[3], y[1]])
+ Top_list.append([y[2], y[3], y[1]])
del Glob_dbs
- answer, Numb = TalkersAnsBase[0], itypes.Number()
- Usr_list.sort()
- Usr_list.reverse()
- for x in Usr_list:
+ answer, Numb = self.AnsBase[0], itypes.Number()
+ Top_list.sort()
+ Top_list.reverse()
+ for x in Top_list:
answer += "\n%d. %s\t\t%d\t%d\t%s" % (Numb.plus(), x[2], x[0], x[1], str(round((float(x[1]) / x[0]), 1)))
- if Numb._int() >= 10:
+ if Numb._int() >= 20:
break
- answer += TalkersAnsBase[3]
else:
- answer = TalkersAnsBase[1]
- elif a1 in ("local", "локальный".decode("utf-8")):
-
- def get_talker_stat(source_, conf):
- filename = cefile(chat_file(conf, TalkersFile))
- with TalkersDesc[conf]:
- with database(filename) as db:
- db("select * from talkers where jid=?", (source_,))
- x = db.fetchone()
- if x:
- answer = TalkersAnsBase[2] % (x[2], x[3], str(round((float(x[3]) / x[2]), 1)))
+ answer = self.AnsBase[1]
else:
- answer = TalkersAnsBase[1]
- return answer
+ answer = AnsBase[2]
+ elif a1 in ("global", "глобальный".decode("utf-8")):
- if a2 in ("mine", "мой".decode("utf-8")):
- source_ = get_source(source[1], source[2])
- if source_:
- answer = get_talker_stat(source_, source[1])
- else:
- answer = TalkersAnsBase[1]
- else:
- if Chats[source[1]].isHere(a2):
- source_ = get_source(source[1], a2)
- else:
- source_ = (list_.pop(0)).lower()
- if not isSource(source_):
- source_ = None
- if source_:
- answer = get_talker_stat(source_, source[1])
+ def get_talker_stat(self, source_):
+ x, y = 0, 0
+ for conf in Chats.keys():
+ filename = cefile(chat_file(conf, self.TalkersFile))
+ with self.TalkersDesc[conf]:
+ with database(filename) as db:
+ db("select * from talkers where jid=?", (source_,))
+ db_desc = db.fetchone()
+ if db_desc:
+ x += db_desc[2]
+ y += db_desc[3]
+ if x:
+ answer = self.AnsBase[2] % (x, y, str(round((float(y) / x), 1)))
+ else:
+ answer = self.AnsBase[1]
+ return answer
+
+ if a2 in ("mine", "мой".decode("utf-8")):
+ source_ = get_source(source[1], source[2])
+ if source_:
+ answer = get_talker_stat(self, source_)
+ else:
+ answer = self.AnsBase[1]
else:
- filename = cefile(chat_file(source[1], TalkersFile))
- with TalkersDesc[source[1]]:
+ if Chats[source[1]].isHere(a2):
+ source_ = get_source(source[1], a2)
+ else:
+ source_ = (list_.pop(0)).lower()
+ if not isSource(source_):
+ source_ = None
+ if source_:
+ answer = get_talker_stat(self, source_)
+ else:
+ Glob_dbs = {}
+ for conf in Chats.keys():
+ filename = cefile(chat_file(conf, self.TalkersFile))
+ with self.TalkersDesc[conf]:
+ with database(filename) as db:
+ db("select * from talkers where (jid like ? or lastnick like ?) order by -msgs", (a2, a2))
+ db_desc = db.fetchmany(10)
+ for x in db_desc:
+ if Glob_dbs.has_key(x[0]):
+ Glob_dbs[x[0]][2] += x[2]
+ Glob_dbs[x[0]][3] += x[3]
+ else:
+ Glob_dbs[x[0]] = x
+ if Glob_dbs:
+ Usr_list = []
+ for x, y in Glob_dbs.items():
+ Usr_list.append([y[2], y[3], y[1]])
+ del Glob_dbs
+ answer, Numb = self.AnsBase[0], itypes.Number()
+ Usr_list.sort()
+ Usr_list.reverse()
+ for x in Usr_list:
+ answer += "\n%d. %s\t\t%d\t%d\t%s" % (Numb.plus(), x[2], x[0], x[1], str(round((float(x[1]) / x[0]), 1)))
+ if Numb._int() >= 10:
+ break
+ answer += self.AnsBase[3]
+ else:
+ answer = self.AnsBase[1]
+ elif a1 in ("local", "локальный".decode("utf-8")):
+
+ def get_talker_stat(self, source_, conf):
+ filename = cefile(chat_file(conf, self.TalkersFile))
+ with self.TalkersDesc[conf]:
with database(filename) as db:
- db("select * from talkers where (jid like ? or lastnick like ?) order by -msgs", (a2, a2))
- db_desc = db.fetchmany(10)
- if db_desc:
- answer, Numb = TalkersAnsBase[0], itypes.Number()
- for x in db_desc:
- answer += "\n%d. %s\t\t%d\t%d\t%s" % (Numb.plus(), x[1], x[2], x[3], str(round((float(x[3]) / x[2]), 1)))
- answer += TalkersAnsBase[3]
+ db("select * from talkers where jid=?", (source_,))
+ x = db.fetchone()
+ if x:
+ answer = self.AnsBase[2] % (x[2], x[3], str(round((float(x[3]) / x[2]), 1)))
else:
- answer = TalkersAnsBase[1]
+ answer = self.AnsBase[1]
+ return answer
+
+ if a2 in ("mine", "мой".decode("utf-8")):
+ source_ = get_source(source[1], source[2])
+ if source_:
+ answer = get_talker_stat(self, source_, source[1])
+ else:
+ answer = self.AnsBase[1]
+ else:
+ if Chats[source[1]].isHere(a2):
+ source_ = get_source(source[1], a2)
+ else:
+ source_ = (list_.pop(0)).lower()
+ if not isSource(source_):
+ source_ = None
+ if source_:
+ answer = get_talker_stat(self, source_, source[1])
+ else:
+ filename = cefile(chat_file(source[1], self.TalkersFile))
+ with self.TalkersDesc[source[1]]:
+ with database(filename) as db:
+ db("select * from talkers where (jid like ? or lastnick like ?) order by -msgs", (a2, a2))
+ db_desc = db.fetchmany(10)
+ if db_desc:
+ answer, Numb = self.AnsBase[0], itypes.Number()
+ for x in db_desc:
+ answer += "\n%d. %s\t\t%d\t%d\t%s" % (Numb.plus(), x[1], x[2], x[3], str(round((float(x[3]) / x[2]), 1)))
+ answer += self.AnsBase[3]
+ else:
+ answer = self.AnsBase[1]
+ else:
+ answer = AnsBase[2]
else:
answer = AnsBase[2]
else:
- answer = AnsBase[2]
+ answer = AnsBase[1]
else:
- answer = AnsBase[1]
- else:
- answer = AnsBase[0]
- Answer(answer, ltype, source, disp)
-
-def calculate_talkers(stanza, isConf, ltype, source, body, isToBs, disp):
- if isConf and ltype == Types[1] and source[2]:
- source_ = get_source(source[1], source[2])
- if source_:
- nick = source[2].strip()
- filename = cefile(chat_file(source[1], TalkersFile))
- with TalkersDesc[source[1]]:
- with database(filename) as db:
- db("select * from talkers where jid=?", (source_,))
- db_desc = db.fetchone()
- if db_desc:
- db("update talkers set lastnick=?, msgs=?, words=? where jid=?", (nick, (db_desc[2] + 1), (db_desc[3] + len(body.split())), source_))
- else:
- db("insert into talkers values (?,?,?,?)", (source_, nick, 1, len(body.split())))
- db.commit()
+ answer = AnsBase[0]
+ Answer(answer, ltype, source, disp)
-def init_talkers_base(conf):
- filename = cefile(chat_file(conf, TalkersFile))
- if not os.path.isfile(filename):
- with database(filename) as db:
- db("create table talkers (jid text, lastnick text, msgs integer, words integer)")
- db.commit()
- TalkersDesc[conf] = iThr.Semaphore()
+ def calculate_talkers(self, stanza, isConf, ltype, source, body, isToBs, disp):
+ if isConf and ltype == Types[1] and source[2]:
+ source_ = get_source(source[1], source[2])
+ if source_:
+ nick = source[2].strip()
+ filename = cefile(chat_file(source[1], self.TalkersFile))
+ with self.TalkersDesc[source[1]]:
+ with database(filename) as db:
+ db("select * from talkers where jid=?", (source_,))
+ db_desc = db.fetchone()
+ if db_desc:
+ db("update talkers set lastnick=?, msgs=?, words=? where jid=?", (nick, (db_desc[2] + 1), (db_desc[3] + len(body.split())), source_))
+ else:
+ db("insert into talkers values (?,?,?,?)", (source_, nick, 1, len(body.split())))
+ db.commit()
-def edit_talkers_desc(conf):
- del TalkersDesc[conf]
+ def init_talkers_base(self, conf):
+ filename = cefile(chat_file(conf, self.TalkersFile))
+ if not os.path.isfile(filename):
+ with database(filename) as db:
+ db("create table talkers (jid text, lastnick text, msgs integer, words integer)")
+ db.commit()
+ self.TalkersDesc[conf] = iThr.Semaphore()
-expansions[exp_name].funcs_add([command_talkers, calculate_talkers, init_talkers_base, edit_talkers_desc])
-expansions[exp_name].ls.extend(["TalkersAnsBase", "TalkersFile", "TalkersDesc"])
+ def edit_talkers_desc(self, conf):
+ del self.TalkersDesc[conf]
-command_handler(command_talkers, {"RU": "трёп", "EN": "talkers"}, 2, exp_name)
+ commands = ((command_talkers, "talkers", 2,),)
-handler_register(init_talkers_base, "01si", exp_name)
-handler_register(edit_talkers_desc, "04si", exp_name)
-handler_register(calculate_talkers, "01eh", exp_name)
+ handlers = (
+ (init_talkers_base, "01si"),
+ (edit_talkers_desc, "04si"),
+ (calculate_talkers, "01eh")
+ )
diff --git a/expansions/talkers/insc.py b/expansions/talkers/insc.py
index ab2dcaa..aa1bfdb 100644
--- a/expansions/talkers/insc.py
+++ b/expansions/talkers/insc.py
@@ -1,14 +1,14 @@
# coding: utf-8
if DefLANG in ("RU", "UA"):
- TalkersAnsBase = tuple([line.decode("utf-8") for line in (
+ AnsBase_temp = tuple([line.decode("utf-8") for line in (
"\n[№][Юзер][Фраз][Слов][Коэф.]", # 0
"нет статистики", # 1
"\n[Фраз][Слов][Коэф.]\n%d\t%d\t%s", # 2
"\n*! Поиск в базе произведён по ключу." # 3
)])
else:
- TalkersAnsBase = (
+ AnsBase_temp = (
"\n[#][User][Messages][Words][Coef.]", # 0
"no statistics", # 1
"\n[Messages][Words][Coef.]\n%d\t%d\t%s", # 2
diff --git a/expansions/talkers/talkers.name b/expansions/talkers/talkers.name
new file mode 100644
index 0000000..669e832
--- /dev/null
+++ b/expansions/talkers/talkers.name
@@ -0,0 +1,4 @@
+{
+ "RU": "трёп",
+ "UA": "трёп"
+} \ No newline at end of file
diff --git a/expansions/turn/code.py b/expansions/turn/code.py
index 7960937..565c128 100644
--- a/expansions/turn/code.py
+++ b/expansions/turn/code.py
@@ -1,71 +1,75 @@
# coding: utf-8
# BlackSmith mark.2
-exp_name = "turn" # /code.py v.x1
-# Id: 21~1a
-# Code © (2011) by WitcherGeralt [WitcherGeralt@rocketmail.com]
+exp_name = "turn" # /code.py v.x2
+# Id: 21~2b
+# Code © (2011) by WitcherGeralt [alkorgun@gmail.com]
expansion_register(exp_name)
-TableRU = '''ёйцукенгшщзхъфывапролджэячсмитьбю.!"№;%:?*()_+/-=\ЁЙЦУКЕНГШЩЗХЪФЫВАПРОЛДЖЭЯЧСМИТЬБЮ.'''.decode("utf-8")
-TableEN = '''`qwertyuiop[]asdfghjkl;'zxcvbnm,./!@#;%^&*()_+.-=\~QWERTYUIOP{}ASDFGHJKL:"ZXCVBNM<>/'''
+class expansion_temp(expansion):
-TurnBase = {}
+ def __init__(self, name):
+ expansion.__init__(self, name)
-def command_turn(ltype, source, body, disp):
-
- def Turn(conf, body):
- desc = {}
- for nick in Chats[conf].get_nicks():
- if Chats[conf].isHereTS(nick):
- for x in (["%s%s" % (nick, Key) for Key in [":",",",">"]] + [nick]):
- if body.count(x):
- Numb = "*%s*" % str(len(desc.keys()) + 1)
- desc[Numb] = x
- body = body.replace(x, Numb)
- Turned = ""
- for x in body:
- if x in TableEN:
- Turned += TableRU[TableEN.index(x)]
- elif x in TableRU:
- Turned += TableEN[TableRU.index(x)]
+ TableRU = '''ёйцукенгшщзхъфывапролджэячсмитьбю.!"№;%:?*()_+/-=\ЁЙЦУКЕНГШЩЗХЪФЫВАПРОЛДЖЭЯЧСМИТЬБЮ.'''.decode("utf-8")
+ TableEN = '''`qwertyuiop[]asdfghjkl;'zxcvbnm,./!@#;%^&*()_+.-=\~QWERTYUIOP{}ASDFGHJKL:"ZXCVBNM<>/'''
+
+ TurnBase = {}
+
+ def command_turn(self, ltype, source, body, disp):
+
+ def Turn(self, conf, body):
+ desc = {}
+ for nick in Chats[conf].get_nicks():
+ if Chats[conf].isHereTS(nick):
+ for x in (["%s%s" % (nick, Key) for Key in [":",",",">"]] + [nick]):
+ if body.count(x):
+ Numb = "*%s*" % str(len(desc.keys()) + 1)
+ desc[Numb] = x
+ body = body.replace(x, Numb)
+ Turned = ""
+ for x in body:
+ if x in self.TableEN:
+ Turned += self.TableRU[self.TableEN.index(x)]
+ elif x in self.TableRU:
+ Turned += self.TableEN[self.TableRU.index(x)]
+ else:
+ Turned += x
+ return sub_desc(Turned, desc)
+
+ if Chats.has_key(source[1]):
+ if body:
+ answer = "*\ %s" % Turn(source[1], body)
else:
- Turned += x
- return sub_desc(Turned, desc)
-
- if Chats.has_key(source[1]):
- if body:
- answer = Turn(source[1], body)
+ source_ = get_source(source[1], source[2])
+ if source_ and self.TurnBase[source[1]].has_key(source_):
+ (Time, body) = self.TurnBase[source[1]].pop(source_)
+ body = "Turn\->\n[%s] <%s>: %s" % (Time, source[2], Turn(self, source[1], body))
+ Msend(source[1], body, disp)
+ else:
+ answer = AnsBase[7]
else:
- source_ = get_source(source[1], source[2])
- if source_ and TurnBase[source[1]].has_key(source_):
- (Time, body) = TurnBase[source[1]].pop(source_)
- body = "Turn\->\n[%s] <%s>: %s" % (Time, source[2], Turn(source[1], body))
- Msend(source[1], body, disp)
- else:
- answer = AnsBase[7]
- else:
- answer = AnsBase[0]
- if locals().has_key(Types[12]):
- Answer(answer, ltype, source, disp)
-
-def collect_turnable(stanza, isConf, ltype, source, body, isToBs, disp):
- if isConf and ltype == Types[1] and source[2]:
- source_ = get_source(source[1], source[2])
- if source_:
- TurnBase[source[1]][source_] = (strTime("%H:%M:%S", False), body)
+ answer = AnsBase[0]
+ if locals().has_key(Types[12]):
+ Answer(answer, ltype, source, disp)
-def init_Turn_Base(conf):
- TurnBase[conf] = {}
+ def collect_turnable(self, stanza, isConf, ltype, source, body, isToBs, disp):
+ if isConf and ltype == Types[1] and source[2]:
+ source_ = get_source(source[1], source[2])
+ if source_:
+ self.TurnBase[source[1]][source_] = (strTime("%H:%M:%S", False), body)
-def edit_Turn_Base(conf):
- del TurnBase[conf]
+ def init_Turn_Base(self, conf):
+ self.TurnBase[conf] = {}
-expansions[exp_name].funcs_add([command_turn, collect_turnable, init_Turn_Base, edit_Turn_Base])
-expansions[exp_name].ls.extend(["TurnBase", "TableRU", "TableEN"])
+ def edit_Turn_Base(self, conf):
+ del self.TurnBase[conf]
-command_handler(command_turn, {"RU": "турн", "EN": "turn"}, 1, exp_name)
+ commands = ((command_turn, "turn", 1,),)
-handler_register(init_Turn_Base, "01si", exp_name)
-handler_register(edit_Turn_Base, "04si", exp_name)
-handler_register(collect_turnable, "01eh", exp_name)
+ handlers = (
+ (init_Turn_Base, "01si"),
+ (edit_Turn_Base, "04si"),
+ (collect_turnable, "01eh")
+ )
diff --git a/expansions/turn/turn.name b/expansions/turn/turn.name
new file mode 100644
index 0000000..b79345f
--- /dev/null
+++ b/expansions/turn/turn.name
@@ -0,0 +1,4 @@
+{
+ "RU": "турн",
+ "UA": "турн"
+} \ No newline at end of file
diff --git a/expansions/user_stats/code.py b/expansions/user_stats/code.py
index 1bcc873..3b3f1c6 100644
--- a/expansions/user_stats/code.py
+++ b/expansions/user_stats/code.py
@@ -1,139 +1,145 @@
# coding: utf-8
# BlackSmith mark.2
-exp_name = "user_stats" # /code.py v.x4
-# Id: 17~3a
-# Code © (2010-2011) by WitcherGeralt [WitcherGeralt@rocketmail.com]
+exp_name = "user_stats" # /code.py v.x5
+# Id: 17~4b
+# Code © (2010-2011) by WitcherGeralt [alkorgun@gmail.com]
expansion_register(exp_name)
-UstatFile = "jstat.db"
+class expansion_temp(expansion):
-UstatDesc = {}
+ def __init__(self, name):
+ expansion.__init__(self, name)
-def command_user_stats(ltype, source, body, disp):
- if Chats.has_key(source[1]):
- if not body:
- body = get_source(source[1], source[2])
- elif Chats[source[1]].isHere(body):
- body = get_source(source[1], body)
- filename = cefile(chat_file(source[1], UstatFile))
- with UstatDesc[source[1]]:
- with database(filename) as db:
- db("select * from stat where jid=?", (body,))
- db_desc = db.fetchone()
- if db_desc:
- answer = UstatAnsBase[0] % (db_desc[3], db_desc[2], db_desc[1])
- if db_desc[3] >= 2 and db_desc[4]:
- answer += UstatAnsBase[1] % (db_desc[4], db_desc[5])
- answer += UstatAnsBase[2] % (", ".join(sorted(db_desc[6].split("-/-"))))
- else:
- answer = UstatAnsBase[3]
- else:
- answer = AnsBase[0]
- Answer(answer, ltype, source, disp)
-
-def command_here(ltype, source, nick, disp):
- if Chats.has_key(source[1]):
- if not nick:
- nick = source[2]
- if Chats[source[1]].isHereTS(nick):
- jtc = Time2Text(time.time() - Chats[source[1]].get_user(nick).date[0])
- if nick != source[2]:
- answer = UstatAnsBase[4] % (nick, jtc)
- else:
- answer = UstatAnsBase[5] % (jtc)
- else:
- answer = UstatAnsBase[6]
- else:
- answer = AnsBase[0]
- Answer(answer, ltype, source, disp)
-
-def calc_stat_04eh(conf, nick, instance, role, stanza, disp):
- if instance and nick != get_self_nick(conf):
- date, filename = strTime(local = False), cefile(chat_file(conf, UstatFile))
- with UstatDesc[conf]:
- with database(filename) as db:
- db("select * from stat where jid=?", (instance,))
- db_desc = db.fetchone()
- if db_desc:
- db("update stat set joined=?, joins=? where jid=?", (date, (db_desc[3] + 1), instance))
- if nick not in db_desc[6].split("-/-"):
- db("update stat set nicks=? where jid=?", ("%s-/-%s" % (db_desc[6], nick), instance))
- arole = "%s/%s" % (role)
- if db_desc[1] != arole:
- db("update stat set arole=? where jid=?", (arole, instance))
- db.commit()
- else:
- db("insert into stat values (?,?,?,?,?,?,?)", (instance, "%s/%s" % (role), date, 1, "", "", nick))
- db.commit()
-
-def calc_stat_05eh(conf, nick, sbody, scode, disp):
- if nick != get_self_nick(conf):
- source_ = get_source(conf, nick)
- if source_:
- sbody = UnicodeType(sbody)
- if scode == sCodes[0]:
- sbody = "banned:(%s)" % (sbody)
- elif scode == sCodes[2]:
- sbody = "kicked:(%s)" % (sbody)
- date, filename = strTime(local = False), cefile(chat_file(conf, UstatFile))
- with UstatDesc[conf]:
- with database(filename) as db:
- db("select * from stat where jid=?", (source_,))
- db_desc = db.fetchone()
- if db_desc:
- db("update stat set seen=?, leave=? where jid=?", (date, sbody, source_))
- db.commit()
+ UstatFile = "jstat.db"
+
+ UstatDesc = {}
-def calc_stat_06eh(conf, old_nick, nick, disp):
- if nick != get_self_nick(conf):
- source_ = get_source(conf, nick)
- if source_:
- filename = cefile(chat_file(conf, UstatFile))
- with UstatDesc[conf]:
+ def command_user_stats(self, ltype, source, body, disp):
+ if Chats.has_key(source[1]):
+ if not body:
+ body = get_source(source[1], source[2])
+ elif Chats[source[1]].isHere(body):
+ body = get_source(source[1], body)
+ filename = cefile(chat_file(source[1], self.UstatFile))
+ with self.UstatDesc[source[1]]:
with database(filename) as db:
- db("select * from stat where jid=?", (source_,))
+ db("select * from stat where jid=?", (body,))
db_desc = db.fetchone()
- if db_desc and nick not in db_desc[6].split("-/-"):
- db("update stat set nicks=? where jid=?", ("%s-/-%s" % (db_desc[6], nick), source_))
- db.commit()
+ if db_desc:
+ answer = self.AnsBase[0] % (db_desc[3], db_desc[2], db_desc[1])
+ if db_desc[3] >= 2 and db_desc[4]:
+ answer += self.AnsBase[1] % (db_desc[4], db_desc[5])
+ answer += self.AnsBase[2] % (", ".join(sorted(db_desc[6].split("-/-"))))
+ else:
+ answer = self.AnsBase[3]
+ else:
+ answer = AnsBase[0]
+ Answer(answer, ltype, source, disp)
-def calc_stat_07eh(conf, nick, role, disp):
- if nick != get_self_nick(conf):
- source_ = get_source(conf, nick)
- if source_:
- filename = cefile(chat_file(conf, UstatFile))
- with UstatDesc[conf]:
+ def command_here(self, ltype, source, nick, disp):
+ if Chats.has_key(source[1]):
+ if not nick:
+ nick = source[2]
+ if Chats[source[1]].isHereTS(nick):
+ jtc = Time2Text(time.time() - Chats[source[1]].get_user(nick).date[0])
+ if nick != source[2]:
+ answer = self.AnsBase[4] % (nick, jtc)
+ else:
+ answer = self.AnsBase[5] % (jtc)
+ else:
+ answer = self.AnsBase[6]
+ else:
+ answer = AnsBase[0]
+ Answer(answer, ltype, source, disp)
+
+ def calc_stat_04eh(self, conf, nick, instance, role, stanza, disp):
+ if instance and nick != get_self_nick(conf):
+ date, filename = strTime(local = False), cefile(chat_file(conf, self.UstatFile))
+ with self.UstatDesc[conf]:
with database(filename) as db:
- db("select * from stat where jid=?", (source_,))
+ db("select * from stat where jid=?", (instance,))
db_desc = db.fetchone()
if db_desc:
+ db("update stat set joined=?, joins=? where jid=?", (date, (db_desc[3] + 1), instance))
+ if nick not in db_desc[6].split("-/-"):
+ db("update stat set nicks=? where jid=?", ("%s-/-%s" % (db_desc[6], nick), instance))
arole = "%s/%s" % (role)
if db_desc[1] != arole:
- db("update stat set arole=? where jid=?", (arole, source_))
+ db("update stat set arole=? where jid=?", (arole, instance))
+ db.commit()
+ else:
+ db("insert into stat values (?,?,?,?,?,?,?)", (instance, "%s/%s" % (role), date, 1, "", "", nick))
+ db.commit()
+
+ def calc_stat_05eh(self, conf, nick, sbody, scode, disp):
+ if nick != get_self_nick(conf):
+ source_ = get_source(conf, nick)
+ if source_:
+ sbody = UnicodeType(sbody)
+ if scode == sCodes[0]:
+ sbody = "banned:(%s)" % (sbody)
+ elif scode == sCodes[2]:
+ sbody = "kicked:(%s)" % (sbody)
+ date, filename = strTime(local = False), cefile(chat_file(conf, self.UstatFile))
+ with self.UstatDesc[conf]:
+ with database(filename) as db:
+ db("select * from stat where jid=?", (source_,))
+ db_desc = db.fetchone()
+ if db_desc:
+ db("update stat set seen=?, leave=? where jid=?", (date, sbody, source_))
db.commit()
-def init_stat_base(conf):
- filename = cefile(chat_file(conf, UstatFile))
- if not os.path.isfile(filename):
- with database(filename) as db:
- db("create table stat (jid text, arole text, joined text, joins integer, seen text, leave text, nicks text)")
- db.commit()
- UstatDesc[conf] = iThr.Semaphore()
-
-def edit_stat_desc(conf):
- del UstatDesc[conf]
-
-expansions[exp_name].funcs_add([command_user_stats, command_here, calc_stat_04eh, calc_stat_05eh, calc_stat_06eh, calc_stat_07eh, init_stat_base, edit_stat_desc])
-expansions[exp_name].ls.extend(["UstatAnsBase", "UstatFile", "UstatDesc"])
-
-command_handler(command_user_stats, {"RU": "юзерстат", "EN": "userstat"}, 2, exp_name)
-command_handler(command_here, {"RU": "пребывание", "EN": "here"}, 1, exp_name)
-
-handler_register(init_stat_base, "01si", exp_name)
-handler_register(edit_stat_desc, "04si", exp_name)
-handler_register(calc_stat_04eh, "04eh", exp_name)
-handler_register(calc_stat_05eh, "05eh", exp_name)
-handler_register(calc_stat_06eh, "06eh", exp_name)
-handler_register(calc_stat_07eh, "07eh", exp_name)
+ def calc_stat_06eh(self, conf, old_nick, nick, disp):
+ if nick != get_self_nick(conf):
+ source_ = get_source(conf, nick)
+ if source_:
+ filename = cefile(chat_file(conf, self.UstatFile))
+ with self.UstatDesc[conf]:
+ with database(filename) as db:
+ db("select * from stat where jid=?", (source_,))
+ db_desc = db.fetchone()
+ if db_desc and nick not in db_desc[6].split("-/-"):
+ db("update stat set nicks=? where jid=?", ("%s-/-%s" % (db_desc[6], nick), source_))
+ db.commit()
+
+ def calc_stat_07eh(self, conf, nick, role, disp):
+ if nick != get_self_nick(conf):
+ source_ = get_source(conf, nick)
+ if source_:
+ filename = cefile(chat_file(conf, self.UstatFile))
+ with self.UstatDesc[conf]:
+ with database(filename) as db:
+ db("select * from stat where jid=?", (source_,))
+ db_desc = db.fetchone()
+ if db_desc:
+ arole = "%s/%s" % (role)
+ if db_desc[1] != arole:
+ db("update stat set arole=? where jid=?", (arole, source_))
+ db.commit()
+
+ def init_stat_base(self, conf):
+ filename = cefile(chat_file(conf, self.UstatFile))
+ if not os.path.isfile(filename):
+ with database(filename) as db:
+ db("create table stat (jid text, arole text, joined text, joins integer, seen text, leave text, nicks text)")
+ db.commit()
+ self.UstatDesc[conf] = iThr.Semaphore()
+
+ def edit_stat_desc(self, conf):
+ del self.UstatDesc[conf]
+
+ commands = (
+ (command_user_stats, "userstat", 2,),
+ (command_here, "here", 1,)
+ )
+
+ handlers = (
+ (init_stat_base, "01si"),
+ (edit_stat_desc, "04si"),
+ (calc_stat_04eh, "04eh"),
+ (calc_stat_05eh, "05eh"),
+ (calc_stat_06eh, "06eh"),
+ (calc_stat_07eh, "07eh")
+ )
diff --git a/expansions/user_stats/here.name b/expansions/user_stats/here.name
new file mode 100644
index 0000000..bdb441a
--- /dev/null
+++ b/expansions/user_stats/here.name
@@ -0,0 +1,4 @@
+{
+ "RU": "пребывание",
+ "UA": "пребывание"
+} \ No newline at end of file
diff --git a/expansions/user_stats/insc.py b/expansions/user_stats/insc.py
index 83f9cd0..c75be61 100644
--- a/expansions/user_stats/insc.py
+++ b/expansions/user_stats/insc.py
@@ -1,7 +1,7 @@
# coding: utf-8
if DefLANG in ("RU", "UA"):
- UstatAnsBase = tuple([line.decode("utf-8") for line in (
+ AnsBase_temp = tuple([line.decode("utf-8") for line in (
"\nВсего входов - %d\nВремя последнего входа - %s\nПоследняя роль - %s", # 0
"\nВремя последнего выхода - %s\nПричина выхода - %s", # 1
"\nНики: %s", # 2
@@ -11,7 +11,7 @@ if DefLANG in ("RU", "UA"):
"здесь нет такого юзера" # 6
)])
else:
- UstatAnsBase = (
+ AnsBase_temp = (
"\nTotal joins - %d\nLast join time - %s\nLast role - %s", # 0
"\nLast leave time - %s\nExit reason - %s", # 1
"\nNicks: %s", # 2
diff --git a/expansions/user_stats/userstat.name b/expansions/user_stats/userstat.name
new file mode 100644
index 0000000..02f3e1e
--- /dev/null
+++ b/expansions/user_stats/userstat.name
@@ -0,0 +1,4 @@
+{
+ "RU": "юзерстат",
+ "UA": "юзерстат"
+} \ No newline at end of file
diff --git a/librarys.zip b/librarys.zip
index 774a1b0..2f04c4d 100644
--- a/librarys.zip
+++ b/librarys.zip
Binary files differ
diff --git a/static/insc.py b/static/insc.py
index d02d71c..63e4a2c 100644
--- a/static/insc.py
+++ b/static/insc.py
@@ -33,7 +33,7 @@ if DefLANG in ("RU", "UA"):
"Клиент «%s» упал!", # 28
"JID «%s» используется в другом клиенте! (отключаю его)", # 29
"это не число" # 30
- )])
+ )])
else:
AnsBase = (
"This command is available only in conferences", # 0
@@ -67,4 +67,4 @@ else:
"Client '%s' falled!", # 28
"JID '%s' used in another client! (I have to disconnect it)", # 29
"This is not a number" # 30
- ) \ No newline at end of file
+ ) \ No newline at end of file