Switch to stable toolchain and add more info to stats command

Signed-off-by: trivernis <trivernis@protonmail.com>
pull/13/head
trivernis 4 years ago
parent 8e71317d51
commit 786925d8e4
Signed by: Trivernis
GPG Key ID: DFFFCC2C7A02DB45

@ -14,7 +14,7 @@ jobs:
- name: Set up toolchain
uses: actions-rs/toolchain@v1
with:
toolchain: nightly
toolchain: stable
override: true
- name: Cache cargo builds
uses: actions/cache@v2

@ -20,7 +20,7 @@ jobs:
- name: Set up toolchain
uses: actions-rs/toolchain@v1
with:
toolchain: nightly
toolchain: stable
override: true
- name: Cache build data
uses: actions/cache@v2

37
Cargo.lock generated

@ -1,5 +1,7 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
version = 3
[[package]]
name = "adler"
version = "1.0.2"
@ -1734,6 +1736,25 @@ version = "0.3.24"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dcf128d1287d2ea9d80910b5f1120d0b8eede3fbf1abe91c40d39ea7d51e6fda"
[[package]]
name = "rustc_version"
version = "0.2.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "138e3e0acb6c9fb258b19b67cb8abd63c00679d2851805ea151465464fe9030a"
dependencies = [
"semver",
]
[[package]]
name = "rustc_version_runtime"
version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4076135c155c07b05e4ab54ba0834aca3fc6a5a01610a2339f5ef3223cf8dee5"
dependencies = [
"rustc_version",
"semver",
]
[[package]]
name = "rustls"
version = "0.19.0"
@ -1860,6 +1881,21 @@ dependencies = [
"markup5ever_rcdom",
]
[[package]]
name = "semver"
version = "0.9.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1d7eb9ef2c18661902cc47e535f9bc51b78acd254da71d375c2f6720d9a40403"
dependencies = [
"semver-parser",
]
[[package]]
name = "semver-parser"
version = "0.7.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "388a1df253eca08550bef6c72392cfe7c30914bf41df5269b68cbd6ff8f570a3"
[[package]]
name = "serde"
version = "1.0.125"
@ -2300,6 +2336,7 @@ dependencies = [
"rand 0.8.3",
"regex",
"reqwest",
"rustc_version_runtime",
"sauce-api",
"serde",
"serde_derive",

@ -32,3 +32,4 @@ sysinfo = "0.16.5"
reqwest = "0.11.2"
chrono-tz = "0.5.3"
sauce-api = "0.7.1"
rustc_version_runtime = "0.2.0"

@ -6,3 +6,5 @@ pub mod shuffle;
pub mod string;
/// Utilities to quickly check strings that represent urls
pub mod url;
pub static VERSION: &str = env!("CARGO_PKG_VERSION");

@ -14,6 +14,7 @@ pub mod error;
pub mod models;
pub mod schema;
pub static VERSION: &str = env!("CARGO_PKG_VERSION");
pub use database::Database;
type PoolConnection = Pool<ConnectionManager<PgConnection>>;

@ -3,3 +3,5 @@ pub mod ephemeral_message;
pub mod error;
pub mod macros;
pub mod menu;
pub static VERSION: &str = env!("CARGO_PKG_VERSION");

@ -1,5 +1,5 @@
[toolchain]
channel = "nightly"
channel = "stable"
targets = [
"x86_64-unknown-linux-gnu",
]

@ -99,7 +99,7 @@ async fn after_hook(ctx: &Context, msg: &Message, cmd_name: &str, error: Command
let database = get_database_from_context(ctx).await;
let _ = database
.add_statistic(
env!("CARGO_PKG_VERSION"),
crate::VERSION,
cmd_name,
SystemTime::now(),
error_msg.is_none(),

@ -9,9 +9,9 @@ use serenity::prelude::*;
use sysinfo::{ProcessExt, SystemExt};
use crate::commands::common::handle_autodelete;
use crate::utils::context_data::get_database_from_context;
const VERSION: &'static str = env!("CARGO_PKG_VERSION");
use crate::providers::music::queue::MusicQueue;
use crate::utils::context_data::{get_database_from_context, Store};
use std::sync::Arc;
#[command]
#[description("Shows some statistics about the bot")]
@ -22,6 +22,7 @@ async fn stats(ctx: &Context, msg: &Message) -> CommandResult {
let database = get_database_from_context(ctx).await;
let mut system = sysinfo::System::new_all();
system.refresh_all();
let kernel_version = system.get_kernel_version().unwrap_or("n/a".to_string());
let own_process = system.get_process(process::id() as i32).unwrap();
let memory_usage = own_process.memory();
@ -39,11 +40,18 @@ async fn stats(ctx: &Context, msg: &Message) -> CommandResult {
let discord_info = format!(
r#"
Version: {}
Compiled with: rustc {}
Owner: <@{}>
Guilds: {}
Voice Connections: {}
Times Used: {}
"#,
VERSION, bot_info.owner.id, guild_count, total_commands_executed
crate::VERSION,
rustc_version_runtime::version(),
bot_info.owner.id,
guild_count,
get_queue_count(ctx).await,
total_commands_executed
);
log::trace!("Discord info {}", discord_info);
@ -79,3 +87,27 @@ async fn stats(ctx: &Context, msg: &Message) -> CommandResult {
Ok(())
}
/// Returns the total number of queues that are not
/// flagged to leave
async fn get_queue_count(ctx: &Context) -> usize {
let queues: Vec<Arc<Mutex<MusicQueue>>> = {
let data = ctx.data.read().await;
let store = data.get::<Store>().unwrap();
store
.music_queues
.iter()
.map(|(_, q)| Arc::clone(q))
.collect()
};
let mut count = 0;
for queue in queues {
let queue = queue.lock().await;
if !queue.leave_flag {
count += 1;
}
}
count
}

@ -4,7 +4,8 @@ use serenity::framework::standard::CommandResult;
use serenity::model::channel::Message;
use crate::commands::common::handle_autodelete;
use crate::commands::music::{get_queue_for_guild, get_voice_manager, is_dj};
use crate::commands::music::{get_voice_manager, is_dj};
use crate::utils::context_data::Store;
use bot_serenityutils::core::SHORT_TIMEOUT;
use bot_serenityutils::ephemeral_message::EphemeralMessage;
@ -23,11 +24,14 @@ async fn leave(ctx: &Context, msg: &Message) -> CommandResult {
}
let manager = get_voice_manager(ctx).await;
let queue = forward_error!(
ctx,
msg.channel_id,
get_queue_for_guild(ctx, &guild.id).await
);
let queue = {
let mut data = ctx.data.write().await;
let store = data.get_mut::<Store>().unwrap();
store
.music_queues
.remove(&guild.id)
.expect("No queue for guild.")
};
let queue_lock = queue.lock().await;
let handler = manager.get(guild.id);

@ -11,6 +11,8 @@ mod messages;
mod providers;
pub mod utils;
pub static VERSION: &str = env!("CARGO_PKG_VERSION");
#[tokio::main]
async fn main() {
init_logger();

Loading…
Cancel
Save