3
3
Description:
4
4
This is a template to create your own discord bot in python.
5
5
6
- Version: 3.0
6
+ Version: 3.1
7
7
"""
8
8
9
9
import json
18
18
from discord_slash import cog_ext , SlashContext
19
19
from discord_slash .utils .manage_commands import create_option
20
20
21
+ from helpers import checks
22
+
21
23
if not os .path .isfile ("config.json" ):
22
24
sys .exit ("'config.json' not found! Please add it and try again." )
23
25
else :
24
26
with open ("config.json" ) as file :
25
27
config = json .load (file )
26
28
27
29
28
- class general (commands .Cog , name = "general" ):
30
+ class General (commands .Cog , name = "general" ):
29
31
def __init__ (self , bot ):
30
32
self .bot = bot
31
33
32
34
@cog_ext .cog_slash (
33
35
name = "botinfo" ,
34
36
description = "Get some useful (or not) information about the bot." ,
35
37
)
38
+ @checks .not_blacklisted ()
36
39
async def botinfo (self , context : SlashContext ):
37
40
"""
38
41
Get some useful (or not) information about the bot.
39
42
"""
40
-
41
- # This is, for now, only temporary
42
- with open ("blacklist.json" ) as file :
43
- blacklist = json .load (file )
44
- if context .author .id in blacklist ["ids" ]:
45
- return
46
-
47
43
embed = discord .Embed (
48
- description = "Used Krypton's template" ,
44
+ description = "Used [ Krypton's](https://krypt0n.co.uk) template" ,
49
45
color = 0x42F56C
50
46
)
51
47
embed .set_author (
@@ -63,7 +59,7 @@ async def botinfo(self, context: SlashContext):
63
59
)
64
60
embed .add_field (
65
61
name = "Prefix:" ,
66
- value = f"{ config [ 'bot_prefix' ] } " ,
62
+ value = f"/ (Slash Commands) " ,
67
63
inline = False
68
64
)
69
65
embed .set_footer (
@@ -75,17 +71,11 @@ async def botinfo(self, context: SlashContext):
75
71
name = "serverinfo" ,
76
72
description = "Get some useful (or not) information about the server." ,
77
73
)
74
+ @checks .not_blacklisted ()
78
75
async def serverinfo (self , context : SlashContext ):
79
76
"""
80
77
Get some useful (or not) information about the server.
81
78
"""
82
-
83
- # This is, for now, only temporary
84
- with open ("blacklist.json" ) as file :
85
- blacklist = json .load (file )
86
- if context .author .id in blacklist ["ids" ]:
87
- return
88
-
89
79
server = context .guild
90
80
roles = [x .name for x in server .roles ]
91
81
role_length = len (roles )
@@ -130,18 +120,13 @@ async def serverinfo(self, context: SlashContext):
130
120
@cog_ext .cog_slash (
131
121
name = "ping" ,
132
122
description = "Check if the bot is alive." ,
123
+ guild_ids = [909709618681364531 ]
133
124
)
125
+ @checks .not_blacklisted ()
134
126
async def ping (self , context : SlashContext ):
135
127
"""
136
128
Check if the bot is alive.
137
129
"""
138
-
139
- # This is, for now, only temporary
140
- with open ("blacklist.json" ) as file :
141
- blacklist = json .load (file )
142
- if context .author .id in blacklist ["ids" ]:
143
- return
144
-
145
130
embed = discord .Embed (
146
131
title = "🏓 Pong!" ,
147
132
description = f"The bot latency is { round (self .bot .latency * 1000 )} ms." ,
@@ -153,17 +138,11 @@ async def ping(self, context: SlashContext):
153
138
name = "invite" ,
154
139
description = "Get the invite link of the bot to be able to invite it." ,
155
140
)
141
+ @checks .not_blacklisted ()
156
142
async def invite (self , context : SlashContext ):
157
143
"""
158
144
Get the invite link of the bot to be able to invite it.
159
145
"""
160
-
161
- # This is, for now, only temporary
162
- with open ("blacklist.json" ) as file :
163
- blacklist = json .load (file )
164
- if context .author .id in blacklist ["ids" ]:
165
- return
166
-
167
146
embed = discord .Embed (
168
147
description = f"Invite me by clicking [here](https://discordapp.com/oauth2/authorize?&client_id={ config ['application_id' ]} &scope=bot&permissions=470150263)." ,
169
148
color = 0xD75BF4
@@ -179,17 +158,11 @@ async def invite(self, context: SlashContext):
179
158
name = "server" ,
180
159
description = "Get the invite link of the discord server of the bot for some support." ,
181
160
)
161
+ @checks .not_blacklisted ()
182
162
async def server (self , context : SlashContext ):
183
163
"""
184
164
Get the invite link of the discord server of the bot for some support.
185
165
"""
186
-
187
- # This is, for now, only temporary
188
- with open ("blacklist.json" ) as file :
189
- blacklist = json .load (file )
190
- if context .author .id in blacklist ["ids" ]:
191
- return
192
-
193
166
embed = discord .Embed (
194
167
description = f"Join the support server for the bot by clicking [here](https://discord.gg/mTBrXyWxAF)." ,
195
168
color = 0xD75BF4
@@ -212,17 +185,11 @@ async def server(self, context: SlashContext):
212
185
)
213
186
],
214
187
)
188
+ @checks .not_blacklisted ()
215
189
async def poll (self , context : SlashContext , title : str ):
216
190
"""
217
191
Create a poll where members can vote.
218
192
"""
219
-
220
- # This is, for now, only temporary
221
- with open ("blacklist.json" ) as file :
222
- blacklist = json .load (file )
223
- if context .author .id in blacklist ["ids" ]:
224
- return
225
-
226
193
embed = discord .Embed (
227
194
title = "A new poll has been created!" ,
228
195
description = f"{ title } " ,
@@ -248,17 +215,11 @@ async def poll(self, context: SlashContext, title: str):
248
215
)
249
216
],
250
217
)
218
+ @checks .not_blacklisted ()
251
219
async def eight_ball (self , context : SlashContext , question : str ):
252
220
"""
253
221
Ask any question to the bot.
254
222
"""
255
-
256
- # This is, for now, only temporary
257
- with open ("blacklist.json" ) as file :
258
- blacklist = json .load (file )
259
- if context .author .id in blacklist ["ids" ]:
260
- return
261
-
262
223
answers = ['It is certain.' , 'It is decidedly so.' , 'You may rely on it.' , 'Without a doubt.' ,
263
224
'Yes - definitely.' , 'As I see, yes.' , 'Most likely.' , 'Outlook good.' , 'Yes.' ,
264
225
'Signs point to yes.' , 'Reply hazy, try again.' , 'Ask again later.' , 'Better not tell you now.' ,
@@ -278,17 +239,11 @@ async def eight_ball(self, context: SlashContext, question: str):
278
239
name = "bitcoin" ,
279
240
description = "Get the current price of bitcoin." ,
280
241
)
242
+ @checks .not_blacklisted ()
281
243
async def bitcoin (self , context ):
282
244
"""
283
245
Get the current price of bitcoin.
284
246
"""
285
-
286
- # This is, for now, only temporary
287
- with open ("blacklist.json" ) as file :
288
- blacklist = json .load (file )
289
- if context .author .id in blacklist ["ids" ]:
290
- return
291
-
292
247
url = "https://api.coindesk.com/v1/bpi/currentprice/BTC.json"
293
248
# Async HTTP request
294
249
async with aiohttp .ClientSession () as session :
@@ -304,4 +259,4 @@ async def bitcoin(self, context):
304
259
305
260
306
261
def setup (bot ):
307
- bot .add_cog (general (bot ))
262
+ bot .add_cog (General (bot ))
0 commit comments