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:
authorAl Korgun <alkorgun@gmail.com>2013-06-25 14:29:17 +0400
committerAl Korgun <alkorgun@gmail.com>2013-06-25 14:29:17 +0400
commit74a57a3a0419e6c2313f715cedcc5cd4b28e542b (patch)
tree7329ee48c8e99e49957784189004d98a42431107 /expansions
parentbaf24e8415e99a974e230ae2cb2c8f232b949189 (diff)
implemented partially support of the work without sqlite; "imdb" fixed; many important and little changes
Diffstat (limited to 'expansions')
-rw-r--r--expansions/alive_keeper/code.py15
-rw-r--r--expansions/allweb/code.py149
-rw-r--r--expansions/basic_control/code.py18
-rw-r--r--expansions/basic_control/insc.py2
-rw-r--r--expansions/books/code.py57
-rw-r--r--expansions/config/code.py62
-rw-r--r--expansions/config/insc.py2
-rw-r--r--expansions/cron/code.py2
-rw-r--r--expansions/info/code.py4
-rw-r--r--expansions/note/code.py7
-rw-r--r--expansions/talkers/code.py75
-rw-r--r--expansions/user_stats/code.py95
-rw-r--r--expansions/wtf/code.py7
-rw-r--r--expansions/wtf/insc.py2
14 files changed, 251 insertions, 246 deletions
diff --git a/expansions/alive_keeper/code.py b/expansions/alive_keeper/code.py
index 7e6472a..af8c6ea 100644
--- a/expansions/alive_keeper/code.py
+++ b/expansions/alive_keeper/code.py
@@ -1,9 +1,9 @@
# coding: utf-8
# BlackSmith mark.2
-# exp_name = "alive_keeper" # /code.py v.x7
-# Id: 16~7c
-# Code © (2011-2012) by WitcherGeralt [alkorgun@gmail.com]
+# exp_name = "alive_keeper" # /code.py v.x8
+# Id: 16~8c
+# Code © (2011-2013) by WitcherGeralt [alkorgun@gmail.com]
class expansion_temp(expansion):
@@ -18,7 +18,7 @@ class expansion_temp(expansion):
while VarCache["alive"]:
sleep(120)
- ThrIds = iThr.ThrNames()
+ ThrIds = iThr.getNames()
for disp_str, disp in Clients.iteritems():
if not hasattr(disp, "aKeeper"):
disp.aKeeper = itypes.Number()
@@ -27,7 +27,7 @@ class expansion_temp(expansion):
ThrName = "%s-%s" % (Types[13], disp_str)
if ThrName in ThrIds:
for Thr in iThr.enumerate():
- if Thr._Thread__name == ThrName:
+ if ThrName == Thr.getName():
Thr.kill()
try:
composeThr(connectAndDispatch, ThrName, (disp_str,)).start()
@@ -58,7 +58,7 @@ class expansion_temp(expansion):
while VarCache["alive"]:
sleep(360)
- ThrIds = iThr.ThrNames()
+ ThrIds = iThr.getNames()
for conf in Chats.itervalues():
if not (online(conf.disp) and conf.IamHere):
continue
@@ -89,8 +89,7 @@ class expansion_temp(expansion):
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, Name2)):
+ if Thr.name.startswith((Name1, Name2)):
Thr.kill()
composeThr(self.alive_keeper, Name1).start()
composeThr(self.conf_alive_keeper, Name2).start()
diff --git a/expansions/allweb/code.py b/expansions/allweb/code.py
index 0db0c16..b5f37be 100644
--- a/expansions/allweb/code.py
+++ b/expansions/allweb/code.py
@@ -1,8 +1,8 @@
# coding: utf-8
# BlackSmith mark.2
-# exp_name = "allweb" # /code.py v.x23
-# Id: 25~23c
+# exp_name = "allweb" # /code.py v.x24
+# Id: 25~24c
# Code © (2011-2013) by WitcherGeralt [alkorgun@gmail.com]
class expansion_temp(expansion):
@@ -272,7 +272,7 @@ class expansion_temp(expansion):
c1st = (ls.pop(0)).lower()
if c1st in ("top250", "топ250".decode("utf-8")):
if ls:
- limit = exec_(int, (ls.pop(0),))
+ limit = apply(int, (ls.pop(0),))
if limit <= 5:
limit = 5
else:
@@ -294,11 +294,10 @@ class expansion_temp(expansion):
'?<a href="/film/\d+?/votes/" class="continue">(.+?)</a> <span.*?>(.+?)</span>', 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(), self.sub_ehtmls(Name), Numb, sub_desc(Numb, ["&nbsp;"])))
- if limit and limit <= Number._int():
+ for Number, (Name, Numb, Count) in enumerate(list, 1):
+ ls.append("%d) %s - %s (%s)" % (Number, self.sub_ehtmls(Name), Numb, sub_desc(Count, ["&nbsp;"])))
+ if limit and limit <= Number:
break
if not limit or limit > 25:
if stype == Types[1]:
@@ -312,7 +311,7 @@ class expansion_temp(expansion):
else:
answer = self.AnsBase[1]
elif isNumber(body):
- Opener = Web("http://m.kinopoisk.ru/movie/%s" % (body), headers = self.kinoHeaders.copy())
+ Opener = Web("http://m.kinopoisk.ru/movie/%d" % int(body), headers = self.kinoHeaders.copy())
try:
data = Opener.get_page(self.UserAgent_Moz)
except Web.Two.HTTPError, exc:
@@ -352,10 +351,9 @@ class expansion_temp(expansion):
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))
+ for Number, (Numb, Name) in enumerate(list, 1):
+ ls.append("%d) %s (#%s)" % (Number, self.sub_ehtmls(Name), Numb))
answer = str.join(chr(10), ls)
elif data.count(self.C3oP):
answer = self.AnsBase[-1]
@@ -370,13 +368,25 @@ class expansion_temp(expansion):
IMDbHeaders = {"Accept-Language": "%s,en" % UserAgents.get(DefLANG, "en-US")}
+ IMDbRequest = { # imdbapi.org
+ "type": "json",
+# "id": "tt", # get info by ID
+# "q": "any title", # for the search
+# "limit": str(choice(range(1, 11))), # for the search
+ "plot": "none", # or "simple" or "full"
+ "episode": "0", # or "1"
+ "lang": UserAgents.get(DefLANG, "en-US"),
+ "aka": "simple", # or "full"
+ "release": "simple", # or "full"
+ }
+
def command_imdb(self, stype, 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),))
+ limit = apply(int, (ls.pop(0),))
if limit <= 5:
limit = 5
else:
@@ -390,18 +400,17 @@ class expansion_temp(expansion):
answer = self.AnsBase[0]
else:
data = data.decode("utf-8")
- list = get_text(data, '<div id="main">', "</div>")
- if list:
+ data = get_text(data, '<div id="main">', "</div>")
+ if data:
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()
+ data = comp.findall(data)
+ if data:
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():
+ for Number, (Numb, Name, Year, Count) in enumerate(data, 1):
+ ls.append("%s) %s %s - %s (%s)" % (Number, self.sub_ehtmls(Name), Year.strip(), Numb, Count))
+ if limit and limit <= Number:
break
if not limit or limit > 25:
if stype == Types[1]:
@@ -413,7 +422,10 @@ class expansion_temp(expansion):
else:
answer = self.AnsBase[1]
elif isNumber(body):
- Opener = Web("http://www.imdb.com/title/tt%s/" % (body), headers = self.IMDbHeaders)
+ IMDbRequest = self.IMDbRequest.copy()
+ IMDbRequest["id"] = ("tt" + body)
+ IMDbRequest["plot"] = "full"
+ Opener = Web("http://imdbapi.org/?", IMDbRequest.iteritems())
try:
data = Opener.get_page(self.UserAgent_Moz)
except Web.Two.HTTPError, exc:
@@ -421,42 +433,46 @@ class expansion_temp(expansion):
except:
answer = self.AnsBase[0]
else:
- data = data.decode("utf-8")
- Name = get_text(data, '<h1 class="header" itemprop="name">', "<span.*?>")
- if Name:
+ try:
+ data = self.json.loads(data)
+ except:
+ answer = self.AnsBase[1]
+ else:
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(unichr(171) + self.decodeHTML(desc).strip() + unichr(187))
- for Title in ("Director", "Star", "Writer"):
- list = get_text(data, "<h4 class=\"inline\">\s*?%s[s]?:\s*?</h4>" % Title, "(?:<span>|</div>)")
- if list:
- comp = compile__(">(.+?)</a>")
- list = comp.findall(list)
- if list:
- ls.append("%ss: %s" % (Title, str.join(", ", list)))
- rValue = get_text(data, '<span itemprop="ratingValue">', "</span>")
- if rValue:
- rCount = get_text(data, '<span itemprop="ratingCount">', "</span>")
- if rCount:
- rValue = "%s (Votes: %s)" % (rValue, rCount)
- ls.append("Rating: %s" % rValue)
- if len(ls) >= 2:
- answer = self.decodeHTML(str.join(chr(10), ls))
+ try:
+
+ assert isinstance(data, dict)
+
+ ls.append("%s, %s, %s." % (data["title"], data["year"], str.join(chr(32), data.get("runtime", ("??",)))))
+ ls.append(", ".join(data["genres"]))
+ ls.append(", ".join(data["country"]))
+ temp = data.get("directors")
+ if temp:
+ ls.append("Directors: " + ", ".join(temp[:3]))
+ temp = data.get("writers")
+ if temp:
+ ls.append("Writers: " + ", ".join(temp[:3]))
+ temp = data.get("actors")
+ if temp:
+ ls.append("Stars: " + ", ".join(temp[:5]))
+ temp = data.get("plot") or data.get("plot_simple")
+ if temp:
+ ls.append(unichr(171) + temp + unichr(187))
+ temp = data.get("rating")
+ if temp:
+ ls.append("IMDb rating: %s (%s)" % (temp, data.get("rating_count", 0)))
+ except (AssertionError, TypeError, LookupError):
+ answer = self.AnsBase[5]
else:
- answer = self.AnsBase[1]
- else:
- answer = self.AnsBase[1]
+ answer = self.sub_ehtmls(str.join(chr(10), ls))
else:
body = (body if chr(42) != c1st else body[2:].strip())
if body:
body = body.encode("utf-8")
- Opener = Web("http://www.imdb.com/find?", [("s", "tt"), ("q", body)], self.IMDbHeaders)
+ IMDbRequest = self.IMDbRequest.copy()
+ IMDbRequest["q"] = body
+ IMDbRequest["limit"] = "10"
+ Opener = Web("http://imdbapi.org/?", IMDbRequest.iteritems())
try:
data = Opener.get_page(self.UserAgent_Moz)
except Web.Two.HTTPError, exc:
@@ -464,19 +480,26 @@ class expansion_temp(expansion):
except:
answer = self.AnsBase[0]
else:
- data = data.decode("utf-8")
- list = get_text(data, "<table.*?>", "</table>")
- if list:
- comp = compile__("<td class=\"result_text\">\s<a href=\"/title/tt(\d+?)/\?ref_=fn_tt_tt_\d+?\">(.+?)</a>(.+?)</td>\s</tr>", 16)
- list = comp.findall(list)
- if list:
- Number = itypes.Number()
- ls = ["\n[#] [Name, Year] (#id)"]
- for Numb, Name, Year in list[:20]:
- ls.append("%d) %s %s (#%s)" % (Number.plus(), self.sub_ehtmls(Name), self.compile_st.sub("", Year.strip()), Numb))
- answer = str.join(chr(10), ls)
+ try:
+ data = self.json.loads(data)
+ except:
+ answer = self.AnsBase[1]
else:
- answer = self.AnsBase[5]
+ try:
+
+ assert isinstance(data, list)
+
+ data = sorted([(desc.get("rating"),
+ desc["title"],
+ desc["year"],
+ desc["imdb_id"][2:]) for desc in data], reverse = True)
+ except (AssertionError, TypeError, LookupError):
+ answer = self.AnsBase[5]
+ else:
+ ls = ["\n[#] [Name, Year] (#id)"]
+ for Number, (Numb, Name, Year, ID) in enumerate(data, 1):
+ ls.append("%d) %s, %s (#%s)" % (Number, Name, Year, ID))
+ answer = self.sub_ehtmls(str.join(chr(10), ls))
else:
answer = AnsBase[2]
else:
diff --git a/expansions/basic_control/code.py b/expansions/basic_control/code.py
index b74a3b9..d5f4dd8 100644
--- a/expansions/basic_control/code.py
+++ b/expansions/basic_control/code.py
@@ -74,7 +74,7 @@ class expansion_temp(expansion):
else:
answer = self.AnsBase[3] % (conf)
sleep(3.6)
- if ejoinTimerName(conf) in iThr.ThrNames():
+ if ejoinTimerName(conf) in iThr.getNames():
answer += self.AnsBase[13]
else:
answer = self.AnsBase[15] % (conf)
@@ -135,20 +135,18 @@ class expansion_temp(expansion):
Name = body.split()[0].lower()
else:
Name = get_disp(disp)
- if InstansesDesc.has_key(Name):
+ if InstancesDesc.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()
+ for Thr in iThr.enumerate():
+ if ThrName == Thr.getName():
+ Thr.kill()
if online(Name):
try:
Clients[Name].disconnect()
except IOError:
pass
- if connect_client(Name, InstansesDesc[Name])[0]:
+ if connect_client(Name, InstancesDesc[Name])[0]:
try:
StartThr(composeThr(Dispatcher, ThrName, (Name,)), -1)
except RuntimeError:
@@ -173,7 +171,7 @@ class expansion_temp(expansion):
Message(conf.name, exit_desclr, conf.disp)
sleep(6)
VarCache["alive"] = False
- iThr.Threads_kill()
+ iThr.killAllThreads()
for disp in Clients.keys():
if online(disp):
sUnavailable(disp, exit_desclr)
@@ -189,7 +187,7 @@ class expansion_temp(expansion):
Message(conf.name, exit_desclr, conf.disp)
sleep(6)
VarCache["alive"] = False
- iThr.Threads_kill()
+ iThr.killAllThreads()
for disp in Clients.keys():
if online(disp):
sUnavailable(disp, exit_desclr)
diff --git a/expansions/basic_control/insc.py b/expansions/basic_control/insc.py
index 41205cb..778fefb 100644
--- a/expansions/basic_control/insc.py
+++ b/expansions/basic_control/insc.py
@@ -28,7 +28,7 @@ else:
"I have joined -> '%s'", # 2
"I can't join -> '%s'", # 3
"Attention! %s (%s) ordered me to leave -> '%s'", # 4
- "Chat is already in list.", # 5
+ "Chat is already in the list.", # 5
"Apparently '%s' isn't a conference. I wouldn't join it.", # 6
"I'm %s -» XMPP BOT. Joined by order from %s", # 7
"Rejoin by command from %s", # 8
diff --git a/expansions/books/code.py b/expansions/books/code.py
index 4b96ac7..9089aad 100644
--- a/expansions/books/code.py
+++ b/expansions/books/code.py
@@ -3,11 +3,12 @@
# BlackSmith mark.2
# exp_name = "books" # /code.py v.x8
# Id: 29~8c
-# Code © (2011-2012) by WitcherGeralt [alkorgun@gmail.com]
+# Code © (2011-2013) by WitcherGeralt [alkorgun@gmail.com]
class expansion_temp(expansion):
def __init__(self, name):
+ check_sqlite()
expansion.__init__(self, name)
import fb2
@@ -82,11 +83,11 @@ class expansion_temp(expansion):
def command_get_books(self, stype, source, body, disp):
if body:
- list = body.split()
- a1 = (list.pop(0)).lower()
+ args = body.split()
+ a1 = (args.pop(0)).lower()
if a1 in ("show", "показать".decode("utf-8")):
- if list:
- a2 = (list.pop(0)).lower()
+ if args:
+ a2 = (args.pop(0)).lower()
if a2 in ("names", "названия".decode("utf-8")):
with database(self.BooksFile) as db:
db("select name from books order by name")
@@ -108,7 +109,7 @@ class expansion_temp(expansion):
}
if desc.has_key(a2):
a2 = desc.get(a2, None)
- if a2 in ls and list:
+ if a2 in ls and args:
a3 = body[((body.lower()).find(a0) + len(a0)):].strip()
if a2 in ("author", "genre"):
with database(self.BooksFile) as db:
@@ -148,7 +149,7 @@ class expansion_temp(expansion):
else:
answer = self.AnsBase[0]
elif a1 in ("info", "инфо".decode("utf-8")):
- if list:
+ if args:
a2 = body[((body.lower()).find(a1) + len(a1)):].strip()
a3 = self.getID(a2)
with database(self.BooksFile) as db:
@@ -184,8 +185,8 @@ class expansion_temp(expansion):
answer = AnsBase[2]
elif a1 in ("read", "читать".decode("utf-8")):
jid = get_source(source[1], source[2])
- if list:
- a2 = (list.pop(0)).lower()
+ if args:
+ a2 = (args.pop(0)).lower()
if a2 in ("next", "далее".decode("utf-8")):
if jid:
with database(self.ReadersFile) as db:
@@ -248,23 +249,23 @@ class expansion_temp(expansion):
answer = AnsBase[2]
else:
with database(self.BooksFile) as db:
- db("select id from books")
- db_desc = db.fetchall()
- if db_desc:
- answer = self.AnsBase[8] % len(db_desc)
+ db("select count(id) from books")
+ count = db.fetchone()
+ if count[0]:
+ answer = self.AnsBase[8] % count
else:
answer = self.AnsBase[0]
Answer(answer, stype, source, disp)
def command_set_books(self, stype, source, body, disp):
if body:
- list = body.split()
- if len(list) >= 2:
- a1 = (list.pop(0)).lower()
+ args = body.split()
+ if len(args) >= 2:
+ a1 = (args.pop(0)).lower()
if a1 in ("add", "добавить".decode("utf-8")):
- a2 = (list.pop(0)).lower()
+ a2 = (args.pop(0)).lower()
if a2 in ("file", "fb2", "файл".decode("utf-8")):
- if list:
+ if args:
Path = body[((body.lower()).find(a2) + len(a2)):].strip()
if AsciiSys:
Path = Path.encode("utf-8")
@@ -299,12 +300,12 @@ class expansion_temp(expansion):
else:
answer = self.AnsBase[15]
elif a1 in ("edit", "править".decode("utf-8")):
- if len(list) >= 4:
- a2 = self.getID(list.pop(0))
+ if len(args) >= 4:
+ a2 = self.getID(args.pop(0))
if a2:
- a3 = (list.pop(0)).lower()
+ a3 = (args.pop(0)).lower()
if a3 in ("info", "инфо".decode("utf-8")):
- a4 = (list.pop(0)).lower()
+ a4 = (args.pop(0)).lower()
a0, ls = a4, "author;year;genre;seq1;seq2;cover;annotation;link;name;c0".split(";")
desc = {
"автор".decode("utf-8"): ls[0],
@@ -322,7 +323,7 @@ class expansion_temp(expansion):
if desc.has_key(a4):
a4 = desc.get(a4, None)
if a4 in ls:
- a5 = (list.pop(0)).lower()
+ a5 = (args.pop(0)).lower()
if a4 in (ls[1], ls[4]):
if isNumber(a5):
a5 = int(a5)
@@ -354,7 +355,7 @@ class expansion_temp(expansion):
db("select page from %s" % a2)
lines = db.fetchall()
llens = len(lines)
- a4 = (list.pop(0)).lower()
+ a4 = (args.pop(0)).lower()
if a4 in ("add", "добавить".decode("utf-8")):
a5 = body[((body.lower()).find(a4) + len(a4)):].strip()
if llens:
@@ -366,9 +367,9 @@ class expansion_temp(expansion):
db.commit()
answer = AnsBase[4]
elif a4 in ("delete", "удалить".decode("utf-8")):
- a5 = (list.pop(0)).lower()
- if list:
- a6 = list.pop(0)
+ a5 = (args.pop(0)).lower()
+ if args:
+ a6 = args.pop(0)
if isNumber(a6):
a6 = int(a6)
if a5 in ("before", "до".decode("utf-8")):
@@ -436,7 +437,7 @@ class expansion_temp(expansion):
else:
answer = AnsBase[2]
elif a1 in ("delete", "удалить".decode("utf-8")):
- a2 = self.getID(list.pop(0))
+ a2 = self.getID(args.pop(0))
if a2:
with database(self.BooksFile) as db:
db("select * from books where id=?", (a2,))
diff --git a/expansions/config/code.py b/expansions/config/code.py
index d46b2f0..e76c4f3 100644
--- a/expansions/config/code.py
+++ b/expansions/config/code.py
@@ -71,12 +71,12 @@ class expansion_temp(expansion):
def command_cls_config(self, stype, source, body, disp):
if body:
- list = body.split()
- if len(list) >= 2:
- body = (list.pop(0)).lower()
+ args = body.split()
+ if len(args) >= 2:
+ body = (args.pop(0)).lower()
if body in ("del", "удалить".decode("utf-8")):
- Name = (list.pop(0)).lower()
- if InstansesDesc.has_key(Name):
+ Name = (args.pop(0)).lower()
+ if InstancesDesc.has_key(Name):
clients = Clients.keys()
if not Clients.has_key(Name) or len(clients) >= 2:
if Name == GenDisp:
@@ -99,12 +99,10 @@ class expansion_temp(expansion):
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 Thr in iThr.enumerate():
+ if ThrName == Thr.getName():
+ Thr.kill()
for conf in Chats.itervalues():
if conf.disp == Name:
if online(Name):
@@ -122,7 +120,7 @@ class expansion_temp(expansion):
pass
if Flood.has_key(Name):
del Flood[Name]
- del InstansesDesc[Name]
+ del InstancesDesc[Name]
for x in ConDisp.sections():
if Name == client_config(ConDisp, x)[0]:
ConDisp.remove_section(x)
@@ -135,22 +133,22 @@ class expansion_temp(expansion):
else:
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 len(args) >= 3:
+ host = (args.pop(0)).lower()
+ user = (args.pop(0)).lower()
+ code = (args.pop(0))
+ if args:
+ port = (args.pop(0))
if not isNumber(port):
port = "5222"
else:
port = "5222"
jid = "%s@%s" % (user, host)
serv = (host)
- if list:
- serv = (list.pop(0)).lower()
+ if args:
+ serv = (args.pop(0)).lower()
if not Clients.has_key(jid):
- if not InstansesDesc.has_key(jid):
+ if not InstancesDesc.has_key(jid):
if connect_client(jid, (serv, port, host, user, code))[0]:
Numb = itypes.Number()
Name = "CLIENT%d" % (len(ConDisp.sections()) + Numb.plus())
@@ -163,7 +161,7 @@ class expansion_temp(expansion):
ConDisp.set(Name, "user", user)
ConDisp.set(Name, "pass", code)
Instance, desc = client_config(ConDisp, Name)
- InstansesDesc[Instance] = desc
+ InstancesDesc[Instance] = desc
cat_file(ConDispFile, self.get_config(ConDisp))
try:
StartThr(composeThr(Dispatcher, "%s-%s" % (Types[13], Instance), (Instance,)), -1)
@@ -183,12 +181,12 @@ class expansion_temp(expansion):
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))
- if list:
- if (list.pop(0)).lower() in ("set", "записать".decode("utf-8")):
+ Name = (args.pop(0)).lower()
+ if InstancesDesc.has_key(Name):
+ if args:
+ code = (args.pop(0))
+ if args:
+ if (args.pop(0)).lower() in ("set", "записать".decode("utf-8")):
changed = True
else:
code, symbols = "", "%s.%s_%s+(!}{#)" % (CharCase[0], CharCase[1], CharCase[2])
@@ -230,11 +228,11 @@ class expansion_temp(expansion):
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)
+ serv = InstancesDesc[Name][0]
+ port = InstancesDesc[Name][1]
+ host = InstancesDesc[Name][2]
+ user = InstancesDesc[Name][3]
+ InstancesDesc[Name] = (serv, port, host, user, code)
answer = AnsBase[4]
else:
answer = AnsBase[7]
diff --git a/expansions/config/insc.py b/expansions/config/insc.py
index 3b79a7a..d697573 100644
--- a/expansions/config/insc.py
+++ b/expansions/config/insc.py
@@ -28,7 +28,7 @@ else:
"Forbidden!", # 7
"The system can not allocate resources to another client.", # 8
"No connection.", # 9
- "This jid is already in list.", # 10
+ "This jid is already in the list.", # 10
"'%s' not in clients-list.", # 11
"'%s' is offline." # 12
) \ No newline at end of file
diff --git a/expansions/cron/code.py b/expansions/cron/code.py
index c2e4608..b48f018 100644
--- a/expansions/cron/code.py
+++ b/expansions/cron/code.py
@@ -199,7 +199,7 @@ class expansion_temp(expansion):
def start_cron(self):
Name = self.def_cron.func_name
for Thr in iThr.enumerate():
- if Thr._Thread__name.startswith(Name):
+ if Thr.name.startswith(Name):
Thr.kill()
if initialize_file(self.CronFile, "({}, 0)"):
cdesc, ccnt = eval(get_file(self.CronFile))
diff --git a/expansions/info/code.py b/expansions/info/code.py
index 374e7b7..b23f4ee 100644
--- a/expansions/info/code.py
+++ b/expansions/info/code.py
@@ -11,8 +11,8 @@ class expansion_temp(expansion):
expansion.__init__(self, name)
def command_online(self, stype, source, body, disp):
- ls, ThrIds = self.AnsBase[7], iThr.ThrNames()
- for numb, disp_ in enumerate(sorted(InstansesDesc.keys()), 1):
+ ls, ThrIds = self.AnsBase[7], iThr.getNames()
+ for numb, disp_ in enumerate(sorted(InstancesDesc.keys()), 1):
alive = str("%s-%s" % (Types[13], disp_) in ThrIds)
connect = online(disp_)
if not connect:
diff --git a/expansions/note/code.py b/expansions/note/code.py
index 750efc1..ed2630f 100644
--- a/expansions/note/code.py
+++ b/expansions/note/code.py
@@ -1,13 +1,14 @@
# coding: utf-8
# BlackSmith mark.2
-# exp_name = "note" # /code.py v.x7
-# Id: 22~6c
-# Code © (2010-2011) by WitcherGeralt [alkorgun@gmail.com]
+# exp_name = "note" # /code.py v.x8
+# Id: 22~7c
+# Code © (2010-2013) by WitcherGeralt [alkorgun@gmail.com]
class expansion_temp(expansion):
def __init__(self, name):
+ check_sqlite()
expansion.__init__(self, name)
NoteFile = dynamic % ("notepad.db")
diff --git a/expansions/talkers/code.py b/expansions/talkers/code.py
index 110002a..34e96b6 100644
--- a/expansions/talkers/code.py
+++ b/expansions/talkers/code.py
@@ -1,19 +1,22 @@
# coding: utf-8
# BlackSmith mark.2
-# exp_name = "talkers" # /code.py v.x5
-# Id: 14~4c
-# Code © (2010-2012) by WitcherGeralt [alkorgun@gmail.com]
+# exp_name = "talkers" # /code.py v.x6
+# Id: 14~5c
+# Code © (2010-2013) by WitcherGeralt [alkorgun@gmail.com]
class expansion_temp(expansion):
def __init__(self, name):
+ check_sqlite()
expansion.__init__(self, name)
TalkersFile = "talkers.db"
TalkersDesc = {}
+ db = lambda self, conf: database(cefile(chat_file(conf, self.TalkersFile)), self.TalkersDesc[conf])
+
def command_talkers(self, stype, source, body, disp):
if Chats.has_key(source[1]):
if body:
@@ -29,11 +32,9 @@ class expansion_temp(expansion):
else:
Number = 0
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 order by -msgs")
- db_desc = db.fetchmany(Number if Number > 0 else 10)
+ with self.db(source[1]) as db:
+ db("select * from talkers order by -msgs")
+ db_desc = db.fetchmany(Number if Number > 0 else 10)
if db_desc:
answer, Numb = self.AnsBase[0], itypes.Number()
for x in db_desc:
@@ -43,11 +44,9 @@ class expansion_temp(expansion):
elif a2 in ("global", "глобальный".decode("utf-8")):
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 order by -msgs")
- db_desc = db.fetchmany(256)
+ with self.db(conf) as db:
+ db("select * from talkers order by -msgs")
+ db_desc = db.fetchmany(256)
for x in db_desc:
if Glob_dbs.has_key(x[0]):
Glob_dbs[x[0]][2] += x[2]
@@ -76,11 +75,9 @@ class expansion_temp(expansion):
def get_talker_stats(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()
+ with self.db(conf) as db:
+ db("select * from talkers where jid=?", (source_,))
+ db_desc = db.fetchone()
if db_desc:
x += db_desc[2]
y += db_desc[3]
@@ -108,11 +105,9 @@ class expansion_temp(expansion):
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)
+ with self.db(conf) 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]
@@ -138,11 +133,9 @@ class expansion_temp(expansion):
a2 = body[((body.lower()).find(a1) + len(a1)):].strip()
def get_talker_stats(source_, conf):
- filename = cefile(chat_file(conf, self.TalkersFile))
- with self.TalkersDesc[conf]:
- with database(filename) as db:
- db("select * from talkers where jid=?", (source_,))
- x = db.fetchone()
+ with self.db(conf) as db:
+ 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:
@@ -165,11 +158,9 @@ class expansion_temp(expansion):
if source_:
answer = get_talker_stats(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)
+ with self.db(source[1]) 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:
@@ -192,16 +183,14 @@ class expansion_temp(expansion):
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()
+ with self.db(source[1]) 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 init_talkers_base(self, conf):
filename = cefile(chat_file(conf, self.TalkersFile))
diff --git a/expansions/user_stats/code.py b/expansions/user_stats/code.py
index 9b395f0..b454c0c 100644
--- a/expansions/user_stats/code.py
+++ b/expansions/user_stats/code.py
@@ -1,30 +1,31 @@
# coding: utf-8
# BlackSmith mark.2
-# exp_name = "user_stats" # /code.py v.x6
-# Id: 17~5c
-# Code © (2010-2012) by WitcherGeralt [alkorgun@gmail.com]
+# exp_name = "user_stats" # /code.py v.x7
+# Id: 17~6c
+# Code © (2010-2013) by WitcherGeralt [alkorgun@gmail.com]
class expansion_temp(expansion):
def __init__(self, name):
+ check_sqlite()
expansion.__init__(self, name)
UstatsFile = "jstat.db"
UstatsDesc = {}
+ db = lambda self, conf: database(cefile(chat_file(conf, self.UstatsFile)), self.UstatsDesc[conf])
+
def command_user_stats(self, stype, 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.UstatsFile))
- with self.UstatsDesc[source[1]]:
- with database(filename) as db:
- db("select * from stat where jid=?", (body,))
- db_desc = db.fetchone()
+ with self.db(source[1]) as db:
+ db("select * from stat where jid=?", (body,))
+ db_desc = db.fetchone()
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]:
@@ -54,22 +55,21 @@ class expansion_temp(expansion):
def calc_stat_04eh(self, conf, nick, instance, role, stanza, disp):
if instance and nick != get_nick(conf):
- date, filename = strfTime(local = False), cefile(chat_file(conf, self.UstatsFile))
- with self.UstatsDesc[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()
+ date = strfTime(local = False)
+ with self.db(conf) 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(self, conf, nick, sbody, scode, disp):
if nick != get_nick(conf):
@@ -80,42 +80,37 @@ class expansion_temp(expansion):
sbody = "banned:(%s)" % (sbody)
elif scode == sCodes[2]:
sbody = "kicked:(%s)" % (sbody)
- date, filename = strfTime(local = False), cefile(chat_file(conf, self.UstatsFile))
- with self.UstatsDesc[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()
+ date = strfTime(local = False)
+ with self.db(conf) 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 calc_stat_06eh(self, conf, old_nick, nick, disp):
if nick != get_nick(conf):
source_ = get_source(conf, nick)
if source_:
- filename = cefile(chat_file(conf, self.UstatsFile))
- with self.UstatsDesc[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()
+ with self.db(conf) 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_nick(conf):
source_ = get_source(conf, nick)
if source_:
- filename = cefile(chat_file(conf, self.UstatsFile))
- with self.UstatsDesc[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()
+ with self.db(conf) 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.UstatsFile))
diff --git a/expansions/wtf/code.py b/expansions/wtf/code.py
index efc5943..ab3575f 100644
--- a/expansions/wtf/code.py
+++ b/expansions/wtf/code.py
@@ -1,13 +1,14 @@
# coding: utf-8
# BlackSmith mark.2
-# exp_name = "wtf" # /code.py v.x3
-# Id: 28~3c
-# Code © (2012) by WitcherGeralt [alkorgun@gmail.com]
+# exp_name = "wtf" # /code.py v.x4
+# Id: 28~4c
+# Code © (2012-2013) by WitcherGeralt [alkorgun@gmail.com]
class expansion_temp(expansion):
def __init__(self, name):
+ check_sqlite()
expansion.__init__(self, name)
Base = dynamic % ("wtf.db")
diff --git a/expansions/wtf/insc.py b/expansions/wtf/insc.py
index fa20ac0..8c8c750 100644
--- a/expansions/wtf/insc.py
+++ b/expansions/wtf/insc.py
@@ -4,7 +4,7 @@ if DefLANG in ("RU", "UA"):
AnsBase_temp = tuple([line.decode("utf-8") for line in (
"Всего %d определений в глобальной базе:\n%s", # 0
"Всего %d определений в базе %s:\n%s", # 1
- "Базы пусты", # 2
+ "Базы пусты.", # 2
"%s - %d соответствий.", # 3
"Нет соответсвий в базах.", # 4
"\->\n%s:\n\t%s\n\nDefined by %s (on %s)", # 5