Skip to content

Commit

Permalink
massive commit that i forgot to do in stages
Browse files Browse the repository at this point in the history
  • Loading branch information
superpenguin612 committed Aug 11, 2021
1 parent bd0c7e2 commit da0e7ed
Show file tree
Hide file tree
Showing 51 changed files with 1,887 additions and 1,448 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@ __pycache__/
.vscode
venv/
ivenv/
dvenv/
localhelpers/
*.pyc
2 changes: 1 addition & 1 deletion Procfile
Original file line number Diff line number Diff line change
@@ -1 +1 @@
worker: python3 -m bot.chsbot.main & python3 -m bot.davidhackerman.main & python3 -m bot.nukeyboy.main & python3 -m bot.colors.main & wait
worker: python3 main.py
1 change: 1 addition & 0 deletions TUTORIAL.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
TODO
79 changes: 0 additions & 79 deletions bot/chsbot/beta.py

This file was deleted.

73 changes: 0 additions & 73 deletions bot/chsbot/main.py

This file was deleted.

File renamed without changes.
83 changes: 64 additions & 19 deletions bot/cogs/events.py → bot/cogs/core/events.py
Original file line number Diff line number Diff line change
@@ -1,29 +1,39 @@
import asyncio
import json
import logging
import os
import time

import asyncpg
import discord
from discord.ext import commands
from discord_slash.context import SlashContext

from bot.helpers import tools
import asyncio
import time
import asyncpg
import os
import json

clogger = logging.getLogger("command")


class Events(commands.Cog):
def __init__(self, bot):
def __init__(self, bot: commands.Bot):
self.bot = bot
_logger = logging.getLogger(__name__)
self.logger = logging.LoggerAdapter(_logger, {"botname": self.bot.name})
self.clogger = logging.getLogger("commands")

async def create_db_pool(self):
DATABASE_URL = os.environ["DATABASE_URL"]
return await asyncpg.create_pool(
DATABASE_URL, min_size=2, max_size=5, ssl="require"
DATABASE_URL, min_size=1, max_size=2, ssl="require"
)

@commands.Cog.listener(name="on_ready")
async def on_ready(self) -> None:
print(
f"Logged in.\nUser: {self.bot.user}\nID: {self.bot.user.id}\n----------------------"
)

self.logger.info(f"Bot is ready.")
self.logger.info(f"User: {self.bot.user}")
self.logger.info(f"ID: {self.bot.user.id}")

if self.bot.user.id == 802211256383438861: # chs bot
await self.bot.change_presence(
activity=discord.Activity(
Expand All @@ -45,6 +55,10 @@ async def on_ready(self) -> None:
)
self.bot.db = await self.create_db_pool()

@commands.Cog.listener(name="on_connect")
async def on_connect(self) -> None:
self.logger.info("Connected to Discord websocket.")

@commands.Cog.listener(name="on_slash_command_error")
async def on_slash_command_error(self, ctx: SlashContext, error: Exception) -> None:
if isinstance(error, commands.CommandOnCooldown):
Expand Down Expand Up @@ -80,26 +94,23 @@ async def on_slash_command_error(self, ctx: SlashContext, error: Exception) -> N
f"Uh oh! Something went wrong, and this error wasn't anticipated. Sorry about that! I'll ping the owners of this bot to fix it.\nError: {error.__class__.__name__}",
)
await ctx.send(embed=embed)
author1 = await ctx.guild.fetch_member(688530998920871969)
await ctx.send(f"{author1.mention}")
# author1 = await ctx.guild.fetch_member(688530998920871969)
# await ctx.send(f"{author1.mention}")
raise error
else:
embed = tools.create_error_embed(
ctx,
f"Uh oh! Something went wrong, and this error wasn't anticipated. Sorry about that! I'll ping the owners of this bot to fix it.\nError: {error.__class__.__name__}",
)
await ctx.send(embed=embed)
author1 = await ctx.guild.fetch_member(688530998920871969)
await ctx.send(f"{author1.mention}")
# author1 = await ctx.guild.fetch_member(688530998920871969)
# await ctx.send(f"{authorx1.mention}")
raise error
await ctx.send(embed=embed)

# --------------------------------------------
# LEGACY COMMANDS
# --------------------------------------------

@commands.Cog.listener(name="on_command_error")
async def on_command_error(self, ctx: commands.Context, error: Exception) -> None:
print(error)
if isinstance(error, commands.CommandOnCooldown):
embed = tools.create_error_embed(
ctx,
Expand Down Expand Up @@ -149,7 +160,41 @@ async def on_command_error(self, ctx: commands.Context, error: Exception) -> Non
# await ctx.send(f"{author1.mention}")
raise error
await ctx.send(embed=embed)
ctx.command.reset_cooldown(ctx)
# ctx.command.reset_cooldown(ctx)

# @commands.Cog.listener()
# async def on_command(self, ctx: commands.Context) -> None:
# self.clogger.info(
# "",
# extra={
# "botname": self.bot.name,
# "username": ctx.author.name,
# "userid": ctx.author.id,
# "guild": ctx.guild.name,
# "guildid": ctx.guild.id,
# "prefix": ctx.prefix,
# "command": ctx.command.qualified_name,
# "arguments": ctx.args,
# "full": ctx.message.content,
# },
# )

# @commands.Cog.listener()
# async def on_slash_command(self, ctx: SlashContext) -> None:
# self.clogger.info(
# "",
# extra={
# "botname": self.bot.name,
# "username": ctx.author.name,
# "userid": ctx.author.id,
# "guild": ctx.guild.name,
# "guildid": ctx.guild.id,
# "prefix": "/",
# "command": ctx.command.qualified_name,
# "arguments": ctx.args,
# "full": ctx.message.content,
# },
# )


def setup(bot: commands.Bot) -> None:
Expand Down
14 changes: 7 additions & 7 deletions bot/cogs/info.py → bot/cogs/core/info.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
import random

import discord
from discord.ext import commands
from bot.helpers import tools
from discord_slash import cog_ext, SlashContext
from discord_slash import SlashContext, cog_ext
from discord_slash.utils.manage_commands import create_option
import random

from bot.helpers import tools


class Info(commands.Cog):
def __init__(self, bot):
def __init__(self, bot: commands.Bot):
self.bot = bot

@cog_ext.cog_slash(
Expand Down Expand Up @@ -86,9 +88,7 @@ async def server_roles(self, ctx: SlashContext) -> None:
embed = tools.create_embed(
ctx,
"Server Roles",
"\n".join(
reversed([role.mention for role in ctx.guild.roles])
), # [::1] reverses roles
"\n".join(reversed([role.mention for role in ctx.guild.roles])),
)
await ctx.send(embed=embed)

Expand Down
6 changes: 4 additions & 2 deletions bot/cogs/owner.py → bot/cogs/core/owner.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import random

import discord
from discord.ext import commands
from discord_slash import cog_ext, SlashContext
from discord_slash import SlashContext, cog_ext
from discord_slash.utils.manage_commands import create_option

from bot.helpers import tools
import random


class Owner(commands.Cog, name="owner"):
Expand Down
Loading

0 comments on commit da0e7ed

Please sign in to comment.