Skip to content

Refactor: Formatting Code to PEP8 Standards #55

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Jun 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 35 additions & 15 deletions cogs/developer.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from __future__ import annotations
from io import BytesIO

import os
import traceback
Expand Down Expand Up @@ -50,7 +49,7 @@ async def _load(self, ctx: commands.Context[CodingBot], cog_: str):
title=f"Successfully loaded extension: `{cog_}`",
color=discord.Color.green(),
)
except Exception as e:
except Exception:
embed = discord.Embed(
title=f"Failed to load extension: `{cog_}`", color=discord.Color.red()
)
Expand All @@ -75,7 +74,7 @@ async def _unload(self, ctx: commands.Context[CodingBot], cog_: str):
title=f"Successfully unloaded extension: `{cog_}`",
color=discord.Color.green(),
)
except Exception as e:
except Exception:
embed = discord.Embed(
title=f"Failed to unload extension: `{cog_}`", color=discord.Color.red()
)
Expand All @@ -99,7 +98,7 @@ async def _reload(self, ctx: commands.Context[CodingBot], cog_: str):
title=f"Successfully reloaded extension: `{cog_}`",
color=discord.Color.green(),
)
except Exception as e:
except Exception:
embed = discord.Embed(
title=f"Failed to reload extension: `{cog_}`", color=discord.Color.red()
)
Expand Down Expand Up @@ -154,7 +153,7 @@ async def _unloadall(self, ctx: commands.Context[CodingBot]):

"""
cogs: Dict[str, List[str]] = {"unloaded": [], "not": []}
processing: Mapping[str, ModuleType] = self.bot.extensions.copy() # type: ignore
processing: Mapping[str, ModuleType] = self.bot.extensions.copy()
for cog in processing:
try:
await self.bot.unload_extension(cog)
Expand Down Expand Up @@ -184,7 +183,7 @@ async def _reloadall(self, ctx: commands.Context[CodingBot]):

"""
cogs: Dict[str, List[str]] = {"reloaded": [], "not": []}
processing: Mapping[str, ModuleType] = self.bot.extensions.copy() # type: ignore
processing: Mapping[str, ModuleType] = self.bot.extensions.copy()
for cog in processing:
try:
await self.bot.reload_extension(cog)
Expand Down Expand Up @@ -254,22 +253,43 @@ async def _getusermetric(
)
record = message_metric[0] if message_metric else None
if record:
deleted_message_percent = (record.deleted_message_count /
record.message_count * 100)
actual_message_percent = ((record.message_count -
record.deleted_message_count) /
record.message_count * 100)
offline_message_percent = record.offline / record.message_count * 100
online_message_percent = record.online / record.message_count * 100
dnd_message_percent = record.dnd / record.message_count * 100
idle_message_percent = record.idle / record.message_count * 100
formatted_message = f"""
**__Message metrics__** For {member.mention}:
\u3164 • **__Total message count__**: {record.message_count}
\u3164 • **__Deleted message count__**: {record.deleted_message_count} (`{record.deleted_message_count / record.message_count * 100:.2f}%`)
\u3164 • **__Actual message count__**: {record.message_count - record.deleted_message_count} (`{(record.message_count - record.deleted_message_count) / record.message_count * 100:.2f}%`)
\u3164 • **__Offline message count__**: {record.offline} (`{record.offline / record.message_count * 100:.2f}%`)
\u3164 • **__Online message count__**: {record.online} (`{record.online / record.message_count * 100:.2f}%`)
\u3164 • **__Dnd message count__**: {record.dnd} (`{record.dnd / record.message_count * 100:.2f}%`)
\u3164 • **__Idle message count__**: {record.idle} (`{record.idle / record.message_count * 100:.2f}%`)
\u3164 • **__Total message count__**: {record.message_count}
\u3164 • **__Deleted message count__**: \
{record.deleted_message_count} (`{deleted_message_percent}%`)
\u3164 • **__Actual message count__**: \
{record.message_count - record.deleted_message_count} \
(`{actual_message_percent}%`)
\u3164 • **__Offline message count__**: \
{record.offline} (`{offline_message_percent}%`)
\u3164 • **__Online message count__**: \
{record.online} (`{online_message_percent}%`)
\u3164 • **__Dnd message count__**: {record.dnd} (`{dnd_message_percent}%`)
\u3164 • **__Idle message count__**: \
{record.idle} (`{idle_message_percent}%`)
"""

revoked_thanks_percent = (revoked_thank_count/total_thank_count*100
if total_thank_count > 0 else 0)
actual_thanks_percent = (surviving_thank_count/total_thank_count*100
if total_thank_count > 0 else 0)
embed = discord.Embed(
title=f"{member.name}#{member.discriminator} Detailed anaylysis",
description=f"Total thanks this month: {total_thank_count}\n"
f"Revoked thanks this month: {revoked_thank_count} (`{revoked_thank_count/total_thank_count*100 if total_thank_count > 0 else 0:.2f}%`)\n"
f"Actual thanks this month: {surviving_thank_count} (`{surviving_thank_count/total_thank_count*100 if total_thank_count > 0 else 0:.2f}%`)"
f"Revoked thanks this month: {revoked_thank_count} "
f"(`{revoked_thanks_percent}%`)\n"
f"Actual thanks this month: \
{surviving_thank_count} (`{actual_thanks_percent}%`)"
f'\n{formatted_message if record else ""}',
timestamp=discord.utils.utcnow(),
)
Expand Down
154 changes: 7 additions & 147 deletions cogs/fun.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,14 @@
from __future__ import annotations

import random
import json
from io import BytesIO
from textwrap import wrap
from typing import TYPE_CHECKING, Optional

import base64
import discord
from discord import utils
from discord.ext import commands
from ext.helpers import create_trash_meme, get_rock
from ext.helpers import create_trash_meme
from ext.http import Http
from ext.ui.view import *

import asyncio

Expand Down Expand Up @@ -44,24 +40,6 @@ async def trash(self, ctx: commands.Context[CodingBot], *, user: discord.Member)
file = await create_trash_meme(avatar_one, avatar_two)
await self.bot.send(ctx, file=file)

# @commands.hybrid_command()
# async def rock(
# self, ctx: commands.Context[CodingBot], *, query: Optional[str] = None
# ):
# """
# Get a random rock
# Usage:
# ------
# `{prefix}rock`: *will get a random rock*
# `{prefix}rock [rock]`: *will get the [rock]*

# """
# rock_info = await get_rock(self)
# return await self.bot.reply(
# ctx,
# embed=rock_info,
# )

@commands.hybrid_command()
async def number(
self, ctx: commands.Context[CodingBot], number: Optional[int] = None
Expand Down Expand Up @@ -190,28 +168,6 @@ async def token(self, ctx: commands.Context[CodingBot]):
)
await self.bot.reply(ctx, embed=embed)

# @commands.hybrid_command(name="animal")
# async def animal(self, ctx: commands.Context[CodingBot], animal: Optional[str] = None):
# options = ("dog", "cat", "panda", "fox", "red_panda", "koala", "bird", "raccoon", "kangaroo")
# if (not animal) or (animal and animal not in options):
# animal = random.choice(options)

# response = await self.http.api["some-random-api"]["animal"](animal)
# if response.status in range(200,300):
# json = await response.json()

# image = json["image"]
# fact = json["fact"]

# embed = discord.Embed(title="Here's the animal image you asked.", color=discord.Color.random())
# embed.set_image(url=image)
# embed.set_footer(text=fact)
# else:
# embed = discord.Embed(title="ERROR!", description=f"Received a bad status code of {response.status}")
# embed.set_footer(text=f"Requested by {ctx.author}", icon_url=ctx.author.display_avatar.url)

# await self.bot.reply(ctx,embed=embed)

@commands.hybrid_group(invoke_without_command=True)
async def binary(self, ctx: commands.Context[CodingBot]):
embed = discord.Embed(
Expand Down Expand Up @@ -258,32 +214,6 @@ async def binary_decode(self, ctx: commands.Context[CodingBot], *, binary: str):

await self.bot.reply(ctx, embed=embed)

# @commands.hybrid_command(name="lyrics")
# async def lyrics(self, ctx: commands.Context[CodingBot], *, query: str = None):
# if not query:
# embed = discord.Embed(title = "Hey! I'm confused", description=f"You must provide a search argument or I couldn't find the lyrics")
# embed.set_footer(text=f"Requested by {ctx.author}", icon_url=ctx.author.display_avatar.url)

# response = await self.http.api["some-random-api"]["lyrics"](query)
# if response.status in range(200, 300):
# json = await response.json()

# lyrics = json['lyrics']
# artist = json['author']
# title = json['title']
# thumbnail = json['thumbnail']['genius']

# for chunk in wrap(lyrics, 4096, replace_whitespace = False):
# embed = discord.Embed(title = f"{artist} - {title}", description = chunk, color=discord.Color.random())
# embed.set_thumbnail(url=thumbnail)
# embed.set_footer(text=f"Requested by {ctx.author}", icon_url=ctx.author.display_avatar.url)

# else:
# embed = discord.Embed(title="ERROR!", description=f"Received a bad status code of {response.status}")
# embed.set_footer(text=f"Requested by {ctx.author}", icon_url=ctx.author.display_avatar.url)

# await self.bot.reply(ctx,embed=embed)

@commands.hybrid_command(name="reverse")
async def reverse(self, ctx: commands.Context[CodingBot], *, text: str):
embed = discord.Embed(
Expand All @@ -299,7 +229,7 @@ async def reverse(self, ctx: commands.Context[CodingBot], *, text: str):
@commands.hybrid_command(name="owofy")
async def owofy(self, ctx: commands.Context[CodingBot], *, text: str):
embed = discord.Embed(
title=f"Owofied Text",
title="Owofied Text",
description=text.replace("o", "OwO"),
color=discord.Color.random(),
)
Expand All @@ -311,7 +241,7 @@ async def owofy(self, ctx: commands.Context[CodingBot], *, text: str):
@commands.hybrid_command(name="mock")
async def mock(self, ctx: commands.Context[CodingBot], *, text: str):
embed = discord.Embed(
title=f"Mocked Text",
title="Mocked Text",
description=text.swapcase(),
color=discord.Color.random(),
)
Expand All @@ -325,7 +255,9 @@ async def _beerparty(
self, ctx: commands.Context, *, reason: commands.clean_content = None
):
reason = ("\nReason: " + reason) if reason else ""
msg = await ctx.send("Open invite to beerparty! React with 🍻 to join!" + reason)
msg = await ctx.send(
"Open invite to beerparty! React with 🍻 to join!" + reason
)
await msg.add_reaction("\U0001f37b")
await asyncio.sleep(60)
msg = await ctx.channel.fetch_message(msg.id)
Expand All @@ -334,80 +266,8 @@ async def _beerparty(
if len(users) == 0:
return await ctx.send("Nobody joined the beerparty :(")
await ctx.send(
", ".join(user.display_name for user in users) + f" joined the beerparty!"
", ".join(user.display_name for user in users) + " joined the beerparty!"
)

# Filters command
# @commands.hybrid_group(invoke_without_command=True)
# async def filter(self, ctx: commands.Context[CodingBot]):
# embed = discord.Embed(title="Filter command", description="Available methods: `invert`, `greyscale`, `colour [hex]`", color=discord.Color.random())
# embed.set_footer(text=f"Requested by {ctx.author}", icon_url=ctx.author.display_avatar.url)
# await self.bot.reply(ctx,embed=embed)

# @filter.command(name="invert")
# async def filter_invert(self, ctx: commands.Context[CodingBot], member: discord.Member = None):
# if not member:
# member = ctx.author
# pfp = member.display_avatar.url
# response = await self.http.api["some-random-api"]["filters"]["invert"](pfp)

# embed = discord.Embed(title="Filter command - Invert", color=discord.Color.random())
# embed.set_image(url=response)
# embed.set_footer(text=f"Requested by {ctx.author}", icon_url=ctx.author.display_avatar.url)
# await self.bot.reply(ctx,embed=embed)

# @filter.command(name="greyscale")
# async def filter_greyscale(self, ctx: commands.Context[CodingBot], member: discord.Member = None):
# if not member:
# member = ctx.author
# pfp = member.display_avatar.url
# response = await self.http.api["some-random-api"]["filters"]["greyscale"](pfp)

# embed = discord.Embed(title="Filter command - Greyscale", color=discord.Color.random())
# embed.set_image(url=response)
# embed.set_footer(text=f"Requested by {ctx.author}", icon_url=ctx.author.display_avatar.url)
# await self.bot.reply(ctx,embed=embed)

# @filter.command(name="colour")
# async def filter_colour(self, ctx: commands.Context[CodingBot], member: discord.Member = None, hex_code: str = None):
# if not member:
# member = ctx.author
# if not hex_code:
# embed = discord.Embed(title="ERROR!", description="No Hex? Hex colour code is required")
# embed.set_footer(text=f"Requested by {ctx.author}", icon_url=ctx.author.display_avatar.url)
# hex_code = hex_code.replace('#', '')
# pfp = member.display_avatar.url
# response = await self.http.api["some-random-api"]["filters"]["greyscale"](pfp, hex_code)

# embed = discord.Embed(title="Filter command - Colour", color=discord.Color.random())
# embed.set_image(url=response)
# embed.set_footer(text=f"Requested by {ctx.author}", icon_url=ctx.author.display_avatar.url)
# await self.bot.reply(ctx,embed=embed)

# @filter.command(name="brightness")
# async def filter_brightness(self, ctx: commands.Context[CodingBot], member: discord.Member = None):
# if not member:
# member = ctx.author
# pfp = member.display_avatar.url
# response = await self.http.api["some-random-api"]["filters"]["brightness"](pfp)

# embed = discord.Embed(title="Filter command - Brightness", color=discord.Color.random())
# embed.set_image(url=response)
# embed.set_footer(text=f"Requested by {ctx.author}", icon_url=ctx.author.display_avatar.url)
# await self.bot.reply(ctx,embed=embed)

# @filter.command(name="threshold")
# async def filter_threshold(self, ctx: commands.Context[CodingBot], member: discord.Member = None):
# if not member:
# member = ctx.author
# pfp = member.display_avatar.url
# response = await self.http.api["some-random-api"]["filters"]["threshold"](pfp)

# embed = discord.Embed(title="Filter command - Threshold", color=discord.Color.random())
# embed.set_image(url=response)
# embed.set_footer(text=f"Requested by {ctx.author}", icon_url=ctx.author.display_avatar.url)
# await self.bot.reply(ctx,embed=embed)


async def setup(bot: CodingBot):
await bot.add_cog(Fun(bot))
6 changes: 3 additions & 3 deletions cogs/general.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
from __future__ import annotations

import datetime
import inspect
import os
from typing import TYPE_CHECKING, List

import discord
from discord.ext import commands
from ext.helpers import UrbanDefinition, UrbanDictionary, find_anime_source
from ext.helpers import UrbanDefinition, UrbanDictionary

if TYPE_CHECKING:
from ext.models import CodingBot
Expand All @@ -34,7 +33,8 @@ async def _source(
------
`{prefix}source` *will send link to my source code*
`{prefix}source [command]` *will send link to the source code of the command*
`{prefix}source [command] [subcommand]` *will send link to the source code of the subcommand*
`{prefix}source [command] [subcommand]`:
*will send link to the source code of the subcommand*
"""
github = "<:githubwhite:804344724621230091>"
embed = discord.Embed(title=f"{github} GitHub (Click Here) {github}")
Expand Down
Loading