Skip to content

Commit 91b645b

Browse files
committed
Added /source command
1 parent 620a9c5 commit 91b645b

File tree

3 files changed

+39
-3
lines changed

3 files changed

+39
-3
lines changed

src/commands/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
pub mod source;

src/commands/source.rs

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
use serenity::builder::CreateCommand;
2+
3+
pub fn register() -> CreateCommand {
4+
CreateCommand::new("source").description("Send github link")
5+
}

src/main.rs

+33-3
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
1+
mod commands;
12
use serenity::{
23
async_trait,
4+
builder::{CreateInteractionResponse, CreateInteractionResponseMessage},
5+
model::application::{Command,Interaction},
36
model::channel::Message,
47
model::{gateway::Ready},
58
prelude::*,
69
utils::MessageBuilder, builder::EditMessage
710
};
811
use url::{Url, Position};
912
use regex::Regex;
10-
use std::{env, fmt::format};
13+
use std::{env};
1114

1215
struct Handler;
1316

@@ -81,15 +84,39 @@ impl EventHandler for Handler {
8184
}
8285

8386
}
87+
88+
89+
}
90+
async fn interaction_create(&self, ctx: Context, interaction: Interaction){
91+
if let Interaction::Command(command) = interaction {
92+
println!("Interaction received");
93+
match command.data.name.as_str(){
94+
"source" => {
95+
let data = CreateInteractionResponseMessage::new().content("https://github.com/Guilamb/interspecies-reviewer/issues");
96+
let builder = CreateInteractionResponse::Message(data);
97+
if let Err(why) = command.create_response(&ctx.http, builder).await {
98+
println!("Cannot respond to slash command: {why}");
99+
}
100+
},
101+
_ => println!("Not implemented"),
102+
103+
};
104+
}
84105
}
85106

86107

87-
async fn ready(&self, _: Context, ready: Ready) {
108+
async fn ready(&self, ctx: Context, ready: Ready) {
88109
println!("{} is connected!", ready.user.name);
110+
111+
112+
Command::create_global_command(&ctx.http, commands::source::register())
113+
.await
114+
.expect("Failed to create global command");
89115
}
90116
}
91117

92118

119+
93120
fn change_link(url: String) -> String {
94121
let issue_list_url = Url::parse(&url);
95122
let mut final_url = "None".to_string();
@@ -129,9 +156,12 @@ fn replace_social_media(website: &str) -> &str {
129156
}
130157
}
131158

159+
160+
161+
132162
#[tokio::main]
133163
async fn main() {
134-
let token = env::var("DISCORD_TOKEN").expect("Token not found");
164+
let token = env::var("DISCORD_TOKEN").expect("Token not found");
135165
let intents = GatewayIntents::GUILD_MESSAGES
136166
| GatewayIntents::DIRECT_MESSAGES
137167
| GatewayIntents::MESSAGE_CONTENT;

0 commit comments

Comments
 (0)