refactor: applying lots of linting
Some checks failed
Docker CI/CD / Docker Build and Push to Docker Hub (push) Has been cancelled
Some checks failed
Docker CI/CD / Docker Build and Push to Docker Hub (push) Has been cancelled
This commit removes unnecessary imports across several modules, enhancing code readability and potentially improving performance. Notably, `KeysUploadError` and `requests` were removed where no longer used, reflecting a cleaner dependency structure. Furthermore, logging calls have been standardized, removing dynamic string generation in favor of static messages. This change not only makes the logs more consistent but also slightly reduces the computational overhead associated with log generation. The removal of unused type hints also contributes to a more focused and maintainable code base. Additionally, the commit includes minor text adjustments for user messages, replacing dynamic content with fixed strings where the dynamism was not needed. This enhances both the clarity and security of user-directed messages by avoiding unnecessary string formatting operations. Finally, the simplification of the migration script and the adjustment in the tools module underscore an ongoing effort to maintain clean and efficient code infrastructure.
This commit is contained in:
parent
5bbcd3cfda
commit
bc06f8939a
10 changed files with 11 additions and 14 deletions
|
@ -1,4 +1,4 @@
|
|||
from nio import RoomMemberEvent, MatrixRoom, KeysUploadError
|
||||
from nio import RoomMemberEvent, MatrixRoom
|
||||
|
||||
async def roommember_callback(room: MatrixRoom, event: RoomMemberEvent, bot):
|
||||
if event.membership == "leave":
|
||||
|
|
|
@ -1,9 +1,8 @@
|
|||
import trackingmore
|
||||
import requests
|
||||
|
||||
from .logging import Logger
|
||||
|
||||
from typing import Dict, List, Tuple, Generator, Optional
|
||||
from typing import Tuple, Optional
|
||||
|
||||
class TrackingMore:
|
||||
api_key: str
|
||||
|
|
|
@ -3,7 +3,7 @@ import requests
|
|||
|
||||
from .logging import Logger
|
||||
|
||||
from typing import Dict, List, Tuple, Generator, Optional
|
||||
from typing import Generator, Optional
|
||||
|
||||
class WolframAlpha:
|
||||
api_key: str
|
||||
|
|
|
@ -23,7 +23,7 @@ async def command_calculate(room: MatrixRoom, event: RoomMessageText, bot):
|
|||
bot.logger.log("Querying calculation API...")
|
||||
|
||||
for subpod in bot.calculation_api.generate_calculation_response(prompt, text, results_only, user=room.room_id):
|
||||
bot.logger.log(f"Sending subpod...")
|
||||
bot.logger.log("Sending subpod...")
|
||||
if isinstance(subpod, bytes):
|
||||
await bot.send_image(room, subpod)
|
||||
else:
|
||||
|
|
|
@ -16,7 +16,7 @@ async def command_imagine(room: MatrixRoom, event: RoomMessageText, bot):
|
|||
return
|
||||
|
||||
for image in images:
|
||||
bot.logger.log(f"Sending image...")
|
||||
bot.logger.log("Sending image...")
|
||||
await bot.send_image(room, image)
|
||||
|
||||
bot.log_api_usage(event, room, f"{bot.image_api.api_code}-{bot.image_api.image_model}", tokens_used)
|
||||
|
|
|
@ -13,7 +13,7 @@ async def command_newroom(room: MatrixRoom, event: RoomMessageText, bot):
|
|||
|
||||
if isinstance(new_room, RoomCreateError):
|
||||
bot.logger.log(f"Failed to create room: {new_room.message}")
|
||||
await bot.send_message(room, f"Sorry, I was unable to create a new room. Please try again later, or create a room manually.", True)
|
||||
await bot.send_message(room, "Sorry, I was unable to create a new room. Please try again later, or create a room manually.", True)
|
||||
return
|
||||
|
||||
bot.logger.log(f"Inviting {event.sender} to new room...")
|
||||
|
@ -21,7 +21,7 @@ async def command_newroom(room: MatrixRoom, event: RoomMessageText, bot):
|
|||
|
||||
if isinstance(invite, RoomInviteError):
|
||||
bot.logger.log(f"Failed to invite user: {invite.message}")
|
||||
await bot.send_message(room, f"Sorry, I was unable to invite you to the new room. Please try again later, or create a room manually.", True)
|
||||
await bot.send_message(room, "Sorry, I was unable to invite you to the new room. Please try again later, or create a room manually.", True)
|
||||
return
|
||||
|
||||
with closing(bot.database.cursor()) as cursor:
|
||||
|
@ -43,4 +43,4 @@ async def command_newroom(room: MatrixRoom, event: RoomMessageText, bot):
|
|||
|
||||
await bot.matrix_client.joined_rooms()
|
||||
await bot.send_message(room, f"Alright, I've created a new room called '{room_name}' and invited you to it. You can find it at {new_room.room_id}", True)
|
||||
await bot.send_message(bot.matrix_client.rooms[new_room.room_id], f"Welcome to the new room! What can I do for you?")
|
||||
await bot.send_message(bot.matrix_client.rooms[new_room.room_id], "Welcome to the new room! What can I do for you?")
|
||||
|
|
|
@ -114,7 +114,7 @@ async def command_roomsettings(room: MatrixRoom, event: RoomMessageText, bot):
|
|||
await bot.send_message(room, f"The current chat model is: '{value}'.", True)
|
||||
return
|
||||
|
||||
message = f"""The following settings are available:
|
||||
message = """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
|
||||
|
|
|
@ -15,7 +15,7 @@ async def command_tts(room: MatrixRoom, event: RoomMessageText, bot):
|
|||
await bot.send_message(room, "Sorry, I couldn't generate an audio file. Please try again later.", True)
|
||||
return
|
||||
|
||||
bot.logger.log(f"Sending audio file...")
|
||||
bot.logger.log("Sending audio file...")
|
||||
await bot.send_file(room, content, "audio.mp3", "audio/mpeg", "m.audio")
|
||||
|
||||
return
|
||||
|
|
|
@ -1,7 +1,5 @@
|
|||
# Migration for Matrix Store - No longer used
|
||||
|
||||
from datetime import datetime
|
||||
from contextlib import closing
|
||||
|
||||
def migration(conn):
|
||||
pass
|
|
@ -1,4 +1,4 @@
|
|||
from .base import BaseTool, Handover
|
||||
from .base import BaseTool
|
||||
|
||||
class Imagedescription(BaseTool):
|
||||
DESCRIPTION = "Describe the content of the images in the conversation."
|
||||
|
|
Loading…
Reference in a new issue