generated from kkrypt0nn/Python-Discord-Bot-Template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
achievement.py
108 lines (94 loc) · 3.69 KB
/
achievement.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
""""
Samuro Bot
Автор: *fennr*
github: https://github.com/fennr/Samuro-HotsBot
Бот для сообществ по игре Heroes of the Storm
"""
from discord import Member
from discord.ext import commands
from datetime import date
from utils.classes import Const
from utils import exceptions, library, check
from utils.classes.Const import config
class Team(commands.Cog, name="Team"):
"""
— Описание модуля Достижений
"""
def __init__(self, bot):
self.bot = bot
@commands.group(name="achievement")
async def achievement(self, ctx):
if ctx.invoked_subcommand is None:
con, cur = library.get.con_cur()
guild_id = library.get.guild_id(ctx)
select = Const.selects.AchievGuild
cur.execute(select, (guild_id,))
records = cur.fetchall()
con.close()
achievements = ''
for record in records:
achievements += f'{record.name}, id = **{record.id}**\n'
if len(achievements) > 0:
await ctx.send(achievements)
@achievement.command(name="create")
@check.is_admin()
async def achievement_create(self, ctx, *name):
con, cur = library.get.con_cur()
guild_id = library.get.guild_id(ctx)
achiev_name = ' '.join(name)
insert = Const.inserts.Achievement
cur.execute(insert, (guild_id, achiev_name))
record = cur.fetchone()
library.commit(con)
await ctx.send(f'Добавлено достижение {achiev_name} (id: {record.id})')
@achievement.command(name="assign")
@check.is_admin()
async def achievement_assign(self, ctx, member: Member, id):
con, cur = library.get.con_cur()
guild_id = library.get.guild_id(ctx)
select = Const.selects.AchievId
cur.execute(select, (id,))
record = cur.fetchone()
print(record)
today = date.today()
try:
insert = Const.inserts.UserAchiev
cur.execute(insert, (member.id, guild_id, id, today))
library.commit(con)
await ctx.send(f"{member.mention} теперь **{record.name}**")
except Exception:
print('На выбранном сервере нет такого достижения')
await ctx.message.delete()
@achievement.command(name="remove")
@check.is_admin()
async def achievement_remove(self, ctx, member: Member, id):
con, cur = library.get.con_cur()
guild_id = library.get.guild_id(ctx)
select = Const.selects.AchievId
cur.execute(select, (id,))
record = cur.fetchone()
achiev_name = record.name
delete = Const.deletes.UserAchiev
cur.execute(delete, (member.id, guild_id, id))
if cur.rowcount:
library.commit(con)
await ctx.send(f"С игрока {member.mention} снято достижение **{achiev_name}**")
else:
con.close()
await ctx.send(f"У игрока {member.mention} нет достижения **{achiev_name}**")
@achievement.command(name="delete")
@check.is_admin()
async def achievement_delete(self, ctx, id: int):
con, cur = library.get.con_cur()
guild_id = library.get.guild_id(ctx)
delete = Const.deletes.AchievId
cur.execute(delete, (id, guild_id))
achiev_name = cur.fetchone()[0]
if cur.rowcount:
library.commit(con)
await ctx.send(f"Достижение **{achiev_name}** удалено")
else:
con.close()
await ctx.send(f"Нет достижения с **id={id}**")
def setup(bot):
bot.add_cog(Team(bot))