Initial commit
This commit is contained in:
33
modules/database.py
Normal file
33
modules/database.py
Normal file
@@ -0,0 +1,33 @@
|
||||
"""Module that provides all database columns"""
|
||||
|
||||
from pymongo import MongoClient
|
||||
from ujson import loads
|
||||
|
||||
with open("config.json", "r", encoding="utf-8") as f:
|
||||
db_config = loads(f.read())["database"]
|
||||
f.close()
|
||||
|
||||
if db_config["user"] is not None and db_config["password"] is not None:
|
||||
con_string = "mongodb://{0}:{1}@{2}:{3}/{4}".format(
|
||||
db_config["user"],
|
||||
db_config["password"],
|
||||
db_config["host"],
|
||||
db_config["port"],
|
||||
db_config["name"],
|
||||
)
|
||||
else:
|
||||
con_string = "mongodb://{0}:{1}/{2}".format(
|
||||
db_config["host"], db_config["port"], db_config["name"]
|
||||
)
|
||||
|
||||
db_client = MongoClient(con_string)
|
||||
db = db_client.get_database(name=db_config["name"])
|
||||
|
||||
collections = db.list_collection_names()
|
||||
|
||||
for collection in ["users", "schedule"]:
|
||||
if collection not in collections:
|
||||
db.create_collection(collection)
|
||||
|
||||
col_users = db.get_collection("users")
|
||||
col_schedule = db.get_collection("schedule")
|
31
modules/kicker.py
Normal file
31
modules/kicker.py
Normal file
@@ -0,0 +1,31 @@
|
||||
from pyrogram.types import Message
|
||||
|
||||
from classes.pyroclient import PyroClient
|
||||
|
||||
|
||||
async def kick_unstarted(
|
||||
app: PyroClient, user_id: int, group_id: int, message_id: int
|
||||
) -> None:
|
||||
user = await app.find_user(user_id, group_id)
|
||||
|
||||
if user.score == 0 and user.failed == 0:
|
||||
banned = await app.ban_chat_member(group_id, user_id)
|
||||
|
||||
if isinstance(banned, Message):
|
||||
await banned.delete()
|
||||
|
||||
await app.delete_messages(group_id, message_id)
|
||||
|
||||
|
||||
async def kick_unverified(
|
||||
app: PyroClient, user_id: int, group_id: int, message_id: int
|
||||
) -> None:
|
||||
user = await app.find_user(user_id, group_id)
|
||||
|
||||
if user.score < 6 or user.failed:
|
||||
banned = await app.ban_chat_member(group_id, user_id)
|
||||
|
||||
if isinstance(banned, Message):
|
||||
await banned.delete()
|
||||
|
||||
await app.delete_messages(group_id, message_id)
|
3
modules/scheduler.py
Normal file
3
modules/scheduler.py
Normal file
@@ -0,0 +1,3 @@
|
||||
from apscheduler.schedulers.asyncio import AsyncIOScheduler
|
||||
|
||||
scheduler = AsyncIOScheduler()
|
51
modules/utils.py
Normal file
51
modules/utils.py
Normal file
@@ -0,0 +1,51 @@
|
||||
from io import BytesIO
|
||||
from pathlib import Path
|
||||
from random import randint, sample
|
||||
from typing import List
|
||||
|
||||
from huepaper import generate
|
||||
from PIL import Image
|
||||
|
||||
from classes.captcha import Captcha
|
||||
|
||||
|
||||
def get_captcha_image(emojis: List[str]) -> Captcha:
|
||||
emojis_all = sample(emojis, 12)
|
||||
emojis_correct = sample(emojis_all, 6)
|
||||
|
||||
output = BytesIO()
|
||||
|
||||
image_options = [
|
||||
(randint(400, 490), randint(90, 280), randint(105, 125)),
|
||||
(randint(60, 180), randint(180, 240), randint(75, 95)),
|
||||
(randint(320, 440), randint(170, 210), randint(35, 45)),
|
||||
(randint(150, 240), randint(240, 320), randint(80, 105)),
|
||||
(randint(350, 450), randint(280, 380), randint(40, 60)),
|
||||
(randint(180, 350), randint(100, 300), randint(45, 65)),
|
||||
]
|
||||
|
||||
base_img = generate(
|
||||
width=500,
|
||||
height=500,
|
||||
hue_max=1.0,
|
||||
lum_min=0.3,
|
||||
lum_max=0.6,
|
||||
sat_min=0.8,
|
||||
sat_max=1.0,
|
||||
)
|
||||
|
||||
for options, emoji in zip(image_options, emojis_correct):
|
||||
width, height, angle = options
|
||||
base_img.paste(
|
||||
Image.open(Path(f"assets/emojis/{emoji}.png"))
|
||||
.resize((120, 120))
|
||||
.rotate(angle),
|
||||
((base_img.width - width), (base_img.height - height)),
|
||||
Image.open(Path(f"assets/emojis/{emoji}.png"))
|
||||
.resize((120, 120))
|
||||
.rotate(angle),
|
||||
)
|
||||
|
||||
base_img.save(output, format="jpeg")
|
||||
|
||||
return Captcha(output, emojis_all, emojis_correct)
|
Reference in New Issue
Block a user