-
Notifications
You must be signed in to change notification settings - Fork 2
/
Shuckbot.py
331 lines (220 loc) · 8.66 KB
/
Shuckbot.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
import logging
import sys
import traceback
from datetime import datetime
from tinydb import TinyDB, Query
import discord
from discord.ext import commands
from modules import tags, imagesearch, metar, imagefun, help, picturebook, cleverbot, games, parameters, openai
params = parameters.params
imagesearch.init(params["googleKey"])
logging.basicConfig(level=logging.INFO)
defaultPrefix = ';'
prefixDB = TinyDB('prefixes.json')
def process_prefix(p_bot, message):
if message.guild is None:
return ';'
result = prefixDB.search(Query().id == message.guild.id)
if not result:
prefixDB.insert({'id': message.guild.id, 'prefix': ';'})
return ';'
else:
return result[0]['prefix']
bot = commands.Bot(command_prefix=process_prefix, intents=discord.Intents.default())
bot.remove_command("help") # discord.py ships with a default help command: must remove it
@bot.command()
async def engines(ctx):
openai.engine_list()
@bot.command(aliases=["shuckbotprefix", "shuckprefix"])
async def prefix(ctx, *args):
if not ctx.message.author.guild_permissions.manage_guild or not ctx.message.author.guild_permissions.administrator:
await ctx.channel.send("You need the **Manage Server** permission to do that.")
elif len(args) > 1 or len(args) == 0 or len(args[0]) > 1:
await ctx.channel.send("**Format**: ;prefix <single character>")
elif not args[0].isascii():
await ctx.channel.send("You must choose an ASCII character!")
else:
prefixDB.update({'prefix': args[0]}, Query().id == ctx.message.guild.id)
await ctx.channel.send("Set server prefix to \"" + args[0] + "\".")
@bot.command()
async def ping(ctx):
now = datetime.now()
sent = await ctx.channel.send("Measuring ping...")
diff = sent.created_at - now
await sent.edit(content="Pong! Shuckbot's ping is **" + str(int(diff.microseconds / 1000)) + "**ms.")
@bot.command(aliases=["help"])
async def page(ctx):
await help.show_help(ctx.message)
@bot.command(aliases=["i", "im", "image"])
async def img(ctx):
await imagesearch.google_search(ctx.message)
@bot.command()
async def r34(ctx):
await imagesearch.r34_search(ctx.message)
@bot.command()
async def invite(ctx):
await ctx.channel.send(
params["url"])
@bot.command(aliases=["picturebook", "photobook"])
async def pb(ctx, *args):
if ' ' not in ctx.message:
await picturebook.get_saved(ctx.message)
else:
_arg = args[0] # the first argument
if _arg == 'add' or _arg == 'save':
await picturebook.save(ctx.message)
elif _arg == 'remove' or _arg == "delete" or _arg == "rm":
await picturebook.remove(ctx.message, params["ownerID"])
@bot.command(aliases=["t"])
async def tag(ctx, *args):
if len(args) == 0:
await tags.syntax_error(ctx.message)
else:
if args[0] == 'add':
await tags.add(ctx.message)
elif args[0] == 'remove' or args[0] == "delete":
await tags.remove(ctx.message, params["ownerID"])
elif args[0] == 'edit':
await tags.edit(ctx.message, params["ownerID"])
elif args[0] == 'owner':
owner_id = tags.owner(ctx.message)
tag_owner = await bot.fetch_user(owner_id)
if tag_owner == 0:
await ctx.channel.send("Tag **" + args[1] + "** does not exist")
else:
await ctx.channel.send("Tag **" + args[1] + "** is owned by `" + str(tag_owner) + "`")
elif args[0] == 'list':
await tags.owned(ctx.message)
elif args[0] == 'random':
await tags.get_random(ctx.message)
else:
await tags.get(ctx.message)
@bot.command()
async def metar(ctx):
await metar.metar(ctx.message, params["avwxKey"])
@bot.command(aliases=["hold"])
async def holding(ctx):
await imagefun.holding_imagemaker(ctx.message)
@bot.command(aliases=["exmilitary"])
async def exm(ctx):
await imagefun.exmilitary_imagemaker(ctx.message)
@bot.command(aliases=["fan", "review", "tnd"])
async def fantano(ctx):
await imagefun.fantano_imagemaker(ctx.message)
@bot.command(aliases=["1bit", "1"])
async def one(ctx):
await imagefun.one_imagemaker(ctx.message)
@bot.command()
async def kim(ctx):
await imagefun.kim_imagemaker(ctx.message)
@bot.command(aliases=["e"])
async def emote(ctx):
await imagefun.get_emoji(ctx.message, bot)
@bot.command(aliases=["pixelsort", "sortpixels"])
async def sort(ctx):
await imagefun.sort_pixels(ctx.message)
@bot.command(aliases=["pixelshuffle"])
async def shuffle(ctx):
await imagefun.pixel_shuffle(ctx.message)
@bot.command(aliases=["scale"])
async def resize(ctx):
await imagefun.resize_img(ctx.message)
@bot.command()
async def size(ctx):
await imagefun.get_size(ctx.message)
@bot.command(aliases=["mina"])
async def twice(ctx):
await imagefun.twice_imagemaker(ctx.message)
@bot.command(aliases=["drawing"])
async def draw(ctx):
await imagefun.drawing_imagemaker(ctx.message)
@bot.command()
async def undo(ctx):
await imagefun.undo_img(ctx.message)
@bot.command(aliases=["loona"])
async def heejin(ctx):
await imagefun.heejin_imagemaker(ctx.message)
@bot.command()
async def school(ctx):
await imagefun.school_imagemaker(ctx.message)
@bot.command(aliases=["lect"])
async def lecture(ctx):
await imagefun.lecture_imagemaker(ctx.message)
@bot.command()
async def tesla(ctx):
await imagefun.tesla_imagemaker(ctx.message)
@bot.command()
async def osu(ctx):
await imagefun.osu_imagemaker(ctx.message)
@bot.command(aliases=["colour", "c"])
async def color(ctx):
await imagefun.get_colour_from_hex(ctx.message)
@bot.command(aliases=["noisy"])
async def mix(ctx):
await imagefun.mixer(ctx.message)
@bot.command()
async def noise(ctx):
await imagefun.noise_imagemaker(ctx.message)
@bot.command(aliases=["gf"])
async def mokou(ctx):
await imagefun.mokou_imagemaker(ctx.message)
@bot.command()
async def shift(ctx):
await imagefun.image_shift(ctx.message)
@bot.command(aliases=["megu"])
async def megumin(ctx):
await imagefun.megumin_imagemaker(ctx.message)
@bot.command()
async def weezer(ctx):
await imagefun.weezer_imagemaker(ctx.message)
@bot.event
async def on_command_error(ctx, error):
if isinstance(error, commands.CommandOnCooldown):
await ctx.send('Sorry, this command is on cooldown! Try again in {:.2f} seconds'.format(error.retry_after))
@commands.cooldown(1, 5, commands.BucketType.guild)
@bot.command(aliases=["g"])
async def game(ctx):
try:
await games.game(ctx.message, bot, params["mapquest"])
except Exception as e:
await ctx.send(f'An error has occured! Go yell at @michaeL#9999 to fix it. You should also give him this:')
await ctx.send(f'```{traceback.format_exc()}```')
@bot.command(aliases=["torgb", "2rgb"])
async def rgb(ctx):
await imagefun.to_rgb(ctx.message)
@bot.command(aliases=["a"])
async def avatar(ctx):
await imagefun.get_avatar(ctx.message)
@bot.command()
async def purple(ctx):
await imagefun.purple(ctx.message)
@bot.command()
async def whatifitwaspurple(ctx):
await imagefun.whatifitwaspurple(ctx.message)
@bot.command(aliases=["tom"])
async def tomscott(ctx):
await imagefun.tom_imagemaker(ctx.message)
@bot.command()
async def sickos(ctx):
await imagefun.sickos_imagemaker(ctx.message)
@bot.command(aliases=['prompt', 'setprompt', 'mode'])
async def changeprompt(ctx):
await openai.change_prompt(ctx.message)
@bot.event
async def on_message(message):
await bot.process_commands(message)
if message.clean_content.lower() == "b" or message.clean_content.lower() == "n":
await imagesearch.advance(message)
elif message.clean_content.lower().startswith("p"):
await imagesearch.jump(message)
elif message.clean_content.lower() == "s":
await imagesearch.stop(message)
elif message.clean_content.startswith("@" + message.guild.get_member(bot.user.id).display_name):
await message.channel.trigger_typing()
try:
await message.channel.send(
# cleverbot.cleverbot_message(message, message.guild.get_member(bot.user.id).display_name))
openai.response(message, message.guild.get_member(bot.user.id).display_name))
except discord.HTTPException:
await message.channel.send("guh")
bot.run(params["token"])