Skip to content

Commit e08d3b7

Browse files
use format macro instead of push_str in chat command where possible
1 parent 42a22f9 commit e08d3b7

1 file changed

Lines changed: 13 additions & 11 deletions

File tree

src/commands/textgen/chat.rs

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -110,11 +110,12 @@ pub async fn chat(ctx: Context<'_>, message: String) -> Result<(), Error> {
110110
pub async fn search_searx(value: Value) -> Result<String, DynError> {
111111
let query = value["query"].as_str().expect("u suhhhh");
112112

113-
let query_encoded: String = urlencoding::encode(query).into_owned();
113+
let query_encoded: String = urlencoding::encode(query).to_string();
114114

115-
let mut full_url_query: String = "https://searx.clowdertech.com/search?q=".to_owned();
116-
full_url_query.push_str(query_encoded.as_str());
117-
full_url_query.push_str("&format=json");
115+
let full_url_query = format!(
116+
"https://searx.clowdertech.com/search?q={}&format=json",
117+
query_encoded.as_str()
118+
);
118119

119120
let response = reqwest::get(full_url_query).await.unwrap();
120121

@@ -123,15 +124,16 @@ pub async fn search_searx(value: Value) -> Result<String, DynError> {
123124
let response_json: serde_json::Value =
124125
serde_json::from_str(response_text.as_str()).expect("JSON was ass bro wtf");
125126

126-
let mut final_result: String = "".to_owned();
127+
let mut final_result = "".to_string();
127128

128129
for result in response_json["results"].as_array().expect("L rizz") {
129-
final_result.push_str(" --- ");
130-
final_result.push_str(result["url"].as_str().expect("L rizz"));
131-
final_result.push_str(" - ");
132-
final_result.push_str(result["title"].as_str().expect("L rizz"));
133-
final_result.push_str(" - ");
134-
final_result.push_str(result["content"].as_str().expect("L rizz"));
130+
let result_string = format!(
131+
" --- {} - {} - {}",
132+
result["url"].as_str().expect("L rizz"),
133+
result["title"].as_str().expect("L rizz"),
134+
result["content"].as_str().expect("L rizz")
135+
);
136+
final_result.push_str(result_string.as_str());
135137
}
136138

137139
let final_string = final_result.replacen(" --- ", "", 1);

0 commit comments

Comments
 (0)