Skip to content

Commit

Permalink
Merge pull request #12 from Romira915/feature/trim-mentions
Browse files Browse the repository at this point in the history
fix: trim mentions
  • Loading branch information
Romira915 authored Sep 28, 2022
2 parents 182e4f8 + a97e600 commit d8c549b
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 5 deletions.
9 changes: 5 additions & 4 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions discord_bot_client/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ log = "0.4.14"
nix = "0.25.0"
openssl = {version = "0.10.41", features = ["vendored"]}
rand = {version = "0.8.5", features = ["alloc"]}
regex = "1.6.0"
reqwest = {version = "0.11.4", features = ["json"]}
serde = "1.0.126"
serde_json = "1.0.66"
Expand Down
7 changes: 6 additions & 1 deletion discord_bot_client/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use commands::{conversation::*, simple::*};
use log::{debug, error, info};

use rand::{distributions::WeightedIndex, prelude::*};
use regex::Regex;
use serde_json::{json, Value};
use serenity::{
async_trait,
Expand Down Expand Up @@ -80,6 +81,10 @@ impl EventHandler for Handler {
log::info!("Hit 会話AI");
let typing = msg.channel_id.start_typing(&ctx.http).unwrap();

let regex: Regex = Regex::new("<@\\d+>").unwrap();
let tmp = regex.replace_all(&content, "");
let content_without_mentions = tmp.trim_start();

let client = reqwest::Client::new();
log::info!("Request to CCE");
let resp = client
Expand All @@ -91,7 +96,7 @@ impl EventHandler for Handler {
config.secret().rinna_cce_subscription_key(),
)
.json(&json!({
"rawInput": format!("B: {}A:",&content),
"rawInput": format!("B: {}A:", content_without_mentions),
"outputLength": 30
}))
.send()
Expand Down

0 comments on commit d8c549b

Please sign in to comment.