-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathbot.py
67 lines (52 loc) · 1.91 KB
/
bot.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
import logging
import os
import re
import discord
from discord.ext import tasks
from dotenv import load_dotenv
load_dotenv()
intents = discord.Intents.default()
intents.message_content = True
client = discord.Client(intents=intents)
SINGLE_EMOJI_REGEX = re.compile(
r"""
^ # Start of string
(?!<.*<) # Negative lookahead to ensure there is not more than one '<' at the beginning
< # Emoji opening delimiter
(a)? # Optional 'a' for animated emoji
: # Colon delimiter
(.+?) # Emoji name
: # Colon delimiter
([0-9]{15,21}) # Emoji ID
> # Emoji closing delimiter
$ # End of string
""",
re.VERBOSE,
)
@tasks.loop(minutes=1.0)
async def change_status():
await client.change_presence(activity=discord.Game(name=f"{len(client.guilds)}개의 서버와 함께"))
@client.event
async def on_ready():
change_status.start()
print(f"Logged in as {client.user}")
@client.event
async def on_message(message: discord.Message):
if not message.guild or message.author.bot:
return
if (m := SINGLE_EMOJI_REGEX.match(message.content)):
embed = discord.Embed(
color = message.author.color if message.author.color != discord.Colour.default() else discord.Colour.greyple()
)
embed.set_author(name=message.author.display_name, icon_url=message.author.display_avatar)
emoji_id = m.group(3)
extension = ".gif" if m.group(1) else ".png"
embed.set_image(url=f"https://cdn.discordapp.com/emojis/{emoji_id}{extension}")
try:
await message.delete()
await message.channel.send(embed=embed, reference=message.reference, mention_author=False)
except discord.Forbidden:
pass
except Exception as e:
logging.exception(e)
client.run(os.getenv('TOKEN'))