Make error messages optional
This commit is contained in:
parent
7993eced35
commit
d30b14af39
2 changed files with 24 additions and 4 deletions
|
@ -4,3 +4,15 @@ democracy: true
|
|||
# If democracy is enabled, this is a blacklist. Otherwise this is a whitelist.
|
||||
filter:
|
||||
- "@user:example.com"
|
||||
|
||||
# Error message switches.
|
||||
# If false, the bot will simply not react when the error occurs.
|
||||
errors:
|
||||
# Sorry, you're not allowed to vote.
|
||||
filtered_users: true
|
||||
# Sorry, you can't vote on votes.
|
||||
vote_on_vote: true
|
||||
# Hey! You can't upvote yourself!
|
||||
upvote_self: true
|
||||
# You already ±1'd that message.
|
||||
already_voted: true
|
||||
|
|
|
@ -42,6 +42,10 @@ class Config(BaseProxyConfig):
|
|||
def do_update(self, helper: ConfigUpdateHelper) -> None:
|
||||
helper.copy("democracy")
|
||||
helper.copy("filter")
|
||||
helper.copy("errors.filtered_users")
|
||||
helper.copy("errors.vote_on_vote")
|
||||
helper.copy("errors.upvote_self")
|
||||
helper.copy("errors.already_voted")
|
||||
|
||||
|
||||
class KarmaBot(Plugin):
|
||||
|
@ -166,15 +170,18 @@ class KarmaBot(Plugin):
|
|||
return
|
||||
in_filter = evt.sender in self.config["filter"]
|
||||
if self.config["democracy"] == in_filter:
|
||||
if self.config["errors.filtered_users"]:
|
||||
await evt.reply("Sorry, you're not allowed to vote.")
|
||||
return
|
||||
if self.karma_t.is_vote_event(target):
|
||||
if self.config["errors.vote_on_vote"]:
|
||||
await evt.reply("Sorry, you can't vote on votes.")
|
||||
return
|
||||
karma_target = await self.client.get_event(evt.room_id, target)
|
||||
if not karma_target:
|
||||
return
|
||||
if karma_target.sender == evt.sender and value > 0:
|
||||
if self.config["errors.upvote_self"]:
|
||||
await evt.reply("Hey! You can't upvote yourself!")
|
||||
return
|
||||
karma_id = dict(given_to=karma_target.sender, given_by=evt.sender, given_in=evt.room_id,
|
||||
|
@ -182,6 +189,7 @@ class KarmaBot(Plugin):
|
|||
existing = self.karma_t.get(**karma_id)
|
||||
if existing is not None:
|
||||
if existing.value == value:
|
||||
if self.config["errors.already_voted"]:
|
||||
await evt.reply(f"You already {self._sign(value)}'d that message.")
|
||||
return
|
||||
existing.update(new_value=value)
|
||||
|
|
Loading…
Reference in a new issue