|
| 1 | +mod commands; |
1 | 2 | use serenity::{
|
2 | 3 | async_trait,
|
| 4 | + builder::{CreateInteractionResponse, CreateInteractionResponseMessage}, |
| 5 | + model::application::{Command,Interaction}, |
3 | 6 | model::channel::Message,
|
4 | 7 | model::{gateway::Ready},
|
5 | 8 | prelude::*,
|
6 | 9 | utils::MessageBuilder, builder::EditMessage
|
7 | 10 | };
|
8 | 11 | use url::{Url, Position};
|
9 | 12 | use regex::Regex;
|
10 |
| -use std::{env, fmt::format}; |
| 13 | +use std::{env}; |
11 | 14 |
|
12 | 15 | struct Handler;
|
13 | 16 |
|
@@ -81,15 +84,39 @@ impl EventHandler for Handler {
|
81 | 84 | }
|
82 | 85 |
|
83 | 86 | }
|
| 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 | + } |
84 | 105 | }
|
85 | 106 |
|
86 | 107 |
|
87 |
| - async fn ready(&self, _: Context, ready: Ready) { |
| 108 | + async fn ready(&self, ctx: Context, ready: Ready) { |
88 | 109 | 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"); |
89 | 115 | }
|
90 | 116 | }
|
91 | 117 |
|
92 | 118 |
|
| 119 | + |
93 | 120 | fn change_link(url: String) -> String {
|
94 | 121 | let issue_list_url = Url::parse(&url);
|
95 | 122 | let mut final_url = "None".to_string();
|
@@ -129,9 +156,12 @@ fn replace_social_media(website: &str) -> &str {
|
129 | 156 | }
|
130 | 157 | }
|
131 | 158 |
|
| 159 | + |
| 160 | + |
| 161 | + |
132 | 162 | #[tokio::main]
|
133 | 163 | 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"); |
135 | 165 | let intents = GatewayIntents::GUILD_MESSAGES
|
136 | 166 | | GatewayIntents::DIRECT_MESSAGES
|
137 | 167 | | GatewayIntents::MESSAGE_CONTENT;
|
|
0 commit comments