Public Access
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
dc014945fd | ||
|
|
09ec866d9a |
No files matched your search
@@ -0,0 +1,35 @@
|
|||||||
|
use std::{env, fs, path::Path, process::Command};
|
||||||
|
|
||||||
|
fn command_output(command: &str, args: &[&str]) -> String {
|
||||||
|
Command::new(command)
|
||||||
|
.args(args)
|
||||||
|
.output()
|
||||||
|
.ok()
|
||||||
|
.filter(|output| output.status.success())
|
||||||
|
.map(|output| String::from_utf8_lossy(&output.stdout).trim().to_owned())
|
||||||
|
.filter(|output| !output.is_empty())
|
||||||
|
.unwrap_or_else(|| "unknown".to_owned())
|
||||||
|
}
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
let out_dir = env::var_os("OUT_DIR").expect("OUT_DIR is set by Cargo");
|
||||||
|
let version = env::var("CARGO_PKG_VERSION").unwrap_or_else(|_| "unknown".to_owned());
|
||||||
|
let rustc = env::var("RUSTC").unwrap_or_else(|_| "rustc".to_owned());
|
||||||
|
let rustc_version = command_output(&rustc, &["--version"]);
|
||||||
|
let target = env::var("TARGET").unwrap_or_else(|_| "unknown".to_owned());
|
||||||
|
|
||||||
|
println!("cargo:rustc-env=TG_BOT_RUSTC_VERSION={rustc_version}");
|
||||||
|
println!("cargo:rustc-env=TG_BOT_TARGET={target}");
|
||||||
|
|
||||||
|
let version_text = format!(
|
||||||
|
"{}\nbuild-time: {}\ncommit: {}\ntarget: {}\nrustc: {}",
|
||||||
|
version,
|
||||||
|
command_output("date", &["-u", "+%Y-%m-%d %H:%M:%S UTC"]),
|
||||||
|
command_output("git", &["rev-parse", "--short", "HEAD"]),
|
||||||
|
target,
|
||||||
|
rustc_version,
|
||||||
|
);
|
||||||
|
|
||||||
|
fs::write(Path::new(&out_dir).join("version.txt"), version_text)
|
||||||
|
.expect("failed to write generated version information");
|
||||||
|
}
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
use crate::{Context, Error};
|
use crate::{Context, Error};
|
||||||
use tracing::{debug, trace, warn};
|
use tracing::{debug, trace, warn};
|
||||||
use crate::shared_functions::trace_message;
|
use crate::messaging::trace_message;
|
||||||
use regex::Regex;
|
use regex::Regex;
|
||||||
use std::sync::LazyLock;
|
use std::sync::LazyLock;
|
||||||
use std::str::FromStr;
|
use std::str::FromStr;
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
use std::process::Command;
|
use std::process::Command;
|
||||||
use crate::{Context, Error};
|
use crate::{Context, Error};
|
||||||
use tracing::{debug, warn, trace};
|
use tracing::{debug, warn, trace};
|
||||||
use crate::shared_functions::trace_message;
|
use crate::messaging::{trace_message, edit_response_message};
|
||||||
|
|
||||||
/// Run and output the contents of the fastfetch command on the machine running the bot
|
/// Run and output the contents of the fastfetch command on the machine running the bot
|
||||||
#[poise::command(slash_command, prefix_command)]
|
#[poise::command(slash_command, prefix_command)]
|
||||||
@@ -31,14 +31,4 @@ pub async fn fastfetch(ctx: Context<'_>) -> Result<(), Error> {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn edit_response_message<'a>(response_message: &poise::ReplyHandle<'a>, ctx: Context<'_>, content: String, silent: bool) -> Result<(), Error> {
|
|
||||||
if silent {
|
|
||||||
response_message.edit(ctx, poise::CreateReply::default().content(content).allowed_mentions(serenity::all::CreateAllowedMentions::new().empty_users())).await?;
|
|
||||||
} else {
|
|
||||||
response_message.edit(ctx, poise::CreateReply::default().content(content)).await?;
|
|
||||||
}
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
|
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
use crate::{Context, Error};
|
use crate::{Context, Error};
|
||||||
use tracing::{debug, trace};
|
use tracing::{debug, trace};
|
||||||
use crate::shared_functions::{trace_message, edit_response_message};
|
use crate::messaging::{trace_message, edit_response_message};
|
||||||
|
|
||||||
/// Find the nth prime number (single threaded)
|
/// Find the nth prime number (single threaded)
|
||||||
#[derive(Debug, poise::ChoiceParameter, Clone, Copy)]
|
#[derive(Debug, poise::ChoiceParameter, Clone, Copy)]
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
use crate::{Context, Error};
|
use crate::{Context, Error};
|
||||||
use crate::shared_functions::get_all_admin_users;
|
use crate::information_queries::get_all_admin_users;
|
||||||
|
use crate::messaging::edit_response_message;
|
||||||
use poise::serenity_prelude as sere;
|
use poise::serenity_prelude as sere;
|
||||||
use tracing::{error, info, debug, trace};
|
use tracing::{error, info, debug, trace};
|
||||||
|
|
||||||
@@ -115,15 +116,6 @@ async fn add_admin_user<'a>(ctx: Context<'a>, msg: &poise::ReplyHandle<'a>, user
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn edit_response_message<'a>(response_message: &poise::ReplyHandle<'a>, ctx: Context<'_>, content: String, silent: bool) -> Result<(), Error> {
|
|
||||||
if silent {
|
|
||||||
response_message.edit(ctx, poise::CreateReply::default().content(content).allowed_mentions(serenity::all::CreateAllowedMentions::new().empty_users())).await?;
|
|
||||||
} else {
|
|
||||||
response_message.edit(ctx, poise::CreateReply::default().content(content)).await?;
|
|
||||||
}
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
|
|
||||||
async fn is_target_admin_user(ctx: Context<'_>, user: &sere::Member) -> Result<bool, Error> {
|
async fn is_target_admin_user(ctx: Context<'_>, user: &sere::Member) -> Result<bool, Error> {
|
||||||
let admins = get_all_admin_users(ctx).await?;
|
let admins = get_all_admin_users(ctx).await?;
|
||||||
for admin in admins {
|
for admin in admins {
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
use crate::{Context, Error};
|
use crate::{Context, Error};
|
||||||
use crate::shared_functions::get_all_admin_users;
|
use crate::information_queries::get_all_admin_users;
|
||||||
|
use crate::messaging::edit_response_message;
|
||||||
use poise::serenity_prelude as sere;
|
use poise::serenity_prelude as sere;
|
||||||
use tracing::{error, debug, trace, info, warn};
|
use tracing::{error, debug, trace, info, warn};
|
||||||
|
|
||||||
@@ -177,15 +178,6 @@ async fn disable_auto_role(ctx: Context<'_>, response_message: &poise::ReplyHand
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn edit_response_message<'a>(response_message: &poise::ReplyHandle<'a>, ctx: Context<'_>, content: String, silent: bool) -> Result<(), Error> {
|
|
||||||
if silent {
|
|
||||||
response_message.edit(ctx, poise::CreateReply::default().content(content).allowed_mentions(serenity::all::CreateAllowedMentions::new().empty_users())).await?;
|
|
||||||
} else {
|
|
||||||
response_message.edit(ctx, poise::CreateReply::default().content(content)).await?;
|
|
||||||
}
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
|
|
||||||
async fn is_auto_role_enabled(ctx: Context<'_>, target_role: &sere::Role) -> Result<bool, Error> {
|
async fn is_auto_role_enabled(ctx: Context<'_>, target_role: &sere::Role) -> Result<bool, Error> {
|
||||||
let query = sqlx::query!("SELECT enabled FROM auto_roles WHERE guild_id = $1 AND role_id = $2;", ctx.guild_id().unwrap().get() as i64, target_role.id.get() as i64).fetch_optional(&ctx.data().pool).await?;
|
let query = sqlx::query!("SELECT enabled FROM auto_roles WHERE guild_id = $1 AND role_id = $2;", ctx.guild_id().unwrap().get() as i64, target_role.id.get() as i64).fetch_optional(&ctx.data().pool).await?;
|
||||||
if query.is_none() {
|
if query.is_none() {
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
use crate::{Context, Error};
|
use crate::{Context, Error};
|
||||||
use poise::serenity_prelude as sere;
|
use poise::serenity_prelude as sere;
|
||||||
use tracing::{trace, debug};
|
use tracing::{trace, debug};
|
||||||
use crate::shared_functions::trace_message;
|
use crate::messaging::trace_message;
|
||||||
|
|
||||||
/// Get the bot's current ping (back and forth)
|
/// Get the bot's current ping (back and forth)
|
||||||
#[poise::command(slash_command, prefix_command)]
|
#[poise::command(slash_command, prefix_command)]
|
||||||
|
|||||||
+22
-9
@@ -1,16 +1,29 @@
|
|||||||
|
use crate::messaging::trace_message;
|
||||||
use crate::{Context, Error};
|
use crate::{Context, Error};
|
||||||
use tracing::{trace, debug};
|
use tracing::{debug, trace};
|
||||||
use crate::shared_functions::trace_message;
|
|
||||||
|
const VERSION: &str = include_str!(concat!(env!("OUT_DIR"), "/version.txt"));
|
||||||
|
|
||||||
/// Get the bot's current version
|
/// Get the bot's current version
|
||||||
#[poise::command(slash_command, prefix_command)]
|
#[poise::command(slash_command, prefix_command)]
|
||||||
pub async fn version(ctx: Context<'_>) -> Result<(), Error> {
|
pub async fn version(ctx: Context<'_>) -> Result<(), Error> {
|
||||||
trace!("version command called by user {} in guild {}", ctx.author().id.get(), ctx.guild_id().unwrap().get());
|
trace!(
|
||||||
trace!("Loading version from environment");
|
"version command called by user {} in guild {}",
|
||||||
let version = std::env::var("CARGO_PKG_VERSION").unwrap_or_else(|_| "Unknown".to_string());
|
ctx.author().id.get(),
|
||||||
let msg = format!("Current version: {}", version);
|
ctx.guild_id().unwrap().get()
|
||||||
trace_message(msg.clone(), ctx.channel_id().to_string(), ctx.guild_id().unwrap().to_string()).await;
|
);
|
||||||
|
trace!("Loading embedded version information");
|
||||||
|
let msg = format!("Current version:\n{VERSION}");
|
||||||
|
trace_message(
|
||||||
|
msg.clone(),
|
||||||
|
ctx.channel_id().to_string(),
|
||||||
|
ctx.guild_id().unwrap().to_string(),
|
||||||
|
)
|
||||||
|
.await;
|
||||||
ctx.say(msg).await?;
|
ctx.say(msg).await?;
|
||||||
debug!("Version command performed for user {} with version {}", ctx.author().name, version);
|
debug!(
|
||||||
|
"Version command performed for user {} with version information",
|
||||||
|
ctx.author().name
|
||||||
|
);
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
@@ -53,17 +53,4 @@ pub async fn get_all_admin_users(ctx: Context<'_>) -> Result<Vec<sere::User>, Er
|
|||||||
}
|
}
|
||||||
|
|
||||||
Ok(admin_users)
|
Ok(admin_users)
|
||||||
}
|
|
||||||
|
|
||||||
pub async fn trace_message(msg: String, channel: String, guild: String) {
|
|
||||||
trace!("Saying \"{}\" in channel {} in guild {}", msg, channel, guild);
|
|
||||||
}
|
|
||||||
|
|
||||||
pub async fn edit_response_message<'a>(response_message: &poise::ReplyHandle<'a>, ctx: Context<'_>, content: String, silent: bool) -> Result<(), Error> {
|
|
||||||
if silent {
|
|
||||||
response_message.edit(ctx, poise::CreateReply::default().content(content).allowed_mentions(serenity::all::CreateAllowedMentions::new().empty_users())).await?;
|
|
||||||
} else {
|
|
||||||
response_message.edit(ctx, poise::CreateReply::default().content(content)).await?;
|
|
||||||
}
|
|
||||||
Ok(())
|
|
||||||
}
|
}
|
||||||
+2
-1
@@ -5,7 +5,8 @@ use tracing_subscriber::EnvFilter;
|
|||||||
pub mod commands;
|
pub mod commands;
|
||||||
pub mod event_handler;
|
pub mod event_handler;
|
||||||
pub mod events;
|
pub mod events;
|
||||||
pub mod shared_functions;
|
pub mod information_queries;
|
||||||
|
pub mod messaging;
|
||||||
|
|
||||||
pub struct Data {
|
pub struct Data {
|
||||||
pub pool: sqlx::PgPool,
|
pub pool: sqlx::PgPool,
|
||||||
|
|||||||
@@ -0,0 +1,16 @@
|
|||||||
|
use crate::{Context, Error};
|
||||||
|
use poise::serenity_prelude as sere;
|
||||||
|
use tracing::trace;
|
||||||
|
|
||||||
|
pub async fn trace_message(msg: String, channel: String, guild: String) {
|
||||||
|
trace!("Saying \"{}\" in channel {} in guild {}", msg, channel, guild);
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn edit_response_message<'a>(response_message: &poise::ReplyHandle<'a>, ctx: Context<'_>, content: String, silent: bool) -> Result<(), Error> {
|
||||||
|
if silent {
|
||||||
|
response_message.edit(ctx, poise::CreateReply::default().content(content).allowed_mentions(serenity::all::CreateAllowedMentions::new().empty_users())).await?;
|
||||||
|
} else {
|
||||||
|
response_message.edit(ctx, poise::CreateReply::default().content(content)).await?;
|
||||||
|
}
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
Reference in new issue
Block a user