Skip to content

Commit

Permalink
implement reboot_server command
Browse files Browse the repository at this point in the history
  • Loading branch information
gamersi committed Oct 2, 2024
1 parent 13a6541 commit 73a6441
Show file tree
Hide file tree
Showing 5 changed files with 81 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "mufbot-dc"
version = "0.1.7"
version = "0.1.8"
edition = "2021"
license = "MIT"
authors = ["gamersi <[email protected]>", "xyloflake <[email protected]>"]
Expand Down
1 change: 1 addition & 0 deletions src/discord.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ pub async fn initiate_bot() {
commands::restart::restart(),
commands::version::version(),
commands::clear_rollouts::clear_rollouts(),
commands::reboot_server::reboot_server(),
],
..Default::default()
})
Expand Down
1 change: 1 addition & 0 deletions src/discord/commands.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
pub mod age;
pub mod buildlist;
pub mod clear_rollouts;
pub mod reboot_server;
pub mod restart;
pub mod rollout;
pub mod shutdown;
Expand Down
77 changes: 77 additions & 0 deletions src/discord/commands/reboot_server.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
use poise::serenity_prelude::{
self, Timestamp
};

#[poise::command(
slash_command,
prefix_command
)]

pub async fn reboot_server(
ctx: crate::discord::commands::Context<'_>
) -> Result<
(),
crate::discord::commands::Error
> {

let guild = ctx
.http()
.get_guild(
crate::env::GUILD_ID
.as_str()
.parse()
.unwrap()
)
.await?;

let role = guild
.roles
.get(
&crate::env::ROLE_ID
.as_str()
.parse()
.unwrap()
)
.unwrap();

if !ctx
.author()
.has_role(
ctx.http(),
&guild,
role
)
.await?
{

ctx.say("You don't have permission to use this command")
.await?;

return Ok(());
}

let embed_author = serenity_prelude::CreateEmbedAuthor::new(&ctx.author().name)
.icon_url(ctx.author().avatar_url().unwrap_or_default());

let embed = serenity_prelude::CreateEmbed::default()
.title("Reboot")
.description("rebooting the server...")
.color(0x804fb3)
.author(embed_author)
.timestamp(Timestamp::now());

let reply =
poise::CreateReply::default()
.embed(embed);

ctx.send(reply).await?;

let _ =
std::process::Command::new(
"reboot"
)
.output()
.expect("failed to reboot");

Ok(())
}

0 comments on commit 73a6441

Please sign in to comment.