aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--bot/__main__.py1
-rw-r--r--bot/cogs/alias.py8
-rw-r--r--bot/cogs/rules.py139
3 files changed, 54 insertions, 94 deletions
diff --git a/bot/__main__.py b/bot/__main__.py
index c9d6fd61e..568285cc3 100644
--- a/bot/__main__.py
+++ b/bot/__main__.py
@@ -51,6 +51,7 @@ bot.load_extension("bot.cogs.bot")
bot.load_extension("bot.cogs.clean")
bot.load_extension("bot.cogs.cogs")
bot.load_extension("bot.cogs.help")
+bot.load_extension("bot.cogs.rules")
# Only load this in production
if not DEBUG_MODE:
diff --git a/bot/cogs/alias.py b/bot/cogs/alias.py
index 0e6b3a7c6..a726e374f 100644
--- a/bot/cogs/alias.py
+++ b/bot/cogs/alias.py
@@ -105,14 +105,6 @@ class Alias:
await self.invoke(ctx, "site faq")
- @command(name="rules", hidden=True)
- async def site_rules_alias(self, ctx):
- """
- Alias for invoking <prefix>site rules.
- """
-
- await self.invoke(ctx, "site rules")
-
@command(name="reload", hidden=True)
async def cogs_reload_alias(self, ctx, *, cog_name: str):
"""
diff --git a/bot/cogs/rules.py b/bot/cogs/rules.py
index fe920199a..7582e8c80 100644
--- a/bot/cogs/rules.py
+++ b/bot/cogs/rules.py
@@ -1,99 +1,73 @@
import re
from typing import Optional
-from discord import Colour, Embed
-from discord.ext.commands import Bot, Context, command
-
from bot.constants import Channels, Roles
from bot.decorators import redirect_output
from bot.pagination import LinePaginator
-STAFF = [
- Roles.admin,
- Roles.moderator,
- Roles.owner,
-]
+from discord import Colour, Embed
+from discord.ext.commands import Bot, Context, command
+
+
+STAFF = Roles.admin, Roles.moderator, Roles.owner
class Rules:
def __init__(self, bot: Bot):
self.bot = bot
+
# We'll get the rules from the API when the
- # site has been updated to the Django Framwork.
+ # site has been updated to the Django Framework.
# Hard-code the rules for now until the new RulesView is released.
- self.rules = [
+
+ self.rules = (
"Be polite, and do not spam.",
- "Follow the [Discord Community Guidelines]",
- "(https://discordapp.com/guidelines).",
- (
- "Don't intentionally make other people uncomfortable - if "
- "someone asks you to stop discussing something,"
- " you should stop."
- ),
- (
- "Be patient both with users asking "
- "questions, and the users answering them."
- ),
- (
- "We will not help you with anything that might break "
- "a law or the terms of service of any other community, site, "
- "service, or otherwise - No piracy, brute-forcing, captcha "
- "circumvention, sneaker bots, or anything else of that nature."
- ),
- (
- "Listen to and respect the staff members - we're "
- "here to help, but we're all human beings."
- ),
- (
- "All discussion should be kept within the relevant "
- "channels for the subject - See the "
- f"[channels page](https://pythondiscord.com/about/channels) "
- "for more information."
- ),
- (
- "This is an English-speaking server, so please speak English "
- f"to the best of your ability - [Google Translate]"
- "(https://translate.google.com/) should be fine if "
- "you're not sure."
- ),
- (
- "Keep all discussions safe for work - No gore, nudity, sexual "
- "soliciting, references to suicide, or anything else of "
- "that nature"
- ),
- (
- "We do not allow advertisements for communities (including "
- "other Discord servers) or commercial projects - Contact "
- "us directly if you want to discuss a partnership!"
- )
- ]
+
+ "Follow the [Discord Community Guidelines](https://discordapp.com/guidelines).",
+
+ "Don't intentionally make other people uncomfortable - if someone asks you to stop "
+ "discussing something, you should stop.",
+
+ "Be patient both with users asking questions, and the users answering them.",
+
+ "We will not help you with anything that might break a law or the terms of service "
+ "of any other community, site, service, or otherwise - No piracy, brute-forcing, "
+ "captcha circumvention, sneaker bots, or anything else of that nature.",
+
+ "Listen to and respect the staff members - we're here to help, but we're all human "
+ "beings.",
+
+ "All discussion should be kept within the relevant channels for the subject - See the "
+ "[channels page](https://pythondiscord.com/about/channels) for more information.",
+
+ "This is an English-speaking server, so please speak English to the best of your "
+ "ability - [Google Translate](https://translate.google.com/) should be fine if you're "
+ "not sure.",
+
+ "Keep all discussions safe for work - No gore, nudity, sexual soliciting, references "
+ "to suicide, or anything else of that nature",
+
+ "We do not allow advertisements for communities (including other Discord servers) or "
+ "commercial projects - Contact us directly if you want to discuss a partnership!"
+ )
self.default_desc = "The rules and guidelines that apply to this " \
"community can be found on our [rules page]" \
"(https://pythondiscord.com/about/rules). We " \
"expect all members of the community to have " \
"read and understood these."
- @command(
- aliases=['r', 'rule'],
- name='rules',
- )
- @redirect_output(
- destination_channel=Channels.bot,
- bypass_roles=STAFF)
- async def rules_command(
- self, ctx: Context, *, rules: Optional[str] = None):
+ @command(aliases=['r', 'rule'], name='rules')
+ @redirect_output(destination_channel=Channels.bot, bypass_roles=STAFF)
+ async def rules_command(self, ctx: Context, *, rules: Optional[str] = None):
"""
Provides a link to the `rules` endpoint of the website, or displays
specific rules, if they are requested.
- :param ctx: The Discord message context
- :param rules: The rules a user wants to get.
- :return:
+
+ **`ctx`:** The Discord message context
+ **`rules`:** The rules a user wants to get.
"""
- rules_embed = Embed(
- title='Rules',
- color=Colour.blurple()
- )
+ rules_embed = Embed(title='Rules', color=Colour.blurple())
rules_embed.set_footer(text='https://pythondiscord.com/about/rules')
if not rules:
@@ -101,11 +75,8 @@ class Rules:
rules_embed.description = self.default_desc
return await ctx.send(embed=rules_embed)
- # Regex magic time.
- # This code block will do the following:
- # Split the rules string across the provided characters ('/', ',', ' ')
- # Returns a list of numbers based on if the numbers correspond to item
- # indices in the rules list
+ # Split the rules input by slash, comma or space
+ # Returns a list of ints if they're in range of rules index
rules_to_get = []
split_rules = re.split(r'[/, ]', rules)
for item in split_rules:
@@ -115,23 +86,19 @@ class Rules:
rule_match = re.search(r'\d?\d[:|-]1?\d', item)
if rule_match:
a, b = sorted(
- [int(x)-1 for x in re.split(r'[:-]',
- rule_match.group())])
- rules_to_get.extend(range(a, b+1)
- )
+ [int(x)-1 for x in re.split(r'[:-]', rule_match.group())])
+ rules_to_get.extend(range(a, b+1))
else:
rules_to_get.append(int(item)-1)
- final_rules = [f'Rule {i+1}: {self.rules[i]}'
- for i in sorted(rules_to_get) if i < len(self.rules)]
+ final_rules = [
+ f'**{i+1}.** {self.rules[i]}' for i in sorted(rules_to_get) if i < len(self.rules)
+ ]
if not final_rules:
- # Param rules was processed, but no rules were matched.
- # Return the default description.
+ # No valid rules in rules input. Return the default description.
rules_embed.description = self.default_desc
return await ctx.send(embed=rules_embed)
- await LinePaginator.paginate(
- final_rules, ctx, rules_embed, max_lines=3
- )
+ await LinePaginator.paginate(final_rules, ctx, rules_embed, max_lines=3)
def setup(bot):