1
1
import random
2
2
3
- import discord
4
3
from discord import app_commands
5
4
from discord .ext import commands
6
- from loguru import logger
7
5
8
6
from tux .utils .embeds import EmbedCreator
9
7
@@ -12,35 +10,39 @@ class Random(commands.Cog):
12
10
def __init__ (self , bot : commands .Bot ) -> None :
13
11
self .bot = bot
14
12
15
- @app_commands .command (name = "coinflip" , description = "Flip a coin." )
16
- async def coinflip (self , interaction : discord .Interaction ) -> None :
13
+ @commands .hybrid_group (name = "random" , description = "Random generation commands." )
14
+ @commands .guild_only ()
15
+ async def random (self , ctx : commands .Context [commands .Bot ]) -> None :
16
+ if ctx .invoked_subcommand is None :
17
+ await ctx .send_help ("random" )
18
+
19
+ @random .command (name = "coinflip" , description = "Flip a coin." )
20
+ async def coinflip (self , ctx : commands .Context [commands .Bot ]) -> None :
17
21
"""
18
22
Flip a coin.
19
23
20
24
Parameters
21
25
----------
22
- interaction : discord.Interaction
23
- The discord interaction object.
26
+ ctx : commands.Context[commands.Bot]
27
+ The context object for the command .
24
28
"""
25
- await interaction .response .send_message (
26
- content = "You got heads!" if random .choice ([True , False ]) else "You got tails!"
27
- )
28
29
29
- logger . info ( f" { interaction . user } used the coinflip command in { interaction . channel } . " )
30
+ await ctx . send ( content = "You got heads!" if random . choice ([ True , False ]) else "You got tails! " )
30
31
31
- @app_commands .command (name = "8ball" , description = "Ask the magic 8ball a question." )
32
+ @random .command (name = "8ball" , description = "Ask the magic 8ball a question." )
32
33
@app_commands .describe (question = "The question to ask the 8ball." )
33
- async def eight_ball (self , interaction : discord . Interaction , question : str ) -> None :
34
+ async def eight_ball (self , ctx : commands . Context [ commands . Bot ], * , question : str ) -> None :
34
35
"""
35
36
Ask the magic 8ball a question.
36
37
37
38
Parameters
38
39
----------
39
- interaction : discord.Interaction
40
- The discord interaction object.
40
+ ctx : commands.Context[commands.Bot]
41
+ The context object for the command .
41
42
question : str
42
43
The question to ask the 8ball.
43
44
"""
45
+
44
46
responses = [
45
47
# Standard responses
46
48
"It is certain" ,
@@ -61,22 +63,25 @@ async def eight_ball(self, interaction: discord.Interaction, question: str) -> N
61
63
"Don't count on it" ,
62
64
"My reply is no" ,
63
65
"My sources say no" ,
66
+ "Probably" ,
64
67
"Outlook not so good" ,
65
68
"Very doubtful" ,
66
- # Custom responses
67
69
"Why the hell are you asking me lmao" ,
68
- "what ???" ,
69
- "hell yeah" ,
70
- "hell no" ,
70
+ "What ???" ,
71
+ "Hell yeah" ,
72
+ "Hell no" ,
71
73
"When pigs fly" ,
72
74
"Ask someone else for once, I'm sick and tired of answering your questions you absolute buffoon." ,
73
75
"I dont know, ask me later" ,
76
+ "I'm not sure" ,
77
+ "Ask your mom" ,
78
+ "Ask Puffy or Beastie" ,
79
+ "Absolutely" ,
74
80
]
75
-
76
81
choice = random .choice (responses )
77
82
78
83
response = f"""Response to "{ question } ":
79
- { "_" * len (choice )}
84
+ { "_" * len (choice )}
80
85
< { choice } >
81
86
{ "-" * len (choice )}
82
87
\\ ^__^
@@ -85,73 +90,58 @@ async def eight_ball(self, interaction: discord.Interaction, question: str) -> N
85
90
||----w |
86
91
|| ||
87
92
"""
93
+ await ctx .reply (content = f"```{ response } ```" )
88
94
89
- await interaction .response .send_message (content = f"```{ response } ```" )
90
-
91
- logger .info (f"{ interaction .user } used the 8ball command in { interaction .channel } ." )
92
-
93
- @app_commands .command (name = "dice" , description = "Roll a dice." )
95
+ @random .command (name = "dice" , description = "Roll a dice." )
94
96
@app_commands .describe (sides = "The number of sides on the dice. (default: 6)" )
95
- async def dice (self , interaction : discord . Interaction , sides : int = 6 ) -> None :
97
+ async def dice (self , ctx : commands . Context [ commands . Bot ] , sides : int = 6 ) -> None :
96
98
"""
97
99
Roll a dice.
98
100
99
101
Parameters
100
102
----------
101
- interaction : discord.Interaction
102
- The discord interaction object.
103
+ ctx : commands.Context[commands.Bot]
104
+ The context object for the command .
103
105
sides : int, optional
104
106
The number of sides on the dice, by default 6.
105
107
"""
108
+
106
109
if sides < 2 :
107
- await interaction . response . send_message (content = "The dice must have at least 2 sides." )
110
+ await ctx . reply (content = "The dice must have at least 2 sides." , ephemeral = True )
108
111
return
109
112
110
113
embed = EmbedCreator .create_info_embed (
111
114
title = f"Dice Roll (D{ sides } )" ,
112
115
description = f"You rolled a { random .randint (1 , sides )} !" ,
113
- interaction = interaction ,
116
+ ctx = ctx ,
114
117
)
115
118
116
- await interaction . response . send_message (embed = embed )
119
+ await ctx . reply (embed = embed )
117
120
118
- logger .info (f"{ interaction .user } used the dice command in { interaction .channel } ." )
119
-
120
- @app_commands .command (name = "randomnumber" , description = "Generate a random number." )
121
+ @random .command (name = "number" , description = "Generate a random number." )
121
122
@app_commands .describe (
122
123
minimum = "The minimum value of the random number. (default: 0)" ,
123
124
maximum = "The maximum value of the random number. (default: 100)" ,
124
125
)
125
- async def random_number (
126
- self , interaction : discord .Interaction , minimum : int = 0 , maximum : int = 100
127
- ) -> None :
126
+ async def random_number (self , ctx : commands .Context [commands .Bot ], minimum : int = 0 , maximum : int = 100 ) -> None :
128
127
"""
129
128
Generate a random number.
130
129
131
130
Parameters
132
131
----------
133
- interaction : discord.Interaction
134
- The discord interaction object.
132
+ ctx : commands.Context[commands.Bot]
133
+ The context object for the command .
135
134
minimum : int, optional
136
135
The minimum value of the random number, by default 0.
137
136
maximum : int, optional
138
137
The maximum value of the random number, by default 100.
139
138
"""
139
+
140
140
if minimum > maximum :
141
- await interaction .response .send_message (
142
- content = "The minimum value must be less than the maximum value."
143
- )
141
+ await ctx .reply (content = "The minimum value must be less than the maximum value." , ephemeral = True )
144
142
return
145
143
146
- embed = EmbedCreator .create_info_embed (
147
- title = "Random Number" ,
148
- description = f"Your random number is: { random .randint (minimum , maximum )} " ,
149
- interaction = interaction ,
150
- )
151
-
152
- await interaction .response .send_message (embed = embed )
153
-
154
- logger .info (f"{ interaction .user } used the randomnumber command in { interaction .channel } ." )
144
+ await ctx .reply (content = f"Your random number is: { random .randint (minimum , maximum )} " )
155
145
156
146
157
147
async def setup (bot : commands .Bot ) -> None :
0 commit comments