1
1
import discord
2
- import time
3
2
import psutil
4
- from discord .ext import commands as cmd
5
-
6
- import teapot
3
+ import time
4
+ import typing
7
5
8
6
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 )
7
+ import teapot
20
8
21
9
22
- def helpcmd (bot ):
10
+ class Commands (discord .ext .commands .Cog ):
11
+ def __init__ (self , bot ):
12
+ self .bot = bot
23
13
24
- @bot .command (aliases = ['?' ])
25
- async def help (ctx , * cog ):
14
+ @discord . ext . commands .command (aliases = ['?' ])
15
+ async def help (self , ctx , * cog ):
26
16
if not cog :
27
17
embed = discord .Embed (description = "📖 Help" , color = 0x7400FF ,
28
18
icon_url = "https://cdn.discordapp.com/avatars/612634758744113182"
29
19
"/7fe078b5ea6b43000dfb7964e3e4d21d.png?size=512" )
30
20
embed .set_thumbnail (url = "https://avatars2.githubusercontent.com/u/60006969?s=200&v=4" )
31
21
cogs_desc = ""
32
- for x in bot .cogs :
33
- cogs_desc += f'**{ x } ** - { bot .cogs [x ].__doc__ } \n '
22
+ for x in self . bot .cogs :
23
+ cogs_desc += f'**{ x } ** - { self . bot .cogs [x ].__doc__ } \n '
34
24
embed .add_field (name = 'Modules' , value = cogs_desc [0 :len (cogs_desc ) - 1 ])
35
25
embed .set_footer (text = f"{ teapot .copyright ()} | Code licensed under the MIT License" )
36
26
await ctx .send (embed = embed )
@@ -41,21 +31,21 @@ async def help(ctx, *cog):
41
31
await ctx .message .add_reaction (emoji = '🛑' )
42
32
else :
43
33
found = False
44
- for x in bot .cogs :
34
+ for x in self . bot .cogs :
45
35
for y in cog :
46
36
if x == y :
47
37
embed = discord .Embed (color = 0x7400FF )
48
38
cog_info = ''
49
- for c in bot .get_cog (y ).get_commands ():
39
+ for c in self . bot .get_cog (y ).get_commands ():
50
40
if not c .hidden :
51
41
cog_info += f"**{ c .name } ** - { c .help } \n "
52
42
embed .add_field (name = f"{ cog [0 ]} Module" , value = cog_info )
53
43
await ctx .send (embed = embed )
54
44
await ctx .message .add_reaction (emoji = '✅' )
55
45
found = True
56
46
if not found :
57
- for x in bot .cogs :
58
- for c in bot .get_cog (x ).get_commands ():
47
+ for x in self . bot .cogs :
48
+ for c in self . bot .get_cog (x ).get_commands ():
59
49
if c .name .lower () == cog [0 ].lower ():
60
50
embed = discord .Embed (title = f"Command: { c .name .lower ().capitalize ()} " ,
61
51
description = f"**Description:** { c .help } \n **Syntax:** { c .qualified_name } { c .signature } " ,
@@ -73,18 +63,17 @@ async def help(ctx, *cog):
73
63
await ctx .message .add_reaction (emoji = '✅' )
74
64
75
65
76
- def info (bot ):
77
- @bot .command (aliases = ['about' ])
78
- async def info (ctx ):
66
+ @discord .ext .commands .command (aliases = ['about' ])
67
+ async def info (self , ctx ):
79
68
embed = discord .Embed (title = "Developers: RedTeaDev, ColaIan" , description = "Multi-purpose Discord Bot" ,
80
69
color = 0x7400FF )
81
70
embed .set_author (name = f"Teapot.py { teapot .version ()} " ,
82
71
icon_url = "https://cdn.discordapp.com/avatars/612634758744113182"
83
72
"/7fe078b5ea6b43000dfb7964e3e4d21d.png?size=512" )
84
73
embed .set_thumbnail (url = "https://avatars2.githubusercontent.com/u/60006969?s=200&v=4" )
85
- embed .add_field (name = "Bot User:" , value = bot .user )
86
- embed .add_field (name = "Guilds:" , value = len (bot .guilds ))
87
- embed .add_field (name = "Members:" , value = len (set (bot .get_all_members ())))
74
+ embed .add_field (name = "Bot User:" , value = self . bot .user )
75
+ embed .add_field (name = "Guilds:" , value = len (self . bot .guilds ))
76
+ embed .add_field (name = "Members:" , value = len (set (self . bot .get_all_members ())))
88
77
embed .add_field (name = "O.S.:" , value = str (teapot .platform ()))
89
78
embed .add_field (name = "Storage Type:" , value = teapot .config .storage_type ())
90
79
embed .add_field (name = "Prefix:" , value = ", " .join (teapot .config .bot_prefix ()))
@@ -96,24 +85,22 @@ async def info(ctx):
96
85
"https://discordapp.com/oauth2/authorize?client_id=669880564270104586&permissions=8"
97
86
"&scope=bot) | [Repository](https://github.com/RedCokeDevelopment/Teapot.py)" ,
98
87
inline = False )
99
- embed .set_footer (text = f"{ teapot .copyright ()} | Code licensed under the MIT License" )
88
+ embed .set_footer (text = f"{ teapot .copyright ()} | Code licensed under MIT License" )
100
89
embed .set_image (
101
90
url = "https://user-images.githubusercontent.com/43201383/72987537-89830a80-3e25-11ea-95ef-ecfa0afcff7e.png" )
102
91
await ctx .send (embed = embed )
103
92
await ctx .message .add_reaction (emoji = '✅' )
104
93
105
94
106
- def ping (bot ):
107
- @bot .command ()
108
- async def ping (ctx ):
109
- await ctx .send (f'Pong! { round (bot .latency * 1000 )} ms' )
95
+ @discord .ext .commands .command ()
96
+ async def ping (self , ctx ):
97
+ await ctx .send (f'Pong! { round (self .bot .latency * 1000 )} ms' )
110
98
await ctx .message .add_reaction (emoji = '✅' )
111
99
112
100
113
- def prune (bot ):
114
- @bot .command (aliases = ['purge' , 'clear' , 'cls' ])
115
- @cmd .has_permissions (manage_messages = True )
116
- async def prune (ctx , amount = 0 ):
101
+ @discord .ext .commands .command (aliases = ['purge' , 'clear' , 'cls' ])
102
+ @discord .ext .commands .has_permissions (manage_messages = True )
103
+ async def prune (self , ctx , amount = 0 ):
117
104
if amount == 0 :
118
105
await ctx .send ("Please specify the number of messages you want to delete!" )
119
106
await ctx .message .add_reaction (emoji = '❌' )
@@ -125,10 +112,9 @@ async def prune(ctx, amount=0):
125
112
await ctx .channel .purge (limit = amount + 1 )
126
113
127
114
128
- def kick (bot ):
129
- @bot .command ()
130
- @cmd .has_permissions (kick_members = True ) # check user permission
131
- async def kick (ctx , member : discord .Member , * , reason = None ):
115
+ @discord .ext .commands .command ()
116
+ @discord .ext .commands .has_permissions (kick_members = True ) # check user permission
117
+ async def kick (self , ctx , member : discord .Member , * , reason = None ):
132
118
try :
133
119
await member .kick (reason = reason )
134
120
await ctx .send (f'{ member } has been kicked!' )
@@ -138,28 +124,39 @@ async def kick(ctx, member: discord.Member, *, reason=None):
138
124
await ctx .message .add_reaction (emoji = '❌' )
139
125
140
126
141
- def ban (bot ):
142
- @bot .command ()
143
- @cmd .has_permissions (ban_members = True ) # check user permission
144
- async def ban (ctx , member : discord .Member , * , reason = None ):
127
+ @discord .ext .commands .command ()
128
+ @discord .ext .commands .has_permissions (ban_members = True ) # check user permission
129
+ async def ban (self , ctx , member : typing .Any [discord .Member , discord .User ], * , reason = None ): # Banning a member who is not in the server is also possible
145
130
try :
146
- await member .ban (reason = reason )
147
- await ctx .send (f'{ member } has been banned!' )
131
+ if isinstance (member , discord .Member ):
132
+ await member .ban (reason = reason )
133
+ else :
134
+ await ctx .guild .ban (member , reason = reason )
135
+
136
+ await ctx .send (f'{ member .name } has been banned!' )
148
137
await ctx .message .add_reaction (emoji = '✅' )
149
138
except Exception as e :
150
139
await ctx .send ("Failed to ban: " + str (e ))
151
140
await ctx .message .add_reaction (emoji = '❌' )
141
+
142
+ @discord .ext .commands .command ()
143
+ @discord .ext .commands .has_permissions (ban_members = True ) # check user permission
144
+ async def unban (self , ctx , member : discord .User , * , reason = None ):
145
+ try :
146
+ await ctx .guild .unban (member , reason = reason )
147
+ await ctx .send (f'{ member .name } has been unbanned!' )
148
+ await ctx .message .add_reaction (emoji = '✅' )
149
+ except Exception as e :
150
+ await ctx .send ("Failed to unban: " + str (e ))
151
+ await ctx .message .add_reaction (emoji = '❌' )
152
152
153
-
154
- def admin (bot ): # WIP...
155
- @bot .command ()
156
- async def admin (ctx ):
153
+ @discord .ext .commands .command () # Work In Progress
154
+ async def admin (self , ctx ):
157
155
await ctx .send (embed = teapot .messages .WIP ())
158
156
159
157
160
- def owner (bot ):
161
- @bot .command ()
162
- async def owner (ctx ):
158
+ @discord .ext .commands .command ()
159
+ async def owner (self , ctx ):
163
160
if ctx .message .author .id == teapot .config .bot_owner ():
164
161
found = False
165
162
for role in ctx .guild .roles :
@@ -176,16 +173,15 @@ async def owner(ctx):
176
173
break
177
174
178
175
179
- def debug (bot ):
180
- @bot .command ()
181
- @cmd .has_permissions (administrator = True )
182
- async def debug (ctx ):
176
+ @discord .ext .commands .command ()
177
+ @discord .ext .commands .has_permissions (administrator = True )
178
+ async def debug (self , ctx ):
183
179
embed = discord .Embed (title = "Developers: RedTea, ColaIan" , description = "Debug info:" ,
184
180
color = 0x7400FF )
185
181
embed .set_author (name = f"Teapot.py { teapot .version ()} " ,
186
182
icon_url = "https://cdn.discordapp.com/avatars/612634758744113182/7fe078b5ea6b43000dfb7964e3e4d21d.png?size=512" )
187
183
embed .set_thumbnail (url = "https://avatars2.githubusercontent.com/u/60006969?s=200&v=4" )
188
- embed .add_field (name = "Bot User:" , value = bot .user , inline = True )
184
+ embed .add_field (name = "Bot User:" , value = self . bot .user , inline = True )
189
185
embed .add_field (name = "System Time:" , value = time .strftime ("%a %b %d %H:%M:%S %Y" , time .localtime ()), inline = True )
190
186
embed .add_field (name = "Memory" ,
191
187
value = str (round (psutil .virtual_memory ()[1 ] / 1024 / 1024 / 1024 )) + "GB / " + str (round (
@@ -205,3 +201,7 @@ async def debug(ctx):
205
201
# embed.set_image(url="https://user-images.githubusercontent.com/43201383/72987537-89830a80-3e25-11ea-95ef-ecfa0afcff7e.png")
206
202
await ctx .message .author .send (embed = embed )
207
203
await ctx .message .add_reaction (emoji = '✅' )
204
+
205
+
206
+ def setup (bot ):
207
+ bot .add_cog (Commands (bot ))
0 commit comments