-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbot.py
126 lines (90 loc) · 2.88 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
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
import discord
import time
from game import Game
from bot_token import t as botToken
client = discord.Client()
@client.event
async def on_ready():
print('We have logged in as {0.user}'.format(client))
db_a = {}
db_m = {}
used_reaction_ids = ['🎣', 'ℹ', '⚙']
symbol = "$"
@client.event
async def on_message(message):
global db_a
global db_m
# if message.author == client.user:
# return
if message.content[:1] == symbol:
msg = message.content[1:].split()
if msg[0] == "play":
m = await message.channel.send("Setup")
m_id = m.id
a_id = message.author.id
try:
db_a[a_id]
except KeyError:
db_a[a_id] = Game(message.author, m_id)
db_m[m_id] = db_a[a_id]
else:
db_a[a_id].update_game_id(m_id)
db_m[m_id] = db_a[a_id]
for x in used_reaction_ids:
await m.add_reaction(x)
if msg[0] == "edit":
x = await message.channel.fetch_message(db_a[message.author.id].game_id)
await x.edit(content = "Hello")
if msg[0] == "print":
print(msg)
if msg[0] == "test":
x = await message.channel.fetch_message(msg[1])
await x.add_reaction('⚙')
if msg[0] == "do":
await message.channel.send(message.content[len(msg[0]) + 2:])
if msg[0] == "r":
await message.channel.send(db_a[message.author.id].get_fish_list())
@client.event
async def on_reaction_add(reaction, user):
global db_a
global db_m
# print("Reaction")
if user == client.user:
return
try:
db_m[reaction.message.id]
except KeyError:
return
try:
db_a[user.id]
except KeyError:
await reaction.remove(user)
return
if (reaction.emoji not in used_reaction_ids) or (db_a[user.id].game_id != reaction.message.id):
await reaction.remove(user)
return
# print("Working")
if reaction.emoji == '🎣':
await on_fish(reaction, user)
if reaction.emoji == 'ℹ':
print("Gear")
if reaction.emoji == '⚙':
print("Gear")
@client.event
async def on_reaction_remove(reaction, user):
global db_a
global db_m
# print("Reaction")
if user == client.user:
return
async def on_fish(reaction, user):
global db_a
if db_a[user.id].is_fishing:
return
db_a[user.id].is_fishing = True
cast = db_a[user.id].cast_reel()
time.sleep(cast[2])
await reaction.message.edit(content = "", embed = cast[0])
await reaction.remove(user)
db_a[user.id].is_fishing = False
client.run(botToken)