Skip to content

Commit

Permalink
v3.3.2-dev4 freply, fixed alias bugs, alias and snippet looks
Browse files Browse the repository at this point in the history
  • Loading branch information
Taaku18 committed Nov 30, 2019
1 parent faeaf49 commit e9e8992
Show file tree
Hide file tree
Showing 7 changed files with 172 additions and 166 deletions.
8 changes: 7 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ This project mostly adheres to [Semantic Versioning](https://semver.org/spec/v2.
however, insignificant breaking changes does not guarantee a major version bump, see the reasoning [here](https://github.com/kyb3r/modmail/issues/319).


# v3.3.2-dev3
# v3.3.2-dev4

### Added

Expand All @@ -20,10 +20,16 @@ however, insignificant breaking changes does not guarantee a major version bump,
- "enable" and "disable" support for yes or no config vars.
- Added "perhaps you meant" section to `?config help`.
- Multi-command alias is now more stable. With support for a single quote escape `\"`.
- New command `?freply`, which behaves exactly like `?reply` with the addition that you can substitute `{channel}`, `{recipient}`, and `{author}` to be their respective values.

### Changed

- The look of alias and snippet when previewing.

### Fixed

- Setting config vars using human time wasn't working.
- Fixed some bugs with aliases.

### Internal

Expand Down
27 changes: 13 additions & 14 deletions bot.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
__version__ = "3.3.2-dev3"
__version__ = "3.3.2-dev4"


import asyncio
Expand Down Expand Up @@ -612,7 +612,7 @@ def check_manual_blocked(self, author: discord.Member) -> bool:
return False

async def _process_blocked(self, message):
sent_emoji, blocked_emoji = await self.retrieve_emoji()
_, blocked_emoji = await self.retrieve_emoji()
if await self.is_blocked(message.author, channel=message.channel, send_message=True):
await self.add_reaction(message, blocked_emoji)
return True
Expand Down Expand Up @@ -770,7 +770,7 @@ async def get_contexts(self, message, *, cls=commands.Context):

view = StringView(message.content)
ctx = cls(prefix=self.prefix, view=view, bot=self, message=message)
ctx.thread = await self.threads.find(channel=ctx.channel)
thread = await self.threads.find(channel=ctx.channel)

if self._skip_check(message.author.id, self.user.id):
return [ctx]
Expand All @@ -791,16 +791,18 @@ async def get_contexts(self, message, *, cls=commands.Context):
if not aliases:
logger.warning("Alias %s is invalid, removing.", invoker)
self.aliases.pop(invoker)

for alias in aliases:
view = StringView(alias)
ctx = cls(prefix=self.prefix, view=view, bot=self, message=message)
ctx.thread = await self.threads.find(channel=ctx.channel)
ctx.view = view
ctx.invoked_with = view.get_word()
ctx.command = self.all_commands.get(ctx.invoked_with)
ctxs += [ctx]
view = StringView(invoked_prefix + alias)
ctx_ = cls(prefix=self.prefix, view=view, bot=self, message=message)
ctx_.thread = thread
discord.utils.find(view.skip_string, prefixes)
ctx_.invoked_with = view.get_word().lower()
ctx_.command = self.all_commands.get(ctx_.invoked_with)
ctxs += [ctx_]
return ctxs

ctx.thread = thread
ctx.invoked_with = invoker
ctx.command = self.all_commands.get(invoker)
return [ctx]
Expand Down Expand Up @@ -872,11 +874,8 @@ async def process_commands(self, message):

# Process snippets
if cmd in self.snippets:
thread = await self.threads.find(channel=message.channel)
snippet = self.snippets[cmd]
if thread:
snippet = self.formatter.format(snippet, recipient=thread.recipient)
message.content = f"{self.prefix}reply {snippet}"
message.content = f"{self.prefix}freply {snippet}"

ctxs = await self.get_contexts(message)
for ctx in ctxs:
Expand Down
45 changes: 36 additions & 9 deletions cogs/modmail.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import discord
from discord.ext import commands
from discord.utils import escape_markdown, escape_mentions
from discord.utils import escape_markdown

from dateutil import parser
from natural.date import duration
Expand All @@ -21,6 +21,7 @@
create_not_found_embed,
format_description,
trigger_typing,
escape_code_block,
)

logger = getLogger(__name__)
Expand Down Expand Up @@ -155,8 +156,10 @@ async def snippet(self, ctx, *, name: str.lower = None):
val = self.bot.snippets.get(name)
if val is None:
embed = create_not_found_embed(name, self.bot.snippets.keys(), "Snippet")
return await ctx.send(embed=embed)
return await ctx.send(escape_mentions(val))
else:
embed = discord.Embed(color=self.bot.main_color)
embed.add_field(name=f"`{name}` will send:", value=val)
return await ctx.send(embed=embed)

if not self.bot.snippets:
embed = discord.Embed(
Expand Down Expand Up @@ -186,8 +189,11 @@ async def snippet_raw(self, ctx, *, name: str.lower):
val = self.bot.snippets.get(name)
if val is None:
embed = create_not_found_embed(name, self.bot.snippets.keys(), "Snippet")
return await ctx.send(embed=embed)
return await ctx.send(escape_markdown(escape_mentions(val)).replace("<", "\\<"))
else:
embed = discord.Embed(color=self.bot.main_color)
val = escape_code_block(val)
embed.add_field(name=f"`{name}` will send:", value=f"```\n{val}```")
return await ctx.send(embed=embed)

@snippet.command(name="add")
@checks.has_permissions(PermissionLevel.SUPPORTER)
Expand Down Expand Up @@ -782,10 +788,32 @@ async def reply(self, ctx, *, msg: str = ""):
async with ctx.typing():
await ctx.thread.reply(ctx.message)

@commands.command()
@commands.command(aliases=["formatreply"])
@checks.has_permissions(PermissionLevel.SUPPORTER)
@checks.thread_only()
async def freply(self, ctx, *, msg: str = ""):
"""
Reply to a Modmail thread with variables.
Works just like `{prefix}reply`, however with the addition of three variables:
- `{channel}` - the `discord.TextChannel` object
- `{recipient}` - the `discord.User` object of the recipient
- `{author}` - the `discord.User` object of the author
Supports attachments and images as well as
automatically embedding image URLs.
"""
msg = self.bot.formatter.format(
msg, channel=ctx.channel, recipient=ctx.thread.recipient, author=ctx.message.author
)
ctx.message.content = msg
async with ctx.typing():
await ctx.thread.reply(ctx.message)

@commands.command(aliases=["anonreply", "anonymousreply"])
@checks.has_permissions(PermissionLevel.SUPPORTER)
@checks.thread_only()
async def anonreply(self, ctx, *, msg: str = ""):
async def areply(self, ctx, *, msg: str = ""):
"""
Reply to a thread anonymously.
Expand Down Expand Up @@ -823,11 +851,10 @@ async def find_linked_message(self, ctx, message_id):
continue
# TODO: use regex to find the linked message id
linked_message_id = str(embed.author.url).split("/")[-1]
break

elif message_id and msg.id == message_id:
url = msg.embeds[0].author.url
linked_message_id = str(url).split("/")[-1]
break

return linked_message_id

Expand Down
8 changes: 4 additions & 4 deletions cogs/plugins.py
Original file line number Diff line number Diff line change
Expand Up @@ -539,12 +539,12 @@ async def plugins_registry(self, ctx, *, plugin_name: typing.Union[int, str] = N

return await ctx.send(embed=embed)

for plugin_name, details in registry:
details = self.registry[plugin_name]
for name, details in registry:
details = self.registry[name]
user, repo = details["repository"].split("/", maxsplit=1)
branch = details.get("branch")

plugin = Plugin(user, repo, plugin_name, branch)
plugin = Plugin(user, repo, name, branch)

embed = discord.Embed(
color=self.bot.main_color,
Expand All @@ -554,7 +554,7 @@ async def plugins_registry(self, ctx, *, plugin_name: typing.Union[int, str] = N
)

embed.add_field(
name="Installation", value=f"```{self.bot.prefix}plugins add {plugin_name}```"
name="Installation", value=f"```{self.bot.prefix}plugins add {name}```"
)

embed.set_author(
Expand Down
Loading

0 comments on commit e9e8992

Please sign in to comment.