1+ import asyncio
12import discord
23import time
34import psutil
4- from discord .ext import commands as cmd
5-
5+ from discord .ext import commands
66import teapot
77
8+ class BasicCommands (commands .Cog ):
9+ """Basic bot commands and utilities"""
810
9- def __init__ (bot ):
10- """ Initialize commands """
11- helpcmd (bot )
12- info (bot )
13- ping (bot )
14- prune (bot )
15- kick (bot )
16- ban (bot )
17- admin (bot )
18- owner (bot )
19- debug (bot )
20-
11+ def __init__ (self , bot ):
12+ self .bot = bot
2113
22- def helpcmd (bot ):
23- bot .remove_command ('help' )
24-
25- @bot .command (aliases = ['?' ])
26- async def help (ctx , * cog ):
14+ @commands .command (aliases = ['?' ])
15+ async def help (self , ctx , * cog ):
16+ """Show help information"""
2717 if not cog :
28- embed = discord .Embed (description = "📖 Help" , color = 0x7400FF ,
29- icon_url = "https://cdn.discordapp.com/avatars/612634758744113182"
30- "/7fe078b5ea6b43000dfb7964e3e4d21d.png?size=512" )
18+ embed = discord .Embed (description = "📖 Help" , color = 0x7400FF )
3119 embed .set_thumbnail (url = "https://avatars2.githubusercontent.com/u/60006969?s=200&v=4" )
3220 cogs_desc = ""
33- for x in bot .cogs :
34- cogs_desc += f'**{ x } ** - { bot .cogs [x ].__doc__ } \n '
35- embed .add_field (name = 'Modules' , value = cogs_desc [0 :len (cogs_desc ) - 1 ])
21+ for x in self . bot .cogs :
22+ cogs_desc += f'**{ x } ** - { self . bot .cogs [x ].__doc__ or "No description" } \n '
23+ embed .add_field (name = 'Modules' , value = cogs_desc [0 :len (cogs_desc ) - 1 ] if cogs_desc else "No modules loaded" )
3624 embed .set_footer (text = f"{ teapot .copyright ()} | Code licensed under the MIT License" )
3725 await ctx .send (embed = embed )
38- await ctx .message .add_reaction (emoji = '✅' )
3926 else :
4027 if len (cog ) > 1 :
4128 await ctx .send (embed = teapot .messages .toomanyarguments ())
42- await ctx .message .add_reaction (emoji = '🛑' )
4329 else :
4430 found = False
45- for x in bot .cogs :
31+ for x in self . bot .cogs :
4632 for y in cog :
4733 if x == y :
4834 embed = discord .Embed (color = 0x7400FF )
4935 cog_info = ''
50- for c in bot .get_cog (y ).get_commands ():
36+ for c in self . bot .get_cog (y ).get_commands ():
5137 if not c .hidden :
52- cog_info += f"**{ c .name } ** - { c .help } \n "
53- embed .add_field (name = f"{ cog [0 ]} Module" , value = cog_info )
38+ cog_info += f"**{ c .name } ** - { c .help or 'No description' } \n "
39+ embed .add_field (name = f"{ cog [0 ]} Module" , value = cog_info if cog_info else "No commands found" )
5440 await ctx .send (embed = embed )
55- await ctx .message .add_reaction (emoji = '✅' )
5641 found = True
5742 if not found :
58- for x in bot .cogs :
59- for c in bot .get_cog (x ).get_commands ():
43+ for x in self . bot .cogs :
44+ for c in self . bot .get_cog (x ).get_commands ():
6045 if c .name .lower () == cog [0 ].lower ():
6146 embed = discord .Embed (title = f"Command: { c .name .lower ().capitalize ()} " ,
62- description = f"**Description:** { c .help } \n **Syntax:** { c .qualified_name } { c .signature } " ,
47+ description = f"**Description:** { c .help or 'No description' } \n **Syntax:** { c .qualified_name } { c .signature } " ,
6348 color = 0x7400FF )
6449 embed .set_author (name = f"Teapot.py { teapot .version ()} " ,
65- icon_url = "https://cdn.discordapp.com/avatars/612634758744113182"
66- "/7fe078b5ea6b43000dfb7964e3e4d21d.png?size=512" )
67- await ctx .message .add_reaction (emoji = '✅' )
50+ icon_url = "https://cdn.discordapp.com/avatars/612634758744113182/7fe078b5ea6b43000dfb7964e3e4d21d.png?size=512" )
6851 found = True
52+ await ctx .send (embed = embed )
53+ break
6954 if not found :
7055 embed = teapot .messages .notfound ("Module" )
71- await ctx .message .add_reaction (emoji = '🛑' )
72- await ctx .send (embed = embed )
73- else :
74- await ctx .message .add_reaction (emoji = '✅' )
75-
56+ await ctx .send (embed = embed )
7657
77- def info ( bot ):
78- @ bot . command ( aliases = [ 'about' ])
79- async def info ( ctx ):
58+ @ commands . command ( aliases = [ 'about' ])
59+ async def info ( self , ctx ):
60+ """Show bot information"""
8061 embed = discord .Embed (title = "Developers: RedTeaDev, ColaIan" , description = "Multi-purpose Discord Bot" ,
8162 color = 0x7400FF )
8263 embed .set_author (name = f"Teapot.py { teapot .version ()} " ,
83- icon_url = "https://cdn.discordapp.com/avatars/612634758744113182"
84- "/7fe078b5ea6b43000dfb7964e3e4d21d.png?size=512" )
64+ icon_url = "https://cdn.discordapp.com/avatars/612634758744113182/7fe078b5ea6b43000dfb7964e3e4d21d.png?size=512" )
8565 embed .set_thumbnail (url = "https://avatars2.githubusercontent.com/u/60006969?s=200&v=4" )
86- embed .add_field (name = "Bot User:" , value = bot .user )
87- embed .add_field (name = "Guilds:" , value = len (bot .guilds ))
88- embed .add_field (name = "Members:" , value = len (set (bot .get_all_members ())))
89- embed .add_field (name = "O.S.:" , value = str (teapot .platform ()))
66+ embed .add_field (name = "Bot User:" , value = self . bot .user )
67+ embed .add_field (name = "Guilds:" , value = len (self . bot .guilds ))
68+ embed .add_field (name = "Members:" , value = len (set (self . bot .get_all_members ())))
69+ embed .add_field (name = "O.S.:" , value = str (teapot .get_platform ()))
9070 embed .add_field (name = "Storage Type:" , value = teapot .config .storage_type ())
9171 embed .add_field (name = "Prefix:" , value = ", " .join (teapot .config .bot_prefix ()))
9272 embed .add_field (name = "Github Repo:" , value = "[Teapot.py](https://github.com/RedCokeDevelopment/Teapot.py)" )
@@ -101,66 +81,54 @@ async def info(ctx):
10181 embed .set_image (
10282 url = "https://user-images.githubusercontent.com/43201383/72987537-89830a80-3e25-11ea-95ef-ecfa0afcff7e.png" )
10383 await ctx .send (embed = embed )
104- await ctx .message .add_reaction (emoji = '✅' )
105-
10684
107- def ping (bot ):
108- @bot .command ()
109- async def ping (ctx ):
110- await ctx .send (f'Pong! { round (bot .latency * 1000 )} ms' )
111- await ctx .message .add_reaction (emoji = '✅' )
85+ @commands .command ()
86+ async def ping (self , ctx ):
87+ """Show bot latency"""
88+ await ctx .send (f'Pong! { round (self .bot .latency * 1000 )} ms' )
11289
113-
114- def prune (bot ):
115- @bot .command (aliases = ['purge' , 'clear' , 'cls' ])
116- @cmd .has_permissions (manage_messages = True )
117- async def prune (ctx , amount = 0 ):
90+ @commands .command (aliases = ['purge' , 'clear' , 'cls' ])
91+ @commands .has_permissions (manage_messages = True )
92+ async def prune (self , ctx , amount : int = 0 ):
93+ """Delete multiple messages"""
11894 if amount == 0 :
11995 await ctx .send ("Please specify the number of messages you want to delete!" )
120- await ctx .message .add_reaction (emoji = '❌' )
12196 elif amount <= 0 : # lower then 0
12297 await ctx .send ("The number must be bigger than 0!" )
123- await ctx .message .add_reaction (emoji = '❌' )
12498 else :
125- await ctx .message .add_reaction (emoji = '✅' )
12699 await ctx .channel .purge (limit = amount + 1 )
127-
128-
129- def kick (bot ):
130- @bot .command ()
131- @cmd .has_permissions (kick_members = True ) # check user permission
132- async def kick (ctx , member : discord .Member , * , reason = None ):
100+ message = await ctx .send (f'Purged { amount } messages!' )
101+ await asyncio .sleep (3 )
102+ await message .delete ()
103+
104+ @commands .command ()
105+ @commands .has_permissions (kick_members = True )
106+ async def kick (self , ctx , member : discord .Member , * , reason = None ):
107+ """Kick a member from the server"""
133108 try :
134109 await member .kick (reason = reason )
135110 await ctx .send (f'{ member } has been kicked!' )
136- await ctx .message .add_reaction (emoji = '✅' )
137111 except Exception as failkick :
138112 await ctx .send ("Failed to kick: " + str (failkick ))
139- await ctx .message .add_reaction (emoji = '❌' )
140-
141113
142- def ban ( bot ):
143- @bot . command ( )
144- @ cmd . has_permissions ( ban_members = True ) # check user permission
145- async def ban ( ctx , member : discord . Member , * , reason = None ):
114+ @ commands . command ()
115+ @commands . has_permissions ( ban_members = True )
116+ async def ban ( self , ctx , member : discord . Member , * , reason = None ):
117+ """Ban a member from the server"""
146118 try :
147119 await member .ban (reason = reason )
148120 await ctx .send (f'{ member } has been banned!' )
149- await ctx .message .add_reaction (emoji = '✅' )
150121 except Exception as e :
151122 await ctx .send ("Failed to ban: " + str (e ))
152- await ctx .message .add_reaction (emoji = '❌' )
153123
154-
155- def admin (bot ): # WIP...
156- @bot .command ()
157- async def admin (ctx ):
124+ @commands .command ()
125+ async def admin (self , ctx ):
126+ """Admin panel (WIP)"""
158127 await ctx .send (embed = teapot .messages .WIP ())
159128
160-
161- def owner (bot ):
162- @bot .command ()
163- async def owner (ctx ):
129+ @commands .command ()
130+ async def owner (self , ctx ):
131+ """Grant owner role to bot owner"""
164132 if ctx .message .author .id == teapot .config .bot_owner ():
165133 found = False
166134 for role in ctx .guild .roles :
@@ -176,22 +144,21 @@ async def owner(ctx):
176144 await ctx .guild .get_member (teapot .config .bot_owner ()).add_roles (role )
177145 break
178146
179-
180- def debug (bot ):
181- @bot .command ()
182- @cmd .has_permissions (administrator = True )
183- async def debug (ctx ):
147+ @commands .command ()
148+ @commands .has_permissions (administrator = True )
149+ async def debug (self , ctx ):
150+ """Show debug information"""
184151 embed = discord .Embed (title = "Developers: RedTea, ColaIan" , description = "Debug info:" ,
185152 color = 0x7400FF )
186153 embed .set_author (name = f"Teapot.py { teapot .version ()} " ,
187154 icon_url = "https://cdn.discordapp.com/avatars/612634758744113182/7fe078b5ea6b43000dfb7964e3e4d21d.png?size=512" )
188155 embed .set_thumbnail (url = "https://avatars2.githubusercontent.com/u/60006969?s=200&v=4" )
189- embed .add_field (name = "Bot User:" , value = bot .user , inline = True )
156+ embed .add_field (name = "Bot User:" , value = self . bot .user , inline = True )
190157 embed .add_field (name = "System Time:" , value = time .strftime ("%a %b %d %H:%M:%S %Y" , time .localtime ()), inline = True )
191158 embed .add_field (name = "Memory" ,
192159 value = str (round (psutil .virtual_memory ()[1 ] / 1024 / 1024 / 1024 )) + "GB / " + str (round (
193160 psutil .virtual_memory ()[0 ] / 1024 / 1024 / 1024 )) + "GB" , inline = True )
194- embed .add_field (name = "O.S.:" , value = str (teapot .platform ()), inline = True )
161+ embed .add_field (name = "O.S.:" , value = str (teapot .get_platform ()), inline = True )
195162 embed .add_field (name = "Storage Type:" , value = teapot .config .storage_type (), inline = True )
196163 embed .add_field (name = "Prefix:" , value = ", " .join (teapot .config .bot_prefix ()), inline = True )
197164 embed .add_field (name = "Github Repo:" , value = "[Teapot.py](https://github.com/RedCokeDevelopment/Teapot.py)" ,
@@ -205,6 +172,9 @@ async def debug(ctx):
205172 "[Repository](https://github.com/RedCokeDevelopment/Teapot.py)" ,
206173 inline = False )
207174 embed .set_footer (text = f"{ teapot .copyright ()} | Code licensed under the MIT License" )
208- # embed.set_image(url="https://user-images.githubusercontent.com/43201383/72987537-89830a80-3e25-11ea-95ef-ecfa0afcff7e.png")
209175 await ctx .message .author .send (embed = embed )
210- await ctx .message .add_reaction (emoji = '✅' )
176+
177+
178+ async def setup (bot ):
179+ bot .remove_command ('help' )
180+ await bot .add_cog (BasicCommands (bot ))
0 commit comments