Skip to content

Commit 63fc9b4

Browse files
authored
Merge pull request #414 from LlmKira/dev
(feat): add `logout` Command
2 parents 30e88c1 + d7966ea commit 63fc9b4

File tree

9 files changed

+82
-17
lines changed

9 files changed

+82
-17
lines changed

app/sender/discord/__init__.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
save_credential,
3838
dict2markdown,
3939
learn_instruction,
40+
logout,
4041
)
4142
from llmkira.openapi.trigger import get_trigger_loop
4243
from ...components.credential import Credential, ProviderError
@@ -319,6 +320,19 @@ async def listen_endpoint_command(
319320
ephemeral=True,
320321
)
321322

323+
@client.include
324+
@crescent.command(
325+
dm_enabled=True, name="logout", description="clear your credential"
326+
)
327+
async def listen_logout_command(ctx: crescent.Context):
328+
reply = await logout(
329+
uid=uid_make(__sender__, ctx.user.id),
330+
)
331+
return await ctx.respond(
332+
ephemeral=True,
333+
content=reply,
334+
)
335+
322336
@client.include
323337
@crescent.command(
324338
dm_enabled=True, name="clear", description="clear your message history"

app/sender/discord/event.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ def help_message():
1616
`/tool` - Check all useful tools
1717
`/clear` - wipe memory of your chat
1818
`/auth` - activate a task (my power)
19-
`/login` - login
19+
`/login` - set credential
20+
`/logout` - clear credential
2021
`/login_via_url` - login via url
2122
`/env` - set environment variable, split by ; , use `/env ENV=NONE` to disable a env.
2223
`/learn` - set your system prompt, reset by `/learn reset`

app/sender/kook/__init__.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
save_credential,
3535
dict2markdown,
3636
learn_instruction,
37+
logout,
3738
)
3839
from llmkira.openapi.trigger import get_trigger_loop
3940
from ...components.credential import ProviderError, Credential
@@ -331,6 +332,15 @@ async def listen_login_command(
331332
type=MessageTypes.KMD,
332333
)
333334

335+
@bot.command(name="logout")
336+
async def listen_logout_command(msg: Message):
337+
reply = await logout(uid=uid_make(__sender__, msg.author_id))
338+
return await msg.reply(
339+
content=convert(reply),
340+
is_temp=True,
341+
type=MessageTypes.KMD,
342+
)
343+
334344
@bot.command(name="clear")
335345
async def listen_clear_command(msg: Message):
336346
await global_message_runtime.update_session(

app/sender/kook/event.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@ def help_message():
3535
`/tool` - Check all useful tools
3636
`/clear` - wipe memory of your chat
3737
`/auth` - activate a task (my power)
38-
`/login` - login openai
38+
`/login` - set credential
39+
`/logout` - clear credential
3940
`/login_via_url` - login via provider url
4041
`/env` - set environment variable, split by ; , use `/env ENV=NONE` to disable a env.
4142
`/learn` - set your system prompt, reset by `/learn reset`

app/sender/slack/__init__.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
login,
2626
dict2markdown,
2727
learn_instruction,
28+
logout,
2829
)
2930
from app.setting.slack import BotSetting
3031
from llmkira.kv_manager.env import EnvManager
@@ -248,6 +249,16 @@ async def listen_login_command(ack: AsyncAck, respond: AsyncRespond, command):
248249
)
249250
return await respond(text=reply)
250251

252+
@bot.command(command="/logout")
253+
async def listen_logout_command(ack: AsyncAck, respond: AsyncRespond, command):
254+
command: SlashCommand = SlashCommand.model_validate(command)
255+
await ack()
256+
if not command.text:
257+
return
258+
_arg = command.text
259+
reply = await logout(uid=uid_make(__sender__, command.user_id))
260+
return await respond(text=reply)
261+
251262
@bot.command(command="/env")
252263
async def listen_env_command(ack: AsyncAck, respond: AsyncRespond, command):
253264
command: SlashCommand = SlashCommand.model_validate(command)

app/sender/slack/event.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ def help_message():
2424
`/clear` - forget...you
2525
`/auth` - activate a task (my power),but outside the thread
2626
`/login` - login via url or raw
27+
`/logout` - clear credential
2728
`/env` - set environment variable, split by ; , use `/env ENV=NONE` to disable a env.
2829
`/learn` - set your system prompt, reset by `/learn reset`
2930

app/sender/telegram/__init__.py

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@
55
# @Software: PyCharm
66
from typing import Optional, Union, List
77

8+
import telegramify_markdown
89
from loguru import logger
910
from telebot import formatting, util
1011
from telebot import types
1112
from telebot.async_telebot import AsyncTeleBot
1213
from telebot.asyncio_storage import StateMemoryStorage
13-
from telebot.formatting import escape_markdown
1414
from telegramify_markdown import convert
1515

1616
from app.sender.util_func import (
@@ -23,6 +23,7 @@
2323
TimerObjectContainer,
2424
dict2markdown,
2525
learn_instruction,
26+
logout,
2627
)
2728
from app.setting.telegram import BotSetting
2829
from llmkira.kv_manager.env import EnvManager
@@ -251,6 +252,17 @@ async def listen_login_command(message: types.Message):
251252
parse_mode="MarkdownV2",
252253
)
253254

255+
@bot.message_handler(commands="logout", chat_types=["private"])
256+
async def listen_logout_command(message: types.Message):
257+
logger.debug("Debug:logout command")
258+
_cmd, _arg = parse_command(command=message.text)
259+
reply = await logout(uid=uid_make(__sender__, message.from_user.id))
260+
await bot.reply_to(
261+
message,
262+
text=reply,
263+
parse_mode="MarkdownV2",
264+
)
265+
254266
@bot.message_handler(commands="env", chat_types=["private"])
255267
async def listen_env_command(message: types.Message):
256268
_cmd, _arg = parse_command(command=message.text)
@@ -299,8 +311,7 @@ async def listen_help_command(message: types.Message):
299311
_message = await bot.reply_to(
300312
message,
301313
text=formatting.format_text(
302-
formatting.mbold("🥕 Help"),
303-
escape_markdown(help_message()),
314+
telegramify_markdown.convert(help_message()),
304315
separator="\n",
305316
),
306317
parse_mode="MarkdownV2",

app/sender/telegram/event.py

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,22 @@
77

88
def help_message():
99
return """
10-
/help - show help message
11-
/chat - just want to chat with me
12-
/task - chat with function_enable
13-
/ask - chat with function_disable
14-
/tool - check all useful tools
15-
/clear - clear the chat history
16-
/auth - auth the tool_call
17-
/learn - set your system prompt, reset by `/learn reset`
10+
# Command List
1811
19-
Private Chat Only:
20-
/login - login via url or something
21-
/env - set v-env split by ; , use `/env ENV=NONE` to disable a env.
12+
`/help` - show help message
13+
`/chat` - just want to chat with me
14+
`/task` - chat with function_enable
15+
`/ask` - chat with function_disable
16+
`/tool` - check all useful tools
17+
`/clear` - clear the chat history
18+
`/auth` - auth the tool_call
19+
`/learn` - set your system prompt, reset by `/learn reset`
2220
23-
!Please confirm that that bot instance is secure, some plugins may be dangerous on unsafe instance.
21+
**Private Chat Only**
22+
23+
`/login` - login via url or something
24+
`/logout` - clear credential
25+
`/env` - set v-env split by ; , use `/env ENV=NONE` to disable a env.
26+
27+
> Please confirm that that bot instance is secure, some plugins may be dangerous on unsafe instance, wink~
2428
"""

app/sender/util_func.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,18 @@ async def login(uid: str, arg_string) -> str:
220220
return error
221221

222222

223+
async def logout(uid: str) -> str:
224+
"""
225+
Logout
226+
:param uid: uid_make
227+
:return: str message
228+
"""
229+
user = await USER_MANAGER.read(user_id=uid)
230+
user.credential = None
231+
await USER_MANAGER.save(user_model=user)
232+
return telegramify_markdown.convert("Logout success! Welcome back master!")
233+
234+
223235
class TimerObjectContainer:
224236
def __init__(self):
225237
self.users = {}

0 commit comments

Comments
 (0)