Skip to content

Commit

Permalink
Fixes from QA Review
Browse files Browse the repository at this point in the history
  • Loading branch information
Neuro Assassin committed Jun 4, 2019
1 parent a916bbf commit c6b2987
Show file tree
Hide file tree
Showing 37 changed files with 1,040 additions and 871 deletions.
3 changes: 2 additions & 1 deletion color/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from .color import Color


def setup(bot):
bot.add_cog(Color(bot))
bot.add_cog(Color(bot))
31 changes: 24 additions & 7 deletions color/color.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from redbot.core import commands, Config
from redbot.core import commands, Config, checks
from PIL import Image
from colour import Color as col
from colour import rgb2hex
Expand All @@ -9,6 +9,8 @@


class Color(commands.Cog):
"""View embeds showcasing the supplied color and information about it"""

def __init__(self, bot):
self.bot = bot
self.conf = Config.get_conf(self, identifier=473541068378341376)
Expand All @@ -19,7 +21,7 @@ def __init__(self, bot):
r"(?i)^(?:(?:(?:0x|#|)((?:[a-fA-F0-9]{3}){1,2}$))|(?:([+-]?(?:[0-9]*[.])?[0-9]+,[+-]?(?:[0-9]*[.])?[0-9]+,[+-]?(?:[0-9]*[.])?[0-9]+))|(?:(\S+)))"
) # The Regex gods are going to kill me

__author__ = "Neuro Assassin#4227 <@473541068378341376>"
__author__ = "Neuro Assassin#4779 <@473541068378341376>"

def have_fun_with_pillow(self, rgb):
im = Image.new("RGB", (200, 200), rgb)
Expand All @@ -38,10 +40,9 @@ async def build_embed(self, co):
title=f"Color Embed for: {hexa}", color=int(hexa.replace("#", "0x"), 0)
)
embed.add_field(name="Hexadecimal Value:", value=hexa)
embed.add_field(
name="Red, Green, Blue (RGB) Value: ",
value=f"{str(co.rgb)}\n{str(tuple([item*255 for item in co.rgb]))}",
)
normal = ", ".join([f"{part:.2f}" for part in co.rgb])
extended = ", ".join([f"{(part*255):.2f}" for part in co.rgb])
embed.add_field(name="Red, Green, Blue (RGB) Value: ", value=f"{normal}\n{extended}")
embed.add_field(name="Hue, Saturation, Luminance (HSL) Value:", value=str(co.hsl))
embed.set_thumbnail(url="attachment://picture.png")
return embed, file
Expand All @@ -52,6 +53,9 @@ async def on_message(self, message):
return
if message.guild and not (await self.conf.guild(message.guild).enabled()):
return
ctx = await self.bot.get_context(message)
if ctx.valid:
return
words = message.content.split(" ")
counter = 0
for word in words:
Expand All @@ -60,6 +64,8 @@ async def on_message(self, message):
if word.startswith("#"):
word = word[1:]
m = self.r.match(word)
if not m:
continue
if m.group(1): # Hex
hexa = m.group(1)
try:
Expand Down Expand Up @@ -100,6 +106,7 @@ async def color(self, ctx):
"""Group command for color commands"""
pass

@checks.bot_has_permissions(embed_links=True)
@color.command()
async def name(self, ctx, name):
"""Provides the hexadecimal value, RGB value and HSL value of a passed color. For example, pass `red` or `blue` as the name argument."""
Expand All @@ -111,6 +118,7 @@ async def name(self, ctx, name):
except (ValueError, AttributeError):
await ctx.send("That color is not recognized.")

@checks.bot_has_permissions(embed_links=True)
@color.command()
async def hex(self, ctx, hexa: str):
"""Provides the RGB value and HSL value of a passed hexadecimal value. Hexadecimal value must in the format of something like `#ffffff` or `0xffffff` to be used."""
Expand All @@ -126,6 +134,7 @@ async def hex(self, ctx, hexa: str):
"Invalid formatting for the hexadecimal. Must be the hexadecimal value, with an optional `0x` or `#` in the beginning."
)

@checks.bot_has_permissions(embed_links=True)
@color.command()
async def rgb(self, ctx, highest: int, r: float, g: float, b: float):
"""Provides the hexadecimal value and HSL value of the rgb value given. Each value must have a space between them. Highest argument must be 1 or 255, indicating the highest value of a single value (r, g, or b)."""
Expand All @@ -142,6 +151,7 @@ async def rgb(self, ctx, highest: int, r: float, g: float, b: float):
except (ValueError, AttributeError):
await ctx.send("That rgb number is not recognized.")

@checks.bot_has_permissions(embed_links=True)
@color.command()
async def hsl(self, ctx, h: float, s: float, l: float):
"""Provides the hexadecimal value and the RGB value of the hsl value given. Each value must have a space between them."""
Expand All @@ -152,9 +162,16 @@ async def hsl(self, ctx, h: float, s: float, l: float):
except (ValueError, AttributeError):
await ctx.send("That hsl number is not recognized.")

@checks.admin()
@color.command()
async def msgshort(self, ctx, enable: bool):
"""Set whether or not the in-message shortcut can be used."""
"""Enable or disable the in-message shortcut.
In-message shortcuts can be used by using the hex, rgb or name after a `#` in the middle of a message, as follows:
`#000000` (hex)
`#1,1,1` (rgb)
`#black` (named)"""
await self.conf.guild(ctx.guild).enabled.set(enable)
if enable:
await ctx.send("The in-message shortcut is now enabled.")
Expand Down
4 changes: 2 additions & 2 deletions color/info.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"author" : ["Neuro Assassin"],
"install_msg" : "Thank you for downloading this cog.",
"install_msg" : "Thank you for downloading this cog. In-message shortcuts are enabled by guild by default. An administrator can change this rule by running `[p]color msgshort false`",
"name" : "color",
"short" : "Tells you the hexadecimal values, rgb values and names of colors",
"description" : "This cog will tell you the hexadecimal value, rgb value and the name of the color that is supplied to it.",
"tags" : ["tools"],
"requirements" : ["colour"],
"requirements" : ["colour", "pillow"],
"hidden" : false
}
3 changes: 2 additions & 1 deletion commandchart/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from .commandchart import CommandChart


def setup(bot):
bot.add_cog(CommandChart(bot))
bot.add_cog(CommandChart(bot))
16 changes: 11 additions & 5 deletions commandchart/commandchart.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from io import BytesIO
from datetime import datetime, timezone
import pytz
import typing

import matplotlib

Expand All @@ -17,14 +18,16 @@

plt.switch_backend("agg")

from redbot.core import commands
from redbot.core import commands, checks


class CommandChart(commands.Cog):
"""Shows the commands most used in a certain channel within the last so-and-so messages"""

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

__author__ = "Neuro Assassin#4227 <@473541068378341376>"
__author__ = "Neuro Assassin#4779 <@473541068378341376>"

async def command_from_message(self, m: discord.Message):
message_context = await self.bot.get_context(m)
Expand Down Expand Up @@ -96,16 +99,19 @@ def create_chart(self, top, others, channel):
image_object.seek(0)
return image_object

@checks.bot_has_permissions(embed_links=True)
@commands.guild_only()
@commands.command()
async def commandchart(self, ctx, channel: discord.TextChannel = None, number: int = 5000):
async def commandchart(
self, ctx, channel: typing.Optional[discord.TextChannel] = None, number: int = 5000
):
"""See the used commands in a certain channel within a certain amount of messages."""
e = discord.Embed(description="Loading...", color=0x000099)
e.set_thumbnail(url="https://cdn.discordapp.com/emojis/544517783224975387.gif?v=1")
em = await ctx.send(embed=e)

if channel is None:
channel = ctx.message.channel
if not channel:
channel = ctx.channel
if not channel.permissions_for(ctx.message.author).read_messages == True:
await em.delete()
return await ctx.send("You do not have the proper permissions to access that channel.")
Expand Down
3 changes: 2 additions & 1 deletion cooldown/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from .cooldown import Cooldown


def setup(bot):
bot.add_cog(Cooldown(bot))
bot.add_cog(Cooldown(bot))
30 changes: 0 additions & 30 deletions cooldown/converters.py

This file was deleted.

67 changes: 46 additions & 21 deletions cooldown/cooldown.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@
import time
import traceback


class Cooldown(commands.Cog):
"""Add or remove cooldowns from/to commands"""

def __init__(self, bot):
self.bot = bot
self.conf = Config.get_conf(self, identifier=473541068378341376)
Expand Down Expand Up @@ -32,15 +35,15 @@ async def initialize(self):
}
commands.cooldown(entry[1], entry[2], switch[entry[3]])(cmd)

@checks.is_owner()
@commands.group()
async def cooldown(self, ctx):
"""Group command for working with cooldowns for commands."""
pass

@checks.is_owner()
@cooldown.command(alises=["update", "change"])
@cooldown.command(alises=["update", "change", "edit"])
async def add(self, ctx, rate: int, per, btype, *, command):
"""Sets a cooldown for a command, allowing a certain amount of times in a certain amount of time for a certain type.
"""Sets a cooldown for a command, allowing a certain amount of times in a certain amount of time for a certain type. If a cooldown already exists for the specified command, then it will be overwritten and edited.
The command argument does not require quotes, as it consumes the rest in order to make cooldowns for subcommands easier.
Expand Down Expand Up @@ -76,6 +79,8 @@ async def add(self, ctx, rate: int, per, btype, *, command):
return await ctx.send(
"Invalid amount of time. There is a non-number in your `per` argument, not including the time type."
)
if rate < 1:
return await ctx.send("The rate argument must be at least 1 or higher.")
np = int(np)
if per.endswith("s"):
ttype = "seconds"
Expand All @@ -94,7 +99,7 @@ async def add(self, ctx, rate: int, per, btype, *, command):
if not btype in ["user", "channel", "guild", "global"]:
return await ctx.send("Invalid bucket type.")
cmd = self.bot.get_command(command)
if cmd == None:
if cmd == None or not str(cmd) == command:
return await ctx.send("Invalid command argument.")

def check(m):
Expand All @@ -104,10 +109,21 @@ def check(m):
and (m.content[0].lower() in ["y", "n"])
)

cooldowns = cmd._buckets._cooldown
if cooldowns:
all_data = await self.conf.data()
if not command in [item[0] for item in all_data]:
extra = "\nThis command also had an original cooldown. Cooldowns are typically on commands for certain reasons, and so editing it is not recommended. Proceed at your own risk."
else:
extra = "\nThis command already had a cooldown from this cog, so its current cooldown will be edited to the new one."
else:
extra = ""

await ctx.send(
(
"You are about to add a cooldown for a command using this cog. "
"Are you sure you wish to set this cooldown? Respond with 'y' or 'n' to this message."
f"{extra}"
)
)
try:
Expand All @@ -125,7 +141,6 @@ def check(m):
else:
return await ctx.send("Not establishing command cooldown.")
data = [command, rate, np, btype]
all_data = await self.conf.data()
changed = False
for position, entry in enumerate(all_data):
if entry[0] == data[0]:
Expand All @@ -138,28 +153,33 @@ def check(m):

await ctx.send("Your cooldown has been established")

@checks.is_owner()
@cooldown.command()
async def remove(self, ctx, *, command):
"""Removes the cooldown from a command, under a specific bucket.
"""Removes the cooldown from a command.
The cooldown can be one set from this cog or from inside the cog's code.
The command argument does not require quotes, as it consumes the rest in order to make cooldowns for subcommands easier.
Please do note however: some commands are meant to have cooldowns. They may prevent something malicious from happening, or maybe your device from breaking or from being used too much. I (Neuro Assassin <@473541068378341376>) take no responsibility for any complications that may result because of this. Use at your own risk.
Bucket Types:
- User
- Channel
- Guild
- Global
Note: Does not actually remove the command cooldown (undocumented), so instead it allows for the command to be run 100000 times every 1 second until the next boot up, where it will not be added."""
Note: Does not actually remove the command cooldown (undocumented), so instead it allows for the command to be run 100000 times every 1 second until the next boot up, where it will not be added (unless you are removing a cooldown from outside of this cog, then it will be kept after restart)."""
cmd = self.bot.get_command(command)
if cmd == None:
if cmd == None or not str(cmd) == command:
return await ctx.send("Invalid command argument.")

cooldowns = cmd._buckets._cooldown
if not cooldowns:
return await ctx.send("This command does not have any cooldown.")

data = await self.conf.data()
if not command in [item[0] for item in data]:
fromcog = False
extra = "\nThis command also had an original cooldown. Cooldowns are typically on commands for certain reasons, and so removing it is not recommended. Proceed at your own risk."
else:
fromcog = True
extra = ""

def check(m):
return (
(m.author.id == ctx.author.id)
Expand All @@ -171,6 +191,7 @@ def check(m):
(
"You are about to remove a cooldown for a command. "
"Are you sure you wish to remove it? Respond with 'y' or 'n' to this message."
f"{extra}"
)
)
try:
Expand All @@ -181,11 +202,15 @@ def check(m):
commands.cooldown(10000, 1, dc.BucketType.user)(cmd)
else:
return await ctx.send("Not removing command cooldown.")
data = await self.conf.data()
for entry in data:
if entry[0] == command:
data.remove(entry)
break
if fromcog:
for entry in data:
if entry[0] == command:
data.remove(entry)
break
else:
data.append([command, 10000, 1, "global"])
await self.conf.data.set(data)

await ctx.send("Your cooldown has been removed.")
await ctx.send(
"Your cooldown has been removed. If this cog originally had a cooldown, then you removed/edited it, and you just removed it, a bot restart is required for the original cooldown to be instated."
)
Loading

0 comments on commit c6b2987

Please sign in to comment.