File tree 7 files changed +187
-2
lines changed
7 files changed +187
-2
lines changed Original file line number Diff line number Diff line change
1
+ import disnake
2
+ from disnake .ext import commands
3
+ from app .Controllers .Discord .greetUser import greet_user
4
+
5
+ class Greet (commands .Cog ):
6
+ """
7
+ A cog that contains a command to greet users.
8
+
9
+ This cog defines a command that greets the user who invoked it. The greeting message is generated
10
+ using the greet_user function from the greetUser controller.
11
+
12
+ Attributes:
13
+ bot (commands.Bot): The bot instance that the cog is attached to.
14
+ """
15
+
16
+ def __init__ (self , bot ):
17
+ """
18
+ Initializes the Greet cog.
19
+
20
+ Args:
21
+ bot (commands.Bot): The bot instance that the cog is attached to.
22
+ """
23
+ self .bot = bot
24
+
25
+ @commands .command ()
26
+ async def hello (self , ctx ):
27
+ """
28
+ Command to greet the user who invoked it using the Controller: app/Controllers/Discord/greetUser.py.
29
+
30
+ This command uses the greet_user function to generate a greeting message for the user who invoked
31
+ the command and sends it as a response in the Discord channel.
32
+
33
+ Args:
34
+ ctx (commands.Context): The context in which the command was invoked.
35
+ """
36
+ greeting = greet_user (ctx .author .name )
37
+ await ctx .send (greeting )
38
+
39
+ def setup (bot ):
40
+ bot .add_cog (Greet (bot ))
Original file line number Diff line number Diff line change 2
2
from disnake .ext import commands
3
3
4
4
class Ping (commands .Cog ):
5
+ """
6
+ A cog that contains a command to check the bot's latency.
7
+
8
+ This cog defines a command named 'ping' that responds with the bot's latency
9
+ when invoked. The latency is calculated and returned in milliseconds.
10
+
11
+ Attributes:
12
+ bot (commands.Bot): The bot instance that the cog is attached to.
13
+ """
14
+
5
15
def __init__ (self , bot ):
16
+ """
17
+ Initializes the Ping cog.
18
+
19
+ Args:
20
+ bot (commands.Bot): The bot instance that the cog is attached to.
21
+ """
6
22
self .bot = bot
7
23
8
24
@commands .command ()
9
25
async def ping (self , ctx ):
26
+ """
27
+ Command to check the bot's latency.
28
+
29
+ This command calculates the bot's latency and sends it as a response in the Discord channel.
30
+
31
+ Args:
32
+ ctx (commands.Context): The context in which the command was invoked.
33
+ """
10
34
latency = round (self .bot .latency * 1000 ) # Calculate bot's latency in milliseconds
11
35
await ctx .send (f'Pong! Latency: { latency } ms' )
12
36
Original file line number Diff line number Diff line change
1
+ import disnake
2
+ from disnake .ext import commands
3
+ from app .Controllers .Discord .greetUser import greet_user
4
+
5
+ class GreetSlash (commands .Cog ):
6
+ """
7
+ A cog that contains a command to greet users.
8
+
9
+ This cog defines a command that greets the user who invoked it. The greeting message is generated
10
+ using the greet_user function from the greetUser controller.
11
+
12
+ Attributes:
13
+ bot (commands.Bot): The bot instance that the cog is attached to.
14
+ """
15
+
16
+ def __init__ (self , bot ):
17
+ """
18
+ Initializes the Greet cog.
19
+
20
+ Args:
21
+ bot (commands.Bot): The bot instance that the cog is attached to.
22
+ """
23
+ self .bot = bot
24
+
25
+ @commands .slash_command (
26
+ name = "hello" ,
27
+ description = "Greet the user"
28
+ )
29
+ async def hello (self , ctx ):
30
+ """
31
+ Command to greet the user who invoked it using the Controller: app/Controllers/Discord/greetUser.py.
32
+
33
+ This command uses the greet_user function to generate a greeting message for the user who invoked
34
+ the command and sends it as a response in the Discord channel.
35
+
36
+ Args:
37
+ ctx (commands.Context): The context in which the command was invoked.
38
+ """
39
+ greeting = greet_user (ctx .author .name )
40
+ await ctx .send (greeting )
41
+
42
+ def setup (bot ):
43
+ bot .add_cog (GreetSlash (bot ))
Original file line number Diff line number Diff line change 2
2
from disnake .ext import commands
3
3
4
4
class PingSlash (commands .Cog ):
5
+ """
6
+ A cog that contains a slash command to check the bot's latency.
7
+
8
+ This cog defines a slash command named 'ping' that responds with the bot's latency
9
+ when invoked. The latency is calculated and returned in milliseconds.
10
+
11
+ Attributes:
12
+ bot (commands.Bot): The bot instance that the cog is attached to.
13
+ """
14
+
5
15
def __init__ (self , bot ):
16
+ """
17
+ Initializes the PingSlash cog.
18
+
19
+ Args:
20
+ bot (commands.Bot): The bot instance that the cog is attached to.
21
+ """
6
22
self .bot = bot
7
23
8
24
@commands .slash_command (
9
25
name = "ping" ,
10
26
description = "Check the bot's latency" ,
11
27
)
12
28
async def ping (self , ctx ):
13
- """Command to check the bot's latency"""
29
+ """
30
+ Command to check the bot's latency.
31
+
32
+ This command calculates the bot's latency and sends it as a response in the Discord channel.
33
+
34
+ Args:
35
+ ctx (commands.Context): The context in which the command was invoked.
36
+ """
14
37
await ctx .send (f"Pong! Latency: { round (self .bot .latency * 1000 )} ms" )
15
38
16
39
def setup (bot ):
Original file line number Diff line number Diff line change
1
+ def greet_user (name ):
2
+ """
3
+ Controller function to greet a user in Discord.
4
+
5
+ This function takes the name of a user and returns a greeting message. It can be used in a Discord bot
6
+ to send personalized greetings to users.
7
+
8
+ Args:
9
+ name (str): The name of the user.
10
+
11
+ Returns:
12
+ str: A greeting message.
13
+ """
14
+ # Do some processing here
15
+ return f"Hello, **{ name } **!"
Original file line number Diff line number Diff line change
1
+ def greet_user (name ):
2
+ """
3
+ Controller function to greet a user.
4
+
5
+ This function is called when the user visits the /example route. It processes the user's name
6
+ and returns a greeting message in HTML format.
7
+
8
+ Args:
9
+ name (str): The name of the user.
10
+
11
+ Returns:
12
+ str: An HTML string with a greeting message.
13
+ """
14
+ # Do some processing here
15
+ return f"<h1>Hello, { name } !</h1>"
Original file line number Diff line number Diff line change 1
1
from flask import current_app as app , render_template
2
+ from app .Controllers .Flask .greetUser import greet_user
2
3
3
4
@app .route ('/' )
4
5
def home ():
5
- return render_template ('index.html' )
6
+ """
7
+ Render the home page.
8
+
9
+ This route renders the index.html template when the user visits the root URL.
10
+
11
+ Returns:
12
+ str: The rendered HTML of the home page.
13
+ """
14
+ return render_template ('index.html' )
15
+
16
+ @app .route ('/<name>' )
17
+ def api_hello (name ):
18
+ """
19
+ Greet the user with the provided name using the Controller: app/Controllers/Discord/greetUser.py.
20
+
21
+ This route calls the greet_user function to generate a greeting message for the user
22
+ with the given name and returns it as a response.
23
+
24
+ Args:
25
+ name (str): The name of the user.
26
+
27
+ Returns:
28
+ str: A greeting message for the user.
29
+ """
30
+ return greet_user (name )
You can’t perform that action at this time.
0 commit comments