Skip to content

Commit

Permalink
0.0.3
Browse files Browse the repository at this point in the history
- bot automatically kicks and band
- still need to add admin and non-admin commands
- first alpha release
  • Loading branch information
BeardedTek committed May 31, 2023
1 parent 2c4a883 commit f953feb
Show file tree
Hide file tree
Showing 6 changed files with 65 additions and 33 deletions.
54 changes: 30 additions & 24 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,9 @@
## NOTE: THIS IS A WORK IN PROGRESS!
### Code in main will change frequenty. This README is for now being used as a guideline for how I plan to lay out this bot.

## Please see [PRE_ALPHA.md](PRE_ALPHA.md) for current info and how to install a current pre-alpha release.


### The first line of defense is a list of watch words that trigger notification to a separate control channel

### The second line of defense is a configurable blacklist/whitelist located in base-config.yaml
### The second line of defense is a configurable words_list located in base-config.yaml

### How to trigger:
- If the word appears on any of the following lists it triggers a start:
Expand All @@ -24,15 +21,12 @@
#### If watchword:
- notify admins in private admin channel
#### If scoldword:
- notify admins in private admin channel
- scold the user with a random entry in 'scolds' as a reply to the message
- Subtract 1 from user's rep
#### If kickword:
- notify admins in private admin channel
- scold the user with a random entry in 'scolds' as a reply to the message
- Subtract 5 from user's rep
#### If autokickword:
- notify admins in private admin channel
- scold the user with a random entry in 'scolds' as a reply to the message
- Subtract 10 from user's rep
- Trigger a 'Kick Action'
Expand All @@ -42,28 +36,40 @@
- Trigger a 'Ban Action'

### Kick Action:
- Send User a DM explaining why they were kicked
- User can rejoin room right away
- If a private channel, user will be sent an invite after 1 minute

### Ban Action:
- Send user a DM explaining wy they were kicked
- User is banned from room

### Room intervention:
#### Should non-admin members of the room feel this should not have been a violation:
- Contact an admin to reverse it
- Send the command: !addrep <user>
- Any room member can only addrep once per hour
#### Should admin members of the room feel this should not have been a violation:
- Can use the following commands to mitigate:
- !addrep <user> <amount>
- !unban <user> <new_rep_value>
#### Should an admin feel a violation is egregious, they can use the following commands:
- !kick <user> : immediately kicks the user
- !ban <user> : immediately bans the user
- !kickban <user> : immediately kicks and bans the user
- !rep <user> <value> : manually adjust their 'rep' score
# Future Features
### Non-admin commands:
- !addrep `user`
- Any room member can only addrep once per user
- This will add up to 5 rep points.
- The maximum a rep value can be is defined in `rep-start` in maubot.yaml
- !scold `user`
- This will remove up to 1 rep point. A non-admin can only use this command 5 times per day.
- !invite `user`
- Send an invite to `user` (@user:example.com)
### Admin commands:
- !redact
- If done as a reply to a message, will remove the message
- ***WARNING*** This cannot be undone
- !addrep `user` `amount`
- Adds `amount` rep points to `user`
- !rep `user` `rep`
- manually adjust `user`'s `rep`
- !scold `user` `amount`
- Scold and remove `amount` rep points from `user`
- !kick `user`
- Immediately kick `user`
- https://docs.mau.fi/python/latest/api/mautrix.client.api.html#mautrix.client.ClientAPI.kick_user
- !ban `user`
- immediately kick and ban `user`
- https://docs.mau.fi/python/latest/api/mautrix.client.api.html#mautrix.client.ClientAPI.ban_user
- !unban `user` `rep`
- Unban `user` and set rep to `rep`
- https://docs.mau.fi/python/latest/api/mautrix.client.api.html#mautrix.client.ClientAPI.unban_user

# Installation
- Download `dev.beardedtek.scoldbot-v001.mbp`
Expand Down
File renamed without changes.
File renamed without changes.
Binary file added releases/dev.beardedtek.scoldbot-v0.0.3.mbp
Binary file not shown.
2 changes: 1 addition & 1 deletion scoldbot/maubot.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ maubot: 0.1.0
id: dev.beardedtek.scoldbot

# A PEP 440 compliant version string.
version: 0.0.2
version: 0.0.3

# The SPDX license identifier for the plugin. https://spdx.org/licenses/
# Optional, assumes all rights reserved if omitted.
Expand Down
42 changes: 34 additions & 8 deletions scoldbot/scoldbot.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ async def database_update(self, sender: str, msg: str, rep: int) -> bool:
return rval

async def update_rep(self,sender: str,msg: str, rep: int) -> None:
print(f"Current Rep: {rep}")
self.log.info(f"Current Rep: {rep}")
row = await self.database.fetchrow(f"SELECT rep FROM rep WHERE sender='{sender}'")
if row:
await self.database_update(sender,msg,rep)
Expand Down Expand Up @@ -138,6 +138,9 @@ async def handle_message(self, evt: MessageEvent) -> None:
Args:
evt: The event to handle
"""
kick = False
ban = False
scold = False
if evt.sender != self.client.mxid:
# Only check if we didn't send the message
# run word_list() for each list we want to check against
Expand All @@ -157,29 +160,52 @@ async def handle_message(self, evt: MessageEvent) -> None:
# Send Message to admin
new_rep = rep
if self.hits['scoldword']:
# Scold the User
scold = True
# -1 from User's Rep
new_rep = rep - 1

if self.hits['kickword']:
# Scold the User
scold = True
# Kick the user
kick = True
# -5 from User's Rep
new_rep = rep -5

if self.hits['autokickword']:
# Scold the User
scold = True
# Kick the user
kick = True
# -10 from User's Rep
new_rep = rep - 10
# Check User's Rep and see if action needs to be taken

await self.send_scold(evt,new_rep)
if new_rep != rep:
await self.update_rep(sender,msg,new_rep)
for rep_kick in self.config['rep-kick']:
if rep > rep_kick > new_rep:
#kick the user
self.log.info(f"KICK {sender}!!!")
if 1 > new_rep:
if not kick:
for rep_kick in self.config['rep-kick']:
if rep > rep_kick > new_rep:
#kick the user
self.log.info(f"KICK {sender}!!!")
kick = True
if 1 > new_rep and not ban:
ban = True
self.log.info(f"KICKBAN {sender}")

# Tale Action
if scold:
await self.send_scold(evt,new_rep)
if kick:
await self.client.kick_user(evt.room_id,
evt.sender,
reason="Violated room language policy")
#pass
if ban:
await self.client.ban_user(evt.room_id,
evt.sender,
reason="You have lost your reputation in this room. Contact a room admin if you'd like to atone for your vulgarity.")
#pass
scold = False
ban = False
kick = False

0 comments on commit f953feb

Please sign in to comment.