-
Notifications
You must be signed in to change notification settings - Fork 29
/
welcome.py
58 lines (48 loc) · 1.79 KB
/
welcome.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
from telethon import events, errors
from telethon.tl import types
MAIN_WELCOME = (
'Hi and welcome to the group. Before asking any questions, **please** '
'read the rules from the group\'s description, and don\'t forget to '
'read [the docs](https://docs.telethon.dev/). Make sure you are '
'using the latest version with `pip3 install -U telethon`, since most '
'problems have already been fixed in newer versions.'
)
WELCOME = {
1109500936: ((MAIN_WELCOME,), {}),
1200633650: ((), {'file': 'plugins/stickers/hello.webp'}),
}
FAREWELL = {
1200633650: ((), {'file': 'plugins/stickers/bye.webp'}),
}
async def delete(map, chat_id):
msg = map.pop(chat_id, None)
if msg:
try:
await msg.delete()
except errors.MessageDeleteForbiddenError:
# We believe this happens when trying to delete old messages
pass
async def init(bot):
last_welcome = {}
last_farewell = {}
@bot.on(events.Raw(types.UpdateChannelParticipant))
async def handler(event):
chat_id = event.channel_id
# https://t.me/c/1109500936/472212
np = event.new_participant
welcome = WELCOME.get(chat_id, None)
farewell = FAREWELL.get(chat_id, None)
joined = np and isinstance(np, types.ChannelParticipant)
left = np and isinstance(np, types.ChannelParticipantLeft)
if not joined and not left:
return
if not welcome and not farewell:
return
if joined and welcome:
args, kwargs = welcome
last_map = last_welcome
if left and farewell:
args, kwargs = farewell
last_map = last_farewell
await delete(last_map, chat_id)
last_map[chat_id] = await bot.send_message(chat_id, *args, **kwargs)