new module: mass-tagger-v2
This commit is contained in:
@@ -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}: <none> -> @{user_name}")
|
||||
current_db[chat_id][user_id] = user_name
|
||||
update_db("db/all.json", current_db)
|
||||
|
||||
return "", ""
|
||||
@@ -0,0 +1,7 @@
|
||||
{
|
||||
"version": 2,
|
||||
"index_file": "index.py",
|
||||
"predefine": "predefine.py",
|
||||
"start_on_boot": true,
|
||||
"alias": "mass-tagger-v2"
|
||||
}
|
||||
@@ -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"}
|
||||
}
|
||||
Reference in New Issue
Block a user