Skip to content

Commit bdb2bcf

Browse files
committed
Paginate config options and patched a thread open bug
1 parent 7f6992f commit bdb2bcf

File tree

6 files changed

+81
-55
lines changed

6 files changed

+81
-55
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ however, insignificant breaking changes does not guarantee a major version bump,
3737
- A reworked interface for `?snippet` and `?alias`.
3838
- Add an `?snippet raw <name>` command for viewing the raw content of a snippet (escaped markdown).
3939
- The placeholder channel for the streaming status changed to https://www.twitch.tv/discordmodmail/.
40+
- Removed unclear `rm` alias for some `remove` commands.
41+
- Paginate `?config options`.
4042

4143
### Fixes
4244

cogs/modmail.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,9 @@ async def snippet(self, ctx, *, name: str.lower = None):
146146

147147
embeds = []
148148

149-
for i, names in enumerate(zip_longest(*(iter(sorted(self.bot.snippets)),) * 15)):
149+
for i, names in enumerate(
150+
zip_longest(*(iter(sorted(self.bot.snippets)),) * 15)
151+
):
150152
description = "\n".join(
151153
": ".join((str(a + i * 15), b))
152154
for a, b in enumerate(

cogs/plugins.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ async def plugin_add(self, ctx, *, plugin_name: str):
260260
)
261261
await ctx.send(embed=embed)
262262

263-
@plugin.command(name="remove", aliases=["del", "delete", "rm"])
263+
@plugin.command(name="remove", aliases=["del", "delete"])
264264
@checks.has_permissions(PermissionLevel.OWNER)
265265
async def plugin_remove(self, ctx, *, plugin_name: str):
266266
"""Remove a plugin."""

cogs/utility.py

Lines changed: 65 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -63,21 +63,22 @@ async def format_cog_help(self, cog, *, no_cog=False):
6363

6464
embeds = []
6565
for format_ in formats:
66-
description = cog.description or "No description." \
67-
if not no_cog else "Miscellaneous commands without a category."
68-
embed = Embed(
69-
description=f'*{description}*',
70-
color=bot.main_color,
66+
description = (
67+
cog.description or "No description."
68+
if not no_cog
69+
else "Miscellaneous commands without a category."
7170
)
71+
embed = Embed(description=f"*{description}*", color=bot.main_color)
7272

7373
embed.add_field(name="Commands", value=format_ or "No commands.")
7474

7575
continued = " (Continued)" if embeds else ""
76-
name = cog.qualified_name + " - Help" if not no_cog else "Miscellaneous Commands"
77-
embed.set_author(
78-
name=name + continued,
79-
icon_url=bot.user.avatar_url,
76+
name = (
77+
cog.qualified_name + " - Help"
78+
if not no_cog
79+
else "Miscellaneous Commands"
8080
)
81+
embed.set_author(name=name + continued, icon_url=bot.user.avatar_url)
8182

8283
embed.set_footer(
8384
text=f'Type "{prefix}{self.command_attrs["name"]} command" '
@@ -184,8 +185,9 @@ async def send_error_message(self, error):
184185
command = self.context.kwargs.get("command")
185186
val = self.context.bot.snippets.get(command)
186187
if val is not None:
187-
return await self.get_destination().send(escape_mentions(f'**`{command}` is a snippet, '
188-
f'content:**\n\n{val}'))
188+
return await self.get_destination().send(
189+
escape_mentions(f"**`{command}` is a snippet, " f"content:**\n\n{val}")
190+
)
189191

190192
val = self.context.bot.aliases.get(command)
191193
if val is not None:
@@ -205,16 +207,16 @@ async def send_error_message(self, error):
205207
)
206208
for i, val in enumerate(values, start=1):
207209
embed.description += f"\n{i}: {escape_markdown(val)}"
208-
embed.set_footer(text=f'Type "{self.clean_prefix}{self.command_attrs["name"]} alias" for more '
209-
'details on aliases.')
210+
embed.set_footer(
211+
text=f'Type "{self.clean_prefix}{self.command_attrs["name"]} alias" for more '
212+
"details on aliases."
213+
)
210214
return await self.get_destination().send(embed=embed)
211215

212216
logger.warning("CommandNotFound: %s", str(error))
213217

214218
embed = Embed(color=Color.red())
215-
embed.set_footer(
216-
text=f'Command/Category "{command}" not found.'
217-
)
219+
embed.set_footer(text=f'Command/Category "{command}" not found.')
218220

219221
choices = set()
220222

@@ -748,10 +750,20 @@ async def config(self, ctx):
748750
@checks.has_permissions(PermissionLevel.OWNER)
749751
async def config_options(self, ctx):
750752
"""Return a list of valid configuration names you can change."""
751-
allowed = self.bot.config.public_keys
752-
valid = ", ".join(f"`{k}`" for k in allowed)
753-
embed = Embed(title="Valid Keys", description=valid, color=self.bot.main_color)
754-
return await ctx.send(embed=embed)
753+
embeds = []
754+
for names in zip_longest(*(iter(sorted(self.bot.config.public_keys)),) * 15):
755+
description = "\n".join(
756+
f"`{name}`" for name in takewhile(lambda x: x is not None, names)
757+
)
758+
embed = Embed(
759+
title="Available configuration keys:",
760+
color=self.bot.main_color,
761+
description=description,
762+
)
763+
embeds.append(embed)
764+
765+
session = PaginatorSession(ctx, *embeds)
766+
await session.run()
755767

756768
@config.command(name="set", aliases=["add"])
757769
@checks.has_permissions(PermissionLevel.OWNER)
@@ -784,7 +796,7 @@ async def config_set(self, ctx, key: str.lower, *, value: str):
784796

785797
return await ctx.send(embed=embed)
786798

787-
@config.command(name="remove", aliases=["del", "delete", "rm"])
799+
@config.command(name="remove", aliases=["del", "delete"])
788800
@checks.has_permissions(PermissionLevel.OWNER)
789801
async def config_remove(self, ctx, key: str.lower):
790802
"""Delete a set configuration variable."""
@@ -867,9 +879,8 @@ async def config_help(self, ctx, key: str.lower):
867879
return await ctx.send(embed=embed)
868880

869881
config_help = self.bot.config.config_help
870-
info = config_help.get(key)
871882

872-
if info is None:
883+
if key not in config_help:
873884
embed = Embed(
874885
title="Error",
875886
color=Color.red(),
@@ -880,30 +891,40 @@ async def config_help(self, ctx, key: str.lower):
880891
def fmt(val):
881892
return val.format(prefix=self.bot.prefix, bot=self.bot)
882893

883-
embed = Embed(
884-
title=f"Configuration description on {key}:",
885-
color=self.bot.main_color
886-
)
887-
embed.add_field(name='Default:', value=fmt(info['default']), inline=False)
888-
embed.add_field(name='Information:', value=fmt(info['description']), inline=False)
889-
example_text = ''
890-
for example in info['examples']:
891-
example_text += f'- {fmt(example)}\n'
892-
embed.add_field(name='Example(s):', value=example_text, inline=False)
894+
index = 0
895+
embeds = []
896+
for i, (current_key, info) in enumerate(config_help.items()):
897+
if current_key == key:
898+
index = i
899+
embed = Embed(
900+
title=f"Configuration description on {current_key}:",
901+
color=self.bot.main_color,
902+
)
903+
embed.add_field(name="Default:", value=fmt(info["default"]), inline=False)
904+
embed.add_field(
905+
name="Information:", value=fmt(info["description"]), inline=False
906+
)
907+
example_text = ""
908+
for example in info["examples"]:
909+
example_text += f"- {fmt(example)}\n"
910+
embed.add_field(name="Example(s):", value=example_text, inline=False)
893911

894-
note_text = ''
895-
for note in info['notes']:
896-
note_text += f'- {fmt(note)}\n'
897-
if note_text:
898-
embed.add_field(name='Note(s):', value=note_text, inline=False)
912+
note_text = ""
913+
for note in info["notes"]:
914+
note_text += f"- {fmt(note)}\n"
915+
if note_text:
916+
embed.add_field(name="Note(s):", value=note_text, inline=False)
899917

900-
if info.get('image') is not None:
901-
embed.set_image(url=fmt(info['image']))
918+
if info.get("image") is not None:
919+
embed.set_image(url=fmt(info["image"]))
902920

903-
if info.get('thumbnail') is not None:
904-
embed.set_thumbnail(url=fmt(info['thumbnail']))
921+
if info.get("thumbnail") is not None:
922+
embed.set_thumbnail(url=fmt(info["thumbnail"]))
923+
embeds += [embed]
905924

906-
return await ctx.send(embed=embed)
925+
paginator = PaginatorSession(ctx, *embeds)
926+
paginator.current = index
927+
await paginator.run()
907928

908929
@commands.group(aliases=["aliases"], invoke_without_command=True)
909930
@checks.has_permissions(PermissionLevel.MODERATOR)
@@ -1265,9 +1286,7 @@ async def permissions_add_level(
12651286
return await ctx.send(embed=embed)
12661287

12671288
@permissions.group(
1268-
name="remove",
1269-
aliases=["del", "delete", "rm", "revoke"],
1270-
invoke_without_command=True,
1289+
name="remove", aliases=["del", "delete", "revoke"], invoke_without_command=True
12711290
)
12721291
@checks.has_permissions(PermissionLevel.OWNER)
12731292
async def permissions_remove(self, ctx):

core/config.py

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

89
from dotenv import load_dotenv
@@ -129,12 +130,12 @@ def populate_cache(self) -> dict:
129130
data.update(
130131
{k.lower(): v for k, v in os.environ.items() if k.lower() in self.all_keys}
131132
)
132-
configjson = os.path.join(
133+
config_json = os.path.join(
133134
os.path.dirname(os.path.dirname(os.path.abspath(__file__))), "config.json"
134135
)
135-
if os.path.exists(configjson):
136+
if os.path.exists(config_json):
136137
logger.debug("Loading envs from config.json.")
137-
with open(configjson, "r") as f:
138+
with open(config_json, "r") as f:
138139
# Config json should override env vars
139140
try:
140141
data.update(
@@ -150,11 +151,13 @@ def populate_cache(self) -> dict:
150151
)
151152
self._cache = data
152153

153-
confighelpjson = os.path.join(
154+
config_help_json = os.path.join(
154155
os.path.dirname(os.path.abspath(__file__)), "config_help.json"
155156
)
156-
with open(confighelpjson, "r") as f:
157-
self.config_help = json.load(f)
157+
with open(config_help_json, "r") as f:
158+
Entry = namedtuple("Entry", ["index", "embed"])
159+
self.config_help = dict(sorted(json.load(f).items()))
160+
158161
return self._cache
159162

160163
async def clean_data(self, key: str, val: typing.Any) -> typing.Tuple[str, str]:

core/thread.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ def _format_info_embed(self, user, log_url, log_count, color):
229229
embed.set_author(name=str(user), icon_url=user.avatar_url, url=log_url)
230230
# embed.set_thumbnail(url=avi)
231231

232-
if member is None:
232+
if member is not None:
233233
joined = str((time - member.joined_at).days)
234234
# embed.add_field(name='Joined', value=joined + days(joined))
235235
embed.description += f", joined {days(joined)}"

0 commit comments

Comments
 (0)