Skip to content

Commit

Permalink
Add bot activity to opts
Browse files Browse the repository at this point in the history
  • Loading branch information
ckcr4lyf committed Jan 23, 2024
1 parent a5f2028 commit 0ac5958
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
3 changes: 2 additions & 1 deletion src/discord.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ use super::stdin;

pub struct Handler {
pub voice_channel_id: String,
pub bot_activity: String,
pub tx: Mutex<mpsc::Sender<bool>>
}

Expand All @@ -19,7 +20,7 @@ impl EventHandler for Handler {
async fn ready(&self, context: Context, _ready: serenity::model::gateway::Ready) {
info!("discord bot is ready");
context.online().await;
context.set_activity(Activity::playing("stdinman")).await; // TODO: Also accept this as config / cli param?
context.set_activity(Activity::playing(self.bot_activity.clone())).await;

let cache_clone = context.cache.clone();
let context_clone = context.clone();
Expand Down
20 changes: 18 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::thread;
use std::{default, thread};

use log::{error, debug};
use songbird::SerenityInit;
Expand All @@ -14,17 +14,21 @@ mod discord;


#[derive(Default, Serialize, Deserialize)]
#[serde(default)] // we need this if we add new fields, otherwise confy will throw error on load (https://github.com/rust-cli/confy/issues/34)
struct StdinmanConfig {
bot_token: String,
voice_channel_id: String,
bot_activity: String
}

#[derive(Parser)]
struct StdinmanArgs {
#[arg(long)]
bot_token: Option<String>,
#[arg(long)]
voice_channel_id: Option<String>
voice_channel_id: Option<String>,
#[arg(long)]
bot_activity: Option<String>,
}

#[tokio::main]
Expand Down Expand Up @@ -67,6 +71,17 @@ async fn main() {
}
};

let bot_activity = match args.bot_activity {
Some(activity) => activity,
None => {
if cfg.bot_activity == "" {
String::from("stdinman")
} else {
cfg.bot_activity
}
}
};

let (tx, rx) = mpsc::channel::<bool>();

// As soon as stdinman is started, data will start to get piped to it (e.g. from ffmpeg)
Expand All @@ -82,6 +97,7 @@ async fn main() {
.register_songbird()
.event_handler(discord::Handler{
voice_channel_id: voice_channel_id,
bot_activity: bot_activity,
tx: tx.into(),
})
.framework(framework)
Expand Down

0 comments on commit 0ac5958

Please sign in to comment.