Skip to content

Commit 3861eba

Browse files
committed
update
1 parent 24c166c commit 3861eba

File tree

2 files changed

+64
-7
lines changed

2 files changed

+64
-7
lines changed

src/ai_message.rs

Lines changed: 61 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -69,18 +69,62 @@ impl Tool for Memory {
6969
}
7070
}
7171

72+
#[derive(Serialize)]
73+
struct MemoryRemove(#[serde(skip)] r2d2::Pool<SqliteConnectionManager>, u64);
74+
7275
#[derive(Serialize)]
7376
struct SocialCredit(#[serde(skip)] r2d2::Pool<SqliteConnectionManager>, u64);
7477

78+
#[derive(Deserialize, Serialize, Debug)]
79+
struct MemoryRemoveArgs {
80+
memory_name: String,
81+
}
82+
83+
impl Tool for MemoryRemove {
84+
const NAME: &'static str = "memory_remove";
85+
type Error = ToolError;
86+
type Args = MemoryRemoveArgs;
87+
type Output = ();
88+
89+
async fn definition(&self, _prompt: String) -> ToolDefinition {
90+
serde_json::from_value(json!({
91+
"name": "memory_remove",
92+
"description": "Remove a memory for the user you are responding to, by name.",
93+
"parameters": {
94+
"type": "object",
95+
"properties": {
96+
"memory_name": {
97+
"type": "string",
98+
"description": "The name of the memory to remove"
99+
}
100+
},
101+
"required": ["memory_name"]
102+
}
103+
}))
104+
.expect("Tool Definition")
105+
}
106+
107+
async fn call(&self, args: Self::Args) -> Result<Self::Output, Self::Error> {
108+
let conn = self.0.get()?;
109+
conn.execute(
110+
"DELETE FROM memory WHERE user_id = ? AND key = ?",
111+
params![self.1, args.memory_name],
112+
)
113+
.map_err(|err| color_eyre::eyre::eyre!("Failed to execute SQL query: {}", err))?;
114+
Ok(())
115+
}
116+
}
117+
75118
#[derive(Deserialize, Serialize, Debug)]
76119
struct SocialCreditArgs {
77120
social_credit: i64,
121+
remove: Option<bool>,
78122
}
79123
impl Tool for SocialCredit {
80124
const NAME: &'static str = "social_credit";
81125
type Error = ToolError;
82126
type Args = SocialCreditArgs;
83-
type Output = ();
127+
type Output = i64;
84128

85129
async fn definition(&self, _prompt: String) -> ToolDefinition {
86130
serde_json::from_value(json!({
@@ -92,14 +136,19 @@ impl Tool for SocialCredit {
92136
"social_credit": {
93137
"type": "number",
94138
"description": "The social credit to add or remove use - to remove"
139+
},
140+
"remove": {
141+
"type": "boolean",
142+
"description": "Set to true to remove the social credit"
95143
}
96-
}
144+
},
145+
"required": ["social_credit"]
97146
}
98147
}))
99148
.expect("Tool Definition")
100149
}
101150

102-
async fn call(&self, args: Self::Args) -> Result<Self::Output, Self::Error> {
151+
async fn call(&self, mut args: Self::Args) -> Result<Self::Output, Self::Error> {
103152
let mut user = {
104153
let db = self.0.get()?;
105154
let mut stm = db.prepare("SELECT * FROM user WHERE id = ?").map_err(|err| color_eyre::eyre::eyre!("Failed to prepare SQL query: {}", err))?;
@@ -108,9 +157,14 @@ impl Tool for SocialCredit {
108157
})
109158
.map_err(|err| color_eyre::eyre::eyre!("Failed to query SQL query: {:?}", err)).unwrap()
110159
};
111-
user.social_credit =user.social_credit.wrapping_add(args.social_credit as i64);
160+
161+
if args.remove == Some(true) && args.social_credit > 0 {
162+
args.social_credit = -args.social_credit;
163+
}
164+
165+
user.social_credit += args.social_credit;
112166
user.update_sync(&*self.0.get()?).map_err(|err| color_eyre::eyre::eyre!("Failed to update SQL query: {:?}", err)).unwrap();
113-
Ok(())
167+
Ok(user.social_credit)
114168
}
115169
}
116170

@@ -173,6 +227,7 @@ you also insult egirl_emily, also called emily at any moment you can, if emily t
173227
You also dislike lynith_dev and make it obvious whenever he asks you something. \
174228
If you find out soemthing something interesting about the person you are talking to save it for example the person likes cars or a particulair software language. \
175229
If someone says something abouit someone else also remember that that person said that so you can use it to your advantage. \
230+
If you see useless memories you can remove them without hesitation.
176231
Do not start your messages with The Trickster:, We know you are talking its automatically prepended
177232
Keep your message to a maximum of 2 sentences. You are replying to {name}.
178233
{name} is level: {level}, xp: {xp}, social credit: {social_credit}. You can use the social credit tool to change {name}'s social credit.
@@ -185,6 +240,7 @@ message context:
185240
{context}", ).replace("\\\n", ""))
186241
.max_tokens(1024)
187242
.tool(Memory(database.clone(), user_id))
243+
.tool(MemoryRemove(database.clone(), user_id))
188244
.tool(SocialCredit(database.clone(), user_id))
189245
.build();
190246

src/commands/level.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ use std::sync::Arc;
55
use serde_rusqlite::{from_row, from_rows};
66
use tokio::sync::Mutex;
77

8+
use twilight_model::{gateway::presence::UserOrId, id::{marker::UserMarker, Id}};
89
use vesper::{
910
prelude::*,
1011
twilight_exports::{InteractionResponse, InteractionResponseData, InteractionResponseType},
@@ -14,8 +15,8 @@ use crate::{database::User, structs::State, utils::levels::xp_required_for_level
1415

1516
#[command]
1617
#[description = "Level "]
17-
pub async fn level(ctx: &SlashContext<'_, Arc<Mutex<State>>>) -> DefaultCommandResult {
18-
let id = ctx.interaction.member.clone().unwrap().user.unwrap().id.get();
18+
pub async fn level(ctx: &SlashContext<'_, Arc<Mutex<State>>>, #[description = "The user to level up"] user: Option<Id<UserMarker>>) -> DefaultCommandResult {
19+
let id = user.unwrap_or(ctx.interaction.member.clone().unwrap().user.unwrap().id).get();
1920
let state = ctx.data.lock().await;
2021

2122
let user = {

0 commit comments

Comments
 (0)