permissions

This commit is contained in:
jude 2022-05-05 09:55:44 +01:00
parent 0df5466052
commit d82cbf2fd6
8 changed files with 475 additions and 321 deletions

View File

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="dataSourceStorageLocal" created-in="CL-213.6777.58">
<component name="dataSourceStorageLocal" created-in="CL-221.5080.224">
<data-source name="MySQL for 5.1 - soundfx@localhost" uuid="1067c1d0-1386-4a39-b3f5-6d48d6f279eb">
<database-info product="" version="" jdbc-version="" driver-name="" driver-version="" dbms="MYSQL" exact-version="0" />
<secret-storage>master_key</secret-storage>

749
Cargo.lock generated

File diff suppressed because it is too large Load Diff

View File

@ -6,7 +6,7 @@ edition = "2018"
[dependencies]
songbird = { git = "https://github.com/serenity-rs/songbird", branch = "next", features = ["builtin-queue"] }
poise = { git = "https://github.com/kangalioo/poise", branch = "master" }
poise = { git = "https://github.com/jellywx/poise", branch = "jellywx-pv2" }
sqlx = { version = "0.5", default-features = false, features = ["runtime-tokio-rustls", "macros", "mysql", "bigdecimal"] }
dotenv = "0.15"
tokio = { version = "1", features = ["fs", "process", "io-util"] }
@ -17,3 +17,6 @@ regex = "1.4"
log = "0.4"
serde_json = "1.0"
dashmap = "4.0"
[patch."https://github.com/serenity-rs/serenity"]
serenity = { git = "https://github.com//serenity-rs/serenity", branch = "current" }

View File

@ -9,7 +9,12 @@ use crate::{
};
/// Upload a new sound to the bot
#[poise::command(slash_command, rename = "upload", category = "Manage")]
#[poise::command(
slash_command,
rename = "upload",
category = "Manage",
required_permissions = "MANAGE_GUILD"
)]
pub async fn upload_new_sound(
ctx: Context<'_>,
#[description = "Name to upload sound to"] name: String,

View File

@ -2,14 +2,15 @@ use poise::serenity::{
builder::CreateActionRow, model::interactions::message_component::ButtonStyle,
};
use crate::models::guild_data::CtxGuildData;
use crate::utils::{join_channel, queue_audio};
use crate::{
cmds::autocomplete_sound, models::sound::SoundCtx, utils::play_from_query, Context, Error,
cmds::autocomplete_sound,
models::{guild_data::CtxGuildData, sound::SoundCtx},
utils::{join_channel, play_from_query, queue_audio},
Context, Error,
};
/// Play a sound in your current voice channel
#[poise::command(slash_command)]
#[poise::command(slash_command, required_permissions = "SPEAK")]
pub async fn play(
ctx: Context<'_>,
#[description = "Name or ID of sound to play"]
@ -35,7 +36,7 @@ pub async fn play(
}
/// Play up to 25 sounds on queue
#[poise::command(slash_command, rename = "queue")]
#[poise::command(slash_command, rename = "queue", required_permissions = "SPEAK")]
pub async fn queue_play(
ctx: Context<'_>,
#[description = "Name or ID for queue position 1"]
@ -196,7 +197,7 @@ pub async fn queue_play(
}
/// Loop a sound in your current voice channel
#[poise::command(slash_command, rename = "loop")]
#[poise::command(slash_command, rename = "loop", required_permissions = "SPEAK")]
pub async fn loop_play(
ctx: Context<'_>,
#[description = "Name or ID of sound to loop"]
@ -222,7 +223,12 @@ pub async fn loop_play(
}
/// Get a menu of sounds with buttons to play them
#[poise::command(slash_command, rename = "soundboard", category = "Play")]
#[poise::command(
slash_command,
rename = "soundboard",
category = "Play",
required_permissions = "SPEAK"
)]
pub async fn soundboard(
ctx: Context<'_>,
#[description = "Name or ID of sound for button 1"]

View File

@ -3,7 +3,7 @@ use songbird;
use crate::{Context, Error};
/// Stop the bot from playing and clear the play queue
#[poise::command(slash_command, rename = "stop")]
#[poise::command(slash_command, rename = "stop", required_permissions = "MANAGE_GUILD")]
pub async fn stop_playing(ctx: Context<'_>) -> Result<(), Error> {
let songbird = songbird::get(ctx.discord()).await.unwrap();
let call_opt = songbird.get(ctx.guild_id().unwrap());
@ -20,7 +20,7 @@ pub async fn stop_playing(ctx: Context<'_>) -> Result<(), Error> {
}
/// Disconnect the bot
#[poise::command(slash_command)]
#[poise::command(slash_command, required_permissions = "SPEAK")]
pub async fn disconnect(ctx: Context<'_>) -> Result<(), Error> {
let songbird = songbird::get(ctx.discord()).await.unwrap();
let _ = songbird.leave(ctx.guild_id().unwrap()).await;

View File

@ -63,7 +63,7 @@ pub async fn listener(ctx: &Context, event: &poise::Event<'_>, data: &Data) -> R
if let Some(channel_id) = past_state.channel_id {
if let Some(Channel::Guild(channel)) = channel_id.to_channel_cached(&ctx) {
if channel.members(&ctx).await.map(|m| m.len()).unwrap_or(0) <= 1 {
let songbird = songbird::get(&ctx).await.unwrap();
let songbird = songbird::get(ctx).await.unwrap();
let _ = songbird.remove(guild_id).await;
}

View File

@ -145,11 +145,8 @@ async fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
})
})
.options(options)
.client_settings(move |client_builder| {
client_builder
.client_settings(move |client_builder| client_builder.register_songbird())
.intents(GatewayIntents::GUILD_VOICE_STATES | GatewayIntents::GUILDS)
.register_songbird()
})
.run_autosharded()
.await?;