Skip to content

Commit 30a6c7f

Browse files
committed
Added raw alias
1 parent 5a26c28 commit 30a6c7f

File tree

10 files changed

+52
-49
lines changed

10 files changed

+52
-49
lines changed

.pylintrc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ ignore-patterns=
1919

2020
# Use multiple processes to speed up Pylint. Specifying 0 will auto-detect the
2121
# number of processors available to use.
22-
jobs=1
22+
jobs=0
2323

2424
# Control the amount of potential inferred values when inferring a single
2525
# object. This can help the performance when dealing with large functions or

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ however, insignificant breaking changes does not guarantee a major version bump,
3939
- `?plugin registry page-number` plugin registry can specify a page number for quick access.
4040
- A reworked interface for `?snippet` and `?alias`.
4141
- Add an `?snippet raw <name>` command for viewing the raw content of a snippet (escaped markdown).
42+
- Add an `?alias raw <name>` command for viewing the raw content of a alias (escaped markdown).
4243
- The placeholder channel for the streaming status changed to https://www.twitch.tv/discordmodmail/.
4344
- Removed unclear `rm` alias for some `remove` commands.
4445
- Paginate `?config options`.

app.json

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,6 @@
1515
"description": "Comma separated user IDs of people that are allowed to use owner only commands. (eval and update).",
1616
"required": true
1717
},
18-
"GITHUB_ACCESS_TOKEN": {
19-
"description": "Your personal access token for GitHub, adding this gives you the ability to use the 'update' command, which will sync your fork with the main repo.",
20-
"required": false
21-
},
2218
"MONGO_URI": {
2319
"description": "Mongo DB connection URI for self-hosting your data.",
2420
"required": true

cogs/modmail.py

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import asyncio
22
import logging
33
from datetime import datetime
4-
from itertools import zip_longest, takewhile
4+
from itertools import zip_longest
55
from typing import Optional, Union
66
from types import SimpleNamespace as param
77

@@ -17,7 +17,7 @@
1717
from core.models import PermissionLevel
1818
from core.paginator import PaginatorSession
1919
from core.time import UserFriendlyTime, human_timedelta
20-
from core.utils import format_preview, User, create_not_found_embed
20+
from core.utils import format_preview, User, create_not_found_embed, format_description
2121

2222
logger = logging.getLogger("Modmail")
2323

@@ -149,12 +149,7 @@ async def snippet(self, ctx, *, name: str.lower = None):
149149
for i, names in enumerate(
150150
zip_longest(*(iter(sorted(self.bot.snippets)),) * 15)
151151
):
152-
description = "\n".join(
153-
": ".join((str(a + i * 15), b))
154-
for a, b in enumerate(
155-
takewhile(lambda x: x is not None, names), start=1
156-
)
157-
)
152+
description = format_description(i, names)
158153
embed = discord.Embed(color=self.bot.main_color, description=description)
159154
embed.set_author(name="Snippets", icon_url=ctx.guild.icon_url)
160155
embeds.append(embed)

cogs/plugins.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,7 @@ async def plugin_remove(self, ctx, *, plugin_name: str):
288288
for i in self.bot.config["plugins"]
289289
):
290290
# if there are no more of such repos, delete the folder
291-
def onerror(func, path, exc_info): # pylint: disable=W0613
291+
def onerror(func, path, _):
292292
if not os.access(path, os.W_OK):
293293
# Is the error an access error?
294294
os.chmod(path, stat.S_IWUSR)

cogs/utility.py

Lines changed: 25 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
get_perm_level,
3434
create_not_found_embed,
3535
parse_alias,
36+
format_description,
3637
)
3738

3839
logger = logging.getLogger("Modmail")
@@ -248,11 +249,10 @@ def __init__(self, bot):
248249
verify_checks=False, command_attrs={"help": "Shows this help message."}
249250
)
250251
# Looks a bit ugly
251-
# noinspection PyProtectedMember
252-
self.bot.help_command._command_impl = checks.has_permissions( # pylint: disable=W0212
252+
self.bot.help_command._command_impl = checks.has_permissions( # pylint: disable=protected-access
253253
PermissionLevel.REGULAR
254254
)(
255-
self.bot.help_command._command_impl # pylint: disable=W0212
255+
self.bot.help_command._command_impl # pylint: disable=protected-access
256256
)
257257

258258
self.bot.help_command.cog = self
@@ -998,19 +998,26 @@ async def alias(self, ctx, *, name: str.lower = None):
998998
embeds = []
999999

10001000
for i, names in enumerate(zip_longest(*(iter(sorted(self.bot.aliases)),) * 15)):
1001-
description = "\n".join(
1002-
": ".join((str(a + i * 15), b))
1003-
for a, b in enumerate(
1004-
takewhile(lambda x: x is not None, names), start=1
1005-
)
1006-
)
1001+
description = format_description(i, names)
10071002
embed = Embed(color=self.bot.main_color, description=description)
10081003
embed.set_author(name="Command Aliases", icon_url=ctx.guild.icon_url)
10091004
embeds.append(embed)
10101005

10111006
session = PaginatorSession(ctx, *embeds)
10121007
await session.run()
10131008

1009+
@alias.command(name="raw")
1010+
@checks.has_permissions(PermissionLevel.MODERATOR)
1011+
async def alias_raw(self, ctx, *, name: str.lower):
1012+
"""
1013+
View the raw content of an alias.
1014+
"""
1015+
val = self.bot.aliases.get(name)
1016+
if val is None:
1017+
embed = create_not_found_embed(name, self.bot.aliases.keys(), "Alias")
1018+
return await ctx.send(embed=embed)
1019+
return await ctx.send(escape_markdown(escape_mentions(val)).replace("<", "\\<"))
1020+
10141021
@alias.command(name="add")
10151022
@checks.has_permissions(PermissionLevel.MODERATOR)
10161023
async def alias_add(self, ctx, name: str.lower, *, value):
@@ -1027,36 +1034,36 @@ async def alias_add(self, ctx, name: str.lower, *, value):
10271034
- This will fail: `{prefix}alias add reply You'll need to type && to work`
10281035
- Correct method: `{prefix}alias add reply "You'll need to type && to work"`
10291036
"""
1037+
embed = None
10301038
if self.bot.get_command(name):
10311039
embed = Embed(
10321040
title="Error",
10331041
color=Color.red(),
10341042
description=f"A command with the same name already exists: `{name}`.",
10351043
)
1036-
return await ctx.send(embed=embed)
10371044

1038-
if name in self.bot.aliases:
1045+
elif name in self.bot.aliases:
10391046
embed = Embed(
10401047
title="Error",
10411048
color=Color.red(),
10421049
description=f"Another alias with the same name already exists: `{name}`.",
10431050
)
1044-
return await ctx.send(embed=embed)
10451051

1046-
if name in self.bot.snippets:
1052+
elif name in self.bot.snippets:
10471053
embed = Embed(
10481054
title="Error",
10491055
color=Color.red(),
10501056
description=f"A snippet with the same name already exists: `{name}`.",
10511057
)
1052-
return await ctx.send(embed=embed)
10531058

1054-
if len(name) > 120:
1059+
elif len(name) > 120:
10551060
embed = Embed(
10561061
title="Error",
10571062
color=Color.red(),
10581063
description=f"Alias names cannot be longer than 120 characters.",
10591064
)
1065+
1066+
if embed is not None:
10601067
return await ctx.send(embed=embed)
10611068

10621069
values = parse_alias(value)
@@ -1106,7 +1113,7 @@ async def alias_add(self, ctx, name: str.lower, *, value):
11061113
return await ctx.send(embed=embed)
11071114
embed.description += f"\n{i}: {val}"
11081115

1109-
self.bot.aliases[name] = "&&".join(values)
1116+
self.bot.aliases[name] = " && ".join(values)
11101117
await self.bot.config.update()
11111118

11121119
return await ctx.send(embed=embed)
@@ -1217,10 +1224,9 @@ async def permissions(self, ctx):
12171224
def _verify_user_or_role(user_or_role):
12181225
if hasattr(user_or_role, "id"):
12191226
return user_or_role.id
1220-
elif user_or_role in {"everyone", "all"}:
1227+
if user_or_role in {"everyone", "all"}:
12211228
return -1
1222-
else:
1223-
raise commands.BadArgument(f'User or Role "{user_or_role}" not found')
1229+
raise commands.BadArgument(f'User or Role "{user_or_role}" not found')
12241230

12251231
@staticmethod
12261232
def _parse_level(name):

core/checks.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ async def predicate(ctx):
3333

3434
if not has_perm and ctx.command.qualified_name != "help":
3535
logger.error(
36-
"You does not have permission to use this command: `%s` (%s).",
36+
"You do not have permission to use this command: `%s` (%s).",
3737
str(ctx.command.qualified_name),
3838
str(permission_level.name),
3939
)
@@ -43,7 +43,7 @@ async def predicate(ctx):
4343
return commands.check(predicate)
4444

4545

46-
async def check_permissions( # pylint: disable=R0911
46+
async def check_permissions( # pylint: disable=too-many-return-statements
4747
ctx, command_name, permission_level
4848
) -> bool:
4949
"""Logic for checking permissions for a command for a user"""

core/config.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import logging
44
import os
55
import typing
6-
from collections import namedtuple
76
from copy import deepcopy
87

98
from dotenv import load_dotenv
@@ -155,7 +154,6 @@ def populate_cache(self) -> dict:
155154
os.path.dirname(os.path.abspath(__file__)), "config_help.json"
156155
)
157156
with open(config_help_json, "r") as f:
158-
Entry = namedtuple("Entry", ["index", "embed"])
159157
self.config_help = dict(sorted(json.load(f).items()))
160158

161159
return self._cache

core/thread.py

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -338,9 +338,9 @@ async def _close(
338338
)
339339

340340
if isinstance(log_data, dict):
341-
prefix = self.bot.config['log_url_prefix'].strip('/')
342-
if prefix == 'NONE':
343-
prefix = ''
341+
prefix = self.bot.config["log_url_prefix"].strip("/")
342+
if prefix == "NONE":
343+
prefix = ""
344344
log_url = f"{self.bot.config['log_url'].strip('/')}{'/' + prefix if prefix else ''}/{log_data['key']}"
345345

346346
if log_data["messages"]:
@@ -410,7 +410,9 @@ async def _close(
410410
await asyncio.gather(*tasks)
411411

412412
async def cancel_closure(
413-
self, auto_close: bool = False, all: bool = False # pylint: disable=W0622
413+
self,
414+
auto_close: bool = False,
415+
all: bool = False, # pylint: disable=redefined-builtin
414416
) -> None:
415417
if self.close_task is not None and (not auto_close or all):
416418
self.close_task.cancel()
@@ -746,8 +748,7 @@ async def send(
746748
file_upload_count += 1
747749

748750
if from_mod:
749-
# noinspection PyUnresolvedReferences,PyDunderSlots
750-
embed.color = self.bot.mod_color # pylint: disable=E0237
751+
embed.colour = self.bot.mod_color
751752
# Anonymous reply sent in thread channel
752753
if anonymous and isinstance(destination, discord.TextChannel):
753754
embed.set_footer(text="Anonymous Reply")
@@ -760,12 +761,10 @@ async def send(
760761
else:
761762
embed.set_footer(text=self.bot.config["anon_tag"])
762763
elif note:
763-
# noinspection PyUnresolvedReferences,PyDunderSlots
764-
embed.color = discord.Color.blurple() # pylint: disable=E0237
764+
embed.colour = discord.Color.blurple()
765765
else:
766766
embed.set_footer(text=f"Recipient")
767-
# noinspection PyUnresolvedReferences,PyDunderSlots
768-
embed.color = self.bot.recipient_color # pylint: disable=E0237
767+
embed.colour = self.bot.recipient_color
769768

770769
try:
771770
await destination.trigger_typing()

core/utils.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
import shlex
33
import typing
44
from difflib import get_close_matches
5-
from distutils.util import strtobool as _stb # pylint: disable=E0401
5+
from distutils.util import strtobool as _stb
6+
from itertools import takewhile
67
from urllib import parse
78

89
import discord
@@ -37,7 +38,7 @@ async def convert(self, ctx, argument):
3738
return discord.Object(int(match.group(1)))
3839

3940

40-
def truncate(text: str, max: int = 50) -> str: # pylint: disable=W0622
41+
def truncate(text: str, max: int = 50) -> str: # pylint: disable=redefined-builtin
4142
"""
4243
Reduces the string to `max` length, by trimming the message into "...".
4344
@@ -253,3 +254,10 @@ def parse_alias(alias):
253254
if not all(cmd):
254255
return []
255256
return cmd
257+
258+
259+
def format_description(i, names):
260+
return "\n".join(
261+
": ".join((str(a + i * 15), b))
262+
for a, b in enumerate(takewhile(lambda x: x is not None, names), start=1)
263+
)

0 commit comments

Comments
 (0)