Skip to content

Commit

Permalink
Bloop 2.7
Browse files Browse the repository at this point in the history
  • Loading branch information
mtbtrq committed Sep 15, 2021
1 parent d0aa0b1 commit 1e7e49a
Show file tree
Hide file tree
Showing 16 changed files with 253 additions and 222 deletions.
Binary file removed SRC/bw.png
Binary file not shown.
12 changes: 12 additions & 0 deletions SRC/cogs/ErrorHandling.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,29 @@
import sys
from discord.ext import commands
import json
from datetime import datetime

with open('./config.json') as jsonload:
config = json.load(jsonload)

noCoolDownUsers = config.get("noCoolDownUsers")

now = datetime.now()

logFileName = f"./logs - {now.strftime('%H ; %M ; %S')}.txt"

print(f"Logging commands to {logFileName}")

class CommandErrorHandler(commands.Cog):

def __init__(self, bot):
self.bot = bot

@commands.Cog.listener()
async def on_command(self, ctx):
logs = open(logFileName, "a")
logs.write(f"\n'{ctx.command}' was executed in '{ctx.guild.name}' (ID: {ctx.guild.id}) by {ctx.author} (ID: {ctx.author.id}) at {datetime.utcnow()} UTC")

@commands.Cog.listener()
async def on_command_error(self, ctx, error):
if hasattr(ctx.command, 'on_error'):
Expand Down
337 changes: 188 additions & 149 deletions SRC/cogs/Minecraft.py

Large diffs are not rendered by default.

6 changes: 1 addition & 5 deletions SRC/cogs/Misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,13 @@ async def ping(self, ctx):
pingembed.add_field(name = "Pong!", value = f"{ping} ms")

await ctx.reply(embed=pingembed, mention_author=False)
print("The Ping Command was executed!")

@commands.command()
async def src(self, ctx):

srcembed = discord.Embed(title="Source Code", url = "https://github.com/Supelion/Bloop", description="Bloop's SRC can be found on GitHub by clicking the title of this embed,\nor by [clicking here](http://tiny.cc/rfx2uz)", color = 0x2f3136)

await ctx.reply(embed=srcembed, mention_author=False)
print("The SRC Command was executed!")

@commands.command()
@commands.cooldown(1, 500,commands.BucketType.user)
Expand All @@ -34,7 +32,6 @@ async def suggest(self, ctx, *, message):
embed.add_field(name = "Suggestion added!", value = f"{message}")

await ctx.reply(embed = embed, mention_author = False)
print("The Suggest Command was executed!")

channel = self.client.get_channel(837363032321294367)
lolembed = discord.Embed(title = "New Suggestion")
Expand All @@ -45,10 +42,9 @@ async def suggest(self, ctx, *, message):
async def invite(self, ctx):
invitembed = discord.Embed(color = 0x2f3136)

invitembed.add_field(name=f"Invite Link :link:", value = "https://bit.ly/bloopBot")
invitembed.add_field(name=f"Invite Link :link:", value = "https://discord.com/oauth2/authorize?client_id=835237831412547607&permissions=2147862592&scope=bot")

await ctx.reply(embed=invitembed, mention_author=False)
print("The Skin Command was executed!")


def setup(client):
Expand Down
7 changes: 2 additions & 5 deletions SRC/cogs/OwnerOnly.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
import discord
import json
import os
import aiohttp
from discord.ext import commands

class owner(commands.Cog):
class Owner(commands.Cog):

def __init__(self, client):
self.client = client
Expand Down Expand Up @@ -263,4 +260,4 @@ async def ownerhelp(self, ctx):
await ctx.reply(embed = ownerhelpembed)

def setup(client):
client.add_cog(owner(client))
client.add_cog(Owner(client))
10 changes: 5 additions & 5 deletions SRC/config.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"token": "ODM2NjU1MTEyMDIxMjEzMjI0.YIhJyw.yikPEnjoryamTO7ey4KJ3Rd8XQw",
"hypixelapikey": "67068c67-02ee-444f-9f2e-8a80a27271e8",
"postgresDSN": "postgresql://postgres:5utBpuE1FRy4trJmVSCt@containers-us-west-11.railway.app:7551/railway",
"bot-log-channel": 873295884903907399,
"noCoolDownUsers": [467962329435471878, 577377630362402817, 704672855245193296]
"token": "INERT YOUR DISCORD BOT TOKEN HERE",
"hypixelapikey": "INSERT YOUR HYPIXEL API KEY HERE",
"bot-log-channel": "INSERT A CHANNEL ID HERE",
"noCoolDownUsers": ["INSERT USER IDS HERE, SEPERATED BY COMMAS"],
"prefix": "."
}
81 changes: 30 additions & 51 deletions SRC/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
import json
from datetime import datetime
from itertools import cycle
import asyncpg
import discord
from discord.ext import commands, tasks
import PIL # I know, we're not usig this module right now, but its for the try except statement
import platform
import PIL # I know, we're not using this module right now, but its for the try except statement

except ImportError:
print("One or many requirements are missing! Installing them now.")
Expand All @@ -18,31 +18,18 @@
config = json.load(f)

token = config.get('token')
postgresDatabaseDSN = config.get('postgresDSN')
botLogChannel = config.get('bot-log-channel')
prefix = config.get('prefix')

os.system("cls")

async def create_db_pool():
client.db = await asyncpg.create_pool(dsn = postgresDatabaseDSN)
print("Connected to the DB!")

await client.db.execute("CREATE TABLE IF NOT EXISTS prefixes(guild_id bigint PRIMARY KEY, prefix text);")
print("Created Table")

PRE = '.'
async def get_pre(bot, message):
if not message.guild:
return commands.when_mentioned_or(PRE)(bot,message)
prefix = await client.db.fetchval('SELECT prefix FROM prefixes WHERE guild_id = $1', message.guild.id)
if not prefix:
prefix = PRE
return commands.when_mentioned_or(prefix)(bot,message)

intents = discord.Intents.default()
intents.members = True
client = commands.Bot(command_prefix = get_pre, case_insensitive = True, help_command=None, intents=intents)
client.launch_time = datetime.utcnow()
client = commands.Bot(command_prefix = prefix, case_insensitive = True, help_command=None, intents=intents)

launch_time = datetime.utcnow()

botVersion = "Bloop v2.7"

for filename in os.listdir('./cogs'):
if filename.endswith('.py'):
Expand All @@ -52,8 +39,18 @@ async def get_pre(bot, message):
async def on_ready():
user = client.get_user(467962329435471878)
await user.send("I'm online. <:online:850325400605425684>")
print(f"I'm ready! I have logged in as {client.user}")
print(f"I have logged in as {client.user}")
print(f"Python Version: {platform.python_version()}")
print(f"Running on: {platform.system()} {platform.release()}")

@client.command()
async def reload(ctx, *, module):
try:
client.reload_extension(module)
await ctx.send("Done!")
except commands.ExtensionError as e:
await ctx.send(f'{e.__class__.__name__}: {e}')

@client.event
async def on_guild_remove(guild):
channel = client.get_channel(botLogChannel)
Expand All @@ -73,32 +70,17 @@ async def changer():
status2 = f"Hypixel Stats! | .help"
status3 = f"Open Source! (.src)| .help"
status4 = f"Server Stats! | .help"
status5 = f"DLCs! | .help"
client.status = cycle([status1, status2, status3, status4, status5])
status5 = f"Map Information! | .help"
status6 = f"Requeue Checker! | .help"
status7 = f"Stats Comparer! | .help"
status8 = f"Watchdog Stats! | .help"
client.status = cycle([status1, status2, status3, status4, status5, status6])
changer.start()

@client.command()
@commands.has_permissions(manage_guild = True)
@commands.cooldown(1, 50,commands.BucketType.guild)
async def prefix(ctx, new=None):
old = await client.db.fetchval('SELECT prefix FROM prefixes WHERE guild_id = $1', ctx.guild.id)
if not new:
old = old or '.'
await ctx.send(f"My prefix here is: `{old}`")
return

if len(new) > 10:
return await ctx.send("Prefixes must be no longer than 10 characters long!")
if not old:
await client.db.execute('INSERT INTO prefixes(guild_id, prefix) VALUES ($1, $2)', ctx.guild.id, new)
else:
await client.db.execute('UPDATE prefixes SET prefix = $1 WHERE guild_id = $2', new, ctx.guild.id)
await ctx.send(f"The new prefix is: `{new}`")

@client.command()
async def stats(ctx):

delta_uptime = datetime.utcnow() - client.launch_time
delta_uptime = datetime.utcnow() - launch_time
hours, remainder = divmod(int(delta_uptime.total_seconds()), 3600)
minutes, seconds = divmod(remainder, 60)
days, hours = divmod(hours, 24)
Expand All @@ -111,12 +93,11 @@ async def stats(ctx):

statsembed.add_field(name = f"Guilds:", value = f"{len(client.guilds)}", inline = False)

statsembed.add_field(name = f"Uptime:", value = f"{hours}h, {minutes}m, {seconds}s.\n\n[Support Website](https://supelion.github.io/bl00p/)", inline = False)
statsembed.add_field(name = f"Uptime:", value = f"{days}d {hours}h, {minutes}m, {seconds}s.\n\n[Support Website](https://supelion.github.io/bl00p/)", inline = False)

statsembed.set_footer(text="Bloop v2.5 | Supelion#4275")
statsembed.set_footer(text=f"{botVersion} | Supelion#4275")

await ctx.reply(embed=statsembed, mention_author=False)
print("The Stats Command was executed!")

@client.command()
async def help(ctx):
Expand All @@ -125,16 +106,14 @@ async def help(ctx):

helpembed.add_field(name = "My Prefix:", value = "``.``")

helpembed.add_field(name='<:minecraft:848988105943810095> Minecraft', value='``bw`` • ``sw`` • ``duels`` • ``profile`` • ``wdr`` • ``server``\n\n``socials`` • ``skin`` • ``p`` • ``uuid`` • ``compare``\n\n``achievement`` • ``map`` • ``requeue``', inline=False)
helpembed.add_field(name='<:minecraft:848988105943810095> Minecraft', value='``bw`` • ``sw`` • ``duels`` • ``profile`` • ``wdr`` • ``server``\n\n``socials`` • ``skin`` • ``p`` • ``uuid`` • ``compare``\n\n``achievement`` • ``map`` • ``requeue`` • ``key``', inline=False)

helpembed.add_field(name='<:misc:844235406877917234> Utility', value='``src`` • ``ping`` • ``invite`` • ``stats`` • ``suggest`` • ``prefix``', inline=False)
helpembed.add_field(name='<:utility:877105943844904980> Utility', value='``src`` • ``ping`` • ``invite`` • ``stats`` • ``suggest``', inline=False)

helpembed.set_thumbnail(url='https://media.discordapp.net/attachments/8350712o70117834773/853578246984433684/lol.png?width=480&height=480')

helpembed.set_footer(text="Bloop v2.5 | Supelion#4275 | All Commmands work in DMs.")
helpembed.set_footer(text=f"{botVersion} | Supelion#4275 | All Commmands work in DMs.")

await ctx.reply(embed=helpembed, mention_author = False)
print("The Help Command was executed!")

client.loop.run_until_complete(create_db_pool())
client.run(f"{token}")
5 changes: 2 additions & 3 deletions SRC/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
asyncpg
discord
aiohttp
pillow
pillow
py-cord
13 changes: 13 additions & 0 deletions SRC/utils/hywrap.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,19 @@ async def guild(uuid : str, hypixelapikey : str = None):
guild = await guildRaw.json()
return guild

# Returns the player's rank, its a little complicated, but gets the job done :D
async def rank(playerdata : dict):
try:
return playerdata["player"]["rank"]
except:
if playerdata["player"].get("monthlyPackageRank") and playerdata["player"].get("monthlyPackageRank") != "NONE":
return playerdata["player"]["monthlyPackageRank"]
else:
try:
return playerdata["player"]["newPackageRank"]
except:
return None

# Returns the recent games of a player
async def recentGames(uuid : str, hypixelapikey : str = None):
if hypixelapikey is None:
Expand Down
4 changes: 0 additions & 4 deletions requirements.txt

This file was deleted.

File renamed without changes.
Binary file added src/images/bw.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
File renamed without changes
File renamed without changes
File renamed without changes
Binary file added src/images/template.pdn
Binary file not shown.

0 comments on commit 1e7e49a

Please sign in to comment.