Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove .commands #333

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions src/commands/general/delete_interaction.rs
TheKodeToad marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
use poise::serenity_prelude::{InteractionType, Message, Permissions};

use crate::{Context, Error};

#[poise::command(context_menu_command = "Delete command", ephemeral)]
pub async fn delete_interaction(ctx: Context<'_>, message: Message) -> Result<(), Error> {
const NO_COMMAND: &str = "❌ This message does not contain a command";

let Some(interaction) = &message.interaction else {
ctx.say(NO_COMMAND).await?;
return Ok(());
};

if interaction.kind != InteractionType::Command {
ctx.say(NO_COMMAND).await?;
return Ok(());
}

let can_manage = interaction
.member
.as_ref()
.and_then(|m| m.permissions)
.and_then(|p| p.contains(Permissions::MANAGE_MESSAGES).then_some(true))
.is_some();

if interaction.user.id != ctx.author().id && !can_manage {
ctx.say("❌ You cannot delete commands run by other users")
.await?;
return Ok(());
}

message.delete(ctx).await?;
ctx.say("🗑️ Deleted command!").await?;
Ok(())
}
22 changes: 0 additions & 22 deletions src/commands/general/help.rs

This file was deleted.

2 changes: 1 addition & 1 deletion src/commands/general/joke.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use eyre::Result;
use log::trace;

/// It's a joke
#[poise::command(slash_command, prefix_command, track_edits = true)]
#[poise::command(slash_command)]
pub async fn joke(ctx: Context<'_>) -> Result<(), Error> {
trace!("Running joke command");

Expand Down
2 changes: 1 addition & 1 deletion src/commands/general/members.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use poise::serenity_prelude::CreateEmbed;
use poise::CreateReply;

/// Returns the number of members in the server
#[poise::command(slash_command, prefix_command, guild_only = true, track_edits = true)]
#[poise::command(slash_command, guild_only = true)]
pub async fn members(ctx: Context<'_>) -> Result<(), Error> {
trace!("Running members command");

Expand Down
2 changes: 1 addition & 1 deletion src/commands/general/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pub mod help;
pub mod delete_interaction;
pub mod joke;
pub mod members;
pub mod ping;
Expand Down
2 changes: 1 addition & 1 deletion src/commands/general/ping.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use poise::CreateReply;
const PING_PREFIX: &str = "<:catstareback:1078622789885497414> Pong!";

/// Replies with pong!
#[poise::command(slash_command, prefix_command, track_edits = true, ephemeral)]
#[poise::command(slash_command, ephemeral)]
pub async fn ping(ctx: Context<'_>) -> Result<(), Error> {
trace!("Running ping command!");

Expand Down
2 changes: 1 addition & 1 deletion src/commands/general/rory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use poise::serenity_prelude::{CreateEmbed, CreateEmbedFooter};
use poise::CreateReply;

/// Gets a Rory photo!
#[poise::command(slash_command, prefix_command, track_edits = true)]
#[poise::command(slash_command)]
pub async fn rory(
ctx: Context<'_>,
#[description = "specify a Rory ID"] id: Option<u64>,
Expand Down
2 changes: 1 addition & 1 deletion src/commands/general/stars.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use poise::serenity_prelude::CreateEmbed;
use poise::CreateReply;

/// Returns GitHub stargazer count
#[poise::command(slash_command, prefix_command, track_edits = true)]
#[poise::command(slash_command)]
pub async fn stars(ctx: Context<'_>) -> Result<(), Error> {
trace!("Running stars command");
let octocrab = &ctx.data().octocrab;
Expand Down
17 changes: 1 addition & 16 deletions src/commands/general/tag.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,7 @@ fn tags() -> &'static Vec<Tag> {
}

/// Send a tag
#[poise::command(
slash_command,
prefix_command,
track_edits = true,
help_text_fn = help
)]
#[poise::command(slash_command)]
pub async fn tag(
ctx: Context<'_>,
#[description = "the tag to send"] name: Choice,
Expand Down Expand Up @@ -78,13 +73,3 @@ pub async fn tag(

Ok(())
}

fn help() -> String {
let tag_list = tags()
.iter()
.map(|tag| format!("`{}`", tag.id))
.collect::<Vec<String>>()
.join(", ");

format!("Available tags: {tag_list}")
}
2 changes: 1 addition & 1 deletion src/commands/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ pub type Command = poise::Command<Data, Error>;

pub fn all() -> Vec<Command> {
vec![
general!(help),
general!(delete_interaction),
general!(joke),
general!(members),
general!(ping),
Expand Down
27 changes: 0 additions & 27 deletions src/handlers/event/delete_on_reaction.rs

This file was deleted.

11 changes: 0 additions & 11 deletions src/handlers/event/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ use poise::serenity_prelude::{ActivityData, Context, FullEvent, OnlineStatus};
use poise::FrameworkContext;

mod analyze_logs;
mod delete_on_reaction;
mod eta;
mod expand_link;
mod give_role;
Expand Down Expand Up @@ -66,16 +65,6 @@ pub async fn handle(
analyze_logs::handle(ctx, new_message, data).await?;
}

FullEvent::ReactionAdd { add_reaction } => {
trace!(
"Received reaction {} on message {} from {}",
add_reaction.emoji,
add_reaction.message_id.to_string(),
add_reaction.user_id.unwrap_or_default().to_string()
);
delete_on_reaction::handle(ctx, add_reaction).await?;
}

FullEvent::ThreadCreate { thread } => {
trace!("Received thread {}", thread.id);
support_onboard::handle(ctx, thread).await?;
Expand Down
14 changes: 2 additions & 12 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
use std::{sync::Arc, time::Duration};
use std::sync::Arc;

use eyre::Context as _;
use log::{info, trace, warn};
use poise::{
serenity_prelude as serenity, EditTracker, Framework, FrameworkOptions, PrefixFrameworkOptions,
};
use poise::{serenity_prelude as serenity, Framework, FrameworkOptions};
use tokio::signal::ctrl_c;
#[cfg(target_family = "unix")]
use tokio::signal::unix::{signal, SignalKind};
Expand Down Expand Up @@ -104,14 +102,6 @@ async fn main() -> eyre::Result<()> {
Box::pin(handlers::handle_event(ctx, event, framework, data))
},

prefix_options: PrefixFrameworkOptions {
prefix: Some(".".into()),
edit_tracker: Some(Arc::from(EditTracker::for_timespan(Duration::from_secs(
3600,
)))),
..Default::default()
},

..Default::default()
};

Expand Down