Skip to content

Commit 72f8962

Browse files
committed
Fix some stuff
1 parent c0e3b54 commit 72f8962

File tree

5 files changed

+58
-34
lines changed

5 files changed

+58
-34
lines changed

CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ however, insignificant breaking changes does not guarantee a major version bump,
3131
- The look of alias and snippet when previewing.
3232
- Message ID of the thread embed is saved in DB, instead of the original message.
3333
- Swapped the position of user and category for `?contact`.
34+
- The log file will no longer grow infinitely large.
35+
- Hard limit of maximum 25 steps for alias.
3436

3537
### Fixed
3638

cogs/modmail.py

+18-17
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,7 @@
1717
from core.paginator import EmbedPaginatorSession
1818
from core.thread import Thread
1919
from core.time import UserFriendlyTime, human_timedelta
20-
from core.utils import (
21-
format_preview,
22-
User,
23-
create_not_found_embed,
24-
format_description,
25-
trigger_typing,
26-
escape_code_block,
27-
match_user_id,
28-
format_channel_name,
29-
)
20+
from core.utils import *
3021

3122
logger = getLogger(__name__)
3223

@@ -161,15 +152,18 @@ async def snippet(self, ctx, *, name: str.lower = None):
161152
if val is None:
162153
embed = create_not_found_embed(name, self.bot.snippets.keys(), "Snippet")
163154
else:
164-
embed = discord.Embed(color=self.bot.main_color)
165-
embed.add_field(name=f"`{name}` will send:", value=val)
155+
embed = discord.Embed(
156+
title=f'Snippet - "{name}":',
157+
description=val,
158+
color=self.bot.main_color
159+
)
166160
return await ctx.send(embed=embed)
167161

168162
if not self.bot.snippets:
169163
embed = discord.Embed(
170164
color=self.bot.error_color, description="You dont have any snippets at the moment."
171165
)
172-
embed.set_footer(text=f'Check "{self.bot.prefix}help snippet" to add a snippet.')
166+
embed.set_footer(text=f'Check "{self.bot.prefix}help snippet add" to add a snippet.')
173167
embed.set_author(name="Snippets", icon_url=ctx.guild.icon_url)
174168
return await ctx.send(embed=embed)
175169

@@ -194,9 +188,11 @@ async def snippet_raw(self, ctx, *, name: str.lower):
194188
if val is None:
195189
embed = create_not_found_embed(name, self.bot.snippets.keys(), "Snippet")
196190
else:
197-
embed = discord.Embed(color=self.bot.main_color)
198-
val = escape_code_block(val)
199-
embed.add_field(name=f"`{name}` will send:", value=f"```\n{val}```")
191+
val = truncate(escape_code_block(val), 2048 - 7)
192+
embed = discord.Embed(title=f'Raw snippet - "{name}":',
193+
description=f"```\n{val}```",
194+
color=self.bot.main_color)
195+
200196
return await ctx.send(embed=embed)
201197

202198
@snippet.command(name="add")
@@ -205,6 +201,11 @@ async def snippet_add(self, ctx, name: str.lower, *, value: commands.clean_conte
205201
"""
206202
Add a snippet.
207203
204+
Simply to add a snippet, do: ```
205+
{prefix}snippet add hey hello there :)
206+
```
207+
then when you type `{prefix}hey`, "hello there :)" will get sent to the recipient.
208+
208209
To add a multi-word snippet name, use quotes: ```
209210
{prefix}snippet add "two word" this is a two word snippet.
210211
```
@@ -1245,7 +1246,7 @@ async def repair(self, ctx):
12451246
)
12461247
)
12471248
if len(users) == 1:
1248-
user = users[0]
1249+
user = users.pop()
12491250
name = format_channel_name(
12501251
user, self.bot.modmail_guild, exclude_channel=ctx.channel
12511252
)

cogs/utility.py

+31-16
Original file line numberDiff line numberDiff line change
@@ -916,23 +916,30 @@ async def alias(self, ctx, *, name: str.lower = None):
916916
description=f"Alias `{name}` is invalid, this alias will now be deleted."
917917
"This alias will now be deleted.",
918918
)
919-
embed.add_field(name=f"{name}` used to be:", value=val)
919+
embed.add_field(name=f"{name}` used to be:", value=utils.truncate(val, 1024))
920920
self.bot.aliases.pop(name)
921921
await self.bot.config.update()
922922
return await ctx.send(embed=embed)
923923

924924
if len(values) == 1:
925-
embed = discord.Embed(color=self.bot.main_color)
926-
embed.add_field(name=f"`{name}` points to:", value=values[0])
927-
else:
928925
embed = discord.Embed(
929-
color=self.bot.main_color,
930-
description=f"**`{name}` points to the following steps:**",
926+
title=f'Alias - "{name}":',
927+
description=values[0],
928+
color=self.bot.main_color
931929
)
932-
for i, val in enumerate(values, start=1):
933-
embed.add_field(name=f"Step {i}:", value=val)
930+
return await ctx.send(embed=embed)
934931

935-
return await ctx.send(embed=embed)
932+
else:
933+
embeds = []
934+
for i, val in enumerate(values, start=1):
935+
embed = discord.Embed(
936+
color=self.bot.main_color,
937+
title=f'Alias - "{name}" - Step {i}:',
938+
description=val
939+
)
940+
embeds += [embed]
941+
session = EmbedPaginatorSession(ctx, *embeds)
942+
return await session.run()
936943

937944
if not self.bot.aliases:
938945
embed = discord.Embed(
@@ -964,15 +971,15 @@ async def alias_raw(self, ctx, *, name: str.lower):
964971
embed = utils.create_not_found_embed(name, self.bot.aliases.keys(), "Alias")
965972
return await ctx.send(embed=embed)
966973

967-
embed = discord.Embed(color=self.bot.main_color)
968-
val = utils.escape_code_block(val)
969-
embed.add_field(name=f"`{name}` points to:", value=f"```\n{val}```")
974+
val = utils.truncate(utils.escape_code_block(val), 2048-7)
975+
embed = discord.Embed(title=f'Raw alias - "{name}":',
976+
description=f"```\n{val}```",
977+
color=self.bot.main_color)
978+
970979
return await ctx.send(embed=embed)
971980

972981
async def make_alias(self, name, value, action):
973982
values = utils.parse_alias(value)
974-
save_aliases = []
975-
976983
if not values:
977984
embed = discord.Embed(
978985
title="Error",
@@ -982,12 +989,20 @@ async def make_alias(self, name, value, action):
982989
embed.set_footer(text=f'See "{self.bot.prefix}alias add" for more details.')
983990
return embed
984991

992+
if len(values) > 25:
993+
embed = discord.Embed(title="Error",
994+
description="Too many steps, max=25.",
995+
color=self.bot.error_color)
996+
return embed
997+
998+
save_aliases = []
999+
9851000
multiple_alias = len(values) > 1
9861001

9871002
embed = discord.Embed(title=f"{action} alias", color=self.bot.main_color)
9881003

9891004
if not multiple_alias:
990-
embed.add_field(name=f"`{name}` points to:", value=values[0])
1005+
embed.add_field(name=f"`{name}` points to:", value=utils.truncate(values[0], 1024))
9911006
else:
9921007
embed.description = f"`{name}` now points to the following steps:"
9931008

@@ -1018,7 +1033,7 @@ async def make_alias(self, name, value, action):
10181033
else:
10191034
save_aliases.append(val)
10201035
if multiple_alias:
1021-
embed.add_field(name=f"Step {i}:", value=val)
1036+
embed.add_field(name=f"Step {i}:", value=utils.truncate(val, 1024))
10221037

10231038
self.bot.aliases[name] = " && ".join(f'"{a}"' for a in save_aliases)
10241039
await self.bot.config.update()

core/models.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import re
33
import sys
44
from enum import IntEnum
5+
from logging.handlers import RotatingFileHandler
56
from string import Formatter
67

78
import discord
@@ -120,7 +121,7 @@ def format(self, record):
120121

121122
def configure_logging(name, level=None):
122123
global ch_debug, log_level
123-
ch_debug = logging.FileHandler(name, mode="a+")
124+
ch_debug = RotatingFileHandler(name, mode="a+", maxBytes=48000, backupCount=1)
124125

125126
formatter_debug = FileFormatter(
126127
"%(asctime)s %(name)s[%(lineno)d] - %(levelname)s: %(message)s",

core/utils.py

+5
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,11 @@
1111
import discord
1212
from discord.ext import commands
1313

14+
__all__ = ['strtobool', 'User', 'truncate', 'format_preview', 'is_image_url',
15+
'parse_image_url', 'human_join', 'days', 'cleanup_code', 'match_user_id',
16+
'create_not_found_embed', 'parse_alias', 'normalize_alias', 'format_description', 'trigger_typing',
17+
'escape_code_block', 'format_channel_name']
18+
1419

1520
def strtobool(val):
1621
if isinstance(val, bool):

0 commit comments

Comments
 (0)