-
Notifications
You must be signed in to change notification settings - Fork 102
/
summoned.py
110 lines (87 loc) · 3.7 KB
/
summoned.py
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
107
108
109
110
import time
from pyrogram import filters
from pyrogram.types import Message
from userbot import UserBot
from userbot.database.summon import SUMMON
from userbot.helpers.file_sending_helpers import send_saved_image
from userbot.helpers.utility import human_time, random_interval
from userbot.plugins.afk import AFK
from userbot.plugins.help import add_command_help
@UserBot.on_message(filters.command("summonhere", ".") & filters.me)
async def summon_here(bot: UserBot, message: Message):
chat_details = SUMMON().find_chat_id(message)
if chat_details is not None:
chat_id = chat_details["chat_id"]
if chat_id == message.chat.id:
await message.edit(
"```Summon message for this group is already enabled...```"
)
elif chat_details is None:
SUMMON().add_chat_id(message)
await message.edit("```Summon message for this group has been enabled!!```")
time.sleep(2)
await message.delete()
@UserBot.on_message(filters.command("summonhere", "!") & filters.me)
async def not_summoned_here(bot: UserBot, message: Message):
if SUMMON().delete_chat_id(message) is True:
await message.edit("```Summon message disabled for this chat```")
else:
await message.edit("```Summon message for this group was never enabled.```")
time.sleep(2)
await message.delete()
@UserBot.on_message(filters.incoming & filters.mentioned & ~filters.reply)
async def summoned(bot: UserBot, message: Message):
chat_details = SUMMON().find_chat_id(message)
if chat_details is not None:
if chat_details["chat_id"] == message.chat.id:
if not AFK:
try:
last_send = chat_details["last_send"]
next_send = chat_details["next_send"]
if (time.time() - last_send) >= next_send:
await send_saved_image(
message,
"summoned_cat",
"summoned_cat.jpg",
)
last_send = time.time()
next_send = random_interval()
SUMMON().update(message, last_send, next_send)
except Exception:
await send_saved_image(message, "summoned_cat", "summoned_cat.jpg")
last_send = time.time()
next_send = random_interval()
SUMMON().update(message, last_send, next_send)
@UserBot.on_message(filters.command("nextsummon", ".") & filters.me)
async def next_summon(bot: UserBot, message: Message):
chat_details = SUMMON().find_chat_id(message)
if chat_details is not None:
if chat_details["chat_id"] == message.chat.id:
try:
last_send = chat_details["last_send"]
next_send = chat_details["next_send"]
delta = (last_send + next_send) - time.time()
await message.edit(f"'''{human_time(seconds=int(delta))}'''")
time.sleep(6)
await message.delete()
except Exception:
await message.edit(
"```This group does not have a summon message interval```"
)
time.sleep(2)
await message.delete()
else:
await message.delete()
else:
await message.delete()
add_command_help(
"summon",
[
[".summonhere", "Enables summoning in the group it is activated in."],
["!summonhere", "Disables summoning in the group it is activated in."],
[
".nextsummon",
"Show the time left for the next summon that will occur in the group.",
],
],
)