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>2012-11-30 06:56:59 +0400
committerAl Korgun <alkorgun@gmail.com>2012-11-30 06:56:59 +0400
commit239c9783d602b52d08d83c4ac60bde2c521ddbba (patch)
treec01019977b8cfb704405309683c409b416603ffd
parent6859929406b0cde290f9ec9b0d72d2bb9d93d308 (diff)
expansion "info" refactored and command "time" added
-rw-r--r--BlackSmith.py26
-rw-r--r--expansions/alive_keeper/code.py2
-rw-r--r--expansions/bot_sends/code.py14
-rw-r--r--expansions/get_iq/code.py87
-rw-r--r--expansions/get_iq/time.en8
-rw-r--r--expansions/get_iq/time.name4
-rw-r--r--expansions/get_iq/time.ru8
-rw-r--r--expansions/info/code.py57
-rw-r--r--expansions/info/insc.py8
9 files changed, 163 insertions, 51 deletions
diff --git a/BlackSmith.py b/BlackSmith.py
index 707a00d..9c1c391 100644
--- a/BlackSmith.py
+++ b/BlackSmith.py
@@ -242,7 +242,7 @@ if not sys.stdin.isatty():
sys.stdout = stdout
sys.stderr = stdout
if eColors:
- eColors = None
+ eColors = not eColors
else:
stdout = sys.stdout
@@ -260,7 +260,7 @@ GenConFile = static % ("config.ini")
ConDispFile = static % ("clients.ini")
ChatsFile = dynamic % ("chats.db")
-(BsMark, BsVer, BsRev) = (2, 37, 0)
+(BsMark, BsVer, BsRev) = (2, 38, 0)
if os.access(SvnCache, os.R_OK):
Cache = open(SvnCache).readlines()
@@ -849,11 +849,11 @@ def Message(inst, body, disp = None):
Sender(disp, xmpp.Message(inst, body.strip(), stype))
def Answer(body, stype, source, disp = None):
- body = object_encode(body)
- if stype == Types[1]:
- instance, body = source[1], "%s: %s" % (source[2], body)
- else:
+ if stype == Types[0]:
instance = source[0]
+ else:
+ body = "%s: %s" % (source[2], object_encode(body))
+ instance = source[1]
Message(instance, body, disp)
def CheckFlood(disp):
@@ -1396,6 +1396,13 @@ def XmppIqCB(disp, stanza):
else:
os_name = "Os[%s]" % (BotOs)
anode.setTagData("os", "%s / PyVer[%s]" % (os_name, PyVer))
+ elif Name == xmpp.NS_URN_TIME:
+ anode = answer.addChild(Types[17], namespace = xmpp.NS_URN_TIME)
+ anode.setTagData("utc", strfTime("%Y-%m-%dT%H:%M:%SZ", False))
+ TimeZone = (time.altzone if time.daylight else time.timezone)
+ anode.setTagData("tzo", "%s%02d:%02d" % (((TimeZone < 0) and "+" or "-"),
+ abs(TimeZone) / 3600,
+ abs(TimeZone) / 60 % 60))
elif Name == xmpp.NS_TIME:
anode = answer.getTag(Types[18])
anode.setTagData("utc", strfTime("%Y%m%dT%H:%M:%S", False))
@@ -1404,13 +1411,6 @@ def XmppIqCB(disp, stanza):
tz = tz.decode("cp1251")
anode.setTagData("tz", tz)
anode.setTagData("display", time.asctime())
- elif Name == xmpp.NS_URN_TIME:
- anode = answer.addChild(Types[17], namespace = xmpp.NS_URN_TIME)
- anode.setTagData("utc", strfTime("%Y-%m-%dT%H:%M:%SZ", False))
- TimeZone = (time.altzone if time.daylight else time.timezone)
- anode.setTagData("tzo", "%s%02d:%02d" % (((TimeZone < 0) and "+" or "-"),
- abs(TimeZone) / 3600,
- abs(TimeZone) / 60 % 60))
Sender(disp, answer)
xmpp_raise()
call_efunctions("03eh", (stanza, disp,))
diff --git a/expansions/alive_keeper/code.py b/expansions/alive_keeper/code.py
index a614a13..be42720 100644
--- a/expansions/alive_keeper/code.py
+++ b/expansions/alive_keeper/code.py
@@ -3,7 +3,7 @@
# BlackSmith mark.2
# exp_name = "alive_keeper" # /code.py v.x5
# Id: 16~5c
-# Code © (2011) by WitcherGeralt [alkorgun@gmail.com]
+# Code © (2011-2012) by WitcherGeralt [alkorgun@gmail.com]
class expansion_temp(expansion):
diff --git a/expansions/bot_sends/code.py b/expansions/bot_sends/code.py
index 5936ed8..80ef6f7 100644
--- a/expansions/bot_sends/code.py
+++ b/expansions/bot_sends/code.py
@@ -1,9 +1,9 @@
# coding: utf-8
# BlackSmith mark.2
-# exp_name = "bot_sends" # /code.py v.x6
-# Id: 18~5c
-# Code © (2010-2011) by WitcherGeralt [alkorgun@gmail.com]
+# exp_name = "bot_sends" # /code.py v.x7
+# Id: 18~6c
+# Code © (2010-2012) by WitcherGeralt [alkorgun@gmail.com]
class expansion_temp(expansion):
@@ -65,13 +65,13 @@ class expansion_temp(expansion):
def command_send(self, stype, source, body, disp):
if body:
- list = body.split()
- if len(list) >= 2:
- sTo = list[0]
+ body = body.split(None, 1)
+ if len(body) == 2:
+ sTo, body = body
if isSource(sTo):
conf = (sTo.split(chr(47)))[0].lower()
if Chats.has_key(conf) or not conf.count("@conf"):
- Message(sTo, self.AnsBase[5] % (source[2], body[(body.find(sTo) + len(sTo)):].strip()))
+ Message(sTo, self.AnsBase[5] % (source[2], body))
answer = AnsBase[4]
else:
answer = AnsBase[8]
diff --git a/expansions/get_iq/code.py b/expansions/get_iq/code.py
index f154533..6a1d03f 100644
--- a/expansions/get_iq/code.py
+++ b/expansions/get_iq/code.py
@@ -1,8 +1,8 @@
# coding: utf-8
# BlackSmith mark.2
-# exp_name = "get_iq" # /code.py v.x6
-# Id: 13~5c
+# exp_name = "get_iq" # /code.py v.x7
+# Id: 13~6c
# Code © (2010-2012) by WitcherGeralt [alkorgun@gmail.com]
class expansion_temp(expansion):
@@ -82,6 +82,88 @@ class expansion_temp(expansion):
answer = self.AnsBase[4]
Answer(answer, stype, source, disp)
+ def command_time(self, stype, source, instance, disp):
+ 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), stype, source, disp)
+ raise iThr.ThrKill("exit")
+ else:
+ instance = source[0]
+ iq = xmpp.Iq(to = instance, typ = Types[10])
+ iq.addChild(Types[18], namespace = xmpp.NS_URN_TIME)
+ iq.setID("Bs-i%d" % Info["outiq"].plus())
+ CallForResponse(disp, iq, self.answer_time0202, {"stype": stype, "source": source, "instance": instance})
+
+ def answer_time0202(self, disp, stanza, stype, source, instance):
+ if xmpp.isResultNode(stanza):
+ hours = None
+ for node in stanza.getChildren():
+ tzo = node.getTagData("tzo")
+ if tzo and tzo.startswith((chr(43), chr(45))):
+ try:
+ hours, minutes = tzo[1:].split(chr(58))
+ symbol = tzo[0]
+ hours, minutes = int(symbol + hours), int(symbol + minutes)
+ except:
+ pass
+ else:
+ break
+ if isinstance(hours, int):
+ plus = (symbol == chr(43))
+ date = list(time.gmtime())
+ days = (31, 31, (28 if (date[0] % 4) else 29), 31, 30, 31, 30, 31, 31, 30, 31, 30, 31)
+ date[4] += minutes
+ date[3] += hours
+ if date[4] >= 60:
+ date[4] -= 60
+ date[3] += 1
+ if date[3] >= 24:
+ date[3] -= 24
+ if plus:
+ date[2] += 1
+ if date[2] > days[date[1]]:
+ date[2] = 1
+ date[1] += 1
+ if date[1] > 12:
+ date[1] = 1
+ date[0] += 1
+ else:
+ date[2] -= 1
+ if not date[2]:
+ date[1] -= 1
+ date[2] = days[date[1]]
+ if not date[1]:
+ date[1] = 12
+ date[0] -= 1
+ try:
+ date = time.struct_time(date)
+ except:
+ answer = self.AnsBase[6]
+ else:
+ answer = time.strftime("%a %b %d %H:%M:%S %Y", date)
+ else:
+ answer = self.AnsBase[6]
+ Answer(answer, stype, source, disp)
+ else:
+ iq = xmpp.Iq(to = instance, typ = Types[10])
+ iq.addChild(Types[18], namespace = xmpp.NS_TIME)
+ iq.setID("Bs-i%d" % Info["outiq"].plus())
+ CallForResponse(disp, iq, self.answer_time0090, {"stype": stype, "source": source})
+
+ def answer_time0090(self, disp, stanza, stype, source):
+ if xmpp.isResultNode(stanza):
+ Time = None
+ for node in stanza.getQueryChildren():
+ if "display" == node.getName():
+ Time = node.getData()
+ answer = Time or self.AnsBase[6]
+ else:
+ answer = self.AnsBase[6]
+ Answer(answer, stype, source, disp)
+
def command_version(self, stype, source, instance, disp):
if instance:
if Chats.has_key(source[1]) and Chats[source[1]].isHere(instance):
@@ -363,6 +445,7 @@ class expansion_temp(expansion):
commands = (
(command_ping, "ping", 1,),
(command_ping_stats, "pstat", 1,),
+ (command_time, "time", 1,),
(command_version, "version", 1,),
(command_vcard, "vcard", 2,),
(command_uptime, "uptime", 1,),
diff --git a/expansions/get_iq/time.en b/expansions/get_iq/time.en
new file mode 100644
index 0000000..4d40048
--- /dev/null
+++ b/expansions/get_iq/time.en
@@ -0,0 +1,8 @@
+shows local time of the user
+time (nick/jid)
+*/time
+bot would show your time
+*/time Dude
+bot would show the time of Dude
+*/time dude@jabr.com
+bot would show the time of dude@jabr.com \ No newline at end of file
diff --git a/expansions/get_iq/time.name b/expansions/get_iq/time.name
new file mode 100644
index 0000000..a97a3dd
--- /dev/null
+++ b/expansions/get_iq/time.name
@@ -0,0 +1,4 @@
+{
+ "RU": "время",
+ "UA": "время"
+} \ No newline at end of file
diff --git a/expansions/get_iq/time.ru b/expansions/get_iq/time.ru
new file mode 100644
index 0000000..a1152a7
--- /dev/null
+++ b/expansions/get_iq/time.ru
@@ -0,0 +1,8 @@
+показывает локальное время пользователя
+время (nick/jid)
+*/время
+бот покажет ваще время
+*/время Dude
+бот покажет время "Dude"
+*/время dude@jab.com
+бот покажет время "dude@jab.com" \ No newline at end of file
diff --git a/expansions/info/code.py b/expansions/info/code.py
index c008197..52d68d6 100644
--- a/expansions/info/code.py
+++ b/expansions/info/code.py
@@ -1,8 +1,8 @@
# coding: utf-8
# BlackSmith mark.2
-# exp_name = "info" # /code.py v.x6
-# Id: 11~5c
+# exp_name = "info" # /code.py v.x7
+# Id: 11~6c
# Code © (2010-2012) by WitcherGeralt [alkorgun@gmail.com]
class expansion_temp(expansion):
@@ -13,7 +13,8 @@ class expansion_temp(expansion):
def command_online(self, stype, source, body, disp):
ls, ThrIds = self.AnsBase[7], iThr.ThrNames()
for numb, disp_ in enumerate(sorted(InstansesDesc.keys()), 1):
- connect, alive = online(disp_), str("%s-%s" % (Types[13], disp_) in ThrIds)
+ alive = str("%s-%s" % (Types[13], disp_) in ThrIds)
+ connect = online(disp_)
if not connect:
connect = None
ls += "\n%d) %s - %s - %s" % (numb, disp_, str(connect), alive)
@@ -63,7 +64,7 @@ class expansion_temp(expansion):
def command_conflist(self, stype, source, body, disp):
ls, Numb, access = [], itypes.Number(), enough_access(source[1], source[2], 7)
for conf_str, conf in sorted(Chats.items()):
- isModer = str(conf.isModer)
+ arole = getattr(conf.get_user(conf.nick), "role", None)
cName = conf_str.split("@")[0]
disp_ = (conf.disp if access else "***")
cPref = str(conf.cPref)
@@ -71,7 +72,7 @@ class expansion_temp(expansion):
for nick in conf.get_users():
if nick.ishere:
online.plus()
- ls.append("%d) %s/%s [%s] \"%s\" (%s) - %s" % (Numb.plus(), cName, conf.nick, disp_, cPref, online._str(), isModer))
+ ls.append("%d) %s/%s [%s] \"%s\" (%s) - %s" % (Numb.plus(), cName, conf.nick, disp_, cPref, online._str(), ("%s/%s" % arole if arole else str(arole))))
if ls:
if stype == Types[1]:
Answer(AnsBase[11], stype, source, disp)
@@ -84,8 +85,6 @@ class expansion_temp(expansion):
if Chats.has_key(source[1]):
if body:
body = body.lower()
- else:
- body = "default"
if body in ("today", "сегодня".decode("utf-8")):
Number = itypes.Number()
Numb = itypes.Number()
@@ -102,22 +101,22 @@ class expansion_temp(expansion):
Numb.plus()
if Number._int():
if stype == Types[1]:
- Answer(AnsBase[11], stype, source, disp)
+ answer = AnsBase[11]
Message(source[0], self.AnsBase[0] % (Number._str(), str.join(chr(10), ls), Numb._str()), disp)
else:
- Answer(self.AnsBase[1], stype, source, disp)
+ answer = self.AnsBase[1]
elif body in ("dates", "даты".decode("utf-8")):
Number = itypes.Number()
ls = []
for nick in Chats[source[1]].sorted_users():
ls.append("%d. %s\t\t%s" % (Number.plus(), nick.nick, nick.date[2]))
if stype == Types[1]:
- Answer(AnsBase[11], stype, source, disp)
+ answer = AnsBase[11]
Message(source[0], self.AnsBase[2] % (Number._str(), str.join(chr(10))), disp)
elif body in ("list", "лист".decode("utf-8")):
ls = sorted(Chats[source[1]].get_nicks())
if stype == Types[1]:
- Answer(AnsBase[11], stype, source, disp)
+ answer = AnsBase[11]
Message(source[0], self.AnsBase[2] % (str(len(ls)), ", ".join(ls)), disp)
else:
Number = itypes.Number()
@@ -133,30 +132,40 @@ class expansion_temp(expansion):
Numb.plus()
if Number._int():
if stype == Types[1]:
- Answer(AnsBase[11], stype, source, disp)
+ answer = AnsBase[11]
Message(source[0], self.AnsBase[3] % (Number._str(), str.join(chr(10), ls), Numb._str()), disp)
else:
- Answer(self.AnsBase[4], stype, source, disp)
+ answer = self.AnsBase[4]
else:
- Answer(AnsBase[0], stype, source, disp)
+ answer = AnsBase[0]
+ if locals().has_key(Types[6]):
+ Answer(answer, stype, source, disp)
+
+ CharsCY = "етуоранкхсвм".decode("utf-8")
+ CharsLA = "etyopahkxcbm"
+
+ eqMap = tuple([(CharsCY[numb], char) for numb, char in enumerate(CharsLA)])
+
+ del CharsCY, CharsLA
def command_search(self, stype, source, body, disp):
if body:
- ls, Numb, access = "", itypes.Number(), enough_access(source[1], source[2], 7)
+ ls, Numb, access = [], itypes.Number(), enough_access(source[1], source[2], 7)
+ body = sub_desc(body.lower(), self.eqMap)
for conf_str, conf in sorted(Chats.items()):
- for nick in sorted(conf.get_nicks()):
- if conf.isHereTS(nick):
- jid = get_source(conf_str, nick)
- if nick.count(body) or (jid and jid.count(body)):
- ls += "\n%d) %s (%s)" % (Numb.plus(), nick, conf_str)
- if jid and access:
- ls += " [%s]" % (jid)
+ for user in conf.sorted_users():
+ if user.ishere:
+ if body in sub_desc(user.nick.lower(), self.eqMap) or (user.source and body in sub_desc(user.source, self.eqMap)):
+ if user.source and access:
+ ls.append("%d) %s (%s) [%s]" % (Numb.plus(), user.nick, conf_str, user.source))
+ else:
+ ls.append("%d) %s (%s)" % (Numb.plus(), user.nick, conf_str))
if Numb._int() >= 20:
break
if Numb._int():
if stype == Types[1]:
- Answer(AnsBase[11], stype, source, disp)
- Message(source[0], self.AnsBase[9] % (Numb._str(), ls), disp)
+ answer = AnsBase[11]
+ Message(source[0], self.AnsBase[9] % (Numb._str(), str.join(chr(10), ls)), disp)
else:
answer = self.AnsBase[10]
else:
diff --git a/expansions/info/insc.py b/expansions/info/insc.py
index 59207f3..cc8e891 100644
--- a/expansions/info/insc.py
+++ b/expansions/info/insc.py
@@ -7,11 +7,11 @@ if DefLANG in ("RU", "UA"):
"При мне заходило %s юзеров:\n%s", # 2
"Здесь было %s юзеров:%s\n+ ещё %s досихпор здесь.", # 3
"При мне ещё никто не выходил, все кто был досихпор здесь.", # 4
- "[№] [Конфа/Ник] [Жид] [Префикc] [Юзеров] [Админ]", # 5
+ "[№] [Конфа/Ник] [Жид] [Префикc] [Юзеров] [Роль]", # 5
"В списке конференций - пусто.", # 6
"[№][Клиент][Коннект][Активен]", # 7
"Список юзеров в чате:", # 8
- "Нашел %s похожих пользователей:%s", # 9
+ "Нашел %s похожих пользователей:\n%s", # 9
"Не знаю." # 10
)])
else:
@@ -21,10 +21,10 @@ else:
"When I was still, there were %s visitors here:\n%s", # 2
"There were %s visitors here:%s\n+ %s are still here.", # 3
"Nobody leaved, all users are steel here.", # 4
- "[#] [Chat/Nick] [Jid] [Prefix] [Users] [Admin]", # 5
+ "[#] [Chat/Nick] [Jid] [Prefix] [Users] [Role]", # 5
"The list of conferences is empty.", # 6
"[#][Client][Connected][isActive]", # 7
"Users-list:", # 8
- "Total %s similar users:%s", # 9
+ "Total %s similar users:\n%s", # 9
"No result." # 10
) \ No newline at end of file