generated from kkrypt0nn/Python-Discord-Bot-Template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhots.py
444 lines (406 loc) · 17.8 KB
/
hots.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
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
""""
Samuro Bot
Автор: *fennr*
github: https://github.com/fennr/Samuro-HotsBot
Бот для сообществ по игре Heroes of the Storm
"""
import inspect
import os
from sys import platform
import subprocess
import discord
from discord import Embed
from discord.ext import commands
from discord.ext.commands import command, Cog, errors
from discord_components import DiscordComponents, Button, ButtonStyle
from utils.library.hots import hero_not_found, find_more_heroes, get_hero, get_master_opinion, add_master_opinion
from utils.classes.Hero import Hero
from utils.hots.heroes import heroes_description, builds, embed_stlk_builds
from utils.hots import nexuscompendium
from utils.hots.patchnotes import last_pn
from utils.hots.skills import skill
from utils.hots.talents import talents
from utils.hots.tierlist import ban_heroes
from utils.hots.twitch import get_streams, get_trovo_streams
from utils.library import files
from utils import check, exceptions
from utils.classes.Const import config
# menu
heroes_label = 'Герой'
skills_label = 'Скиллы'
talent_label = 'Таланты'
lastpn_label = 'Патч'
# hero
descrp_label = 'Описание'
patchn_label = 'Патчноуты'
builds_label = 'Билды'
# skills
basic_label = 'Базовые'
heroic_label = "Героические"
trait_label = 'Особые'
# talents
lvl_01_label = '1'
lvl_04_label = '4'
lvl_07_label = '7'
lvl_10_label = '10'
lvl_13_label = '13'
lvl_16_label = '16'
lvl_20_label = '20'
mailing_channel_id = {
'test_fenrir': 845658540341592098, # test
'ru hots': 642853714515722241, # общение
'Dungeon': 858455796412710922, # hots камеры
'Stlk': 124864790110797824, # общие
'Читер': 841669769115336704 # хотс
}
class Hots(Cog, name='Hots'):
"""
— Команды связанные с хотсом помимо информации о героях
"""
def __init__(self, bot):
self.bot = bot
@command(name='weekly')
async def rotation(self, ctx):
"""
- Список героев еженедельной ротации
"""
embed = nexuscompendium.weekly_rotation()
await ctx.send(embed=embed)
@command(name="replay")
async def replay_parser(self, ctx, full=None):
attachment = ctx.message.attachments[0]
replay = f'data/replays/{attachment.filename}'
await attachment.save(replay)
if platform == 'linux':
command = ["./scripts/HeroesDecode/Linux/heroesdecode", "-p", replay]
elif platform == 'win32':
command = ["./scripts/HeroesDecode/Windows/heroesdecode", "-p", replay]
if full is not None:
command.append("-s")
p = subprocess.Popen(
command,
stdin=subprocess.PIPE,
stdout=subprocess.PIPE,
)
stdout, stderr = p.communicate()
p.wait()
out = stdout.decode('cp866')
output_file = f'{replay}.txt'
with open(output_file, "w") as file:
file.write(out)
await ctx.send(file=discord.File(output_file))
os.remove(output_file)
os.remove(replay)
#print(out)
#print(stderr)
@command(name="rqg")
async def rqg_site(self, ctx):
stormru_id = 124864790110797824
rqg_emoji = 'RQG2'
rqg_url = 'https://heroeslounge.gg/team/view/RQG'
guild = self.bot.get_guild(stormru_id)
emoji = discord.utils.get(guild.emojis, name=rqg_emoji)
await ctx.send(f"{emoji} Rage & Quit Gaming {emoji}\n"
f"Киберспортивная команда СНГ региона, основанная в 2020 году\n"
f"Состав: {rqg_url}")
@command(name="pancho")
async def pancho(self, ctx, hero_name):
"""
- Мнение Мастера
"""
pancho = get_master_opinion(ctx, hero_name)
if isinstance(pancho, Embed):
await ctx.send(embed=pancho)
else:
await ctx.send(pancho)
@command(name="pancho_add")
@check.is_owner()
async def pancho_add(self, ctx, hero_name, url):
error = add_master_opinion(hero_name, url)
if not error:
await ctx.send("Запись была добавлена")
else:
await ctx.send("Ошибка при записи")
@command(name="patchnotes")
async def hots_notes(self, ctx):
"""
- Информация по патчноутам
"""
embed = last_pn(None, ctx.author)
await ctx.send(embed=embed)
@command(name='ban')
async def ban_list(self, ctx):
"""
- Список героев рекомендуемых к бану
"""
embed = ban_heroes()
await ctx.send(
embed=embed
)
@command(name='sales')
async def sales(self, ctx):
"""
- Список скидок на героев
"""
embed = nexuscompendium.sales()
await ctx.send(
embed=embed
)
@command(name='ranked')
async def ranked(self, ctx):
"""
- Информация о сроках текущего сезона
"""
embed = nexuscompendium.ranked()
await ctx.send(
embed=embed
)
@command(name='data')
async def heroes_data(self, ctx, hero_name):
"""
- Полное описания героя
"""
if hero_name is not None:
hero = get_hero(hero_name)
if isinstance(hero, Hero):
embed = builds(hero, ctx.author)
default_hero_name = hero.en.lower().replace('.', '').replace("'", "")
heroespn_url = 'https://heroespatchnotes.com/hero/'
heroespn_url_full = heroespn_url + default_hero_name.replace(' ', '') + '.html'
menu_buttons = [
Button(style=ButtonStyle.blue, label=heroes_label, disabled=True),
Button(style=ButtonStyle.blue, label=skills_label),
Button(style=ButtonStyle.blue, label=talent_label),
Button(style=ButtonStyle.blue, label=lastpn_label),
]
hero_buttons = [
Button(style=ButtonStyle.grey, label=descrp_label),
Button(style=ButtonStyle.grey, label=builds_label, disabled=True),
Button(style=ButtonStyle.URL, label=patchn_label, url=heroespn_url_full),
]
await ctx.send(
embed=embed,
components=[
hero_buttons,
menu_buttons
],
)
else:
embed = find_more_heroes(hero, ctx.author, command='data')
await ctx.send(embed=embed)
else:
embed = hero_not_found()
await ctx.send(embed=embed)
@command(name='streams')
async def streams(self, ctx, count=5):
"""
- Ссылки на запущенные стримы на твиче
"""
if isinstance(int(count), int):
embed = get_streams(int(count))
else:
embed = get_streams()
await ctx.send(
embed=embed
)
@command(name='trovo')
async def streams_trovo(self, ctx, limit=5):
"""
- Запущенные на trovo стримы
"""
embed = get_trovo_streams(limit)
await ctx.send(embed=embed)
@command(name='stlk')
async def stlk_builds(self, ctx, *hero_name):
"""
- Авторские билды от про игрока **STLK**
"""
if len(hero_name) == 0:
param = inspect.Parameter(name="hero_name", kind=inspect.Parameter.VAR_POSITIONAL)
raise commands.MissingRequiredArgument(param)
name = ' '.join(hero_name)
hero = get_hero(name)
if isinstance(hero, Hero):
embed = embed_stlk_builds(hero, ctx.author, ad=True)
else:
embed = find_more_heroes(hero, ctx.author, command="stlk")
await ctx.send(embed=embed)
@Cog.listener()
async def on_button_click(self, res):
"""
Possible interaction types:
- Pong
- ChannelMessageWithSource
- DeferredChannelMessageWithSource
- DeferredUpdateMessage
- UpdateMessage
"""
try:
embed = None
components = None
hero_name, tail = res.raw_data['message']['embeds'][0]['title'].split(' / ', maxsplit=1)
text, author = res.raw_data['message']['embeds'][-1]['footer']['text'].split(': ', maxsplit=1)
hero = Hero(hero_name)
default_hero_name = hero_name.lower().replace('.', '').replace("'", "")
heroespn_url = 'https://heroespatchnotes.com/hero/'
heroespn_url_full = heroespn_url + default_hero_name.replace(' ', '') + '.html'
menu_buttons = [
Button(style=ButtonStyle.blue, label=heroes_label),
Button(style=ButtonStyle.blue, label=skills_label),
Button(style=ButtonStyle.blue, label=talent_label),
Button(style=ButtonStyle.blue, label=lastpn_label),
]
hero_buttons = [
Button(style=ButtonStyle.grey, label=descrp_label),
Button(style=ButtonStyle.grey, label=builds_label),
Button(style=ButtonStyle.URL, label=patchn_label, url=heroespn_url_full),
]
skill_buttons = [
Button(style=ButtonStyle.grey, label=basic_label),
Button(style=ButtonStyle.grey, label=heroic_label),
Button(style=ButtonStyle.grey, label=trait_label),
]
talent_buttons1 = [
Button(style=ButtonStyle.grey, label=lvl_01_label),
Button(style=ButtonStyle.grey, label=lvl_04_label),
Button(style=ButtonStyle.grey, label=lvl_07_label),
Button(style=ButtonStyle.grey, label=lvl_10_label),
]
talent_buttons2 = [
Button(style=ButtonStyle.grey, label=lvl_13_label),
Button(style=ButtonStyle.grey, label=lvl_16_label),
Button(style=ButtonStyle.grey, label=lvl_20_label),
]
skill_components = [
skill_buttons,
menu_buttons
]
hero_components = [
hero_buttons,
menu_buttons
]
talent_components = [
talent_buttons1,
talent_buttons2,
menu_buttons
]
lastpn_components = [
menu_buttons
]
if res.component.label == descrp_label:
embed = heroes_description(hero, author)
components = hero_components
components[0][0] = Button(style=ButtonStyle.grey, label=descrp_label, disabled=True)
components[1][0] = Button(style=ButtonStyle.blue, label=heroes_label, disabled=True)
if res.component.label == builds_label or \
res.component.label == heroes_label:
embed = builds(hero, author)
components = hero_components
components[0][1] = Button(style=ButtonStyle.grey, label=builds_label, disabled=True)
components[1][0] = Button(style=ButtonStyle.blue, label=heroes_label, disabled=True)
if res.component.label == skills_label:
embed = skill(hero, author)
components = skill_components
components[0][0] = Button(style=ButtonStyle.grey, label=basic_label, disabled=True)
components[1][1] = Button(style=ButtonStyle.blue, label=skills_label, disabled=True)
if res.component.label == basic_label:
embed = skill(hero, author, 'basic')
components = skill_components
components[0][0] = Button(style=ButtonStyle.grey, label=basic_label, disabled=True)
components[1][1] = Button(style=ButtonStyle.blue, label=skills_label, disabled=True)
if res.component.label == heroic_label:
embed = skill(hero, author, 'heroic')
components = skill_components
components[0][1] = Button(style=ButtonStyle.grey, label=heroic_label, disabled=True)
components[1][1] = Button(style=ButtonStyle.blue, label=skills_label, disabled=True)
if res.component.label == trait_label:
embed = skill(hero, author, 'trait')
components = skill_components
components[0][2] = Button(style=ButtonStyle.grey, label=trait_label, disabled=True)
components[1][1] = Button(style=ButtonStyle.blue, label=skills_label, disabled=True)
if res.component.label == talent_label or \
res.component.label == lvl_01_label:
embed = talents(hero, 1, author)
components = talent_components
components[0][0] = Button(style=ButtonStyle.grey, label=lvl_01_label, disabled=True)
components[2][2] = Button(style=ButtonStyle.blue, label=talent_label, disabled=True)
if res.component.label == lvl_04_label:
embed = talents(hero, 4, author)
components = talent_components
components[0][1] = Button(style=ButtonStyle.grey, label=lvl_04_label, disabled=True)
components[2][2] = Button(style=ButtonStyle.blue, label=talent_label, disabled=True)
if res.component.label == lvl_07_label:
embed = talents(hero, 7, author)
components = talent_components
components[0][2] = Button(style=ButtonStyle.grey, label=lvl_07_label, disabled=True)
components[2][2] = Button(style=ButtonStyle.blue, label=talent_label, disabled=True)
if res.component.label == lvl_10_label:
embed = talents(hero, 10, author)
components = talent_components
components[0][3] = Button(style=ButtonStyle.grey, label=lvl_10_label, disabled=True)
components[2][2] = Button(style=ButtonStyle.blue, label=talent_label, disabled=True)
if res.component.label == lvl_13_label:
embed = talents(hero, 13, author)
components = talent_components
components[1][0] = Button(style=ButtonStyle.grey, label=lvl_13_label, disabled=True)
components[2][2] = Button(style=ButtonStyle.blue, label=talent_label, disabled=True)
if res.component.label == lvl_16_label:
embed = talents(hero, 16, author)
components = talent_components
components[1][1] = Button(style=ButtonStyle.grey, label=lvl_16_label, disabled=True)
components[2][2] = Button(style=ButtonStyle.blue, label=talent_label, disabled=True)
if res.component.label == lvl_20_label:
embed = talents(hero, 20, author)
components = talent_components
components[1][2] = Button(style=ButtonStyle.grey, label=lvl_20_label, disabled=True)
components[2][2] = Button(style=ButtonStyle.blue, label=talent_label, disabled=True)
if res.component.label == lastpn_label:
embed = last_pn(hero, author)
components = lastpn_components
components[0][3] = Button(style=ButtonStyle.blue, label=lastpn_label, disabled=True)
if author == str(res.user):
await res.respond(
type=7, embed=embed, components=components
)
else:
error_text = 'Команда вызвана другим пользователем, взаимодействие невозможно\n' \
'Введите /data :hero: для получения информации по герою'
await res.respond(
type=4, content=f"{error_text}"
)
# можно использовать или embed или content content=f"{res.component.label} pressed",
except:
pass
@heroes_data.error
@stlk_builds.error
async def hots_handler(self, ctx, error):
#print("Обработка ошибок hots")
error = getattr(error, 'original', error) # получаем пользовательские ошибки
print(error)
#print(type(error))
print(f"Сообщение вызвавшее ошибку: '{ctx.message.content}' guild {ctx.guild} by {ctx.author}")
if isinstance(error, errors.MissingRequiredArgument):
embed = Embed(
title="Ошибка! Введите все аргументы",
color=config.error
)
embed.add_field(
name="Пример:",
value=f"_{config.bot_prefix}{ctx.command} Самуро_",
inline=False
)
embed.set_footer(
text=f"{config.bot_prefix}help для просмотра справки по командам" # context.message.author если использовать без slash
)
await ctx.send(embed=embed)
elif isinstance(error, exceptions.HeroNotFoundError):
text = "Ошибка! Герой не найден"
embed = Embed(
title=text,
color=config.error
)
embed = files.add_footer(embed)
await ctx.send(embed=embed)
def setup(bot):
DiscordComponents(bot) # If you have this in an on_ready() event you can remove this line.
bot.add_cog(Hots(bot))