-
Notifications
You must be signed in to change notification settings - Fork 4
/
main.py
305 lines (238 loc) · 10.5 KB
/
main.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
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
# Work with Python 3.6
import asyncio
import datetime
import logging
import random
import discord.ext.commands
import Python.BGG
import Python.Dice
import Python.YouTube
import Python.data_storage
from util.config import TOKEN
# if not os.path.isfile('boardgamebot.db'):
# util.database_initialization.intitialize_db()
# sentry_sdk.init(sentry_url)
logger = logging.Logger('catch_all')
Bot_Prefix = ("?", "!")
players = {}
client = discord.ext.commands.Bot(command_prefix=Bot_Prefix)
@client.command(name='BGGCheck',
description="Returns the BGG information on a game",
brief="Returns the Board Game Geek information of a game",
aliases=['bggck', 'bglookup', 'bg']
)
async def bgg_check(ctx, *, gamename):
main_response = Python.BGG.game_lookup(gamename)
filepath = Python.BGG.image_lookup(gamename)
embed = discord.Embed()
if "error" not in filepath:
embed.set_image(url=filepath)
if filepath == "error":
await ctx.send(main_response)
return
await ctx.send(main_response, embed=embed)
@bgg_check.error
async def bgg_check_error(ctx, error):
if isinstance(error, BaseException):
await ctx.send('Unexpected error, try again. If the error persists,'
' get help here https://discord.gg/9pS2JdC')
logger.error(error, exc_info=True)
@client.command(name='Expansion_Check',
description="Returns expansions for the selected game if any",
brief="Returns expansions of a game",
aliases=['exp', 'expchk', 'expansion']
)
async def expansion_check(ctx, *, game):
main_response = Python.BGG.game_expansion(game)
await ctx.send(main_response)
@expansion_check.error
async def expansion_check_error(ctx, error):
if isinstance(error, BaseException):
await ctx.send('Unexpected error, try again. If the error persists,'
' get help here https://discord.gg/9pS2JdC')
logger.error(error, exc_info=True)
@client.command(name='Random_Game',
description="Returns a random game title from a provided list",
brief="Returns a random title from a provided list of games",
aliases=['randompick', 'randbg', 'rbg']
)
async def random_game(ctx, *, arg):
possible_responses = arg.split(',')
await ctx.send(random.choice(possible_responses))
@random_game.error
async def random_game_error(ctx, error):
if isinstance(error, BaseException):
await ctx.send('Unexpected error, try again. If the error persists,'
' get help here https://discord.gg/9pS2JdC')
logger.error(error, exc_info=True)
@client.command(name='Random_Owned_Game',
description="Returns a random game title from a user's owned \
list",
brief="Returns a random title from a user's owned list of \
games",
aliases=['randomownedpick', 'randobg', 'robg']
)
async def random_users_game(ctx, name):
random_game_name = Python.BGG.random_owned_game(name)
await ctx.send(random_game_name)
@random_users_game.error
async def random_users_game_error(ctx, error):
if isinstance(error, BaseException):
await ctx.send('Unexpected error, try again. If the error persists,'
' get help here https://discord.gg/9pS2JdC')
logger.error(error, exc_info=True)
@client.command(name='What_Game_Can_We_Play',
description="Looks up a user's collection and how many people are playing to see what games you could play",
brief="Looks up a user's collection and how many people are playing to see what games you could play",
aliases=['wgcwp', 'wcwp', 'whatcanweplay']
)
async def what_game_can_we_play(ctx, *, arg):
user_input = arg.split(',')
name = user_input[0]
number_of_players = int(user_input[1])
games_we_can_play = Python.BGG.what_games_can_we_play(name, number_of_players)
if games_we_can_play.__len__() > 2000:
for chunk in [games_we_can_play[i:i + 2000] for i in range(0, len(games_we_can_play), 2000)]:
await ctx.send(chunk + '\n')
return
await ctx.send(games_we_can_play)
@what_game_can_we_play.error
async def what_game_can_we_play_error(ctx, error):
if isinstance(error, BaseException):
await ctx.send('Unexpected error, try again. If the error persists,'
' get help here https://discord.gg/9pS2JdC')
logger.error(error, exc_info=True)
@client.command(name='HowToPlay',
description="Returns the top search result video from YouTube \
on how to play",
brief="How to play video",
aliases=['htp', 'how', 'video']
)
async def youtube_how_to(ctx, *, game_name):
main_response = Python.YouTube.how_to_play(game_name)
await ctx.send(main_response)
@youtube_how_to.error
async def youtube_how_to_error(ctx, error):
if isinstance(error, BaseException):
await ctx.send('Unexpected error, try again. If the error persists,'
' get help here https://discord.gg/9pS2JdC')
logger.error(error, exc_info=True)
@client.command()
async def schedule(ctx):
time_now = datetime.datetime.now()
await ctx.say(str(time_now))
@client.command(name='GetHotGames',
description="Returns BoardGameGeeks current hot games",
brief="Returns BoardGameGeeks current hot games",
aliases=['ghg', 'gethotgames', 'hot']
)
async def get_hot_games(ctx):
response = Python.BGG.hot_games()
await ctx.send(response)
@get_hot_games.error
async def get_hot_games_error(ctx, error):
if isinstance(error, BaseException):
await ctx.send('Unexpected error, try again. If the error persists,'
' get help here https://discord.gg/9pS2JdC')
logger.error(error, exc_info=True)
@client.command(name='GetHotCompanies',
description="Returns BoardGameGeeks current hot board game companies",
brief="Returns BoardGameGeeks current hot board game companies",
aliases=['ghc', 'gethotcompanies']
)
async def get_hot_companies(ctx):
response = Python.BGG.hot_companies()
await ctx.send(response)
@get_hot_companies.error
async def get_hot_companies_error(ctx, error):
if isinstance(error, BaseException):
await ctx.send('Unexpected error, try again. If the error persists,'
' get help here https://discord.gg/9pS2JdC')
logger.error(error, exc_info=True)
@client.command(name='AskQuestion',
description="Returns a search of Stack Exchange similar questions",
brief="Returns a search of Stack Exchange similar questions",
aliases=['ask', 'ASK', 'question']
)
async def ask(ctx, *, arg):
user_input = arg.split(',')
game = user_input[0]
question = user_input[1]
response = Python.BGG.search_stackexchange(game, question)
await ctx.send(response)
@ask.error
async def ask_error(ctx, error):
if isinstance(error, BaseException):
await ctx.send('Unexpected error, try again. If the error persists,'
' get help here https://discord.gg/9pS2JdC')
logger.error(error, exc_info=True)
@client.command(name='Lookup_BGG_User',
description='Lookup BGG user',
brief="lookup bgg user",
aliases=['gamesowned', 'lookup-games', 'go']
)
async def lookup_bgg_user(ctx, name):
response = Python.BGG.user_lookup(name)
await ctx.send("Games that " + name + " owns: \n\n" + response)
@lookup_bgg_user.error
async def lookup_bgg_user_error(ctx, error):
if isinstance(error, BaseException):
await ctx.send('Unexpected error, try again. If the error persists,'
' get help here https://discord.gg/9pS2JdC')
logger.error(error, exc_info=True)
@client.command(name="Dice_Roll",
description="Returns the value of a dice roll number is specified by command",
brief="Returns the value of a dice roll",
aliases=['dice']
)
async def dice_roll(ctx, sides):
dice_roll = Python.Dice.dice(int(sides))
await ctx.send("The " + str(sides) + " sided die resulted in: " + str(dice_roll))
@dice_roll.error
async def dice_roll_error(ctx, error):
if isinstance(error, BaseException):
await ctx.send('Unexpected error, try again. If the error persists,'
' get help here https://discord.gg/9pS2JdC')
logger.error(error, exc_info=True)
@client.command(name='Game_Ambiance',
description="Returns the top search result video from YouTube",
brief="Ambiance video",
aliases=['amb', 'ambiance']
)
async def game_ambiance_playlist(ctx, *, topic):
main_response = Python.YouTube.game_ambiance(topic)
await ctx.send("Here's the result for " + topic +
" ambiance \n" + main_response)
@game_ambiance_playlist.error
async def game_ambiance_playlist_error(ctx, error):
if isinstance(error, BaseException):
await ctx.send('Unexpected error, try again. If the error persists,'
' get help here https://discord.gg/9pS2JdC')
logger.error(error, exc_info=True)
@client.command(name='Next_Video',
description="Returns the next video in the last youtube search",
brief="Return next video",
aliases=['nextvid', 'nxt', 'nvideo']
)
async def next_video(ctx):
response = Python.YouTube.search_next_video()
await ctx.send("Next video: \n" + response)
@next_video.error
async def next_video_error(ctx, error):
if isinstance(error, BaseException):
await ctx.send('Unexpected error, try again. If the error persists,'
' get help here https://discord.gg/9pS2JdC')
logger.error(error, exc_info=True)
@client.event
async def on_ready():
print('Ready!')
async def list_servers():
await client.wait_until_ready()
while not client.is_closed():
print("Current servers:")
for guild in client.guilds:
print(guild.name)
await client.change_presence(activity=discord.Game(name=Python.BGG.random_owned_game("matta174")))
await asyncio.sleep(600)
client.loop.create_task(list_servers())
client.run(TOKEN)