Skip to content

Commit

Permalink
feat: Remove poll command
Browse files Browse the repository at this point in the history
  • Loading branch information
oSumAtrIX committed Jan 21, 2024
1 parent b9b7eee commit dc0b760
Show file tree
Hide file tree
Showing 15 changed files with 1 addition and 399 deletions.
10 changes: 0 additions & 10 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,3 @@
DISCORD_AUTHORIZATION_TOKEN=
# The connection string to the MongoDB database
MONGODB_URI=''

# The api server for the poll command
API_SERVER=''
# The client id for the api
API_CLIENT_ID=''
# The client secret for the api
API_CLIENT_SECRET=''

# The poll secret used for the poll command
POLL_SECRET=''
68 changes: 0 additions & 68 deletions src/api/client.rs

This file was deleted.

3 changes: 0 additions & 3 deletions src/api/mod.rs

This file was deleted.

6 changes: 0 additions & 6 deletions src/api/model/auth.rs

This file was deleted.

1 change: 0 additions & 1 deletion src/api/model/mod.rs

This file was deleted.

30 changes: 0 additions & 30 deletions src/api/routing.rs

This file was deleted.

51 changes: 0 additions & 51 deletions src/commands/misc.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
use poise::serenity_prelude::{CreateActionRow, CreateAllowedMentions, CreateButton, ReactionType};
use poise::{CreateReply, ReplyHandle};

use crate::utils::message::clone_message;
use crate::{Context, Error};

/// Make the Discord bot sentient.
Expand Down Expand Up @@ -50,52 +48,3 @@ pub async fn reply(
send_ephermal(&ctx, &format!("Response: {message}")).await?;
Ok(())
}

/// Start a poll.
#[poise::command(slash_command)]
pub async fn poll(
ctx: Context<'_>,
#[description = "The id of the poll"] id: u64, /* This is currently unused in the API, leaving as a placeholder in case it is required. */
#[description = "A link to a message to clone"] message_link: String,
#[description = "The minumum server age in days to allow members to poll"] age: u16,
#[description = "Enable pings"] ping: bool,
) -> Result<(), Error> {
let get_id =
|segments: &mut std::str::Split<char>| segments.next_back().unwrap().parse::<u64>();

let url = reqwest::Url::parse(&message_link)?;
let mut segments = url.path_segments().ok_or("Invalid Discord message link")?;

if segments.clone().count() != 4 {
return Err("Invalid Discord message link".into());
}

let message_id = get_id(&mut segments)?;
let channel_id = get_id(&mut segments)?;

let message = ctx
.serenity_context()
.http
.get_message(channel_id.into(), message_id.into())
.await?;

let message = clone_message(&message).components(vec![CreateActionRow::Buttons(vec![
CreateButton::new(format!("poll:{id}:{age}"))
.label("Vote")
.emoji(ReactionType::Unicode("🗳️".to_string())),
])]);

ctx.send(if ping {
message.allowed_mentions(
CreateAllowedMentions::default()
.all_roles(true)
.all_users(true)
.everyone(true),
)
} else {
message
})
.await?;

Ok(())
}
15 changes: 0 additions & 15 deletions src/db/model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,21 +23,6 @@ pub struct LockedChannel {
pub overwrites: Option<Vec<PermissionOverwrite>>,
}

#[skip_serializing_none]
#[derive(Serialize, Deserialize, Debug, Default)]
pub struct Poll {
pub author: Option<PollAuthor>,
pub image_url: Option<String>,
pub votes: Option<u16>,
}

#[skip_serializing_none]
#[derive(Serialize, Deserialize, Debug, Default)]
pub struct PollAuthor {
pub name: Option<String>,
pub id: Option<u64>,
}

impl From<Muted> for Document {
fn from(muted: Muted) -> Self {
to_document(&muted)
Expand Down
54 changes: 0 additions & 54 deletions src/events/interaction.rs

This file was deleted.

4 changes: 0 additions & 4 deletions src/events/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ use tokio::sync::RwLock;

mod guild_member_addition;
mod guild_member_update;
mod interaction;
mod message_create;
mod ready;

Expand All @@ -28,9 +27,6 @@ pub async fn event_handler(
new,
..
} => guild_member_update::guild_member_update(ctx, old_if_available, new).await,
serenity::FullEvent::InteractionCreate { interaction } => {
interaction::interaction_create(ctx, interaction, data).await?
},
_ => {},
}
Ok(())
Expand Down
2 changes: 1 addition & 1 deletion src/events/ready.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ pub async fn load_muted_members(ctx: &serenity::Context, data: &Arc<RwLock<Data>
guild_id.into(),
user_id.into(),
mute_role_id,
amount_left as u64, // i64 as u64 is handled properly here
amount_left as u64,
),
);
}
Expand Down
11 changes: 0 additions & 11 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ use std::collections::HashMap;
use std::env;
use std::sync::Arc;

use api::client::Api;
use commands::{configuration, misc, moderation};
use db::database::Database;
use events::event_handler;
Expand All @@ -15,7 +14,6 @@ use utils::bot::load_configuration;

use crate::model::application::Configuration;

mod api;
mod commands;
mod db;
mod events;
Expand All @@ -35,8 +33,6 @@ pub struct Data {
configuration: Configuration,
database: Arc<Database>,
pending_unmutes: HashMap<u64, JoinHandle<Result<(), Error>>>,
poll_secret: String,
api: Api,
}

#[tokio::main]
Expand All @@ -54,7 +50,6 @@ async fn main() {
moderation::ban(),
moderation::unban(),
misc::reply(),
misc::poll(),
];
poise::set_qualified_names(&mut commands);

Expand Down Expand Up @@ -92,12 +87,6 @@ async fn main() {
.unwrap(),
),
pending_unmutes: HashMap::new(),
poll_secret: env::var("POLL_SECRET").unwrap(),
api: Api::new(
reqwest::Url::parse(&env::var("API_SERVER").unwrap()).unwrap(),
env::var("API_CLIENT_ID").unwrap(),
env::var("API_CLIENT_SECRET").unwrap(),
),
})))
})
})
Expand Down
52 changes: 0 additions & 52 deletions src/utils/message.rs

This file was deleted.

0 comments on commit dc0b760

Please sign in to comment.