Skip to content

Commit

Permalink
fareply, anonsnippet config, disable_updates config, resolves #2905
Browse files Browse the repository at this point in the history
  • Loading branch information
fourjr committed Nov 30, 2020
1 parent 812494a commit 05b261b
Show file tree
Hide file tree
Showing 8 changed files with 64 additions and 4 deletions.
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,19 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
This project mostly adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html);
however, insignificant breaking changes do not guarantee a major version bump, see the reasoning [here](https://github.com/kyb3r/modmail/issues/319). If you're a plugin developer, note the "BREAKING" section.

# v3.7.14-dev1
# v3.7.14-dev2

### Added

- `update_notifications` configuration option to toggle bot autoupdate notifications. ([GH #2896](https://github.com/kyb3r/modmail/issues/2896))
- `?fareply`, anonymously reply with variables.
- `anonymous_snippets` config variable to toggle if snippets should be anonymous. ([GH #2905](https://github.com/kyb3r/modmail/issues/2905))
- `disable_updates` config variable to control if the update command should be disabled or not.

### Improved

- Added command validation to `autotrigger add/edit`.
- `GITHUB_TOKEN` is now no longer required in Heroku setups.

### Fixed

Expand Down
2 changes: 1 addition & 1 deletion app.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
},
"GITHUB_TOKEN": {
"description": "A github personal access token with the repo scope.",
"required": true
"required": false
}
}
}
7 changes: 5 additions & 2 deletions bot.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
__version__ = "3.7.14-dev1"
__version__ = "3.7.14-dev2"


import asyncio
Expand Down Expand Up @@ -1069,7 +1069,10 @@ async def process_commands(self, message):
# Process snippets
if cmd in self.snippets:
snippet = self.snippets[cmd]
message.content = f"{self.prefix}freply {snippet}"
if self.config["anonymous_snippets"]:
message.content = f"{self.prefix}fareply {snippet}"
else:
message.content = f"{self.prefix}freply {snippet}"

ctxs = await self.get_contexts(message)
for ctx in ctxs:
Expand Down
23 changes: 23 additions & 0 deletions cogs/modmail.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import asyncio
from operator import truediv
import re
from datetime import datetime
from itertools import zip_longest
Expand Down Expand Up @@ -835,6 +836,28 @@ async def freply(self, ctx, *, msg: str = ""):
async with ctx.typing():
await ctx.thread.reply(ctx.message)

@commands.command(aliases=["formatanonreply"])
@checks.has_permissions(PermissionLevel.SUPPORTER)
@checks.thread_only()
async def fareply(self, ctx, *, msg: str = ""):
"""
Anonymously reply to a Modmail thread with variables.
Works just like `{prefix}areply`, 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, anonymous=True)

@commands.command(aliases=["anonreply", "anonymousreply"])
@checks.has_permissions(PermissionLevel.SUPPORTER)
@checks.thread_only()
Expand Down
1 change: 1 addition & 0 deletions cogs/utility.py
Original file line number Diff line number Diff line change
Expand Up @@ -1896,6 +1896,7 @@ async def github(self, ctx):
@commands.command()
@checks.has_permissions(PermissionLevel.OWNER)
@checks.github_token_required(ignore_if_not_heroku=True)
@checks.updates_enabled()
@trigger_typing
async def update(self, ctx, *, flag: str = ""):
"""
Expand Down
16 changes: 16 additions & 0 deletions core/checks.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,3 +121,19 @@ async def predicate(ctx):
"personal access token from developer settings."
)
return commands.check(predicate)

def updates_enabled():
"""
A decorator that ensures
updates are enabled
"""

async def predicate(ctx):
return not ctx.bot.config["disable_updates"]

predicate.fail_msg = (
"Updates are disabled on this bot instance. "
"View `?config help disable_updates` for "
"more information."
)
return commands.check(predicate)
4 changes: 4 additions & 0 deletions core/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ class ConfigManager:
"close_on_leave_reason": "The recipient has left the server.",
"alert_on_mention": False,
"show_timestamp": True,
"anonymous_snippets": False,
# moderation
"recipient_color": str(discord.Color.gold()),
"mod_color": str(discord.Color.green()),
Expand Down Expand Up @@ -143,6 +144,7 @@ class ConfigManager:
# github access token for private repositories
"github_token": None,
"disable_autoupdates": False,
"disable_updates": False,
# Logging
"log_level": "INFO",
# data collection
Expand Down Expand Up @@ -173,8 +175,10 @@ class ConfigManager:
"data_collection",
"enable_eval",
"disable_autoupdates",
"disable_updates",
"update_notifications",
"thread_contact_silently",
"anonymous_snippets",
}

enums = {
Expand Down
9 changes: 9 additions & 0 deletions core/config_help.json
Original file line number Diff line number Diff line change
Expand Up @@ -849,5 +849,14 @@
"notes": [
"This configuration can only to be set through `.env` file or environment (config) variables."
]
},
"disable_updates": {
"default": "No",
"description": "Controls if the update command should be disabled or not.",
"examples": [
],
"notes": [
"This configuration can only to be set through `.env` file or environment (config) variables."
]
}
}

0 comments on commit 05b261b

Please sign in to comment.