From 5515e0c18aa6441263e5032dd549139d9c4684a1 Mon Sep 17 00:00:00 2001 From: dymik739 Date: Tue, 15 Sep 2026 11:22:36 +0300 Subject: [PATCH] new module: mass-tagger-v2 --- modules/mass-tagger-v2/index.py | 71 +++++++++++++++++++++++++++++ modules/mass-tagger-v2/meta.json | 7 +++ modules/mass-tagger-v2/predefine.py | 4 ++ 3 files changed, 82 insertions(+) create mode 100644 modules/mass-tagger-v2/index.py create mode 100644 modules/mass-tagger-v2/meta.json create mode 100644 modules/mass-tagger-v2/predefine.py diff --git a/modules/mass-tagger-v2/index.py b/modules/mass-tagger-v2/index.py new file mode 100644 index 0000000..c068cc1 --- /dev/null +++ b/modules/mass-tagger-v2/index.py @@ -0,0 +1,71 @@ +import os +import json +import datetime + +def readfile(path): + if os.path.exists(module_path + path): + return open(module_path + path).read() + else: + return '' + + +def load_from(path): + data = readfile(path) + + if data: + return json.loads(data) + else: + return {} + + +def writefile(path, data): + open(module_path + path, "w").write(data) + + +def update_db(path, db_data): + writefile(path, json.dumps(db_data)) + + +def append_file(path, data): + open(module_path + path, "a").write(data) + + +def log(data): + print(f"[mass-tagger-v2 {datetime.datetime.now().strftime('%Y-%m-%d_%H-%M-%S')}]: {data}") + append_file("db/update_log.txt", f"{datetime.datetime.now().strftime('%Y-%m-%d_%H-%M-%S')}: {data}\n") + + +module_path = "" + + +def process(msg, path): + global module_path + module_path = path + + current_db = load_from("db/all.json") + + chat_id = str(msg.chat.id) + user_id = str(msg.from_user.id) + user_name = str(msg.from_user.username) + + if ("@all" in msg.text) and (chat_id in current_db): + tags_from_db = set(current_db[chat_id].values()) + real_tags = [f"@{i}" for i in tags_from_db if i != "None"] + return f"Користувач {msg.from_user.username} використав масовий" \ + f" тег з повідомленням:\n{msg.text}\n\n" \ + f"{' '.join(real_tags)}", "" + + if chat_id not in current_db: + log(f"Added chat {chat_id}") + current_db[chat_id] = dict() + update_db("db/all.json", current_db) + + if (user_id not in current_db[chat_id]) or (current_db[chat_id][user_id] != user_name): + if (user_id in current_db[chat_id]): + log(f"Updated record for {user_id} in {chat_id}: @{current_db[chat_id][user_id]} -> @{user_name}") + else: + log(f"Updated record for {user_id} in {chat_id}: -> @{user_name}") + current_db[chat_id][user_id] = user_name + update_db("db/all.json", current_db) + + return "", "" diff --git a/modules/mass-tagger-v2/meta.json b/modules/mass-tagger-v2/meta.json new file mode 100644 index 0000000..9a54c4d --- /dev/null +++ b/modules/mass-tagger-v2/meta.json @@ -0,0 +1,7 @@ +{ + "version": 2, + "index_file": "index.py", + "predefine": "predefine.py", + "start_on_boot": true, + "alias": "mass-tagger-v2" +} diff --git a/modules/mass-tagger-v2/predefine.py b/modules/mass-tagger-v2/predefine.py new file mode 100644 index 0000000..3eeadb6 --- /dev/null +++ b/modules/mass-tagger-v2/predefine.py @@ -0,0 +1,4 @@ +self.tag_sets = { + "%testing": {"@dmytrofiot23"}, + "%students": {"@dmytrofiot23", "@Rhinemann", "@Vlad86557", "@nonGratis", "@aposijl", "@Bacant150", "@Investor3221", "@Fvggggu", "@andrux4", "@danya946", "@Antntipo", "@eugeneholovatenko", "@brazoo", "@kozak_yana", "@dfttime", "@forkreros", "@nikitobus1", "@m1x3d0", "@BohdanOstrykov", "@theNightingal3", "@maks1mka_77g", "@victoriavodyana", "@cyberbebebe", "@misha1tigr", "@artemm4ekk", "@jwnsn", "@nstchpnk", "@telegadimki", "@Dedinsyult", "@sashkamg", "@sandrokovi3"} +}