-
Notifications
You must be signed in to change notification settings - Fork 1
/
bot.old.py
482 lines (407 loc) · 12.1 KB
/
bot.old.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
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
# Doesn't support slash commands, probs gonna get yeeted by Discord
#Requirements (to use this script, install v):
#pip install py-cord python-dotenv asyncio pymongo[srv] certifi
#Logging
import logging
with open("latest.log", "w") as f: pass
logging.basicConfig(
level=logging.DEBUG,
filename="latest.log",
format="[%(levelname)s]: %(message)s"
)
logging.debug("1.0.0.2")
#Imports
logging.debug("Importing...")
import discord
import os
import sys
import random
import certifi
import re
import time
import math
import requests
import asyncio
from discord.ext import commands, tasks
from discord.utils import get
from dotenv import load_dotenv
from pymongo import *
from bson.objectid import ObjectId
from decimal import Decimal
from jokeapi import Jokes
#Import all speedy jsons, use default json module as failsafe
try:
import ujson as json
except (ModuleNotFoundError, ImportError):
try:
import simplejson as json
except (ModuleNotFoundError, ImportError):
import json
#Load Environment variables
logging.debug("Loading env...")
load_dotenv()
#Mango- I mean, MongoDB stuff
logging.debug("Opening MongoDB client...")
client = MongoClient(
str(
os.getenv(
"MANGO"
)
),
tlsCAFile=certifi.where()
)
db = client["FBBDB"]
#Bot stuff
logging.debug("Defining bot constants...")
pf = "fb."
intents = discord.Intents.all()
bot = commands.Bot(
command_prefix=pf,
strip_after_prefix=True,
intents=intents
)
mentionre = re.compile(r"(.*<@[0-9]+>.*)|(.*<@![0-9]+>.*)")
msgst = {}
kawaiit = "767200055652253719.cTHpJ7bN9V0xFjdK5pWh"
#Reading from file
logging.debug("Reading things from data JSON file...")
with open("dat.json", "r") as f:
#Load crap from data file
yeetus = json.loads(f.read())
m8answers = yeetus["8ball"]
del yeetus
# --Functions--
logging.debug("Defining helper functions")
def prec(n):
return Decimal(str(n))
def bround(n, a=0):
return prec(
round(
prec(
n
),
a
)
)
def isAuthorized(i):
"""Is message author in Authorized? (me or Blue)"""
logging.debug("call: isAuthorized()")
if (i == 588132098875850752) or (i == 832740090094682152):
return True
else:
return False
def isFbb(text):
"""Is text fishbluebot"""
logging.debug("call: isFbb()")
print(text)
text = str(text)
if (
text == str(
bot.user.name
)
) or (
text == str(
bot.user
)
) or (
text == "<@" + str(
bot.user.id
) + ">"
) or (
text == "<@!" + str(
bot.user.id
) + ">"
):
return True
else:
return False
def isMention(text):
#Is text a mention?
logging.debug("call: isMention()")
global mentionre
if mentionre.match(text) == None:
return False
else:
return True
def idFromMention(mention):
#Get User ID from mention
logging.debug("call: idFromMention()")
if mention.startswith("<@!"):
return str(mention)[3:-1]
else:
return str(mention)[2:-1]
def kawaii(sub):
r = requests.get(f"https://kawaii.red/api/gif/{sub}/token={kawaiit}/")
return str(r.json()['response'])
# --Discord Events--
logging.debug("Defining commands...")
@bot.event
async def on_ready():
"""logged in?"""
logging.debug("call: on_ready()")
print(f"fishbluebot has logged on in to Discord as {bot.user}!")
@bot.listen("on_message")
async def on_message_listener(message):
#When someone messages
global msgst
logging.debug("call: on_message()")
if message.author == bot.user:
#Is the author of the message the bot?
return
if message.author.bot:
return #Prevent bots from running commands.
@bot.event
async def on_command_error(ctx, error):
if isinstance(error, discord.ext.commands.errors.CommandNotFound):
embed = discord.Embed(
title="Error",
description="Unknown Command",
color=discord.Color.red()
)
await ctx.send(embed=embed)
elif isinstance(error, discord.ext.commands.errors.MissingRequiredArgument):
embed = discord.Embed(
title="Error",
description="You're missing an argument!",
color=discord.Color.red()
)
await ctx.send(embed=embed)
elif isinstance(error, commands.MissingPermissions):
embed = discord.Embed(
title="Error",
description="Insufficient permissions!",
color=discord.Color.red()
)
await ctx.send(embed=embed)
else:
embed = discord.Embed(
title="Error",
description=str(error),
color=discord.Color.red()
)
embed.set_footer(text="Is this a bug? Report it to help make this bot better!")
await ctx.send(embed=embed)
# --Commands--
@bot.command()
async def ping(ctx):
"""Ping"""
logging.debug("call: ping()")
await ctx.send("pong")
@bot.command(aliases=["8ball"])
async def magic8ball(ctx, *args):
"""Magic 8-ball. Ask it your questions."""
logging.debug("call: magic8ball()")
global m8answers
await ctx.send(
m8answers[
ord(
os.urandom(
1
)
) % len(
m8answers
)
]
)
@bot.command()
async def killswitch(ctx):
"""Killswitch"""
logging.debug("call: killswitch()")
logging.info(f"Someone attempted to kill the bot, ID: {ctx.message.author.id}")
if isAuthorized(ctx.message.author.id):
await ctx.send("I am now commiting die.")
print("ouchie someone killed me")
logging.warning("Exiting...")
sys.exit()
else:
await ctx.send("rude why are you trying to kill me >:(")
@bot.command()
async def kill(ctx, person):
"""Kill people. Idk y."""
logging.debug("call: kill()")
if isMention(person):
if int(ctx.message.author.id) == int(idFromMention(person)):
await ctx.send("Aw c'mon, don't kill yourself.")
return
else:
if person.strip() == ctx.message.author.name:
await ctx.send("Aw c'mon, don't kill yourself.")
return
if ("@everyone" in person) or ("@here" in person):
await ctx.send("Mass genocide isn't allowed yet. Try again later.")
return
if isMention(person):
person = await bot.fetch_user(int(idFromMention(person)))
person = person.name
else:
pass
embed = discord.Embed(
title=f"{ctx.message.author.name} has violently murdered {person}!",
description="oof",
)
embed.set_image(url=kawaii("kill"))
await ctx.send(embed=embed)
@bot.command()
async def bruh(ctx):
"""Bruh."""
logging.debug("call: bruh()")
await ctx.send("""██████╗░██████╗░██╗░░░██╗██╗░░██╗░░░
██╔══██╗██╔══██╗██║░░░██║██║░░██║░░░
██████╦╝██████╔╝██║░░░██║███████║░░░
██╔══██╗██╔══██╗██║░░░██║██╔══██║░░░
██████╦╝██║░░██║╚██████╔╝██║░░██║██╗
╚═════╝░╚═╝░░╚═╝░╚═════╝░╚═╝░░╚═╝╚═╝""")
@bot.command()
async def tree(ctx, size=3):
"""Prints little trees."""
if size > 30:
await ctx.send("DoSing me is illegal at the moment.")
return
else:
size = int(size)
a = 1
b = 2 * size - 1
out = ""
char = "*"
for i in range(0, size):
out += "".join([char for j in range(0, a)]).center(b) + "\n"
a += 2
for i in range(0, int(math.ceil(size / 20))):
out += char.center(b) + "\n"
await ctx.send("```" + chr(8203) + out[:-1] + "```")
@bot.command()
async def logsclear(ctx):
"""Clears logs of FBB."""
if isAuthorized(ctx.message.author.id):
with open("latest.log", "w") as f: pass
await ctx.send("Logs have been erased.")
print("Logs have been erased.")
else:
await ctx.send("You don't have sufficient permissions to run this command.")
@bot.command()
async def joke(ctx):
"""Prints a random corny joke."""
logging.debug("call: joke()")
j = await Jokes()
jk = await j.get_joke(
blacklist=[
"nsfw",
"racist",
"sexist"
]
)
if jk["type"] == "single":
await ctx.send(jk["joke"])
else:
await ctx.send(jk["setup"])
await asyncio.sleep(1)
await ctx.send(jk["delivery"])
@bot.command()
async def coinflip(ctx):
"""Flips a coin."""
logging.debug("call: coinflip()")
if random.randint(0, 1):
await ctx.send("Heads!")
else:
await ctx.send("Tails!")
@bot.command()
async def kiss(ctx, person):
"""Kiss people. Idk y."""
logging.debug("call: kiss()")
if isFbb(person):
await ctx.send("no thank you, I refuse")
return
if isMention(person):
if int(ctx.message.author.id) == int(idFromMention(person)):
await ctx.send("wut.")
return
else:
if person.strip() == ctx.message.author.name:
await ctx.send("wut.")
return
if ("@everyone" in person) or ("@here" in person):
await ctx.send("oof ur being real amorous here")
return
if isMention(person):
person = await bot.fetch_user(int(idFromMention(person)))
person = person.name
else:
pass
embed = discord.Embed(
title=f"{ctx.message.author.name} has kissed {person}!",
description="idk what to say tbh",
)
embed.set_image(url=kawaii("kiss"))
await ctx.send(embed=embed)
@bot.command(aliases=["new-ticket", "new_ticket"])
async def newticket(ctx, *args):
"""Allows you to open new tickets."""
logging.debug("call: newticket()")
if len(args) < 1:
topic = "unknown topic"
else:
topic = " ".join(args)
ticket_channel = await ctx.guild.create_text_channel(
f"ticket-{ctx.message.author.name}-{topic}",
category=get(
bot.get_guild(
837710846280073279
).categories,
id=946872728361791499
)
)
await ticket_channel.set_permissions(
ctx.guild.get_role(
ctx.guild.id
),
send_messages=False,
read_messages=False
)
for role in ctx.guild.roles:
if role.permissions.manage_guild:
await ticket_channel.set_permissions(
role,
send_messages=True,
read_messages=True,
add_reactions=True,
embed_links=True,
attach_files=True,
read_message_history=True,
external_emojis=True
)
await ticket_channel.set_permissions(
ctx.author,
send_messages=True,
read_messages=True,
add_reactions=True,
embed_links=True,
attach_files=True,
read_message_history=True,
external_emojis=True
)
embed = discord.Embed(
title="Ticket Creator",
description=f"Your ticket has been created for {topic}.",
color=discord.Color.from_rgb(2, 0, 255)
)
await ctx.send(embed=embed)
@bot.command(aliases=["close-ticket", "close_ticket"])
async def closeticket(ctx):
"""Allows you to close tickets."""
logging.debug("call: closeticket()")
if ctx.channel.name.startswith("ticket-"):
await ctx.channel.delete()
else:
embed = discord.Embed(
title="Ticket Creator",
description="Please run this in the ticket channel you want to close!",
color = discord.Color.from_rgb(101, 3, 1)
)
await ctx.send(embed=embed)
bot.run(
str(
os.getenv(
"DISCORD_TOKEN"
)
)
)