-
Notifications
You must be signed in to change notification settings - Fork 1
/
add_reaction_bot.py
63 lines (40 loc) · 1.44 KB
/
add_reaction_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
import re
import unicodedata
import discord
with open("bot.token") as tokenfile:
TOKEN = tokenfile.read()
def transform_unicode_emoji(char):
#絵文字のA(0x1f1e6) - アルファベットのA(0x0041) + 入力する文字
return chr(0x1f1e6 - 0x0041 + ord(char.upper()))
def str_to_reactions(string):
reactions = []
for char in string:
reactions.append(transform_unicode_emoji(char))
return reactions
def is_japanese(string):
for char in string:
name = unicodedata.name(char)
if "CJK UNIFIED" in name or "HIRAGANA" in name or "KATAKANA" in name:
return True
return False
client = discord.Client()
@client.event
async def on_ready():
print('login!')
@client.event
async def on_message(message):
if message.author.bot:
return
if message.content.startswith("!!reaction"):
array_message = re.split("[ /]" ,message.content)
msg_channel_id_int = int(array_message[-3])
msg_id_int = int(array_message[-2])
if not is_japanese(array_message[-1]):
reactions = str_to_reactions(array_message[-1])
msg_channel = client.get_channel(msg_channel_id_int)
msg_id = await msg_channel.fetch_message(msg_id_int)
for reaction in reactions:
await msg_id.add_reaction(reaction)
else:
await message.channel.send("Error! Use Alphabet Only")
client.run(TOKEN)