mirror of
https://github.com/tgbot-collection/YYeTsBot.git
synced 2025-11-25 11:29:38 +08:00
one key ban in bot
This commit is contained in:
@@ -182,6 +182,32 @@ def send_search(message):
|
|||||||
base_send_search(message)
|
base_send_search(message)
|
||||||
|
|
||||||
|
|
||||||
|
@bot.message_handler(content_types=["document"])
|
||||||
|
def ban_user(message):
|
||||||
|
if str(message.chat.id) != MAINTAINER:
|
||||||
|
return
|
||||||
|
|
||||||
|
mem = io.BytesIO()
|
||||||
|
file_id = message.document.file_id
|
||||||
|
file_info = bot.get_file(file_id)
|
||||||
|
content = bot.download_file(file_info.file_path)
|
||||||
|
mem.write(content)
|
||||||
|
user_list = mem.getvalue().decode("u8").split("\n")
|
||||||
|
yy = fansub.YYeTsOffline()
|
||||||
|
client = yy.mongo
|
||||||
|
user_col = client["zimuzu"]["users"]
|
||||||
|
text = ""
|
||||||
|
for line in user_list:
|
||||||
|
user, reason = line.split(maxsplit=1)
|
||||||
|
ban = {"disable": True, "reason": reason}
|
||||||
|
user_col.update_one({"username": user}, {"$set": {"status": ban}})
|
||||||
|
status = f"{user} 已经被禁言,原因:{reason}\n"
|
||||||
|
logging.info("Banning %s", status)
|
||||||
|
text += status
|
||||||
|
bot.reply_to(message, text)
|
||||||
|
mem.close()
|
||||||
|
|
||||||
|
|
||||||
def base_send_search(message, instance=None):
|
def base_send_search(message, instance=None):
|
||||||
if instance is None:
|
if instance is None:
|
||||||
fan = fansub.FansubEntrance()
|
fan = fansub.FansubEntrance()
|
||||||
|
|||||||
22
yyetsweb/commands/ban_user.py
Normal file
22
yyetsweb/commands/ban_user.py
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
#!/usr/local/bin/python3
|
||||||
|
# coding: utf-8
|
||||||
|
|
||||||
|
# YYeTsBot - ban_user.py
|
||||||
|
# 3/26/22 10:26
|
||||||
|
#
|
||||||
|
|
||||||
|
__author__ = "Benny <benny.think@gmail.com>"
|
||||||
|
|
||||||
|
from common import Mongo
|
||||||
|
from tqdm import tqdm
|
||||||
|
|
||||||
|
client = Mongo()
|
||||||
|
user_col = client.db["users"]
|
||||||
|
|
||||||
|
with open("ban_user.txt", "r") as f:
|
||||||
|
for line in tqdm(f, desc="Banning user..."):
|
||||||
|
user, reason = line.split(maxsplit=1)
|
||||||
|
ban = {"disable": True, "reason": reason}
|
||||||
|
user_col.update_one({"username": user}, {"$set": {"status": ban}})
|
||||||
|
|
||||||
|
print("Done!")
|
||||||
21
yyetsweb/commands/common.py
Normal file
21
yyetsweb/commands/common.py
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
#!/usr/local/bin/python3
|
||||||
|
# coding: utf-8
|
||||||
|
|
||||||
|
# YYeTsBot - common.py
|
||||||
|
# 3/26/22 10:40
|
||||||
|
#
|
||||||
|
|
||||||
|
__author__ = "Benny <benny.think@gmail.com>"
|
||||||
|
|
||||||
|
import pymongo
|
||||||
|
import os
|
||||||
|
|
||||||
|
|
||||||
|
class Mongo:
|
||||||
|
def __init__(self):
|
||||||
|
self.client = pymongo.MongoClient(host=os.getenv("mongo") or "localhost", connect=False,
|
||||||
|
connectTimeoutMS=5000, serverSelectionTimeoutMS=5000)
|
||||||
|
self.db = self.client["zimuzu"]
|
||||||
|
|
||||||
|
def __del__(self):
|
||||||
|
self.client.close()
|
||||||
Reference in New Issue
Block a user