readme and moved magic numbers to env vars
This commit is contained in:
parent
6ed775f2c4
commit
3de4b9d98e
25
README.md
Normal file
25
README.md
Normal file
@ -0,0 +1,25 @@
|
||||
# SoundFX 2
|
||||
## The complete (second) Rust rewrite of SoundFX
|
||||
|
||||
SoundFX 2 is the Rust rewrite of SoundFX. SoundFX 2 attempts to retain all functionality of the original bot, in a more
|
||||
efficient and robust package. SoundFX 2 is as asynchronous as it can get, and runs on the Tokio runtime.
|
||||
|
||||
### Building
|
||||
|
||||
Use the Cargo.toml file to build it. Simple as. Don't need any shit like MySQL libs and stuff because SQLx includes its
|
||||
own pure Rust one. Needs Rust 1.43+
|
||||
|
||||
### Running & Config
|
||||
|
||||
The bot connects to the MySQL server URL defined in a `.env` file in the working directory of the program.
|
||||
|
||||
Config options:
|
||||
* `DISCORD_TOKEN`- your token (required)
|
||||
* `DATABASE_URL`- your database URL (required)
|
||||
* `DISCONNECT_CYCLES`- specifies the number of inactivity cycles before the bot should disconnect itself from a voice channel
|
||||
* `DISCONNECT_CYCLE_LENGTH`- specifies the delay between cleanup cycles
|
||||
* `MAX_SOUNDS`- specifies how many sounds a user should be allowed without Patreon
|
||||
* `PATREON_GUILD`- specifies the ID of the guild being used for Patreon benefits
|
||||
* `PATREON_ROLE`- specifies the role being checked for Patreon benefits
|
||||
* `CACHING_LOCATION`- specifies the location in which to cache the audio files (defaults to `/tmp/`)
|
||||
|
17
src/main.rs
17
src/main.rs
@ -103,6 +103,11 @@ lazy_static! {
|
||||
dotenv().unwrap();
|
||||
env::var("PATREON_ROLE").unwrap().parse::<u64>().unwrap()
|
||||
};
|
||||
|
||||
static ref DISCONNECT_CYCLES: u8 = {
|
||||
dotenv().unwrap();
|
||||
env::var("DISCONNECT_CYCLES").unwrap_or("2").parse::<u64>().unwrap()
|
||||
};
|
||||
}
|
||||
|
||||
#[group]
|
||||
@ -617,7 +622,7 @@ async fn play_audio(sound: &mut Sound, guild: GuildData, handler: &mut VoiceHand
|
||||
sound.plays += 1;
|
||||
sound.commit(pool).await?;
|
||||
|
||||
voice_guilds.insert(GuildId(guild.id), 1);
|
||||
voice_guilds.insert(GuildId(guild.id), *DISCONNECT_CYCLES);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
@ -668,18 +673,22 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
|
||||
let cvm = Arc::clone(&client.voice_manager);
|
||||
|
||||
let disconnect_cycle_delay = env::var("DISCONNECT_CYCLE_DELAY")
|
||||
.unwrap_or("300".to_string())
|
||||
.parse::<u64>()?;
|
||||
|
||||
// select on the client and client auto disconnector (when the client terminates, terminate the disconnector
|
||||
tokio::select! {
|
||||
_ = client.start() => {}
|
||||
_ = disconnect_from_inactive(cvm, voice_guilds) => {}
|
||||
_ = disconnect_from_inactive(cvm, voice_guilds, disconnect_cycle_delay) => {}
|
||||
};
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn disconnect_from_inactive(voice_manager_mutex: Arc<SerenityMutex<ClientVoiceManager>>, voice_guilds: Arc<Mutex<HashMap<GuildId, u8>>>) {
|
||||
async fn disconnect_from_inactive(voice_manager_mutex: Arc<SerenityMutex<ClientVoiceManager>>, voice_guilds: Arc<Mutex<HashMap<GuildId, u8>>>, wait_time: u64) {
|
||||
loop {
|
||||
time::delay_for(Duration::from_secs(30)).await;
|
||||
time::delay_for(Duration::from_secs(wait_time)).await;
|
||||
|
||||
let mut voice_guilds_acquired = voice_guilds.lock().await;
|
||||
let mut voice_manager = voice_manager_mutex.lock().await;
|
||||
|
Loading…
Reference in New Issue
Block a user