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-25 01:49:04 +0400
committerAl Korgun <alkorgun@gmail.com>2012-11-25 01:49:04 +0400
commit46ba2c68d796fb338aae36f563c6df1ec9467592 (patch)
tree315ca92105ba5a3bdf587362e833d92d24dbdd12
parent4c3a832c9f544f56df0887b62280c8c326e4b11d (diff)
expansion "wtf" added
-rw-r--r--BlackSmith.py8
-rw-r--r--expansions/books/books.en2
-rw-r--r--expansions/books/books.ru2
-rw-r--r--expansions/books/code.py22
-rw-r--r--expansions/sconf_attrs/code.py10
-rw-r--r--expansions/wtf/code.py183
-rw-r--r--expansions/wtf/def.en10
-rw-r--r--expansions/wtf/def.name4
-rw-r--r--expansions/wtf/def.ru10
-rw-r--r--expansions/wtf/insc.py30
-rw-r--r--expansions/wtf/wtf.en10
-rw-r--r--expansions/wtf/wtf.name4
-rw-r--r--expansions/wtf/wtf.ru10
13 files changed, 281 insertions, 24 deletions
diff --git a/BlackSmith.py b/BlackSmith.py
index 5355299..c94a726 100644
--- a/BlackSmith.py
+++ b/BlackSmith.py
@@ -1203,11 +1203,7 @@ def Size2Text(Size):
if not (ls and Size):
return str.join(chr(32), ext)
-def enumerated_list(list):
- ls, Numb = [], itypes.Number()
- for line in list:
- ls.append(AnsBase[12] % (Numb.plus(), line))
- return str.join(chr(10), ls)
+enumerated_list = lambda ls: str.join(chr(10), ["%d) %s" % (numb, line) for numb, line in enumerate(ls, 1)])
isNumber = lambda obj: (not exec_(int, (obj,)) is None)
@@ -1498,7 +1494,7 @@ def Xmpp_Message_Cb(disp, stanza):
if Cmds.has_key(command):
VarCache["idle"] = time.time()
VarCache["action"] = AnsBase[27] % command.upper()
- Cmds[command].execute(stype, (source, instance, nick), ((Copy.pop(0)).rstrip() if Copy else ""), disp)
+ Cmds[command].execute(stype, (source, instance, nick), (Copy.pop() if Copy else ""), disp)
else:
call_efunctions("01eh", (stanza, isConf, stype, (source, instance, nick), body, isToBs, disp,))
diff --git a/expansions/books/books.en b/expansions/books/books.en
index 847f293..beda23e 100644
--- a/expansions/books/books.en
+++ b/expansions/books/books.en
@@ -1,4 +1,4 @@
-watch/read library content
+shows library content
books ([show] (names)/([author/genre/cycle] [parameters]))/([info] [book's_name])/([read] ((page_number) [book's_name])/(next))
*/books
bot would show books count
diff --git a/expansions/books/books.ru b/expansions/books/books.ru
index a5b0df7..c7cf49e 100644
--- a/expansions/books/books.ru
+++ b/expansions/books/books.ru
@@ -1,4 +1,4 @@
-просмотр/чтение содержимого библиотеки
+просмотр содержимого библиотеки
книги ([показать] (названия)/([автор/жанр/серию] [параметры]))/([инфо] [имя_книги])/([читать] ((номер_страницы) [имя_книги])/(далее))
*/книги
бот покажет количество книг в библиотеке
diff --git a/expansions/books/code.py b/expansions/books/code.py
index df89245..c049ae0 100644
--- a/expansions/books/code.py
+++ b/expansions/books/code.py
@@ -1,8 +1,8 @@
# coding: utf-8
# BlackSmith mark.2
-exp_name = "books" # /code.py v.x5 alpha
-# Id: 29~5b
+exp_name = "books" # /code.py v.x6 alpha
+# Id: 29~6b
# Code © (2011-2012) by WitcherGeralt [alkorgun@gmail.com]
expansion_register(exp_name)
@@ -16,7 +16,7 @@ class expansion_temp(expansion):
BooksFile, ReadersFile = dynamic % ("books.db"), dynamic % ("readers.db")
- def importFB2(self, path):
+ def importFB2(self, path, nick):
book = get_file(path)
book_enc = self.fb2.get_enc(book)
if not book_enc:
@@ -36,7 +36,7 @@ class expansion_temp(expansion):
db("select * from books where id=?", (a2,))
db_desc = db.fetchone()
if not db_desc:
- db("insert into books (id, name, nick, date) values (?,?,?,?)", (a2, Name, "WitcherGeralt", time.asctime()))
+ db("insert into books (id, name, nick, date) values (?,?,?,?)", (a2, Name, nick, time.asctime()))
if author:
db("update books set author=? where id=?", (author, a2))
if date:
@@ -175,7 +175,7 @@ class expansion_temp(expansion):
ls.append("Link: %s" % (link))
if Annt:
ls.append("Annotation:\n\t%s" % (Annt))
- ls.append("\nAdded by: %s (The Last Upd.: %s)" % (Nick, Date))
+ ls.append("\nAdded by %s (The Last Upd. %s)" % (Nick, Date))
answer = str.join(chr(10), ls)
else:
answer = self.AnsBase[3]
@@ -265,16 +265,16 @@ class expansion_temp(expansion):
if a2 in ("file", "fb2", "файл".decode("utf-8")):
if list:
Path = body[((body.lower()).find(a2) + len(a2)):].strip()
- try:
- exists = os.path.isfile(Path)
- except:
- exists = False
- if exists:
+ if AsciiSys:
+ Path = Path.encode("utf-8")
+ if os.path.isfile(Path):
try:
- self.importFB2(Path)
+ self.importFB2(Path, source[2].strip())
except SelfExc:
answer = exc_info()[1]
except:
+ if AsciiSys:
+ Path = Path.decode("utf-8")
collectExc(self.importFB2, "library add fb2 %s" % Path)
answer = AnsBase[7]
else:
diff --git a/expansions/sconf_attrs/code.py b/expansions/sconf_attrs/code.py
index e91d95e..d36b87d 100644
--- a/expansions/sconf_attrs/code.py
+++ b/expansions/sconf_attrs/code.py
@@ -98,15 +98,15 @@ class expansion_temp(expansion):
def command_status(self, ltype, source, body, disp):
if body:
- list = body.split(None, 2)
- if len(list) == 3:
- state = list[1].lower()
+ body = body.split(None, 2)
+ if len(body) == 3:
+ state = (body.pop(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()
+ chat, status = body
body = "%s|%s" % (state, status)
+ chat = chat.lower()
if chat in ("everywhere", "везде".decode("utf-8")):
for conf in Chats.keys():
Chats[conf].change_status(state, status)
diff --git a/expansions/wtf/code.py b/expansions/wtf/code.py
new file mode 100644
index 0000000..be16ce7
--- /dev/null
+++ b/expansions/wtf/code.py
@@ -0,0 +1,183 @@
+# coding: utf-8
+
+# BlackSmith mark.2
+exp_name = "wtf" # /code.py v.x1
+# Id: 28~1b
+# Code © (2012) by WitcherGeralt [alkorgun@gmail.com]
+
+expansion_register(exp_name)
+
+class expansion_temp(expansion):
+
+ def __init__(self, name):
+ expansion.__init__(self, name)
+
+ Base = dynamic % ("wtf.db")
+ ChatBase = "wtf.db"
+
+ def command_wtf(self, ltype, source, body, disp):
+ if body:
+ ls = body.split(None, 1)
+ ar = (ls.pop(0)).lower()
+ if ar in ("all", "всё".decode("utf-8")):
+ ls = []
+ with database(self.Base) as db:
+ db("select name from wtf order by name")
+ defs = db.fetchall()
+ if defs:
+ ls.append(self.AnsBase[0] % (len(defs), enumerated_list([name[0].capitalize() for name in defs])))
+ if Chats.has_key(source[1]):
+ with database(cefile(chat_file(source[1], self.ChatBase))) as db:
+ db("select name from wtf order by name")
+ defs = db.fetchall()
+ if defs:
+ ls.append(self.AnsBase[1] % (len(defs), source[1], enumerated_list([name[0].capitalize() for name in defs])))
+ if ls:
+ answer = self.AnsBase[-1] + str.join(chr(10)*2, ls)
+ else:
+ answer = self.AnsBase[2]
+ elif ar in ("search", "искать".decode("utf-8")):
+ if ls:
+ body = ls[0].lower()
+ ls = []
+ with database(self.Base) as db:
+ db("select name, data from wtf order by name")
+ desc = db.fetchall()
+ if desc:
+ for name, data in desc:
+ data = data.lower()
+ numb = data.count(body)
+ if numb or body in name or name in body:
+ ls.append(self.AnsBase[3] % (name.capitalize(), numb))
+ if Chats.has_key(source[1]):
+ with database(cefile(chat_file(source[1], self.ChatBase))) as db:
+ db("select name, data from wtf order by name")
+ desc = db.fetchall()
+ if desc:
+ for name, data in desc:
+ data = data.lower()
+ numb = data.count(body)
+ if numb or body in name or name in body:
+ ls.append(self.AnsBase[3] % (name.capitalize(), numb))
+ if ls:
+ answer = self.AnsBase[-1] + enumerated_list(ls)
+ else:
+ answer = self.AnsBase[4]
+ else:
+ name = body.lower()
+ answer = None
+ with database(self.Base) as db:
+ db("select * from wtf where name=?", (name,))
+ desc = db.fetchone()
+ if desc:
+ name, data, nick, date = desc
+ answer = self.AnsBase[5] % (name.capitalize(), data, nick, date)
+ if Chats.has_key(source[1]) and not answer:
+ with database(cefile(chat_file(source[1], self.ChatBase))) as db:
+ db("select * from wtf where name=?", (name,))
+ desc = db.fetchone()
+ if desc:
+ name, data, nick, date = desc
+ answer = self.AnsBase[5] % (name.capitalize(), data, nick, date)
+ if not answer:
+ answer = self.AnsBase[6] % (name)
+ else:
+ ls = []
+ with database(self.Base) as db:
+ db("select name from wtf order by name")
+ defs = db.fetchall()
+ if defs:
+ ls.append(self.AnsBase[7] % len(defs))
+ if Chats.has_key(source[1]):
+ with database(cefile(chat_file(source[1], self.ChatBase))) as db:
+ db("select name from wtf order by name")
+ defs = db.fetchall()
+ if defs:
+ ls.append(self.AnsBase[8] % (len(defs), source[1]))
+ if ls:
+ answer = self.AnsBase[-1] + str.join(chr(10), ls)
+ else:
+ answer = self.AnsBase[2]
+ Answer(answer, ltype, source, disp)
+
+ sep = chr(61)
+
+ def addDef(self, base, name, data, nick):
+ with database(base) as db:
+ db("select date from wtf where name=?", (name,))
+ date = db.fetchone()
+ if data:
+ if date:
+ db("update wtf set data=?, nick=?, date=? where name=?", (data, nick, time.asctime(), name))
+ else:
+ db("insert into wtf values (?,?,?,?)", (name, data, nick, time.asctime()))
+ db.commit()
+ answer = AnsBase[4]
+ elif date:
+ db("delete from wtf where name=?", (name,))
+ db.commit()
+ answer = AnsBase[4]
+ else:
+ answer = self.AnsBase[6] % (name)
+ return answer
+
+ def command_def(self, ltype, source, body, disp):
+ if body:
+ ls = body.split(None, 1)
+ ar = (ls.pop(0)).lower()
+ if ar in ("globally", "глобально".decode("utf-8")):
+ if enough_access(source[1], source[2], 7):
+ if ls and self.sep in ls[0]:
+ ls = ls[0].split(self.sep, 1)
+ name, data = ls
+ name, data = (name.rstrip()).lower(), data.lstrip()
+ if name and len(name) <= 64:
+ answer = self.addDef(self.Base, name, data, source[2])
+ else:
+ answer = AnsBase[2]
+ else:
+ answer = AnsBase[2]
+ else:
+ answer = AnsBase[10]
+ elif self.sep in body:
+ ls = body.split(self.sep, 1)
+ name, data = ls
+ name, data = (name.rstrip()).lower(), data.lstrip()
+ if name and len(name) <= 64:
+ with database(self.Base) as db:
+ db("select date from wtf where name=?", (name,))
+ date = db.fetchone()
+ if date and data:
+ answer = self.AnsBase[9] % (name)
+ else:
+ answer = self.addDef(cefile(chat_file(source[1], self.ChatBase)), name, data, source[2])
+ else:
+ answer = AnsBase[2]
+ else:
+ answer = AnsBase[2]
+ else:
+ answer = AnsBase[1]
+ Answer(answer, ltype, source, disp)
+
+ def init_wtf_base(self):
+ if not os.path.isfile(self.Base):
+ with database(self.Base) as db:
+ db("create table wtf (name text, data text, nick text, date text)")
+ db.commit()
+
+ def init_local_wtf_base(self, conf):
+ filename = cefile(chat_file(conf, self.ChatBase))
+ if not os.path.isfile(filename):
+ with database(filename) as db:
+ db("create table wtf (name text, data text, nick text, date text)")
+ db.commit()
+
+ commands = (
+ (command_wtf, "wtf", 2,),
+ (command_def, "def", 4,)
+ )
+
+ handlers = (
+ (init_wtf_base, "00si"),
+ (init_local_wtf_base, "01si")
+ )
diff --git a/expansions/wtf/def.en b/expansions/wtf/def.en
new file mode 100644
index 0000000..2d6c1d9
--- /dev/null
+++ b/expansions/wtf/def.en
@@ -0,0 +1,10 @@
+control of wtf-bases
+def (globally) [name] [=] (definition)
+*/def google = Young Skynet
+bot would add "google" to the base of conference
+*/def google =
+bot would delete "google" from the base of conference
+*/def globally apple = Fruiterer
+bot would add "apple" to the global base (access 7)
+*/def globally apple =
+bot would delete "apple" from the global base (access 7) \ No newline at end of file
diff --git a/expansions/wtf/def.name b/expansions/wtf/def.name
new file mode 100644
index 0000000..0178896
--- /dev/null
+++ b/expansions/wtf/def.name
@@ -0,0 +1,4 @@
+{
+ "RU": "задать",
+ "UA": "задать"
+} \ No newline at end of file
diff --git a/expansions/wtf/def.ru b/expansions/wtf/def.ru
new file mode 100644
index 0000000..039ec62
--- /dev/null
+++ b/expansions/wtf/def.ru
@@ -0,0 +1,10 @@
+контроллер баз определений (wtf)
+задать (глобально) [название] [=] (определение)
+*/задать google = Young Skynet
+бот добавит "google" в базу определений конференции
+*/задать google =
+бот удалит "google" из базы определений конференции
+*/задать глобально apple = Fruiterer
+бот добавит "apple" в глобальную базу определений (доступ 7)
+*/задать глобально apple =
+бот удалит "apple" из глобальной базы определений (доступ 7) \ No newline at end of file
diff --git a/expansions/wtf/insc.py b/expansions/wtf/insc.py
new file mode 100644
index 0000000..d698c63
--- /dev/null
+++ b/expansions/wtf/insc.py
@@ -0,0 +1,30 @@
+# coding: utf-8
+
+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
+ "%s - %d соответствий.", # 3
+ "Нет соответсвий в базах.", # 4
+ "\->\n%s:\n\t%s\n\nDefined by %s (on %s)", # 5
+ "Определения «%s» в базе нет.", # 6
+ "Всего %d определений в глобальной базе.", # 7
+ "Всего %d определений в базе %s.", # 8
+ "Определение «%s» уже есть в глобальной базе.", # 9
+ "\->\n" # -1
+ )])
+else:
+ AnsBase_temp = (
+ "There are %d definitions in global base:\n%s", # 0
+ "There are %d definitions in the base of %s:\n%s", # 1
+ "The bases are empty.", # 2
+ "%s - %d hits.", # 3
+ "No hits in the bases.", # 4
+ "\->\n%s:\n\t%s\n\nDefined by %s (on %s)", # 5
+ "There is no '%s' in the base.", # 6
+ "There are %d definitions in the global base.", # 7
+ "There are %d definitions in the base of %s.", # 8
+ "'%s' is already in the global base.", # 9
+ "\->\n" # -1
+ ) \ No newline at end of file
diff --git a/expansions/wtf/wtf.en b/expansions/wtf/wtf.en
new file mode 100644
index 0000000..c3ea9a2
--- /dev/null
+++ b/expansions/wtf/wtf.en
@@ -0,0 +1,10 @@
+shows wtf-base content
+wtf (definition's_name/all/search) (search_key)
+*/wtf
+bot would show definitions count
+*/wtf bot
+bot would show definition of "bot" (if it exists in the bases)
+*/wtf all
+bot would show all names of the definitions
+*/wtf search porn
+bot would search "porn" in the bases \ No newline at end of file
diff --git a/expansions/wtf/wtf.name b/expansions/wtf/wtf.name
new file mode 100644
index 0000000..8541d3f
--- /dev/null
+++ b/expansions/wtf/wtf.name
@@ -0,0 +1,4 @@
+{
+ "RU": "показать",
+ "UA": "показать"
+} \ No newline at end of file
diff --git a/expansions/wtf/wtf.ru b/expansions/wtf/wtf.ru
new file mode 100644
index 0000000..b51f52f
--- /dev/null
+++ b/expansions/wtf/wtf.ru
@@ -0,0 +1,10 @@
+просмотр содержимого баз определений (wtf)
+показать (название_определения/всё/искать) (ключ_поиска)
+*/показать
+бот покажет количество определений в базах
+*/показать бот
+бот покажет определение "бот" (если оно есть в базах)
+*/показать всё
+бот покажет названия всех определений в базах
+*/показать искать прон
+бот будет искать "прон" в базах \ No newline at end of file