mirror of
https://github.com/dsec-hub/dsec-discord-bot.git
synced 2026-09-22 07:44:26 +00:00
Merge pull request #3 from dsec-hub/new_thread_title
updated gitignore, updated thread title to be leetcode titles
This commit is contained in:
commit
b83ba5428d
2 changed files with 26 additions and 3 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
|
@ -1,2 +1,3 @@
|
||||||
/target
|
/target
|
||||||
.env
|
.env
|
||||||
|
.env.*
|
||||||
|
|
|
||||||
|
|
@ -62,8 +62,30 @@ async fn create_leetcode_thread(
|
||||||
let current_channel_id = &new_message.channel_id;
|
let current_channel_id = &new_message.channel_id;
|
||||||
|
|
||||||
if leetcode_channel_id.eq(current_channel_id) {
|
if leetcode_channel_id.eq(current_channel_id) {
|
||||||
let new_thread = serenity::CreateThread::new("🧠 DSEC LeetCode Challenge Answers");
|
fn create_title_from_message(message: impl Into<String>) -> String {
|
||||||
current_channel_id.create_thread_from_message(ctx, new_message.id, new_thread).await?;
|
let message_string: String = message.into();
|
||||||
|
|
||||||
|
let title = message_string
|
||||||
|
.lines()
|
||||||
|
.next()
|
||||||
|
.map(|line| {
|
||||||
|
let start = line
|
||||||
|
.char_indices()
|
||||||
|
.nth(2)
|
||||||
|
.map(|(i, _)| i)
|
||||||
|
.unwrap_or(line.len());
|
||||||
|
&line[start..]
|
||||||
|
})
|
||||||
|
.unwrap_or("")
|
||||||
|
.to_string();
|
||||||
|
title
|
||||||
|
}
|
||||||
|
|
||||||
|
let new_thread =
|
||||||
|
serenity::CreateThread::new(create_title_from_message(&new_message.content));
|
||||||
|
current_channel_id
|
||||||
|
.create_thread_from_message(ctx, new_message.id, new_thread)
|
||||||
|
.await?;
|
||||||
};
|
};
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue