File size: 3,391 Bytes
78b07ad
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
from pyrogram import Client
from pyrogram.types import Message

from . import Config, HelpMenu, db, hellbot, on_message


@on_message("stan", allow_stan=True)
async def stanUsers(client: Client, message: Message):
    hell = await hellbot.edit(message, "__Fetching users...__")

    users = await db.get_stans(client.me.id)
    if not users:
        return await hellbot.delete(hell, "__No stans found!__")

    text = f"**Total stans:** `{len(users)}`\n\n"
    for user in users:
        try:
            user = await client.get_users(user["user_id"])
            mention = user.mention
            userid = user.id
        except Exception:
            userid = user["user_id"]
            mention = "Unknown Peer"
        text += f"• {mention} (`{userid}`)\n"

    await hell.edit(text)


@on_message("addstan", allow_stan=False)
async def addstan(client: Client, message: Message):
    if len(message.command) < 2:
        if not message.reply_to_message:
            return await hellbot.delete(
                message,
                "__Reply to a user or give me a user id to add them as a stan!__",
            )
        user = message.reply_to_message.from_user
    else:
        try:
            user = await client.get_users(message.command[1])
        except Exception:
            return await hellbot.delete(
                message, "__Give me a valid user id to add them as a stan!__"
            )

    if user.id == client.me.id:
        return await hellbot.delete(message, "__I can't be a stan of myself!__")

    if await db.is_stan(client.me.id, user.id):
        return await hellbot.delete(message, "__This user is already a stan!__")

    await db.add_stan(client.me.id, user.id)
    await hellbot.delete(message, f"__Added {user.mention} as a stan!__")

    Config.AUTH_USERS.add(user.id)
    Config.STAN_USERS.add(user.id)


@on_message("delstan", allow_stan=False)
async def delstan(client: Client, message: Message):
    if len(message.command) < 2:
        if not message.reply_to_message:
            return await hellbot.delete(
                message,
                "__Reply to a user or give me a user id to remove them from stans!__",
            )
        user = message.from_user
    else:
        try:
            user = await client.get_users(message.command[1])
        except Exception:
            return await hellbot.delete(
                message, "__Give me a valid user id to remove them from stans!__"
            )

    if await db.is_stan(client.me.id, user.id):
        await db.rm_stan(client.me.id, user.id)
        await hellbot.delete(message, f"__Removed {user.mention} from stans!__")

        Config.AUTH_USERS.remove(user.id)
        Config.STAN_USERS.remove(user.id)
    else:
        await hellbot.delete(message, "__This user is not a stan!__")


HelpMenu("stan").add(
    "stan",
    None,
    "Get a list of stan users for your client.",
    "stan",
    "A stan user can access some of the commands of your client.",
).add(
    "addstan",
    "<reply/username/userid>",
    "Add a stan user in your client.",
    "addstan",
    "Be careful while adding a stan user.",
).add(
    "delstan",
    "<reply/username/userid>",
    "Remove a stan user from your client.",
    "delstan",
).info(
    "Stan Users"
).done()