This repository was archived by the owner on Mar 5, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathadmin_commands.py
More file actions
150 lines (143 loc) · 5.82 KB
/
admin_commands.py
File metadata and controls
150 lines (143 loc) · 5.82 KB
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
# from modules.pokemon_functionality import PokemonFunctionality
from classes import PokeBotCog
from cogs.logic.admin_logic import AdminLogic
from discord.ext import commands
from modules.pokebot_exceptions import (
HigherReleaseQuantitySpecifiedException,
LootboxDoesNotExistException,
NotEnoughLootboxQuantityException,
PokemonDoesNotExistException,
UnregisteredTrainerException
)
from utils.utils import format_shiny_pokemon_name, is_name_shiny
class AdminCommands(PokeBotCog):
def __init__(self, bot):
super().__init__()
self.admin_logic = AdminLogic(bot)
@commands.command(name='give', pass_context=True, hidden=True)
@commands.has_role('PokeBot Admin')
async def give(
self,
ctx: commands.Context,
user_id: int = commands.parameter(
description="ID of the trainer to give a pokemon too"
),
pkmn_name: str = commands.parameter(
description="Name of the pokemon to delete"
),
shiny: str = commands.parameter(
description="Specify 's' or not to give a shiny pokemon",
default=''
)
) -> None:
"""
Gives a pokemon to a trainer (admin only cmd)
"""
try:
is_shiny = False
if shiny == 's':
is_shiny = True
str_user_id = str(user_id)
await self.admin_logic.give_pokemon(
str_user_id,
pkmn_name,
is_shiny
)
formatted_pkmn_name = pkmn_name.title()
if is_shiny:
formatted_pkmn_name = "(Shiny) " + formatted_pkmn_name
await ctx.send(f"{ctx.message.author.mention} gave a"
f" **{formatted_pkmn_name}** to <@{str_user_id}>")
except PokemonDoesNotExistException as e:
await self.post_pokemon_does_not_exist_exception_msg(ctx, e)
@commands.command(name='delete', pass_context=True, hidden=True)
@commands.has_role('PokeBot Admin')
async def delete(
self,
ctx: commands.Context,
user_id: int = commands.parameter(
description="ID of the trainer to give a pokemon too"
),
pkmn_name: str = commands.parameter(
description=("Name of the pokemon to delete i.e. "
"'pikachu', '(shiny)pikachu'")
)
) -> None:
"""
Deletes a pokemon from the trainer (admin only cmd)
"""
try:
str_user_id = str(user_id)
formatted_pkmn_name = pkmn_name.lower()
await self.admin_logic.delete_pokemon(str_user_id,
formatted_pkmn_name)
if is_name_shiny(pkmn_name):
formatted_pkmn_name = format_shiny_pokemon_name(pkmn_name)
else:
formatted_pkmn_name = formatted_pkmn_name.title()
await ctx.send(f"{ctx.message.author.mention} deleted a"
f" **{formatted_pkmn_name}** from trainer"
f" <@{str_user_id}>")
except UnregisteredTrainerException as e:
await self.post_unregistered_trainer_admin_exception_msg(ctx, e)
except HigherReleaseQuantitySpecifiedException as e:
await self.post_higher_quantity_specified_exception_msg(ctx, e)
except PokemonDoesNotExistException as e:
await self.post_pokemon_does_not_exist_exception_msg(ctx, e)
@commands.command(name='giveloot', pass_context=True, hidden=True)
@commands.has_role('PokeBot Admin')
async def giveloot(
self,
ctx: commands.Context,
user_id: int = commands.parameter(
description="ID of the trainer to give a pokemon too"
),
lootbox: str = commands.parameter(
description="Specify either 'bronze', 'silver' or 'gold' lootbox"
)
) -> None:
"""
Gives a trainer a specified lootbox
"""
try:
str_user_id = str(user_id)
formatted_lootbox = lootbox.lower()
await self.admin_logic.give_lootbox(str_user_id,
formatted_lootbox)
await ctx.send(f"{ctx.message.author.mention} gave a"
f" **{formatted_lootbox.title()}** lootbox"
f" to trainer <@{str_user_id}>")
except LootboxDoesNotExistException as e:
await self.post_lootbox_does_not_exist(ctx, e)
@commands.command(name='deleteloot', pass_context=True, hidden=True)
@commands.has_role('PokeBot Admin')
async def deleteloot(
self,
ctx: commands.Context,
user_id: int = commands.parameter(
description="ID of the trainer to give a pokemon too"
),
lootbox: str = commands.parameter(
description="Specify either 'bronze', 'silver' or 'gold' lootbox"
)
) -> None:
"""
Deletes a lootbox from a trainer's inventory
"""
try:
str_user_id = str(user_id)
formatted_lootbox = lootbox.lower()
await self.admin_logic.delete_lootbox(str_user_id,
formatted_lootbox)
await ctx.send(f"{ctx.message.author.mention} deleted a"
f" **{formatted_lootbox.title()}** lootbox from"
f" trainer <@{str_user_id}>")
except UnregisteredTrainerException as e:
await self.post_unregistered_trainer_admin_exception_msg(ctx, e)
except LootboxDoesNotExistException as e:
await self.post_lootbox_does_not_exist(ctx, e)
except NotEnoughLootboxQuantityException as e:
await self.post_not_enough_lootbox_quantity_admin_exception_msg(
ctx,
e
)