forked from TeamUltroid/Ultroid
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgreetings.py
205 lines (180 loc) · 6.53 KB
/
greetings.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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
# Ultroid - UserBot
# Copyright (C) 2021-2022 TeamUltroid
#
# This file is a part of < https://github.com/TeamUltroid/Ultroid/ >
# PLease read the GNU Affero General Public License in
# <https://www.github.com/TeamUltroid/Ultroid/blob/main/LICENSE/>.
"""
✘ Commands Available -
---- Welcomes ----
• `{i}setwelcome <message/reply to message>`
Set welcome message in the current chat.
• `{i}clearwelcome`
Delete the welcome in the current chat.
• `{i}getwelcome`
Get the welcome message in the current chat.
---- GoodByes ----
• `{i}setgoodbye <message/reply to message>`
Set goodbye message in the current chat.
• `{i}cleargoodbye`
Delete the goodbye in the current chat.
• `{i}getgoodbye`
Get the goodbye message in the current chat.
• `{i}thankmembers on/off`
Send a thank you sticker on hitting a members count of 100*x in your groups.
"""
import os
from telegraph import upload_file as uf
from telethon.utils import pack_bot_file_id
from pyUltroid.dB.greetings_db import (
add_goodbye,
add_thanks,
add_welcome,
delete_goodbye,
delete_welcome,
get_goodbye,
get_welcome,
must_thank,
remove_thanks,
)
from pyUltroid.fns.tools import create_tl_btn, format_btn, get_msg_button
from . import HNDLR, eor, get_string, mediainfo, ultroid_cmd
from ._inline import something
Note = "\n\nNote: `{mention}`, `{group}`, `{count}`, `{name}`, `{fullname}`, `{username}`, `{userid}` can be used as formatting parameters.\n\n"
@ultroid_cmd(pattern="setwelcome", groups_only=True)
async def setwel(event):
x = await event.eor(get_string("com_1"))
r = await event.get_reply_message()
btn = format_btn(r.buttons) if (r and r.buttons) else None
try:
text = event.text.split(maxsplit=1)[1]
except IndexError:
text = r.text if r else None
if r and r.media:
wut = mediainfo(r.media)
if wut.startswith(("pic", "gif")):
dl = await r.download_media()
variable = uf(dl)
os.remove(dl)
m = f"https://graph.org{variable[0]}"
elif wut == "video":
if r.media.document.size > 8 * 1000 * 1000:
return await eor(x, get_string("com_4"), time=5)
dl = await r.download_media()
variable = uf(dl)
os.remove(dl)
m = f"https://graph.org{variable[0]}"
elif wut == "web":
m = None
else:
m = pack_bot_file_id(r.media)
if r.text:
txt = r.text
if not btn:
txt, btn = get_msg_button(r.text)
add_welcome(event.chat_id, txt, m, btn)
else:
add_welcome(event.chat_id, None, m, btn)
await eor(x, get_string("grt_1"))
elif text:
if not btn:
txt, btn = get_msg_button(text)
add_welcome(event.chat_id, txt, None, btn)
await eor(x, get_string("grt_1"))
else:
await eor(x, get_string("grt_3"), time=5)
@ultroid_cmd(pattern="clearwelcome$", groups_only=True)
async def clearwel(event):
if not get_welcome(event.chat_id):
return await event.eor(get_string("grt_4"), time=5)
delete_welcome(event.chat_id)
await event.eor(get_string("grt_5"), time=5)
@ultroid_cmd(pattern="getwelcome$", groups_only=True)
async def listwel(event):
wel = get_welcome(event.chat_id)
if not wel:
return await event.eor(get_string("grt_4"), time=5)
msgg, med = wel["welcome"], wel["media"]
if wel.get("button"):
btn = create_tl_btn(wel["button"])
return await something(event, msgg, med, btn)
await event.reply(f"**Welcome Note in this chat**\n\n`{msgg}`", file=med)
await event.delete()
@ultroid_cmd(pattern="setgoodbye", groups_only=True)
async def setgb(event):
x = await event.eor(get_string("com_1"))
r = await event.get_reply_message()
btn = format_btn(r.buttons) if (r and r.buttons) else None
try:
text = event.text.split(maxsplit=1)[1]
except IndexError:
text = r.text if r else None
if r and r.media:
wut = mediainfo(r.media)
if wut.startswith(("pic", "gif")):
dl = await r.download_media()
variable = uf(dl)
os.remove(dl)
m = f"https://graph.org{variable[0]}"
elif wut == "video":
if r.media.document.size > 8 * 1000 * 1000:
return await eor(x, get_string("com_4"), time=5)
dl = await r.download_media()
variable = uf(dl)
os.remove(dl)
m = f"https://graph.org{variable[0]}"
elif wut == "web":
m = None
else:
m = pack_bot_file_id(r.media)
if r.text:
txt = r.text
if not btn:
txt, btn = get_msg_button(r.text)
add_goodbye(event.chat_id, txt, m, btn)
else:
add_goodbye(event.chat_id, None, m, btn)
await eor(x, "`Goodbye note saved`")
elif text:
if not btn:
txt, btn = get_msg_button(text)
add_goodbye(event.chat_id, txt, None, btn)
await eor(x, "`Goodbye note saved`")
else:
await eor(x, get_string("grt_7"), time=5)
@ultroid_cmd(pattern="cleargoodbye$", groups_only=True)
async def clearwgb(event):
if not get_goodbye(event.chat_id):
return await event.eor(get_string("grt_6"), time=5)
delete_goodbye(event.chat_id)
await event.eor("`Goodbye Note Deleted`", time=5)
@ultroid_cmd(pattern="getgoodbye$", groups_only=True)
async def listgd(event):
wel = get_goodbye(event.chat_id)
if not wel:
return await event.eor(get_string("grt_6"), time=5)
msgg = wel["goodbye"]
med = wel["media"]
if wel.get("button"):
btn = create_tl_btn(wel["button"])
return await something(event, msgg, med, btn)
await event.reply(f"**Goodbye Note in this chat**\n\n`{msgg}`", file=med)
await event.delete()
@ultroid_cmd(pattern="thankmembers (on|off)", groups_only=True)
async def thank_set(event):
type_ = event.pattern_match.group(1).strip()
if not type_ or type_ == "":
await eor(
event,
f"**Current Chat Settings:**\n**Thanking Members:** `{must_thank(event.chat_id)}`\n\nUse `{HNDLR}thankmembers on` or `{HNDLR}thankmembers off` to toggle current settings!",
)
return
chat = event.chat_id
if type_.lower() == "on":
add_thanks(chat)
elif type_.lower() == "off":
remove_thanks(chat)
await eor(
event,
f"**Done! Thank you members has been turned** `{type_.lower()}` **for this chat**!",
)