Compare commits

..

No commits in common. "32ebad29ca2820061959368f56afc61e3fb420ac" and "c0f6bd8b11311e2907ce5a2609411e915c90c1eb" have entirely different histories.

9 changed files with 16 additions and 183 deletions

2
app.py
View File

@ -4,7 +4,7 @@ from pyrogram.client import Client
app = Client("holochecker", bot_token=configGet("bot_token", "bot"), api_id=configGet("api_id", "bot"), api_hash=configGet("api_hash", "bot")) app = Client("holochecker", bot_token=configGet("bot_token", "bot"), api_id=configGet("api_id", "bot"), api_hash=configGet("api_hash", "bot"))
async def isAnAdmin(admin_id): async def isAnAdmin(admin_id):
if (admin_id == configGet("owner")) or (admin_id in configGet("admins")): if admin_id == configGet("owner") or admin_id in configGet("admins"):
return True return True
async for member in app.get_chat_members(configGet("admin_group")): async for member in app.get_chat_members(configGet("admin_group")):
if member.user.id == admin_id: if member.user.id == admin_id:

View File

@ -1,9 +1,6 @@
from app import isAnAdmin from typing import Union
from typing import List, Union from pyrogram.types import User, ChatMember
from pyrogram.types import User, ChatMember, ChatPrivileges, Chat
from pyrogram.client import Client
from modules.database import col_users, col_context, col_warnings, col_applications, col_sponsorships from modules.database import col_users, col_context, col_warnings, col_applications, col_sponsorships
from modules.utils import configGet
class UserNotFoundError(Exception): class UserNotFoundError(Exception):
"""HoloUser could not find user with such an ID in database""" """HoloUser could not find user with such an ID in database"""
@ -12,59 +9,6 @@ class UserNotFoundError(Exception):
self.user_id = user_id self.user_id = user_id
super().__init__(f"User of type {type(self.user)} with id {self.user_id} was not found") super().__init__(f"User of type {type(self.user)} with id {self.user_id} was not found")
class UserInvalidError(Exception):
"""Provided to HoloUser object is not supported"""
def __init__(self, user):
self.user = user
super().__init__(f"Could not find HoloUser by using {type(self.user)} as an input type")
class HoloUser(): class HoloUser():
def __init__(self, user: Union[User, ChatMember, int]) -> None:
def __init__(self, user: Union[List[User], User, ChatMember, int]) -> None: pass
# Determine input object class and extract id
if isinstance(user, list) and len(user) != 0:
self.id = user[0].id
elif isinstance(user, User):
self.id = user.id
elif isinstance(user, ChatMember):
self.id = user.user.id
elif isinstance(user, int):
self.id = user
else:
raise UserInvalidError(user)
# Find user record in DB
holo_user = col_users.find_one({"user": self.id})
if holo_user is None:
raise UserNotFoundError(user=user, user_id=self.id)
self.db_id = holo_user["_id"]
self.label = holo_user["label"]
async def set_label(self, app: Client, chat: Chat, label: str):
"""Set label in destination group
### Args:
* app (`Client`): Pyrogram client
* label (`str`): Label you want to set
"""
self.label = label
await app.promote_chat_member(configGet("destination_group"), self.id)
if (not await isAnAdmin(self.id)) and (chat.id == configGet("admin_group")):
await app.set_administrator_title(configGet("destination_group"), self.id, label)
async def reset_label(self, app: Client, chat: Chat):
"""Reset label in destination group
### Args:
* app (`Client`): Pyrogram client
"""
self.label = ""
await app.set_administrator_title(configGet("destination_group"), self.id, "")
if (not await isAnAdmin(self.id)) and (chat.id == configGet("admin_group")):
await app.promote_chat_member(configGet("destination_group"), self.id, privileges=ChatPrivileges(
can_manage_chat=False
))

View File

@ -1,33 +1,20 @@
from app import app, isAnAdmin from app import app
from pyrogram import filters from pyrogram import filters
from pyrogram.types import ChatPrivileges from modules.utils import should_quote, find_user
from modules.utils import should_quote, find_user, configGet
from classes.holo_user import HoloUser
@app.on_message(~ filters.scheduled & filters.private & filters.command(["label"], prefixes=["/"])) @app.on_message(~ filters.scheduled & filters.private & filters.command(["label"], prefixes=["/"]))
async def cmd_label(app, msg): async def cmd_label(app, msg):
if msg.chat.id == configGet("admin_group") or await isAnAdmin(msg.from_user.id): if len(msg.command) < 3:
await msg.reply_text("Invalid syntax:\n`/label USER NICKNAME`")
return
if len(msg.command) < 3: target = await find_user(app, msg.command[1])
await msg.reply_text("Invalid syntax:\n`/label USER NICKNAME`")
return
target = await find_user(app, msg.command[1]) if target is not None:
if target is not None: nickname = " ".join(msg.command[2:])
await msg.reply_text(f"Setting **{target.id}**'s label to **{nickname}**...", quote=should_quote(msg))
target = HoloUser(target)
nickname = " ".join(msg.command[2:]) else:
await msg.reply_text(f"User not found")
if nickname.lower() == "reset":
await target.reset_label(app, msg.chat)
await msg.reply_text(f"Resetting **{target.id}**'s label...", quote=should_quote(msg))
else:
await target.set_label(app, msg.chat, nickname)
await msg.reply_text(f"Setting **{target.id}**'s label to **{nickname}**...", quote=should_quote(msg))
else:
await msg.reply_text(f"User not found")

View File

@ -1,6 +0,0 @@
{
"$jsonSchema": {
"required": [],
"properties": {}
}
}

View File

@ -1,6 +0,0 @@
{
"$jsonSchema": {
"required": [],
"properties": {}
}
}

View File

@ -1,36 +0,0 @@
{
"$jsonSchema": {
"required": [
"origin",
"origin.chat",
"origin.id",
"destination",
"destination.chat",
"destination.id"
],
"properties": {
"origin": {
"bsonType": "object"
},
"origin.chat": {
"bsonType": ["int", "long"],
"description": "Telegram ID of message's origin chat"
},
"origin.id": {
"bsonType": ["int", "long"],
"description": "ID of message in origin chat"
},
"destination": {
"bsonType": "object"
},
"destination.chat": {
"bsonType": ["int", "long"],
"description": "Telegram ID of message's destination chat"
},
"destination.id": {
"bsonType": ["int", "long"],
"description": "ID of message in destination chat"
}
}
}
}

View File

@ -1,6 +0,0 @@
{
"$jsonSchema": {
"required": [],
"properties": {}
}
}

View File

@ -1,38 +0,0 @@
{
"$jsonSchema": {
"required": [
"user",
"link",
"tg_name",
"tg_phone",
"tg_locale",
"tg_username"
],
"properties": {
"user": {
"bsonType": ["int", "long"],
"description": "Telegram ID of user"
},
"link": {
"bsonType": "string",
"description": "Invite link to destination group"
},
"tg_name": {
"bsonType": "string",
"description": "Telegram first name"
},
"tg_phone": {
"bsonType": "string",
"description": "Telegram phone number"
},
"tg_locale": {
"bsonType": "string",
"description": "Telegram locale"
},
"tg_username": {
"bsonType": "string",
"description": "Telegram username"
}
}
}
}

View File

@ -1,6 +0,0 @@
{
"$jsonSchema": {
"required": [],
"properties": {}
}
}