1
+ import asyncio
1
2
import discord
2
3
import time
3
4
import psutil
4
- from discord .ext import commands as cmd
5
-
5
+ from discord .ext import commands
6
6
import teapot
7
7
8
+ class BasicCommands (commands .Cog ):
9
+ """Basic bot commands and utilities"""
8
10
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
21
13
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"""
27
17
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 )
31
19
embed .set_thumbnail (url = "https://avatars2.githubusercontent.com/u/60006969?s=200&v=4" )
32
20
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" )
36
24
embed .set_footer (text = f"{ teapot .copyright ()} | Code licensed under the MIT License" )
37
25
await ctx .send (embed = embed )
38
- await ctx .message .add_reaction (emoji = '✅' )
39
26
else :
40
27
if len (cog ) > 1 :
41
28
await ctx .send (embed = teapot .messages .toomanyarguments ())
42
- await ctx .message .add_reaction (emoji = '🛑' )
43
29
else :
44
30
found = False
45
- for x in bot .cogs :
31
+ for x in self . bot .cogs :
46
32
for y in cog :
47
33
if x == y :
48
34
embed = discord .Embed (color = 0x7400FF )
49
35
cog_info = ''
50
- for c in bot .get_cog (y ).get_commands ():
36
+ for c in self . bot .get_cog (y ).get_commands ():
51
37
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" )
54
40
await ctx .send (embed = embed )
55
- await ctx .message .add_reaction (emoji = '✅' )
56
41
found = True
57
42
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 ():
60
45
if c .name .lower () == cog [0 ].lower ():
61
46
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 } " ,
63
48
color = 0x7400FF )
64
49
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" )
68
51
found = True
52
+ await ctx .send (embed = embed )
53
+ break
69
54
if not found :
70
55
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 )
76
57
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"""
80
61
embed = discord .Embed (title = "Developers: RedTeaDev, ColaIan" , description = "Multi-purpose Discord Bot" ,
81
62
color = 0x7400FF )
82
63
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" )
85
65
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 ()))
90
70
embed .add_field (name = "Storage Type:" , value = teapot .config .storage_type ())
91
71
embed .add_field (name = "Prefix:" , value = ", " .join (teapot .config .bot_prefix ()))
92
72
embed .add_field (name = "Github Repo:" , value = "[Teapot.py](https://github.com/RedCokeDevelopment/Teapot.py)" )
@@ -101,66 +81,54 @@ async def info(ctx):
101
81
embed .set_image (
102
82
url = "https://user-images.githubusercontent.com/43201383/72987537-89830a80-3e25-11ea-95ef-ecfa0afcff7e.png" )
103
83
await ctx .send (embed = embed )
104
- await ctx .message .add_reaction (emoji = '✅' )
105
-
106
84
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' )
112
89
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"""
118
94
if amount == 0 :
119
95
await ctx .send ("Please specify the number of messages you want to delete!" )
120
- await ctx .message .add_reaction (emoji = '❌' )
121
96
elif amount <= 0 : # lower then 0
122
97
await ctx .send ("The number must be bigger than 0!" )
123
- await ctx .message .add_reaction (emoji = '❌' )
124
98
else :
125
- await ctx .message .add_reaction (emoji = '✅' )
126
99
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"""
133
108
try :
134
109
await member .kick (reason = reason )
135
110
await ctx .send (f'{ member } has been kicked!' )
136
- await ctx .message .add_reaction (emoji = '✅' )
137
111
except Exception as failkick :
138
112
await ctx .send ("Failed to kick: " + str (failkick ))
139
- await ctx .message .add_reaction (emoji = '❌' )
140
-
141
113
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"""
146
118
try :
147
119
await member .ban (reason = reason )
148
120
await ctx .send (f'{ member } has been banned!' )
149
- await ctx .message .add_reaction (emoji = '✅' )
150
121
except Exception as e :
151
122
await ctx .send ("Failed to ban: " + str (e ))
152
- await ctx .message .add_reaction (emoji = '❌' )
153
123
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)"""
158
127
await ctx .send (embed = teapot .messages .WIP ())
159
128
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"""
164
132
if ctx .message .author .id == teapot .config .bot_owner ():
165
133
found = False
166
134
for role in ctx .guild .roles :
@@ -176,22 +144,21 @@ async def owner(ctx):
176
144
await ctx .guild .get_member (teapot .config .bot_owner ()).add_roles (role )
177
145
break
178
146
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"""
184
151
embed = discord .Embed (title = "Developers: RedTea, ColaIan" , description = "Debug info:" ,
185
152
color = 0x7400FF )
186
153
embed .set_author (name = f"Teapot.py { teapot .version ()} " ,
187
154
icon_url = "https://cdn.discordapp.com/avatars/612634758744113182/7fe078b5ea6b43000dfb7964e3e4d21d.png?size=512" )
188
155
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 )
190
157
embed .add_field (name = "System Time:" , value = time .strftime ("%a %b %d %H:%M:%S %Y" , time .localtime ()), inline = True )
191
158
embed .add_field (name = "Memory" ,
192
159
value = str (round (psutil .virtual_memory ()[1 ] / 1024 / 1024 / 1024 )) + "GB / " + str (round (
193
160
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 )
195
162
embed .add_field (name = "Storage Type:" , value = teapot .config .storage_type (), inline = True )
196
163
embed .add_field (name = "Prefix:" , value = ", " .join (teapot .config .bot_prefix ()), inline = True )
197
164
embed .add_field (name = "Github Repo:" , value = "[Teapot.py](https://github.com/RedCokeDevelopment/Teapot.py)" ,
@@ -205,6 +172,9 @@ async def debug(ctx):
205
172
"[Repository](https://github.com/RedCokeDevelopment/Teapot.py)" ,
206
173
inline = False )
207
174
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")
209
175
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