dont track activity in non-space rooms, and include configurable sleep time to avoid ratelimiting
This commit is contained in:
@@ -1,6 +1,11 @@
|
|||||||
# the room-id of the matrix room or space to use as your "full user list"
|
# the room-id of the matrix room or space to use as your "full user list"
|
||||||
parent_room: "!somerandomcharacters:server.tld"
|
parent_room: "!somerandomcharacters:server.tld"
|
||||||
|
|
||||||
|
# sleep time between actions. you can drop this to 0 if your bot has no
|
||||||
|
# ratelimits imposed on its homeserver, otherwise you may want to increase this
|
||||||
|
# to avoid errors.
|
||||||
|
sleep: 1
|
||||||
|
|
||||||
# whether to encrypt rooms when using the room creation commands
|
# whether to encrypt rooms when using the room creation commands
|
||||||
encrypt: False
|
encrypt: False
|
||||||
|
|
||||||
|
|||||||
+38
-24
@@ -23,6 +23,7 @@ from .db import upgrade_table
|
|||||||
|
|
||||||
class Config(BaseProxyConfig):
|
class Config(BaseProxyConfig):
|
||||||
def do_update(self, helper: ConfigUpdateHelper) -> None:
|
def do_update(self, helper: ConfigUpdateHelper) -> None:
|
||||||
|
helper.copy("sleep")
|
||||||
helper.copy("admins")
|
helper.copy("admins")
|
||||||
helper.copy("moderators")
|
helper.copy("moderators")
|
||||||
helper.copy("parent_room")
|
helper.copy("parent_room")
|
||||||
@@ -224,7 +225,7 @@ class CommunityBot(Plugin):
|
|||||||
ban_event_map['ban_list'][user].append(roomname)
|
ban_event_map['ban_list'][user].append(roomname)
|
||||||
else:
|
else:
|
||||||
ban_event_map['ban_list'][user].append(room)
|
ban_event_map['ban_list'][user].append(room)
|
||||||
time.sleep(0.5)
|
time.sleep(self.config['sleep'])
|
||||||
except MNotFound:
|
except MNotFound:
|
||||||
pass
|
pass
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
@@ -242,6 +243,7 @@ class CommunityBot(Plugin):
|
|||||||
try:
|
try:
|
||||||
l_id = await self.client.resolve_room_alias(l)
|
l_id = await self.client.resolve_room_alias(l)
|
||||||
list_id = l_id["room_id"]
|
list_id = l_id["room_id"]
|
||||||
|
time.sleep(self.config['sleep'])
|
||||||
#self.log.debug(f"DEBUG banlist id resolves to: {list_id}")
|
#self.log.debug(f"DEBUG banlist id resolves to: {list_id}")
|
||||||
except:
|
except:
|
||||||
evt.reply("i don't recognize that list, sorry")
|
evt.reply("i don't recognize that list, sorry")
|
||||||
@@ -347,26 +349,38 @@ class CommunityBot(Plugin):
|
|||||||
if not self.config["track_messages"] or not self.config["track_users"]:
|
if not self.config["track_messages"] or not self.config["track_users"]:
|
||||||
pass
|
pass
|
||||||
else:
|
else:
|
||||||
q = """
|
rooms_to_manage = await self.get_space_roomlist()
|
||||||
INSERT INTO user_events(mxid, last_message_timestamp)
|
# only attempt to track rooms in the space, ignore any other rooms
|
||||||
VALUES ($1, $2)
|
# the bot may happen to be in line banlist policy rooms etc.
|
||||||
ON CONFLICT(mxid)
|
if evt.room_id not in rooms_to_manage:
|
||||||
DO UPDATE SET last_message_timestamp=$2
|
return
|
||||||
"""
|
else:
|
||||||
await self.database.execute(q, evt.sender, evt.timestamp)
|
q = """
|
||||||
|
INSERT INTO user_events(mxid, last_message_timestamp)
|
||||||
|
VALUES ($1, $2)
|
||||||
|
ON CONFLICT(mxid)
|
||||||
|
DO UPDATE SET last_message_timestamp=$2
|
||||||
|
"""
|
||||||
|
await self.database.execute(q, evt.sender, evt.timestamp)
|
||||||
|
|
||||||
@event.on(EventType.REACTION)
|
@event.on(EventType.REACTION)
|
||||||
async def update_reaction_timestamp(self, evt: MessageEvent) -> None:
|
async def update_reaction_timestamp(self, evt: MessageEvent) -> None:
|
||||||
if not self.config["track_reactions"] or not self.config["track_users"]:
|
if not self.config["track_reactions"] or not self.config["track_users"]:
|
||||||
pass
|
pass
|
||||||
else:
|
else:
|
||||||
q = """
|
rooms_to_manage = await self.get_space_roomlist()
|
||||||
INSERT INTO user_events(mxid, last_message_timestamp)
|
# only attempt to track rooms in the space, ignore any other rooms
|
||||||
VALUES ($1, $2)
|
# the bot may happen to be in line banlist policy rooms etc.
|
||||||
ON CONFLICT(mxid)
|
if evt.room_id not in rooms_to_manage:
|
||||||
DO UPDATE SET last_message_timestamp=$2
|
return
|
||||||
"""
|
else:
|
||||||
await self.database.execute(q, evt.sender, evt.timestamp)
|
q = """
|
||||||
|
INSERT INTO user_events(mxid, last_message_timestamp)
|
||||||
|
VALUES ($1, $2)
|
||||||
|
ON CONFLICT(mxid)
|
||||||
|
DO UPDATE SET last_message_timestamp=$2
|
||||||
|
"""
|
||||||
|
await self.database.execute(q, evt.sender, evt.timestamp)
|
||||||
|
|
||||||
@command.new("community", help="manage rooms and members of a space")
|
@command.new("community", help="manage rooms and members of a space")
|
||||||
async def community(self) -> None:
|
async def community(self) -> None:
|
||||||
@@ -480,7 +494,7 @@ class CommunityBot(Plugin):
|
|||||||
purge_list[user].append(roomname)
|
purge_list[user].append(roomname)
|
||||||
else:
|
else:
|
||||||
purge_list[user].append(room)
|
purge_list[user].append(room)
|
||||||
time.sleep(0.5)
|
time.sleep('sleep')
|
||||||
except MNotFound:
|
except MNotFound:
|
||||||
pass
|
pass
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
@@ -526,7 +540,7 @@ class CommunityBot(Plugin):
|
|||||||
purge_list[user].append(roomname)
|
purge_list[user].append(roomname)
|
||||||
else:
|
else:
|
||||||
purge_list[user].append(room)
|
purge_list[user].append(room)
|
||||||
time.sleep(0.5)
|
time.sleep(self.config['sleep'])
|
||||||
except MNotFound:
|
except MNotFound:
|
||||||
pass
|
pass
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
@@ -594,7 +608,7 @@ class CommunityBot(Plugin):
|
|||||||
unban_list[user].append(roomname)
|
unban_list[user].append(roomname)
|
||||||
else:
|
else:
|
||||||
unban_list[user].append(room)
|
unban_list[user].append(room)
|
||||||
time.sleep(0.5)
|
time.sleep(self.config['sleep'])
|
||||||
except MNotFound:
|
except MNotFound:
|
||||||
pass
|
pass
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
@@ -646,7 +660,7 @@ class CommunityBot(Plugin):
|
|||||||
#self.log.info(mymsg)
|
#self.log.info(mymsg)
|
||||||
room_id = await self.client.create_room(alias_localpart=sanitized_name, name=roomname,
|
room_id = await self.client.create_room(alias_localpart=sanitized_name, name=roomname,
|
||||||
invitees=invitees, power_level_override=pl_override)
|
invitees=invitees, power_level_override=pl_override)
|
||||||
time.sleep(0.5)
|
time.sleep(self.config['sleep'])
|
||||||
|
|
||||||
await evt.respond(f"updating room states...", edits=mymsg)
|
await evt.respond(f"updating room states...", edits=mymsg)
|
||||||
parent_event_content = json.dumps({'auto_join': False, 'suggested': False, 'via': [server]})
|
parent_event_content = json.dumps({'auto_join': False, 'suggested': False, 'via': [server]})
|
||||||
@@ -655,11 +669,11 @@ class CommunityBot(Plugin):
|
|||||||
'room_id': parent_room}]})
|
'room_id': parent_room}]})
|
||||||
|
|
||||||
await self.client.send_state_event(parent_room, 'm.space.child', parent_event_content, state_key=room_id)
|
await self.client.send_state_event(parent_room, 'm.space.child', parent_event_content, state_key=room_id)
|
||||||
time.sleep(0.5)
|
time.sleep(self.config['sleep'])
|
||||||
await self.client.send_state_event(room_id, 'm.space.parent', child_event_content, state_key=parent_room)
|
await self.client.send_state_event(room_id, 'm.space.parent', child_event_content, state_key=parent_room)
|
||||||
time.sleep(0.5)
|
time.sleep(self.config['sleep'])
|
||||||
await self.client.send_state_event(room_id, 'm.room.join_rules', join_rules_content, state_key="")
|
await self.client.send_state_event(room_id, 'm.room.join_rules', join_rules_content, state_key="")
|
||||||
time.sleep(0.5)
|
time.sleep(self.config['sleep'])
|
||||||
|
|
||||||
if self.config["encrypt"] or force_encryption:
|
if self.config["encrypt"] or force_encryption:
|
||||||
encryption_content = json.dumps({"algorithm": "m.megolm.v1.aes-sha2"})
|
encryption_content = json.dumps({"algorithm": "m.megolm.v1.aes-sha2"})
|
||||||
@@ -667,7 +681,7 @@ class CommunityBot(Plugin):
|
|||||||
await self.client.send_state_event(room_id, 'm.room.encryption', encryption_content,
|
await self.client.send_state_event(room_id, 'm.room.encryption', encryption_content,
|
||||||
state_key="")
|
state_key="")
|
||||||
await evt.respond(f"encrypting room...", edits=mymsg)
|
await evt.respond(f"encrypting room...", edits=mymsg)
|
||||||
time.sleep(0.5)
|
time.sleep(self.config['sleep'])
|
||||||
|
|
||||||
await evt.respond(f"room created and updated, alias is #{sanitized_name}:{server}", edits=mymsg)
|
await evt.respond(f"room created and updated, alias is #{sanitized_name}:{server}", edits=mymsg)
|
||||||
|
|
||||||
@@ -788,7 +802,7 @@ class CommunityBot(Plugin):
|
|||||||
self.log.warning(e)
|
self.log.warning(e)
|
||||||
error_list.append(roomname or room)
|
error_list.append(roomname or room)
|
||||||
|
|
||||||
time.sleep(0.5)
|
time.sleep(self.config['sleep'])
|
||||||
|
|
||||||
results = "the following rooms were updated:<p><code>{success_list}</code></p>the following errors were \
|
results = "the following rooms were updated:<p><code>{success_list}</code></p>the following errors were \
|
||||||
recorded:<p><code>{error_list}</code></p>".format(success_list=success_list, error_list=error_list)
|
recorded:<p><code>{error_list}</code></p>".format(success_list=success_list, error_list=error_list)
|
||||||
|
|||||||
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
maubot: 0.1.0
|
maubot: 0.1.0
|
||||||
id: org.jobmachine.communitybot
|
id: org.jobmachine.communitybot
|
||||||
version: 0.1.16
|
version: 0.1.17
|
||||||
license: MIT
|
license: MIT
|
||||||
modules:
|
modules:
|
||||||
- community
|
- community
|
||||||
|
|||||||
Reference in New Issue
Block a user