Last active
January 29, 2022 00:38
-
-
Save mdvsh/c391a5085f57430c6360a5b24b278e93 to your computer and use it in GitHub Desktop.
A dope discord bot (son of Bruh) I wrote to complement the existing bot (BruhBot) on my Class's Discord Server. HIGHLIGHT : Notes Generator and Markov Chain Chatbot
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from fpdf import FPDF | |
from PIL import Image | |
def makePdf(pdfFileName, listPages, dir = ''): | |
if (dir): | |
dir += "/" | |
cover = Image.open(dir + str(listPages[0])) | |
width, height = cover.size | |
pdf = FPDF(unit = "pt", format = [width, height]) | |
for page in listPages: | |
pdf.add_page() | |
pdf.image(dir + str(page), 0, 0) | |
pdf.output(dir + pdfFileName, "F") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
import random | |
import discord | |
from discord.ext import commands | |
from dotenv import load_dotenv | |
from phy import makePdf | |
fpepe = os.path.join('/home/pseudocodenerd/Documents/son_of_bruh/notes') | |
# fp = os.path | |
load_dotenv() | |
TOKEN = os.getenv('DISCORD_TOKEN') | |
client = discord.Client() | |
bot = commands.Bot(command_prefix='^', description='son of bruh') | |
@bot.event | |
async def on_ready(): | |
print( | |
'Logged in as', bot.user.name, '\n', | |
bot.user.id, | |
'---------------------------------------------------------------' | |
) | |
@bot.command() | |
async def add(ctx, a: int, b: int): | |
await ctx.send(a+b) | |
@bot.command() | |
async def multiply(ctx, a: int, b: int): | |
await ctx.send(a*b) | |
@bot.command() | |
async def greet(ctx): | |
await ctx.send(":smiley: :wave: hey Wassup !") | |
@bot.command() | |
async def ping(ctx): | |
await ctx.send(f"**Beep-Boop. Current Latency:**\n `{round(bot.latency*1000)}ms`") | |
@bot.command(help='Yeet/Purge/Remove specified number of messages.') | |
async def yeet(ctx, num=5): | |
yeet = '<:3892_dab_emoji:696010771720568872>' | |
await ctx.channel.send('Yeeting {} message(s).'.format(num)) | |
await ctx.channel.purge(limit=num+1) | |
@bot.command(help='Simulates rolling dice.') | |
async def roll(ctx, number_of_dice: int, number_of_sides: int = 6): | |
await ctx.send(f"*shakey shakey*:game_die: Rolling {number_of_dice} dice of {number_of_sides} sides each :game_die:*shakey shakey*") | |
if number_of_dice >= 50 or number_of_sides >= 50: | |
await ctx.send('i know what you wanna do.') | |
exit | |
else: | |
dice = [ | |
str(random.choice(range(1, number_of_sides + 1))) | |
for _ in range(number_of_dice) | |
] | |
await ctx.send(", ".join(dice)) | |
exit | |
bot.remove_command('help') | |
@bot.command(help='Generate notes in `.pdf` format of a specified subject consisting of images.') | |
async def notes(ctx, channel: discord.TextChannel): | |
embed = discord.Embed(title="PDF Notes Generator", description="`^notes #<subject_channel>` to get pdf notes delivered to your DM's.", color=0xff9f43) | |
embed.add_field(name="Available Subjects", value="`#eng`, `#phy`, `#chem`, `#eng`.") | |
embed.add_field(name="Current Job", value="`#{}`".format(channel.name)) | |
embed.add_field(name="Requested By", value="**{}**".format(ctx.author.name)) | |
embed.add_field(name="ETA of Notes", value="30s+", inline=False) | |
await ctx.send(embed=embed) | |
c, listPages = 1, [] | |
print('Making notes of', channel.name) | |
async for messages in channel.history(limit=100, oldest_first=True): | |
if len(messages.attachments) == 0: | |
pass | |
else: | |
for image in messages.attachments: | |
# print(image.filename) | |
if ('png' in image.filename) or ('PNG' in image.filename): | |
await image.save('/home/pseudocodenerd/Documents/son_of_bruh/notes/{}_{}.png'.format(channel.name, str(c))) | |
listPages.append('{}_{}.png'.format(channel.name, str(c))) | |
c+=1 | |
else: | |
await image.save('/home/pseudocodenerd/Documents/son_of_bruh/notes/{}_{}.jpg'.format(channel.name, str(c))) | |
listPages.append('{}_{}.jpg'.format(channel.name, str(c))) | |
c+=1 | |
f_name = channel.name + "_notes.pdf" | |
makePdf(f_name, listPages, '/home/pseudocodenerd/Documents/son_of_bruh/notes') | |
# await ctx.author.send(file=discord.File('/home/pseudocodenerd/Documents/son_of_bruh/notes/{}'.format(f_name), filename=f_name)) | |
with open('/home/pseudocodenerd/Documents/son_of_bruh/notes/{}'.format(f_name), 'rb') as fp: | |
await ctx.author.send(file=discord.File(fp, f_name)) | |
@bot.command() | |
async def help(ctx): | |
embed = discord.Embed(title="Son of Bruh", description="Heir of Bruh Land. Smarter. Dumber. More Fun. List of commands are:", color=0x00b894) | |
embed.add_field(name="^notes <channel_name>", value="Get `.pdf` notes delivered fresh to your inbox. **TRY NOW !!**", inline=False) | |
embed.add_field(name="^add X Y", value="Returns the sum of **X** and **Y**", inline=False) | |
embed.add_field(name="^multiply X Y", value="Returm the product of **X** and **Y**", inline=False) | |
embed.add_field(name="^greet", value="Hola to the homie !", inline=False) | |
embed.add_field(name="^roll X Y", value="Simulate rolling of **X** dice, each with **Y** number of sides.", inline=False) | |
embed.add_field(name="^yeet X", value="Yeet **X** message(s) from the channel. Required **OG+**.", inline=False) | |
embed.add_field(name="^help", value="Gives this message", inline=False) | |
await ctx.send(embed=embed) | |
@bot.event | |
async def on_message(message): | |
# fallback for recursive messaging | |
try: | |
if message.author == client.user: | |
return | |
if message.content == '69' or message.content == '420': | |
emoji = '<:nice:696011334592102464>' | |
response = 'Nice' | |
await message.channel.send(response) | |
await message.add_reaction(emoji) | |
if message.content.lower().startswith('hm'): | |
channel = message.channel | |
bot_message = 'da fuck are you hmm-ing about' | |
await channel.send(bot_message) | |
emoji = '<:cool_angry:703472388259708938>' | |
await message.add_reaction(emoji) | |
# if (message.content)[0] == 'f' or (message.content)[0] == 'F': | |
# global j | |
# j = random.randrange(1, 3) | |
# while j>=0: | |
# await message.channel.send('F.') | |
# j-=1 | |
await bot.process_commands(message) | |
except discord.Forbidden: | |
pass | |
bot.run(TOKEN) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment