Skip to content

Commit 05b261b

Browse files
committed
fareply, anonsnippet config, disable_updates config, resolves modmail-dev#2905
1 parent 812494a commit 05b261b

File tree

8 files changed

+64
-4
lines changed

8 files changed

+64
-4
lines changed

CHANGELOG.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,19 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
66
This project mostly adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html);
77
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.
88

9-
# v3.7.14-dev1
9+
# v3.7.14-dev2
1010

1111
### Added
1212

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

1518
### Improved
1619

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

1923
### Fixed
2024

app.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
},
3434
"GITHUB_TOKEN": {
3535
"description": "A github personal access token with the repo scope.",
36-
"required": true
36+
"required": false
3737
}
3838
}
3939
}

bot.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
__version__ = "3.7.14-dev1"
1+
__version__ = "3.7.14-dev2"
22

33

44
import asyncio
@@ -1069,7 +1069,10 @@ async def process_commands(self, message):
10691069
# Process snippets
10701070
if cmd in self.snippets:
10711071
snippet = self.snippets[cmd]
1072-
message.content = f"{self.prefix}freply {snippet}"
1072+
if self.config["anonymous_snippets"]:
1073+
message.content = f"{self.prefix}fareply {snippet}"
1074+
else:
1075+
message.content = f"{self.prefix}freply {snippet}"
10731076

10741077
ctxs = await self.get_contexts(message)
10751078
for ctx in ctxs:

cogs/modmail.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import asyncio
2+
from operator import truediv
23
import re
34
from datetime import datetime
45
from itertools import zip_longest
@@ -835,6 +836,28 @@ async def freply(self, ctx, *, msg: str = ""):
835836
async with ctx.typing():
836837
await ctx.thread.reply(ctx.message)
837838

839+
@commands.command(aliases=["formatanonreply"])
840+
@checks.has_permissions(PermissionLevel.SUPPORTER)
841+
@checks.thread_only()
842+
async def fareply(self, ctx, *, msg: str = ""):
843+
"""
844+
Anonymously reply to a Modmail thread with variables.
845+
846+
Works just like `{prefix}areply`, however with the addition of three variables:
847+
- `{{channel}}` - the `discord.TextChannel` object
848+
- `{{recipient}}` - the `discord.User` object of the recipient
849+
- `{{author}}` - the `discord.User` object of the author
850+
851+
Supports attachments and images as well as
852+
automatically embedding image URLs.
853+
"""
854+
msg = self.bot.formatter.format(
855+
msg, channel=ctx.channel, recipient=ctx.thread.recipient, author=ctx.message.author
856+
)
857+
ctx.message.content = msg
858+
async with ctx.typing():
859+
await ctx.thread.reply(ctx.message, anonymous=True)
860+
838861
@commands.command(aliases=["anonreply", "anonymousreply"])
839862
@checks.has_permissions(PermissionLevel.SUPPORTER)
840863
@checks.thread_only()

cogs/utility.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1896,6 +1896,7 @@ async def github(self, ctx):
18961896
@commands.command()
18971897
@checks.has_permissions(PermissionLevel.OWNER)
18981898
@checks.github_token_required(ignore_if_not_heroku=True)
1899+
@checks.updates_enabled()
18991900
@trigger_typing
19001901
async def update(self, ctx, *, flag: str = ""):
19011902
"""

core/checks.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,3 +121,19 @@ async def predicate(ctx):
121121
"personal access token from developer settings."
122122
)
123123
return commands.check(predicate)
124+
125+
def updates_enabled():
126+
"""
127+
A decorator that ensures
128+
updates are enabled
129+
"""
130+
131+
async def predicate(ctx):
132+
return not ctx.bot.config["disable_updates"]
133+
134+
predicate.fail_msg = (
135+
"Updates are disabled on this bot instance. "
136+
"View `?config help disable_updates` for "
137+
"more information."
138+
)
139+
return commands.check(predicate)

core/config.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ class ConfigManager:
8080
"close_on_leave_reason": "The recipient has left the server.",
8181
"alert_on_mention": False,
8282
"show_timestamp": True,
83+
"anonymous_snippets": False,
8384
# moderation
8485
"recipient_color": str(discord.Color.gold()),
8586
"mod_color": str(discord.Color.green()),
@@ -143,6 +144,7 @@ class ConfigManager:
143144
# github access token for private repositories
144145
"github_token": None,
145146
"disable_autoupdates": False,
147+
"disable_updates": False,
146148
# Logging
147149
"log_level": "INFO",
148150
# data collection
@@ -173,8 +175,10 @@ class ConfigManager:
173175
"data_collection",
174176
"enable_eval",
175177
"disable_autoupdates",
178+
"disable_updates",
176179
"update_notifications",
177180
"thread_contact_silently",
181+
"anonymous_snippets",
178182
}
179183

180184
enums = {

core/config_help.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -849,5 +849,14 @@
849849
"notes": [
850850
"This configuration can only to be set through `.env` file or environment (config) variables."
851851
]
852+
},
853+
"disable_updates": {
854+
"default": "No",
855+
"description": "Controls if the update command should be disabled or not.",
856+
"examples": [
857+
],
858+
"notes": [
859+
"This configuration can only to be set through `.env` file or environment (config) variables."
860+
]
852861
}
853862
}

0 commit comments

Comments
 (0)