Public Access
Compare commits
3
Commits
0.2.0
..
dc014945fd
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
dc014945fd | ||
|
|
09ec866d9a | ||
|
|
bada6696a2 |
No files matched your search
+1
-1
@@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "tg-dev-srv-bot"
|
||||
version = "0.1.2"
|
||||
version = "0.2.1"
|
||||
edition = "2024"
|
||||
license = "GPL-3.0-or-later"
|
||||
description = "Bot for the TeenGovernment Development Server"
|
||||
|
||||
+1
-1
@@ -4,6 +4,6 @@ COPY . .
|
||||
RUN SQLX_OFFLINE=true cargo install --path .
|
||||
|
||||
FROM debian:trixie
|
||||
RUN apt-get update && apt-get install -y ca-certificates libgmp-dev libmpfr-dev libmpc-dev && rm -rf /var/lib/apt/lists/*
|
||||
RUN apt-get update && apt-get install -y ca-certificates libgmp-dev libmpfr-dev libmpc-dev libquadmath0 && rm -rf /var/lib/apt/lists/*
|
||||
COPY --from=builder /usr/local/cargo/bin/tg-dev-srv-bot /usr/local/bin/tg-dev-srv-bot
|
||||
CMD ["tg-dev-srv-bot"]
|
||||
@@ -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 tracing::{debug, trace, warn};
|
||||
use crate::shared_functions::trace_message;
|
||||
use crate::messaging::trace_message;
|
||||
use regex::Regex;
|
||||
use std::sync::LazyLock;
|
||||
use std::str::FromStr;
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
use std::process::Command;
|
||||
use crate::{Context, Error};
|
||||
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
|
||||
#[poise::command(slash_command, prefix_command)]
|
||||
@@ -32,13 +32,3 @@ pub async fn fastfetch(ctx: Context<'_>) -> Result<(), Error> {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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 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)
|
||||
#[derive(Debug, poise::ChoiceParameter, Clone, Copy)]
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
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 tracing::{error, info, debug, trace};
|
||||
|
||||
@@ -115,15 +116,6 @@ async fn add_admin_user<'a>(ctx: Context<'a>, msg: &poise::ReplyHandle<'a>, user
|
||||
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> {
|
||||
let admins = get_all_admin_users(ctx).await?;
|
||||
for admin in admins {
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
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 tracing::{error, debug, trace, info, warn};
|
||||
|
||||
@@ -177,15 +178,6 @@ async fn disable_auto_role(ctx: Context<'_>, response_message: &poise::ReplyHand
|
||||
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> {
|
||||
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() {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
use crate::{Context, Error};
|
||||
use poise::serenity_prelude as sere;
|
||||
use tracing::{trace, debug};
|
||||
use crate::shared_functions::trace_message;
|
||||
use crate::messaging::trace_message;
|
||||
|
||||
/// Get the bot's current ping (back and forth)
|
||||
#[poise::command(slash_command, prefix_command)]
|
||||
|
||||
+21
-8
@@ -1,16 +1,29 @@
|
||||
use crate::messaging::trace_message;
|
||||
use crate::{Context, Error};
|
||||
use tracing::{trace, debug};
|
||||
use crate::shared_functions::trace_message;
|
||||
use tracing::{debug, trace};
|
||||
|
||||
const VERSION: &str = include_str!(concat!(env!("OUT_DIR"), "/version.txt"));
|
||||
|
||||
/// Get the bot's current version
|
||||
#[poise::command(slash_command, prefix_command)]
|
||||
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!("Loading version from environment");
|
||||
let version = std::env::var("CARGO_PKG_VERSION").unwrap_or_else(|_| "Unknown".to_string());
|
||||
let msg = format!("Current version: {}", version);
|
||||
trace_message(msg.clone(), ctx.channel_id().to_string(), ctx.guild_id().unwrap().to_string()).await;
|
||||
trace!(
|
||||
"version command called by user {} in guild {}",
|
||||
ctx.author().id.get(),
|
||||
ctx.guild_id().unwrap().get()
|
||||
);
|
||||
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?;
|
||||
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(())
|
||||
}
|
||||
@@ -54,16 +54,3 @@ pub async fn get_all_admin_users(ctx: Context<'_>) -> Result<Vec<sere::User>, Er
|
||||
|
||||
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 event_handler;
|
||||
pub mod events;
|
||||
pub mod shared_functions;
|
||||
pub mod information_queries;
|
||||
pub mod messaging;
|
||||
|
||||
pub struct Data {
|
||||
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