|
@@ -3,10 +3,15 @@ from nio.rooms import MatrixRoom
|
|
|
|
|
|
|
|
|
|
async def command_roomsettings(room: MatrixRoom, event: RoomMessageText, bot):
|
|
async def command_roomsettings(room: MatrixRoom, event: RoomMessageText, bot):
|
|
- setting = event.body.split()[2]
|
|
|
|
|
|
+ setting = event.body.split()[2] if len(event.body.split()) > 2 else None
|
|
value = " ".join(event.body.split()[3:]) if len(
|
|
value = " ".join(event.body.split()[3:]) if len(
|
|
event.body.split()) > 3 else None
|
|
event.body.split()) > 3 else None
|
|
|
|
|
|
|
|
+ if setting == "classification":
|
|
|
|
+ setting = "use_classification"
|
|
|
|
+ if setting == "systemmessage":
|
|
|
|
+ setting = "system_message"
|
|
|
|
+
|
|
if setting == "system_message":
|
|
if setting == "system_message":
|
|
if value:
|
|
if value:
|
|
bot.logger.log("Adding system message...")
|
|
bot.logger.log("Adding system message...")
|
|
@@ -28,38 +33,52 @@ async def command_roomsettings(room: MatrixRoom, event: RoomMessageText, bot):
|
|
await bot.send_message(room, f"The current system message is: '{system_message}'.", True)
|
|
await bot.send_message(room, f"The current system message is: '{system_message}'.", True)
|
|
return
|
|
return
|
|
|
|
|
|
- if setting == "classification":
|
|
|
|
|
|
+ if setting in ("use_classification", "always_reply"):
|
|
if value:
|
|
if value:
|
|
if value.lower() in ["true", "false"]:
|
|
if value.lower() in ["true", "false"]:
|
|
value = value.lower() == "true"
|
|
value = value.lower() == "true"
|
|
|
|
|
|
- bot.logger.log("Setting classification status...")
|
|
|
|
|
|
+ bot.logger.log(f"Setting {setting} status for {room.room_id} to {value}...")
|
|
|
|
|
|
with bot.database.cursor() as cur:
|
|
with bot.database.cursor() as cur:
|
|
cur.execute(
|
|
cur.execute(
|
|
"""INSERT INTO room_settings (room_id, setting, value) VALUES (?, ?, ?)
|
|
"""INSERT INTO room_settings (room_id, setting, value) VALUES (?, ?, ?)
|
|
ON CONFLICT (room_id, setting) DO UPDATE SET value = ?;""",
|
|
ON CONFLICT (room_id, setting) DO UPDATE SET value = ?;""",
|
|
- (room.room_id, "use_classification", "1" if value else "0", "1" if value else "0")
|
|
|
|
|
|
+ (room.room_id, setting, "1" if value else "0", "1" if value else "0")
|
|
)
|
|
)
|
|
|
|
|
|
- await bot.send_message(room, f"Alright, I've set use_classification to: '{value}'.", True)
|
|
|
|
|
|
+ await bot.send_message(room, f"Alright, I've set {setting} to: '{value}'.", True)
|
|
return
|
|
return
|
|
|
|
|
|
await bot.send_message(room, "You need to provide a boolean value (true/false).", True)
|
|
await bot.send_message(room, "You need to provide a boolean value (true/false).", True)
|
|
return
|
|
return
|
|
|
|
|
|
- bot.logger.log("Retrieving classification status...")
|
|
|
|
|
|
+ bot.logger.log(f"Retrieving {setting} status for {room.room_id}...")
|
|
|
|
+
|
|
|
|
+ with bot.database.cursor() as cur:
|
|
|
|
+ cur.execute(
|
|
|
|
+ """SELECT value FROM room_settings WHERE room_id = ? AND setting = ?;""",
|
|
|
|
+ (room.room_id, setting)
|
|
|
|
+ )
|
|
|
|
+
|
|
|
|
+ value = cur.fetchone()[0]
|
|
|
|
|
|
- use_classification = bot.room_uses_classification(room)
|
|
|
|
|
|
+ if not value:
|
|
|
|
+ if setting == "use_classification":
|
|
|
|
+ value = False
|
|
|
|
+ elif setting == "always_reply":
|
|
|
|
+ value = True
|
|
|
|
+ else:
|
|
|
|
+ value = bool(int(value))
|
|
|
|
|
|
- await bot.send_message(room, f"The current classification status is: '{use_classification}'.", True)
|
|
|
|
|
|
+ await bot.send_message(room, f"The current {setting} status is: '{value}'.", True)
|
|
return
|
|
return
|
|
|
|
|
|
- message = f"""
|
|
|
|
- The following settings are available:
|
|
|
|
|
|
+ message = f"""The following settings are available:
|
|
|
|
|
|
- - system_message [message]: Get or set the system message to be sent to the chat model
|
|
|
|
- - classification [true/false]: Get or set whether the room uses classification
|
|
|
|
- """
|
|
|
|
|
|
+- system_message [message]: Get or set the system message to be sent to the chat model
|
|
|
|
+- classification [true/false]: Get or set whether the room uses classification
|
|
|
|
+- always_reply [true/false]: Get or set whether the bot should reply to all messages (if false, only reply to mentions and commands)
|
|
|
|
+"""
|
|
|
|
|
|
await bot.send_message(room, message, True)
|
|
await bot.send_message(room, message, True)
|