mirror of
https://github.com/mruwnik/memory.git
synced 2025-11-13 00:04:05 +01:00
fix typing indicator
This commit is contained in:
parent
ff3ca4f109
commit
131427255a
@ -394,7 +394,8 @@ class MessageCollector(commands.Bot):
|
|||||||
logger.error(f"DM channel not available for {user_identifier}")
|
logger.error(f"DM channel not available for {user_identifier}")
|
||||||
return False
|
return False
|
||||||
|
|
||||||
await channel.trigger_typing()
|
async with channel.typing():
|
||||||
|
pass
|
||||||
return True
|
return True
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
@ -431,30 +432,10 @@ class MessageCollector(commands.Bot):
|
|||||||
logger.error(f"Channel {channel_name} not found")
|
logger.error(f"Channel {channel_name} not found")
|
||||||
return False
|
return False
|
||||||
|
|
||||||
await channel.trigger_typing()
|
async with channel.typing():
|
||||||
|
pass
|
||||||
return True
|
return True
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.error(f"Failed to trigger typing for channel {channel_name}: {e}")
|
logger.error(f"Failed to trigger typing for channel {channel_name}: {e}")
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
async def run_collector():
|
|
||||||
"""Run the Discord message collector"""
|
|
||||||
if not settings.DISCORD_BOT_TOKEN:
|
|
||||||
logger.error("DISCORD_BOT_TOKEN not configured")
|
|
||||||
return
|
|
||||||
|
|
||||||
collector = MessageCollector()
|
|
||||||
|
|
||||||
try:
|
|
||||||
await collector.start(settings.DISCORD_BOT_TOKEN)
|
|
||||||
except Exception as e:
|
|
||||||
logger.error(f"Discord collector failed: {e}")
|
|
||||||
raise
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
|
||||||
import asyncio
|
|
||||||
|
|
||||||
asyncio.run(run_collector())
|
|
||||||
|
|||||||
@ -7,7 +7,7 @@ import logging
|
|||||||
import re
|
import re
|
||||||
import textwrap
|
import textwrap
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from typing import Any
|
from typing import Any, cast
|
||||||
|
|
||||||
from sqlalchemy import exc as sqlalchemy_exc
|
from sqlalchemy import exc as sqlalchemy_exc
|
||||||
from sqlalchemy.orm import Session, scoped_session
|
from sqlalchemy.orm import Session, scoped_session
|
||||||
@ -133,10 +133,20 @@ def should_process(message: DiscordMessage) -> bool:
|
|||||||
if not (res := re.search(r"<number>(.*)</number>", response)):
|
if not (res := re.search(r"<number>(.*)</number>", response)):
|
||||||
return False
|
return False
|
||||||
try:
|
try:
|
||||||
return int(res.group(1)) > 100 - message.chattiness_threshold
|
if int(res.group(1)) < 100 - message.chattiness_threshold:
|
||||||
|
return False
|
||||||
except ValueError:
|
except ValueError:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
if not (bot_id := _resolve_bot_id(message)):
|
||||||
|
return False
|
||||||
|
|
||||||
|
if message.channel and message.channel.server:
|
||||||
|
discord.trigger_typing_channel(bot_id, message.channel.name)
|
||||||
|
else:
|
||||||
|
discord.trigger_typing_dm(bot_id, cast(int | str, message.from_id))
|
||||||
|
return True
|
||||||
|
|
||||||
|
|
||||||
def _resolve_bot_id(discord_message: DiscordMessage) -> int | None:
|
def _resolve_bot_id(discord_message: DiscordMessage) -> int | None:
|
||||||
recipient = discord_message.recipient_user
|
recipient = discord_message.recipient_user
|
||||||
@ -181,15 +191,6 @@ def process_discord_message(message_id: int) -> dict[str, Any]:
|
|||||||
"message_id": message_id,
|
"message_id": message_id,
|
||||||
}
|
}
|
||||||
|
|
||||||
if discord_message.channel and discord_message.channel.server:
|
|
||||||
discord.trigger_typing_channel(
|
|
||||||
bot_id, discord_message.channel.name
|
|
||||||
)
|
|
||||||
else:
|
|
||||||
discord.trigger_typing_dm(bot_id, discord_message.from_id)
|
|
||||||
|
|
||||||
response: str | None = None
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
response = call_llm(session, discord_message, settings.DISCORD_MODEL)
|
response = call_llm(session, discord_message, settings.DISCORD_MODEL)
|
||||||
except Exception:
|
except Exception:
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user