Skip to content

Commit

Permalink
Add !muteall and !unmuteall
Browse files Browse the repository at this point in the history
  • Loading branch information
xNul committed Sep 13, 2020
1 parent 208a8f4 commit 004267d
Showing 1 changed file with 67 additions and 8 deletions.
75 changes: 67 additions & 8 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
use tokio::net::TcpListener;
use tokio::prelude::*;
use serenity::async_trait;
use serenity::client::{Client, Context, EventHandler};
use serenity::model::channel::Message;
use serenity::model::gateway::{Activity, Ready};
use serenity::framework::standard::{
StandardFramework,
CommandResult,
Expand All @@ -14,24 +13,27 @@ use serenity::framework::standard::{

mod config;

use std::env;

#[group]
#[commands(ping)]
#[commands(ping, muteall, unmuteall, kill, revive, reset)]
struct General;

struct Handler;

#[async_trait]
impl EventHandler for Handler {}
impl EventHandler for Handler {
async fn ready(&self, ctx: Context, ready: Ready) {
println!("{} is connected!", ready.user.name);
ctx.set_activity(Activity::playing("Among Us")).await;
}
}

#[tokio::main]
async fn main() {
let framework = StandardFramework::new()
.configure(|c| c.prefix("!")) // set the bot's prefix to "~"
.group(&GENERAL_GROUP);

let mut client = Client::new(config::token)
let mut client = Client::new(config::TOKEN)
.event_handler(Handler)
.framework(framework)
.await
Expand All @@ -48,4 +50,61 @@ async fn ping(ctx: &Context, msg: &Message) -> CommandResult {
msg.reply(ctx, "Pong!").await?;

Ok(())
}
}

#[command]
async fn muteall(ctx: &Context, msg: &Message) -> CommandResult {
msg.reply(ctx, msg.content.as_str()).await?;

let guild = msg.guild(&ctx.cache).await.unwrap();
let voice_states = guild.voice_states;
let voice_state = voice_states.get(&msg.author.id).unwrap();
let voice_channel_id = voice_state.channel_id.unwrap();
let voice_channel = guild.channels.get(&voice_channel_id).unwrap();
let voice_channel_members = voice_channel.members(&ctx.cache).await.unwrap();

for member in voice_channel_members.iter() {
member.edit(&ctx.http, |em| em.mute(true)).await.unwrap();
}

Ok(())
}

#[command]
async fn unmuteall(ctx: &Context, msg: &Message) -> CommandResult {
msg.reply(ctx, msg.content.as_str()).await?;

let guild = msg.guild(&ctx.cache).await.unwrap();
let voice_states = guild.voice_states;
let voice_state = voice_states.get(&msg.author.id).unwrap();
let voice_channel_id = voice_state.channel_id.unwrap();
let voice_channel = guild.channels.get(&voice_channel_id).unwrap();
let voice_channel_members = voice_channel.members(&ctx.cache).await.unwrap();

for member in voice_channel_members.iter() {
member.edit(&ctx.http, |em| em.mute(false)).await.unwrap();
}

Ok(())
}

#[command]
async fn kill(ctx: &Context, msg: &Message) -> CommandResult {
msg.reply(ctx, msg.content.as_str()).await?;

Ok(())
}

#[command]
async fn revive(ctx: &Context, msg: &Message) -> CommandResult {
msg.reply(ctx, msg.content.as_str()).await?;

Ok(())
}

#[command]
async fn reset(ctx: &Context, msg: &Message) -> CommandResult {
msg.reply(ctx, msg.content.as_str()).await?;

Ok(())
}

0 comments on commit 004267d

Please sign in to comment.