aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Leon Sandøy <[email protected]>2018-07-22 12:15:09 +0200
committerGravatar Leon Sandøy <[email protected]>2018-07-22 12:15:09 +0200
commitd321962d0d966bd9b77c05a89fcc2862a6e98a01 (patch)
tree005b7998550323323fbba528cb978b9657f33aa7
parentCompleted clean cog (diff)
Moving constants into the yaml, fixing feedback from gdudes review.
-rw-r--r--bot/cogs/clean.py35
-rw-r--r--bot/cogs/modlog.py29
-rw-r--r--bot/constants.py13
-rw-r--r--config-default.yml15
4 files changed, 50 insertions, 42 deletions
diff --git a/bot/cogs/clean.py b/bot/cogs/clean.py
index 7675206a7..fe9b14003 100644
--- a/bot/cogs/clean.py
+++ b/bot/cogs/clean.py
@@ -6,15 +6,13 @@ from discord.ext.commands import Bot, Context, group
from bot.cogs.modlog import ModLog
from bot.constants import (
- Channels, CleanMessages, Icons,
+ Channels, CleanMessages, Colours, Icons,
Keys, NEGATIVE_REPLIES, Roles, URLs
)
from bot.decorators import with_role
log = logging.getLogger(__name__)
-COLOUR_RED = Colour(0xcd6d6d)
-
class Clean:
@@ -67,7 +65,7 @@ class Clean:
# Is this an acceptable amount of messages to clean?
if amount > CleanMessages.message_limit:
embed = Embed(
- color=Colour.red(),
+ color=Colour(Colours.soft_red),
title=random.choice(NEGATIVE_REPLIES),
description=f"You cannot clean more than {CleanMessages.message_limit} messages."
)
@@ -77,7 +75,7 @@ class Clean:
# Are we already performing a clean?
if self.cleaning:
embed = Embed(
- color=Colour.red(),
+ color=Colour(Colours.soft_red),
title=random.choice(NEGATIVE_REPLIES),
description="Multiple simultaneous cleaning processes is not allowed."
)
@@ -119,20 +117,17 @@ class Clean:
self.mod_log.ignore_message_deletion(*message_ids)
# Use bulk delete to actually do the cleaning. It's far faster.
+ predicate = None
+
if bots_only:
- await ctx.channel.purge(
- limit=amount,
- check=predicate_bots_only,
- )
+ predicate = predicate_bots_only
elif user:
- await ctx.channel.purge(
- limit=amount,
- check=predicate_specific_user,
- )
- else:
- await ctx.channel.purge(
- limit=amount
- )
+ predicate = predicate_specific_user
+
+ await ctx.channel.purge(
+ limit=amount,
+ check=predicate
+ )
# Reverse the list to restore chronological order
if message_log:
@@ -141,7 +136,7 @@ class Clean:
else:
# Can't build an embed, nothing to clean!
embed = Embed(
- color=Colour.red(),
+ color=Colour(Colours.soft_red),
description="No matching messages could be found."
)
await ctx.send(embed=embed)
@@ -154,7 +149,7 @@ class Clean:
)
embed = Embed(
- color=COLOUR_RED,
+ color=Colour(Colours.soft_red),
description=message
)
@@ -188,7 +183,7 @@ class Clean:
@with_role(Roles.moderator, Roles.admin, Roles.owner)
async def clean_all(self, ctx: Context, amount: int = 10):
"""
- Delete all messages, regardless of posted,
+ Delete all messages, regardless of poster,
and stop cleaning after traversing `amount` messages.
"""
diff --git a/bot/cogs/modlog.py b/bot/cogs/modlog.py
index 2f13fe32b..dfeca473d 100644
--- a/bot/cogs/modlog.py
+++ b/bot/cogs/modlog.py
@@ -13,15 +13,12 @@ from discord import (
from discord.abc import GuildChannel
from discord.ext.commands import Bot
-from bot.constants import Channels, Emojis, Icons
+from bot.constants import Channels, Colours, Emojis, Icons
from bot.constants import Guild as GuildConstant
log = logging.getLogger(__name__)
-BULLET_POINT = "\u2022"
-COLOUR_RED = Colour(0xcd6d6d)
-COLOUR_GREEN = Colour(0x68c290)
GUILD_CHANNEL = Union[CategoryChannel, TextChannel, VoiceChannel]
CHANNEL_CHANGES_UNSUPPORTED = ("permissions",)
@@ -85,7 +82,7 @@ class ModLog:
else:
message = f"{channel.name} (`{channel.id}`)"
- await self.send_log_message(Icons.hash_green, COLOUR_GREEN, title, message)
+ await self.send_log_message(Icons.hash_green, Colour(Colours.soft_green), title, message)
async def on_guild_channel_delete(self, channel: GUILD_CHANNEL):
if channel.guild.id != GuildConstant.id:
@@ -104,7 +101,7 @@ class ModLog:
message = f"{channel.name} (`{channel.id}`)"
await self.send_log_message(
- Icons.hash_red, COLOUR_RED,
+ Icons.hash_red, Colour(Colours.soft_red),
title, message
)
@@ -150,7 +147,7 @@ class ModLog:
message = ""
for item in sorted(changes):
- message += f"{BULLET_POINT} {item}\n"
+ message += f"{Emojis.bullet} {item}\n"
if after.category:
message = f"**{after.category}/#{after.name} (`{after.id}`)**\n{message}"
@@ -167,7 +164,7 @@ class ModLog:
return
await self.send_log_message(
- Icons.crown_green, COLOUR_GREEN,
+ Icons.crown_green, Colour(Colours.soft_green),
"Role created", f"`{role.id}`"
)
@@ -176,7 +173,7 @@ class ModLog:
return
await self.send_log_message(
- Icons.crown_red, COLOUR_RED,
+ Icons.crown_red, Colour(Colours.soft_red),
"Role removed", f"{role.name} (`{role.id}`)"
)
@@ -222,7 +219,7 @@ class ModLog:
message = ""
for item in sorted(changes):
- message += f"{BULLET_POINT} {item}\n"
+ message += f"{Emojis.bullet} {item}\n"
message = f"**{after.name} (`{after.id}`)**\n{message}"
@@ -270,7 +267,7 @@ class ModLog:
message = ""
for item in sorted(changes):
- message += f"{BULLET_POINT} {item}\n"
+ message += f"{Emojis.bullet} {item}\n"
message = f"**{after.name} (`{after.id}`)**\n{message}"
@@ -285,7 +282,7 @@ class ModLog:
return
await self.send_log_message(
- Icons.user_ban, COLOUR_RED,
+ Icons.user_ban, Colour(Colours.soft_red),
"User banned", f"{member.name}#{member.discriminator} (`{member.id}`)",
thumbnail=member.avatar_url_as(static_format="png")
)
@@ -325,7 +322,7 @@ class ModLog:
message = f"{Emojis.new} {message}"
await self.send_log_message(
- Icons.sign_in, COLOUR_GREEN,
+ Icons.sign_in, Colour(Colours.soft_green),
"User joined", message,
thumbnail=member.avatar_url_as(static_format="png")
)
@@ -335,7 +332,7 @@ class ModLog:
return
await self.send_log_message(
- Icons.sign_out, COLOUR_RED,
+ Icons.sign_out, Colour(Colours.soft_red),
"User left", f"{member.name}#{member.discriminator} (`{member.id}`)",
thumbnail=member.avatar_url_as(static_format="png")
)
@@ -404,7 +401,7 @@ class ModLog:
message = ""
for item in sorted(changes):
- message += f"{BULLET_POINT} {item}\n"
+ message += f"{Emojis.bullet} {item}\n"
message = f"**{after.name}#{after.discriminator} (`{after.id}`)**\n{message}"
@@ -482,7 +479,7 @@ class ModLog:
)
await self.send_log_message(
- Icons.message_delete, COLOUR_RED,
+ Icons.message_delete, Colour(Colours.soft_red),
"Message deleted",
response,
channel_id=Channels.message_log
diff --git a/bot/constants.py b/bot/constants.py
index b49cb48f6..532a2af1d 100644
--- a/bot/constants.py
+++ b/bot/constants.py
@@ -198,20 +198,29 @@ class Cooldowns(metaclass=YAMLGetter):
tags: int
+class Colours(metaclass=YAMLGetter):
+ section = "style"
+ subsection = "colours"
+
+ soft_red: int
+ soft_green: int
+
+
class Emojis(metaclass=YAMLGetter):
- section = "bot"
+ section = "style"
subsection = "emojis"
green_chevron: str
red_chevron: str
white_chevron: str
+ bullet: str
new: str
pencil: str
class Icons(metaclass=YAMLGetter):
- section = "bot"
+ section = "style"
subsection = "icons"
crown_blurple: str
diff --git a/config-default.yml b/config-default.yml
index 118ba165d..d55a50d57 100644
--- a/config-default.yml
+++ b/config-default.yml
@@ -6,12 +6,23 @@ bot:
# Per channel, per tag.
tags: 60
+ clean:
+ # Maximum number of messages to traverse for clean commands
+ message_limit: 10000
+
+
+style:
+ colours:
+ soft_red: 0xcd6d6d
+ soft_green: 0x68c290
+
emojis:
green_chevron: "<:greenchevron:418104310329769993>"
red_chevron: "<:redchevron:418112778184818698>"
white_chevron: "<:whitechevron:418110396973711363>"
lemoneye2: "<:lemoneye2:435193765582340098>"
+ bullet: "\u2022"
pencil: "\u270F"
new: "\U0001F195"
@@ -37,10 +48,6 @@ bot:
user_unban: "https://cdn.discordapp.com/emojis/469952898692808704.png"
user_update: "https://cdn.discordapp.com/emojis/469952898684551168.png"
- clean:
- # Maximum number of messages to traverse for clean commands
- message_limit: 10000
-
guild:
id: 267624335836053506