Started on the roles function, felt around a bit
nothing works yet.
This commit is contained in:
parent
af2f1ef2ea
commit
b2ba7c8b9f
47
src/io.rs
47
src/io.rs
|
|
@ -25,7 +25,7 @@
|
|||
use crate::modules::handler;
|
||||
use crate::votes::EventHolder;
|
||||
use distance::levenshtein;
|
||||
use poise::serenity_prelude::{self as serenity};
|
||||
use poise::serenity_prelude::{self as serenity, EditMember};
|
||||
use poise::Modal as _;
|
||||
|
||||
use crate::error_handling::IdleError;
|
||||
|
|
@ -355,6 +355,43 @@ pub async fn long_vote(
|
|||
// .await?;
|
||||
Ok(())
|
||||
}
|
||||
#[poise::command(slash_command, prefix_command)]
|
||||
async fn add_role(
|
||||
ctx: Context<'_>,
|
||||
#[description = "Role"] role: serenity::Role,
|
||||
) -> Result<(), GenericError> {
|
||||
if ctx
|
||||
.author()
|
||||
.has_role(ctx, ctx.guild_id().unwrap(), &role)
|
||||
.await?
|
||||
{
|
||||
ctx.reply(format!("User does have role {}.", &role)).await?;
|
||||
let builder = EditMember::new();
|
||||
|
||||
ctx.http()
|
||||
.remove_member_role(
|
||||
ctx.guild().unwrap().id,
|
||||
ctx.author().id,
|
||||
role.id,
|
||||
Some(&"Self requested."),
|
||||
)
|
||||
.await?;
|
||||
|
||||
// let id = ctx.author().id;
|
||||
// let invoker = ctx.guild_id().unwrap().member(ctx.http(), id);
|
||||
|
||||
// ctx.guild_id()
|
||||
// .unwrap()
|
||||
// .edit_member(ctx.http(), ctx.author().id, builder)
|
||||
// .roles()
|
||||
// .await?;
|
||||
} else {
|
||||
ctx.reply(format!("User doesn't have role {}.", &role))
|
||||
.await?;
|
||||
}
|
||||
// ctx.reply("you did it! you added a role").await?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// The main discord interaction loop
|
||||
///
|
||||
|
|
@ -366,7 +403,13 @@ pub async fn discord_main_loop(event_holder: EventHolder) {
|
|||
let intents = serenity::GatewayIntents::non_privileged();
|
||||
let framework = poise::Framework::builder()
|
||||
.options(poise::FrameworkOptions {
|
||||
commands: vec![vote_command(), vote_modal(), short_vote(), long_vote()],
|
||||
commands: vec![
|
||||
vote_command(),
|
||||
vote_modal(),
|
||||
short_vote(),
|
||||
long_vote(),
|
||||
add_role(),
|
||||
],
|
||||
..Default::default()
|
||||
})
|
||||
.setup(|ctx, _ready, framework| {
|
||||
|
|
|
|||
|
|
@ -27,7 +27,7 @@ use poise::serenity_prelude::{self, CacheHttp, ChannelId};
|
|||
#[cfg(not(tarpaulin_include))] // This loop is untestable instead the logic is kept to the minimal
|
||||
pub async fn main_scheduler_loop(mut interval: tokio::time::Interval, ev_ctx: EventHolder) {
|
||||
loop {
|
||||
fk_around(&ev_ctx).await;
|
||||
// fk_around(&ev_ctx).await;
|
||||
interval.tick().await;
|
||||
// tokio::spawn(async {watchdog_update().await;}); // For async task
|
||||
let ev = ev_ctx.clone();
|
||||
|
|
|
|||
|
|
@ -0,0 +1,21 @@
|
|||
# Refresh roles setup
|
||||
Admin-only command
|
||||
## Prepwork
|
||||
- Retrieve all roles
|
||||
- Separe them in groups of X (maximum per message)
|
||||
- Make sure we know which messages to delete (probably will be a bot-only channel so all messages should be fine)
|
||||
|
||||
## Command execution
|
||||
- Delete all messages (only the right ones)
|
||||
- Repost all messages
|
||||
- We need as many messages as will fit all the buttons
|
||||
- (optional) last message "new roles XXX" with links to where the buttons are?
|
||||
|
||||
## Buttons
|
||||
- One button per role
|
||||
- Toggles role on-click
|
||||
|
||||
# Add / Remove roles
|
||||
- /roles_add and /roles_remove with an option fed from list of roles
|
||||
- if possible, as many options as people want
|
||||
- /roles_list returns a list of all user roles
|
||||
Loading…
Reference in New Issue