Public Access
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3af00e4660 | ||
|
|
8f7be551a3 | ||
|
|
f75fa18f2d | ||
|
|
7d7fcb9860 | ||
|
|
41f8544a6a | ||
|
|
a22f5781c2 | ||
|
|
4298cf385b | ||
|
|
a3c8a351e8 | ||
|
|
f869d92012 | ||
|
|
dc014945fd | ||
|
|
09ec866d9a |
@@ -1,43 +0,0 @@
|
|||||||
name: Build Docker Package
|
|
||||||
|
|
||||||
on:
|
|
||||||
workflow_dispatch:
|
|
||||||
push:
|
|
||||||
branches: [main]
|
|
||||||
release:
|
|
||||||
types: [published]
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
build:
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
steps:
|
|
||||||
- name: Checkout
|
|
||||||
uses: actions/checkout@v3
|
|
||||||
|
|
||||||
- name: Set up Docker Buildx
|
|
||||||
uses: docker/setup-buildx-action@v2
|
|
||||||
|
|
||||||
- name: Log in to Gitea Container Registry
|
|
||||||
uses: docker/login-action@v2
|
|
||||||
with:
|
|
||||||
registry: git.ewenlau.net
|
|
||||||
username: ${{ secrets.GIT_USERNAME }}
|
|
||||||
password: ${{ secrets.GIT_PASSWORD }}
|
|
||||||
|
|
||||||
- name: Extract Docker metadata
|
|
||||||
id: meta
|
|
||||||
uses: docker/metadata-action@v4
|
|
||||||
with:
|
|
||||||
images: git.ewenlau.net/${{ secrets.GIT_USERNAME }}/tg-dev-srv-bot
|
|
||||||
tags: |
|
|
||||||
type=raw,value=dev,enable=${{ github.event_name == 'push' }}
|
|
||||||
type=semver,pattern={{version}},enable=${{ github.event_name == 'release' }}
|
|
||||||
type=raw,value=latest,enable=${{ github.event_name == 'release' }}
|
|
||||||
|
|
||||||
- name: Build and push
|
|
||||||
uses: docker/build-push-action@v4
|
|
||||||
with:
|
|
||||||
context: .
|
|
||||||
push: true
|
|
||||||
tags: ${{ steps.meta.outputs.tags }}
|
|
||||||
labels: ${{ steps.meta.outputs.labels }}
|
|
||||||
+181
-8
@@ -1,10 +1,10 @@
|
|||||||
name: Run cargo test
|
name: CI and release
|
||||||
|
|
||||||
on:
|
on:
|
||||||
push:
|
push:
|
||||||
branches: [ "main" ]
|
branches: [main]
|
||||||
pull_request:
|
pull_request:
|
||||||
branches: [ "main" ]
|
branches: [main]
|
||||||
workflow_dispatch:
|
workflow_dispatch:
|
||||||
|
|
||||||
env:
|
env:
|
||||||
@@ -17,6 +17,8 @@ jobs:
|
|||||||
test:
|
test:
|
||||||
name: Run tests
|
name: Run tests
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
permissions:
|
||||||
|
contents: read
|
||||||
services:
|
services:
|
||||||
postgres:
|
postgres:
|
||||||
image: postgres:16-alpine
|
image: postgres:16-alpine
|
||||||
@@ -32,7 +34,7 @@ jobs:
|
|||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout repository
|
- name: Checkout repository
|
||||||
uses: actions/checkout@v3
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
- name: Install system dependencies
|
- name: Install system dependencies
|
||||||
run: |
|
run: |
|
||||||
@@ -40,10 +42,181 @@ jobs:
|
|||||||
sudo apt-get install -y libgmp-dev libmpfr-dev libmpc-dev
|
sudo apt-get install -y libgmp-dev libmpfr-dev libmpc-dev
|
||||||
|
|
||||||
- name: Set up Rust
|
- name: Set up Rust
|
||||||
uses: actions-rust-lang/setup-rust-toolchain@v1
|
run: |
|
||||||
with:
|
if ! command -v rustup >/dev/null 2>&1; then
|
||||||
cache: false
|
curl --proto '=https' --tlsv1.2 --silent --show-error --fail \
|
||||||
rustflags: ""
|
https://sh.rustup.rs --output /tmp/rustup-init.sh
|
||||||
|
sh /tmp/rustup-init.sh -y --profile minimal
|
||||||
|
echo "$HOME/.cargo/bin" >> "$GITHUB_PATH"
|
||||||
|
export PATH="$HOME/.cargo/bin:$PATH"
|
||||||
|
fi
|
||||||
|
|
||||||
|
rustup toolchain install stable --profile minimal
|
||||||
|
rustup default stable
|
||||||
|
|
||||||
- name: Run tests
|
- name: Run tests
|
||||||
run: cargo test --verbose
|
run: cargo test --verbose
|
||||||
|
|
||||||
|
release_metadata:
|
||||||
|
name: Detect release commit
|
||||||
|
if: github.event_name == 'push'
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
permissions:
|
||||||
|
contents: read
|
||||||
|
outputs:
|
||||||
|
is_release: ${{ steps.release_commit.outputs.is_release }}
|
||||||
|
version: ${{ steps.release_commit.outputs.version }}
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- name: Checkout repository
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
|
- name: Detect release commit
|
||||||
|
id: release_commit
|
||||||
|
shell: bash
|
||||||
|
run: |
|
||||||
|
subject="$(git log -1 --pretty=%s)"
|
||||||
|
echo "is_release=false" >> "$GITHUB_OUTPUT"
|
||||||
|
|
||||||
|
if [[ "$subject" =~ ^Release\ ([0-9]+\.[0-9]+\.[0-9]+)$ ]]; then
|
||||||
|
echo "is_release=true" >> "$GITHUB_OUTPUT"
|
||||||
|
echo "version=${BASH_REMATCH[1]}" >> "$GITHUB_OUTPUT"
|
||||||
|
fi
|
||||||
|
|
||||||
|
container:
|
||||||
|
name: Build and publish container
|
||||||
|
needs: release_metadata
|
||||||
|
if: github.event_name == 'push'
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- name: Checkout repository
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
|
- name: Set up Docker Buildx
|
||||||
|
uses: docker/setup-buildx-action@v3
|
||||||
|
|
||||||
|
- name: Log in to Gitea Container Registry
|
||||||
|
uses: docker/login-action@v3
|
||||||
|
with:
|
||||||
|
registry: git.ewenlau.net
|
||||||
|
username: ${{ secrets.GIT_USERNAME }}
|
||||||
|
password: ${{ secrets.GIT_PASSWORD }}
|
||||||
|
|
||||||
|
- name: Extract Docker metadata
|
||||||
|
id: meta
|
||||||
|
uses: docker/metadata-action@v5
|
||||||
|
with:
|
||||||
|
images: git.ewenlau.net/${{ secrets.GIT_USERNAME }}/tg-dev-srv-bot
|
||||||
|
tags: |
|
||||||
|
type=raw,value=dev
|
||||||
|
type=raw,value=${{ needs.release_metadata.outputs.version }},enable=${{ needs.release_metadata.outputs.is_release == 'true' }}
|
||||||
|
type=raw,value=latest,enable=${{ needs.release_metadata.outputs.is_release == 'true' }}
|
||||||
|
|
||||||
|
- name: Build and push
|
||||||
|
uses: docker/build-push-action@v6
|
||||||
|
with:
|
||||||
|
context: .
|
||||||
|
push: true
|
||||||
|
tags: ${{ steps.meta.outputs.tags }}
|
||||||
|
labels: ${{ steps.meta.outputs.labels }}
|
||||||
|
|
||||||
|
release:
|
||||||
|
name: Create release
|
||||||
|
needs: [release_metadata, container]
|
||||||
|
if: success() && needs.release_metadata.outputs.is_release == 'true'
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
permissions:
|
||||||
|
contents: write
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- name: Checkout complete history
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
with:
|
||||||
|
fetch-depth: 0
|
||||||
|
|
||||||
|
- name: Generate linked release notes
|
||||||
|
env:
|
||||||
|
SERVER_URL: ${{ github.server_url }}
|
||||||
|
REPOSITORY: ${{ github.repository }}
|
||||||
|
shell: bash
|
||||||
|
run: |
|
||||||
|
previous_tag="$(
|
||||||
|
git tag --merged HEAD^ --sort=-version:refname \
|
||||||
|
| grep -E '^[0-9]+\.[0-9]+\.[0-9]+$' \
|
||||||
|
| head -n 1 || true
|
||||||
|
)"
|
||||||
|
|
||||||
|
if [[ -n "$previous_tag" ]]; then
|
||||||
|
range="${previous_tag}..HEAD"
|
||||||
|
heading="## Commits since ${previous_tag}"
|
||||||
|
else
|
||||||
|
range="HEAD"
|
||||||
|
heading="## Commits"
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "$heading" > release-notes.md
|
||||||
|
echo >> release-notes.md
|
||||||
|
while IFS=$'\t' read -r sha subject; do
|
||||||
|
short_sha="${sha:0:7}"
|
||||||
|
printf -- '- [`%s`](%s/%s/commit/%s) %s\n' \
|
||||||
|
"$short_sha" "$SERVER_URL" "$REPOSITORY" "$sha" "$subject"
|
||||||
|
done < <(git log --reverse --pretty=tformat:'%H%x09%s' "$range") \
|
||||||
|
>> release-notes.md
|
||||||
|
|
||||||
|
- name: Publish release
|
||||||
|
env:
|
||||||
|
API_URL: ${{ github.api_url }}
|
||||||
|
REPOSITORY: ${{ github.repository }}
|
||||||
|
RELEASE_TOKEN: ${{ secrets.GITEA_TOKEN }}
|
||||||
|
VERSION: ${{ needs.release_metadata.outputs.version }}
|
||||||
|
shell: bash
|
||||||
|
run: |
|
||||||
|
release_url="${API_URL}/repos/${REPOSITORY}/releases/tags/${VERSION}"
|
||||||
|
status="$(
|
||||||
|
curl --silent --show-error \
|
||||||
|
--output existing-release.json \
|
||||||
|
--write-out '%{http_code}' \
|
||||||
|
--header "Authorization: token ${RELEASE_TOKEN}" \
|
||||||
|
"$release_url"
|
||||||
|
)"
|
||||||
|
|
||||||
|
if [[ "$status" == "200" ]]; then
|
||||||
|
echo "Release ${VERSION} already exists; nothing to do."
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [[ "$status" != "404" ]]; then
|
||||||
|
cat existing-release.json >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
jq --null-input \
|
||||||
|
--arg tag_name "$VERSION" \
|
||||||
|
--arg name "Release $VERSION" \
|
||||||
|
--arg target_commitish "$GITHUB_SHA" \
|
||||||
|
--rawfile body release-notes.md \
|
||||||
|
'{
|
||||||
|
tag_name: $tag_name,
|
||||||
|
target_commitish: $target_commitish,
|
||||||
|
name: $name,
|
||||||
|
body: $body,
|
||||||
|
draft: false,
|
||||||
|
prerelease: false
|
||||||
|
}' > release.json
|
||||||
|
|
||||||
|
status="$(
|
||||||
|
curl --silent --show-error \
|
||||||
|
--output created-release.json \
|
||||||
|
--write-out '%{http_code}' \
|
||||||
|
--request POST \
|
||||||
|
--header "Authorization: token ${RELEASE_TOKEN}" \
|
||||||
|
--header "Content-Type: application/json" \
|
||||||
|
--data @release.json \
|
||||||
|
"${API_URL}/repos/${REPOSITORY}/releases"
|
||||||
|
)"
|
||||||
|
|
||||||
|
if [[ "$status" != "201" ]]; then
|
||||||
|
cat created-release.json >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|||||||
+4
-1
@@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "tg-dev-srv-bot"
|
name = "tg-dev-srv-bot"
|
||||||
version = "0.2.1"
|
version = "0.3.1"
|
||||||
edition = "2024"
|
edition = "2024"
|
||||||
license = "GPL-3.0-or-later"
|
license = "GPL-3.0-or-later"
|
||||||
description = "Bot for the TeenGovernment Development Server"
|
description = "Bot for the TeenGovernment Development Server"
|
||||||
@@ -19,8 +19,11 @@ num-bigint = "0.5.1"
|
|||||||
num-traits = "0.2.19"
|
num-traits = "0.2.19"
|
||||||
ollama-rs = { version = "0.3.5", features = ["stream"] }
|
ollama-rs = { version = "0.3.5", features = ["stream"] }
|
||||||
poise = "0.6.2"
|
poise = "0.6.2"
|
||||||
|
qapi = { version = "0.15.0", features = ["qmp", "qga"] }
|
||||||
|
reqwest = { version = "0.13", default-features = false, features = ["json", "rustls"] }
|
||||||
regex = "1.12.4"
|
regex = "1.12.4"
|
||||||
rug = "1.30.0"
|
rug = "1.30.0"
|
||||||
|
serde = { version = "1", features = ["derive"] }
|
||||||
serenity = "0.12.5"
|
serenity = "0.12.5"
|
||||||
sqlx = { version = "0.9.0", features = ["postgres", "runtime-tokio", "macros"] }
|
sqlx = { version = "0.9.0", features = ["postgres", "runtime-tokio", "macros"] }
|
||||||
tokio = { version = "1.52.3", features = ["full"] }
|
tokio = { version = "1.52.3", features = ["full"] }
|
||||||
|
|||||||
+1
-1
@@ -4,6 +4,6 @@ COPY . .
|
|||||||
RUN SQLX_OFFLINE=true cargo install --path .
|
RUN SQLX_OFFLINE=true cargo install --path .
|
||||||
|
|
||||||
FROM debian:trixie
|
FROM debian:trixie
|
||||||
RUN apt-get update && apt-get install -y ca-certificates libgmp-dev libmpfr-dev libmpc-dev libquadmath0 && rm -rf /var/lib/apt/lists/*
|
RUN apt-get update && apt-get install -y ca-certificates libgmp-dev libmpfr-dev libmpc-dev libquadmath0 fastfetch && rm -rf /var/lib/apt/lists/*
|
||||||
COPY --from=builder /usr/local/cargo/bin/tg-dev-srv-bot /usr/local/bin/tg-dev-srv-bot
|
COPY --from=builder /usr/local/cargo/bin/tg-dev-srv-bot /usr/local/bin/tg-dev-srv-bot
|
||||||
CMD ["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");
|
||||||
|
}
|
||||||
+214
-39
@@ -1,5 +1,6 @@
|
|||||||
use crate::{Context, Error};
|
use crate::{Context, Error};
|
||||||
use tracing::{debug, error, trace};
|
use crate::messaging::trace_message;
|
||||||
|
use tracing::{debug, error, info, trace, warn};
|
||||||
use ollama_rs::Ollama;
|
use ollama_rs::Ollama;
|
||||||
use std::env;
|
use std::env;
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
@@ -18,66 +19,119 @@ pub async fn prompt(
|
|||||||
#[description = "Include recent messages (max 10)"]
|
#[description = "Include recent messages (max 10)"]
|
||||||
include_messages: Option<u8>,
|
include_messages: Option<u8>,
|
||||||
) -> Result<(), Error> {
|
) -> Result<(), Error> {
|
||||||
debug!("{} has requested to prompt EwiAI with '{}'", ctx.author().name, prompt);
|
let channel_str = ctx.channel_id().to_string();
|
||||||
|
let guild_str = ctx.guild_id().map_or_else(|| "DM".to_string(), |g| g.to_string());
|
||||||
|
|
||||||
|
trace!("prompt command called by user {} (ID: {}) in channel {} (guild: {})", ctx.author().name, ctx.author().id, channel_str, guild_str);
|
||||||
|
debug!("{} has requested to prompt EwiAI with '{}' (include_messages: {:?})", ctx.author().name, prompt, include_messages);
|
||||||
|
|
||||||
|
trace!("Checking environment variable TG_BOT_OLLAMA_HOST...");
|
||||||
let host = match env::var("TG_BOT_OLLAMA_HOST") {
|
let host = match env::var("TG_BOT_OLLAMA_HOST") {
|
||||||
Ok(h) => h,
|
Ok(h) => {
|
||||||
Err(_) => {
|
trace!("Successfully retrieved TG_BOT_OLLAMA_HOST = {}", h);
|
||||||
ctx.say("Error: Expected an ollama url in the environment (`TG_BOT_OLLAMA_HOST`).").await?;
|
h
|
||||||
|
}
|
||||||
|
Err(e) => {
|
||||||
|
warn!("TG_BOT_OLLAMA_HOST environment variable missing: {}", e);
|
||||||
|
let err_msg = "Error: Expected an ollama url in the environment (`TG_BOT_OLLAMA_HOST`).";
|
||||||
|
trace_message(err_msg, channel_str.clone(), guild_str.clone()).await;
|
||||||
|
ctx.say(err_msg).await?;
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
let formatted_host = if !host.starts_with("http://") && !host.starts_with("https://") {
|
let formatted_host = if !host.starts_with("http://") && !host.starts_with("https://") {
|
||||||
format!("http://{}", host)
|
let f = format!("http://{}", host);
|
||||||
|
trace!("Formatted Ollama host address to include http:// prefix: {}", f);
|
||||||
|
f
|
||||||
} else {
|
} else {
|
||||||
|
trace!("Ollama host address already has URL scheme: {}", host);
|
||||||
host
|
host
|
||||||
};
|
};
|
||||||
|
|
||||||
|
trace!("Building Ollama client instance for host {} on port 11434...", formatted_host);
|
||||||
let ollama = Ollama::builder()
|
let ollama = Ollama::builder()
|
||||||
.host(&formatted_host)
|
.host(&formatted_host)
|
||||||
.port(11434)
|
.port(11434)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
|
trace!("Requesting local model list from Ollama server...");
|
||||||
let model_list = match ollama.list_local_models().await {
|
let model_list = match ollama.list_local_models().await {
|
||||||
Ok(m) => m,
|
Ok(m) => {
|
||||||
|
debug!("Successfully retrieved {} models from Ollama server", m.len());
|
||||||
|
trace!("Local models available: {:?}", m.iter().map(|model| &model.name).collect::<Vec<_>>());
|
||||||
|
m
|
||||||
|
}
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
ctx.say(format!("Error: Failed to connect to Ollama: {}", e)).await?;
|
error!("Failed to connect to Ollama server at {}: {}", formatted_host, e);
|
||||||
|
let err_msg = format!("Error: Failed to connect to Ollama: {}", e);
|
||||||
|
trace_message(&err_msg, channel_str.clone(), guild_str.clone()).await;
|
||||||
|
ctx.say(err_msg).await?;
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
let mut needs_create = true;
|
let mut needs_create = true;
|
||||||
let yesterday = Utc::now() - chrono::Duration::days(1);
|
let yesterday = Utc::now() - chrono::Duration::days(1);
|
||||||
|
trace!("Checking model list against yesterday's cutoff timestamp ({})", yesterday);
|
||||||
|
|
||||||
for model in &model_list {
|
for model in &model_list {
|
||||||
|
trace!("Inspecting model entry: '{}', modified_at: '{}'", model.name, model.modified_at);
|
||||||
if model.name.starts_with("EwiAI") {
|
if model.name.starts_with("EwiAI") {
|
||||||
if let Ok(modified) = DateTime::parse_from_rfc3339(&model.modified_at) {
|
debug!("Found matching model candidate: '{}'", model.name);
|
||||||
if modified.with_timezone(&Utc) > yesterday {
|
match DateTime::parse_from_rfc3339(&model.modified_at) {
|
||||||
needs_create = false;
|
Ok(modified) => {
|
||||||
|
let modified_utc = modified.with_timezone(&Utc);
|
||||||
|
trace!("Parsed model modified_at: {} (UTC: {})", modified, modified_utc);
|
||||||
|
if modified_utc > yesterday {
|
||||||
|
info!("Model '{}' is up to date (modified {} > cutoff {})", model.name, modified_utc, yesterday);
|
||||||
|
needs_create = false;
|
||||||
|
} else {
|
||||||
|
trace!("Model '{}' was modified at {}, which is older than cutoff {}", model.name, modified_utc, yesterday);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Err(e) => {
|
||||||
|
warn!("Failed to parse modified_at date '{}' for model '{}': {}", model.modified_at, model.name, e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if needs_create {
|
if needs_create {
|
||||||
|
info!("EwiAI model is missing or out of date. Initiating model creation/update...");
|
||||||
let system_prompt = system_prompt();
|
let system_prompt = system_prompt();
|
||||||
let _ = ctx.say("EwiAI model is missing or out of date. Creating/updating model (this may take a bit)...").await?;
|
trace!("Generated system prompt for model creation (length: {} chars)", system_prompt.len());
|
||||||
|
trace!("System prompt content: {}", system_prompt);
|
||||||
|
let notice_msg = "EwiAI model is missing or out of date. Creating/updating model (this may take a bit)...";
|
||||||
|
trace_message(notice_msg, channel_str.clone(), guild_str.clone()).await;
|
||||||
|
let _ = ctx.say(notice_msg).await?;
|
||||||
|
|
||||||
|
trace!("Sending create_model request to Ollama for 'EwiAI' based on 'gemma4:e2b-it-qat'...");
|
||||||
if let Err(e) = ollama.create_model(CreateModelRequest::new("EwiAI".into())
|
if let Err(e) = ollama.create_model(CreateModelRequest::new("EwiAI".into())
|
||||||
.system(system_prompt.into())
|
.system(system_prompt.into())
|
||||||
.from_model("gemma4:e2b-it-qat".into())).await {
|
.from_model("gemma4:e2b-it-qat".into())).await {
|
||||||
ctx.say(format!("Error creating model: {}", e)).await?;
|
error!("Failed to create model EwiAI: {}", e);
|
||||||
|
let err_msg = format!("Error creating model: {}", e);
|
||||||
|
trace_message(&err_msg, channel_str.clone(), guild_str.clone()).await;
|
||||||
|
ctx.say(err_msg).await?;
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
|
info!("Successfully created/updated EwiAI model");
|
||||||
|
} else {
|
||||||
|
trace!("Skipping model creation; existing model is up to date.");
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut final_prompt = String::new();
|
let mut final_prompt = String::new();
|
||||||
if let Some(mut limit) = include_messages {
|
if let Some(mut limit) = include_messages {
|
||||||
|
trace!("include_messages specified: {}", limit);
|
||||||
if limit > 10 {
|
if limit > 10 {
|
||||||
|
trace!("Clamping include_messages limit from {} to 10", limit);
|
||||||
limit = 10;
|
limit = 10;
|
||||||
}
|
}
|
||||||
|
trace!("Fetching last {} messages from channel {}", limit, channel_str);
|
||||||
match ctx.channel_id().messages(ctx.http(), poise::serenity_prelude::GetMessages::new().limit(limit)).await {
|
match ctx.channel_id().messages(ctx.http(), poise::serenity_prelude::GetMessages::new().limit(limit)).await {
|
||||||
Ok(msgs) => {
|
Ok(msgs) => {
|
||||||
|
debug!("Retrieved {} messages from channel {}", msgs.len(), channel_str);
|
||||||
final_prompt.push_str("Recent channel messages:\n");
|
final_prompt.push_str("Recent channel messages:\n");
|
||||||
for msg in msgs.iter().rev() {
|
for msg in msgs.iter().rev() {
|
||||||
let mut content = msg.content.clone();
|
let mut content = msg.content.clone();
|
||||||
@@ -85,24 +139,38 @@ pub async fn prompt(
|
|||||||
content.truncate(100);
|
content.truncate(100);
|
||||||
content.push_str("...");
|
content.push_str("...");
|
||||||
}
|
}
|
||||||
|
trace!("Appending message from author {} (ID: {}): snippet='{}'", msg.author.name, msg.author.id, content);
|
||||||
final_prompt.push_str(&format!("{} (ID: {}): {}\n", msg.author.name, msg.author.id, content));
|
final_prompt.push_str(&format!("{} (ID: {}): {}\n", msg.author.name, msg.author.id, content));
|
||||||
}
|
}
|
||||||
final_prompt.push_str("\n");
|
final_prompt.push_str("\n");
|
||||||
}
|
}
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
error!("Failed to get messages: {:?}", e);
|
error!("Failed to get messages from channel {}: {:?}", channel_str, e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
final_prompt.push_str(&format!("The user talking to you is {} (ID: {}).\nThat user is telling you the following: {}", ctx.author().name, ctx.author().id, prompt));
|
final_prompt.push_str(&format!("The user talking to you is {} (ID: {}).\nThat user is telling you the following: {}", ctx.author().name, ctx.author().id, prompt));
|
||||||
|
trace!("Final prompt assembled (length: {} chars)", final_prompt.len());
|
||||||
trace!("Final prompt: {}", final_prompt);
|
trace!("Final prompt: {}", final_prompt);
|
||||||
|
|
||||||
let reply = ctx.say("Thinking...\n-# The hardware this thing runs is really slow, expect a long wait").await?;
|
let thinking_msg = "Thinking...\n-# The hardware this thing runs is really slow, expect a long wait";
|
||||||
let mut stream = match ollama.generate_stream(GenerationRequest::new("EwiAI".into(), final_prompt).system(system_prompt())).await {
|
trace_message(thinking_msg, channel_str.clone(), guild_str.clone()).await;
|
||||||
Ok(s) => s,
|
trace!("Sending initial thinking message...");
|
||||||
|
let reply = ctx.say(thinking_msg).await?;
|
||||||
|
|
||||||
|
let sys_prompt = system_prompt();
|
||||||
|
trace!("Generating stream from Ollama model 'EwiAI' with system prompt length {}...", sys_prompt.len());
|
||||||
|
let mut stream = match ollama.generate_stream(GenerationRequest::new("EwiAI".into(), final_prompt).system(sys_prompt)).await {
|
||||||
|
Ok(s) => {
|
||||||
|
debug!("Successfully initiated generation stream");
|
||||||
|
s
|
||||||
|
}
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
reply.edit(ctx, CreateReply::default().content(format!("Error during generation: {}", e))).await?;
|
error!("Error starting generation stream with Ollama: {}", e);
|
||||||
|
let err_msg = format!("Error during generation: {}", e);
|
||||||
|
trace_message(&err_msg, channel_str.clone(), guild_str.clone()).await;
|
||||||
|
reply.edit(ctx, CreateReply::default().content(err_msg)).await?;
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -110,28 +178,39 @@ pub async fn prompt(
|
|||||||
let mut response_text = String::new();
|
let mut response_text = String::new();
|
||||||
let mut last_update = std::time::Instant::now();
|
let mut last_update = std::time::Instant::now();
|
||||||
let mut final_response = None;
|
let mut final_response = None;
|
||||||
|
let mut chunk_count = 0usize;
|
||||||
|
|
||||||
|
trace!("Reading chunks from generation stream...");
|
||||||
while let Some(res) = stream.next().await {
|
while let Some(res) = stream.next().await {
|
||||||
match res {
|
match res {
|
||||||
Ok(chunks) => {
|
Ok(chunks) => {
|
||||||
|
chunk_count += chunks.len();
|
||||||
|
trace!("Received stream batch containing {} chunk(s)", chunks.len());
|
||||||
for chunk in chunks {
|
for chunk in chunks {
|
||||||
|
trace!("Chunk response segment: '{}', done: {}", chunk.response, chunk.done);
|
||||||
response_text.push_str(&chunk.response);
|
response_text.push_str(&chunk.response);
|
||||||
if chunk.done {
|
if chunk.done {
|
||||||
|
debug!("Stream chunk marked done");
|
||||||
final_response = Some(chunk);
|
final_response = Some(chunk);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if last_update.elapsed() >= Duration::from_secs(1) && !response_text.is_empty() {
|
if last_update.elapsed() >= Duration::from_secs(1) && !response_text.is_empty() {
|
||||||
|
trace!("Throttled stream update: updating reply message (response_text length: {} chars)...", response_text.len());
|
||||||
let _ = reply.edit(ctx, CreateReply::default().content(&response_text)).await;
|
let _ = reply.edit(ctx, CreateReply::default().content(&response_text)).await;
|
||||||
last_update = std::time::Instant::now();
|
last_update = std::time::Instant::now();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
let _ = reply.edit(ctx, CreateReply::default().content(format!("{} [Stream Error: {}]", response_text, e))).await;
|
error!("Error encountered while reading stream chunk: {}", e);
|
||||||
|
let err_msg = format!("{} [Stream Error: {}]", response_text, e);
|
||||||
|
trace_message(&err_msg, channel_str.clone(), guild_str.clone()).await;
|
||||||
|
let _ = reply.edit(ctx, CreateReply::default().content(err_msg)).await;
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
info!("Stream completed. Total chunks received: {}, output length: {} chars", chunk_count, response_text.len());
|
||||||
|
|
||||||
if let Some(stats) = final_response {
|
if let Some(stats) = final_response {
|
||||||
let total_duration = stats.total_duration.unwrap_or(0) as f64 / 1_000_000_000.0;
|
let total_duration = stats.total_duration.unwrap_or(0) as f64 / 1_000_000_000.0;
|
||||||
@@ -139,14 +218,21 @@ pub async fn prompt(
|
|||||||
let eval_duration = stats.eval_duration.unwrap_or(0) as f64 / 1_000_000_000.0;
|
let eval_duration = stats.eval_duration.unwrap_or(0) as f64 / 1_000_000_000.0;
|
||||||
let tokens_per_sec = if eval_duration > 0.0 { eval_count as f64 / eval_duration } else { 0.0 };
|
let tokens_per_sec = if eval_duration > 0.0 { eval_count as f64 / eval_duration } else { 0.0 };
|
||||||
|
|
||||||
|
debug!("Generation stats: total_duration={:.2}s, eval_count={}, eval_duration={:.2}s, tok/s={:.2}", total_duration, eval_count, eval_duration, tokens_per_sec);
|
||||||
|
|
||||||
let stats_text = format!(
|
let stats_text = format!(
|
||||||
"\n\n*Generated in {:.2}s ({:.2} tok/s)*",
|
"\n\n*Generated in {:.2}s ({:.2} tok/s)*",
|
||||||
total_duration, tokens_per_sec
|
total_duration, tokens_per_sec
|
||||||
);
|
);
|
||||||
response_text.push_str(&stats_text);
|
response_text.push_str(&stats_text);
|
||||||
|
} else {
|
||||||
|
trace!("No final response stats available from stream");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
trace_message(&response_text, channel_str.clone(), guild_str.clone()).await;
|
||||||
|
trace!("Sending final edit to reply message...");
|
||||||
let _ = reply.edit(ctx, CreateReply::default().content(&response_text)).await;
|
let _ = reply.edit(ctx, CreateReply::default().content(&response_text)).await;
|
||||||
|
debug!("prompt command finished successfully for user {}", ctx.author().name);
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
@@ -158,66 +244,119 @@ pub async fn answer(
|
|||||||
#[description = "How many messages to include (max 10)"]
|
#[description = "How many messages to include (max 10)"]
|
||||||
messages_count: Option<u8>,
|
messages_count: Option<u8>,
|
||||||
) -> Result<(), Error> {
|
) -> Result<(), Error> {
|
||||||
debug!("{} has requested EwiAI to answer", ctx.author().name);
|
let channel_str = ctx.channel_id().to_string();
|
||||||
|
let guild_str = ctx.guild_id().map_or_else(|| "DM".to_string(), |g| g.to_string());
|
||||||
|
|
||||||
|
trace!("answer command called by user {} (ID: {}) in channel {} (guild: {})", ctx.author().name, ctx.author().id, channel_str, guild_str);
|
||||||
|
debug!("{} has requested EwiAI to answer (messages_count: {:?})", ctx.author().name, messages_count);
|
||||||
|
|
||||||
|
trace!("Checking environment variable TG_BOT_OLLAMA_HOST...");
|
||||||
let host = match env::var("TG_BOT_OLLAMA_HOST") {
|
let host = match env::var("TG_BOT_OLLAMA_HOST") {
|
||||||
Ok(h) => h,
|
Ok(h) => {
|
||||||
Err(_) => {
|
trace!("Successfully retrieved TG_BOT_OLLAMA_HOST = {}", h);
|
||||||
ctx.say("Error: Expected an ollama url in the environment (`TG_BOT_OLLAMA_HOST`).").await?;
|
h
|
||||||
|
}
|
||||||
|
Err(e) => {
|
||||||
|
warn!("TG_BOT_OLLAMA_HOST environment variable missing: {}", e);
|
||||||
|
let err_msg = "Error: Expected an ollama url in the environment (`TG_BOT_OLLAMA_HOST`).";
|
||||||
|
trace_message(err_msg, channel_str.clone(), guild_str.clone()).await;
|
||||||
|
ctx.say(err_msg).await?;
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
let formatted_host = if !host.starts_with("http://") && !host.starts_with("https://") {
|
let formatted_host = if !host.starts_with("http://") && !host.starts_with("https://") {
|
||||||
format!("http://{}", host)
|
let f = format!("http://{}", host);
|
||||||
|
trace!("Formatted Ollama host address to include http:// prefix: {}", f);
|
||||||
|
f
|
||||||
} else {
|
} else {
|
||||||
|
trace!("Ollama host address already has URL scheme: {}", host);
|
||||||
host
|
host
|
||||||
};
|
};
|
||||||
|
|
||||||
|
trace!("Building Ollama client instance for host {} on port 11434...", formatted_host);
|
||||||
let ollama = Ollama::builder()
|
let ollama = Ollama::builder()
|
||||||
.host(&formatted_host)
|
.host(&formatted_host)
|
||||||
.port(11434)
|
.port(11434)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
|
trace!("Requesting local model list from Ollama server...");
|
||||||
let model_list = match ollama.list_local_models().await {
|
let model_list = match ollama.list_local_models().await {
|
||||||
Ok(m) => m,
|
Ok(m) => {
|
||||||
|
debug!("Successfully retrieved {} models from Ollama server", m.len());
|
||||||
|
trace!("Local models available: {:?}", m.iter().map(|model| &model.name).collect::<Vec<_>>());
|
||||||
|
m
|
||||||
|
}
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
ctx.say(format!("Error: Failed to connect to Ollama: {}", e)).await?;
|
error!("Failed to connect to Ollama server at {}: {}", formatted_host, e);
|
||||||
|
let err_msg = format!("Error: Failed to connect to Ollama: {}", e);
|
||||||
|
trace_message(&err_msg, channel_str.clone(), guild_str.clone()).await;
|
||||||
|
ctx.say(err_msg).await?;
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
let mut needs_create = true;
|
let mut needs_create = true;
|
||||||
let yesterday = Utc::now() - chrono::Duration::days(1);
|
let yesterday = Utc::now() - chrono::Duration::days(1);
|
||||||
|
trace!("Checking model list against yesterday's cutoff timestamp ({})", yesterday);
|
||||||
|
|
||||||
for model in &model_list {
|
for model in &model_list {
|
||||||
|
trace!("Inspecting model entry: '{}', modified_at: '{}'", model.name, model.modified_at);
|
||||||
if model.name.starts_with("EwiAI") {
|
if model.name.starts_with("EwiAI") {
|
||||||
if let Ok(modified) = DateTime::parse_from_rfc3339(&model.modified_at) {
|
debug!("Found matching model candidate: '{}'", model.name);
|
||||||
if modified.with_timezone(&Utc) > yesterday {
|
match DateTime::parse_from_rfc3339(&model.modified_at) {
|
||||||
needs_create = false;
|
Ok(modified) => {
|
||||||
|
let modified_utc = modified.with_timezone(&Utc);
|
||||||
|
trace!("Parsed model modified_at: {} (UTC: {})", modified, modified_utc);
|
||||||
|
if modified_utc > yesterday {
|
||||||
|
info!("Model '{}' is up to date (modified {} > cutoff {})", model.name, modified_utc, yesterday);
|
||||||
|
needs_create = false;
|
||||||
|
} else {
|
||||||
|
trace!("Model '{}' was modified at {}, which is older than cutoff {}", model.name, modified_utc, yesterday);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Err(e) => {
|
||||||
|
warn!("Failed to parse modified_at date '{}' for model '{}': {}", model.modified_at, model.name, e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if needs_create {
|
if needs_create {
|
||||||
|
info!("EwiAI model is missing or out of date. Initiating model creation/update...");
|
||||||
let system_prompt = system_prompt();
|
let system_prompt = system_prompt();
|
||||||
let _ = ctx.say("EwiAI model is missing or out of date. Creating/updating model (this may take a bit)...").await?;
|
trace!("Generated system prompt for model creation (length: {} chars)", system_prompt.len());
|
||||||
|
trace!("System prompt content: {}", system_prompt);
|
||||||
|
let notice_msg = "EwiAI model is missing or out of date. Creating/updating model (this may take a bit)...";
|
||||||
|
trace_message(notice_msg, channel_str.clone(), guild_str.clone()).await;
|
||||||
|
let _ = ctx.say(notice_msg).await?;
|
||||||
|
|
||||||
|
trace!("Sending create_model request to Ollama for 'EwiAI' based on 'gemma4:e2b-it-qat'...");
|
||||||
if let Err(e) = ollama.create_model(CreateModelRequest::new("EwiAI".into())
|
if let Err(e) = ollama.create_model(CreateModelRequest::new("EwiAI".into())
|
||||||
.system(system_prompt.into())
|
.system(system_prompt.into())
|
||||||
.from_model("gemma4:e2b-it-qat".into())).await {
|
.from_model("gemma4:e2b-it-qat".into())).await {
|
||||||
ctx.say(format!("Error creating model: {}", e)).await?;
|
error!("Failed to create model EwiAI: {}", e);
|
||||||
|
let err_msg = format!("Error creating model: {}", e);
|
||||||
|
trace_message(&err_msg, channel_str.clone(), guild_str.clone()).await;
|
||||||
|
ctx.say(err_msg).await?;
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
|
info!("Successfully created/updated EwiAI model");
|
||||||
|
} else {
|
||||||
|
trace!("Skipping model creation; existing model is up to date.");
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut final_prompt = String::new();
|
let mut final_prompt = String::new();
|
||||||
let mut limit = messages_count.unwrap_or(5);
|
let mut limit = messages_count.unwrap_or(5);
|
||||||
|
trace!("messages_count limit: {}", limit);
|
||||||
if limit > 10 {
|
if limit > 10 {
|
||||||
|
trace!("Clamping messages_count limit from {} to 10", limit);
|
||||||
limit = 10;
|
limit = 10;
|
||||||
}
|
}
|
||||||
|
trace!("Fetching last {} messages from channel {}", limit, channel_str);
|
||||||
match ctx.channel_id().messages(ctx.http(), poise::serenity_prelude::GetMessages::new().limit(limit)).await {
|
match ctx.channel_id().messages(ctx.http(), poise::serenity_prelude::GetMessages::new().limit(limit)).await {
|
||||||
Ok(msgs) => {
|
Ok(msgs) => {
|
||||||
|
debug!("Retrieved {} messages from channel {}", msgs.len(), channel_str);
|
||||||
final_prompt.push_str("Recent channel messages:\n");
|
final_prompt.push_str("Recent channel messages:\n");
|
||||||
for msg in msgs.iter().rev() {
|
for msg in msgs.iter().rev() {
|
||||||
let mut content = msg.content.clone();
|
let mut content = msg.content.clone();
|
||||||
@@ -225,23 +364,37 @@ pub async fn answer(
|
|||||||
content.truncate(100);
|
content.truncate(100);
|
||||||
content.push_str("...");
|
content.push_str("...");
|
||||||
}
|
}
|
||||||
|
trace!("Appending message from author {} (ID: {}): snippet='{}'", msg.author.name, msg.author.id, content);
|
||||||
final_prompt.push_str(&format!("{} (ID: {}): {}\n", msg.author.name, msg.author.id, content));
|
final_prompt.push_str(&format!("{} (ID: {}): {}\n", msg.author.name, msg.author.id, content));
|
||||||
}
|
}
|
||||||
final_prompt.push_str("\n");
|
final_prompt.push_str("\n");
|
||||||
}
|
}
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
error!("Failed to get messages: {:?}", e);
|
error!("Failed to get messages from channel {}: {:?}", channel_str, e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
final_prompt.push_str(&format!("Please respond to the messages above."));
|
final_prompt.push_str("Please respond to the messages above.");
|
||||||
|
trace!("Final prompt assembled (length: {} chars)", final_prompt.len());
|
||||||
trace!("Final prompt: {}", final_prompt);
|
trace!("Final prompt: {}", final_prompt);
|
||||||
|
|
||||||
let reply = ctx.say("Thinking...\n-# The hardware this thing runs is really slow, expect a long wait").await?;
|
let thinking_msg = "Thinking...\n-# The hardware this thing runs is really slow, expect a long wait";
|
||||||
let mut stream = match ollama.generate_stream(GenerationRequest::new("EwiAI".into(), final_prompt).system(system_prompt())).await {
|
trace_message(thinking_msg, channel_str.clone(), guild_str.clone()).await;
|
||||||
Ok(s) => s,
|
trace!("Sending initial thinking message...");
|
||||||
|
let reply = ctx.say(thinking_msg).await?;
|
||||||
|
|
||||||
|
let sys_prompt = system_prompt();
|
||||||
|
trace!("Generating stream from Ollama model 'EwiAI' with system prompt length {}...", sys_prompt.len());
|
||||||
|
let mut stream = match ollama.generate_stream(GenerationRequest::new("EwiAI".into(), final_prompt).system(sys_prompt)).await {
|
||||||
|
Ok(s) => {
|
||||||
|
debug!("Successfully initiated generation stream");
|
||||||
|
s
|
||||||
|
}
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
reply.edit(ctx, CreateReply::default().content(format!("Error during generation: {}", e))).await?;
|
error!("Error starting generation stream with Ollama: {}", e);
|
||||||
|
let err_msg = format!("Error during generation: {}", e);
|
||||||
|
trace_message(&err_msg, channel_str.clone(), guild_str.clone()).await;
|
||||||
|
reply.edit(ctx, CreateReply::default().content(err_msg)).await?;
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -249,28 +402,39 @@ pub async fn answer(
|
|||||||
let mut response_text = String::new();
|
let mut response_text = String::new();
|
||||||
let mut last_update = std::time::Instant::now();
|
let mut last_update = std::time::Instant::now();
|
||||||
let mut final_response = None;
|
let mut final_response = None;
|
||||||
|
let mut chunk_count = 0usize;
|
||||||
|
|
||||||
|
trace!("Reading chunks from generation stream...");
|
||||||
while let Some(res) = stream.next().await {
|
while let Some(res) = stream.next().await {
|
||||||
match res {
|
match res {
|
||||||
Ok(chunks) => {
|
Ok(chunks) => {
|
||||||
|
chunk_count += chunks.len();
|
||||||
|
trace!("Received stream batch containing {} chunk(s)", chunks.len());
|
||||||
for chunk in chunks {
|
for chunk in chunks {
|
||||||
|
trace!("Chunk response segment: '{}', done: {}", chunk.response, chunk.done);
|
||||||
response_text.push_str(&chunk.response);
|
response_text.push_str(&chunk.response);
|
||||||
if chunk.done {
|
if chunk.done {
|
||||||
|
debug!("Stream chunk marked done");
|
||||||
final_response = Some(chunk);
|
final_response = Some(chunk);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if last_update.elapsed() >= Duration::from_secs(1) && !response_text.is_empty() {
|
if last_update.elapsed() >= Duration::from_secs(1) && !response_text.is_empty() {
|
||||||
|
trace!("Throttled stream update: updating reply message (response_text length: {} chars)...", response_text.len());
|
||||||
let _ = reply.edit(ctx, CreateReply::default().content(&response_text)).await;
|
let _ = reply.edit(ctx, CreateReply::default().content(&response_text)).await;
|
||||||
last_update = std::time::Instant::now();
|
last_update = std::time::Instant::now();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
let _ = reply.edit(ctx, CreateReply::default().content(format!("{} [Stream Error: {}]", response_text, e))).await;
|
error!("Error encountered while reading stream chunk: {}", e);
|
||||||
|
let err_msg = format!("{} [Stream Error: {}]", response_text, e);
|
||||||
|
trace_message(&err_msg, channel_str.clone(), guild_str.clone()).await;
|
||||||
|
let _ = reply.edit(ctx, CreateReply::default().content(err_msg)).await;
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
info!("Stream completed. Total chunks received: {}, output length: {} chars", chunk_count, response_text.len());
|
||||||
|
|
||||||
if let Some(stats) = final_response {
|
if let Some(stats) = final_response {
|
||||||
let total_duration = stats.total_duration.unwrap_or(0) as f64 / 1_000_000_000.0;
|
let total_duration = stats.total_duration.unwrap_or(0) as f64 / 1_000_000_000.0;
|
||||||
@@ -278,18 +442,29 @@ pub async fn answer(
|
|||||||
let eval_duration = stats.eval_duration.unwrap_or(0) as f64 / 1_000_000_000.0;
|
let eval_duration = stats.eval_duration.unwrap_or(0) as f64 / 1_000_000_000.0;
|
||||||
let tokens_per_sec = if eval_duration > 0.0 { eval_count as f64 / eval_duration } else { 0.0 };
|
let tokens_per_sec = if eval_duration > 0.0 { eval_count as f64 / eval_duration } else { 0.0 };
|
||||||
|
|
||||||
|
debug!("Generation stats: total_duration={:.2}s, eval_count={}, eval_duration={:.2}s, tok/s={:.2}", total_duration, eval_count, eval_duration, tokens_per_sec);
|
||||||
|
|
||||||
let stats_text = format!(
|
let stats_text = format!(
|
||||||
"\n\n*Generated in {:.2}s ({:.2} tok/s)*",
|
"\n\n*Generated in {:.2}s ({:.2} tok/s)*",
|
||||||
total_duration, tokens_per_sec
|
total_duration, tokens_per_sec
|
||||||
);
|
);
|
||||||
response_text.push_str(&stats_text);
|
response_text.push_str(&stats_text);
|
||||||
|
} else {
|
||||||
|
trace!("No final response stats available from stream");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
trace_message(&response_text, channel_str.clone(), guild_str.clone()).await;
|
||||||
|
trace!("Sending final edit to reply message...");
|
||||||
let _ = reply.edit(ctx, CreateReply::default().content(&response_text)).await;
|
let _ = reply.edit(ctx, CreateReply::default().content(&response_text)).await;
|
||||||
|
debug!("answer command finished successfully for user {}", ctx.author().name);
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn system_prompt() -> String {
|
fn system_prompt() -> String {
|
||||||
format!("You are EwiAI, an AI in the TeenGovernment Development Server. Your developer is Ewi/ewenlau (discord user id: 713354021124964422, discord username: ewenlau). Be slightly unhelpful, in a sarcastic way, but still answer the question. The current date is {}", Utc::now().to_string())
|
let now_str = Utc::now().to_string();
|
||||||
|
trace!("Generating system_prompt with current UTC timestamp: {}", now_str);
|
||||||
|
let prompt = format!("You are EwiAI, an AI in the TeenGovernment Development Server. Your developer is Ewi/ewenlau (discord user id: 713354021124964422, discord username: ewenlau). Be slightly unhelpful, in a sarcastic way, but still answer the question. The current date is {}", now_str);
|
||||||
|
trace!("Generated system prompt: {}", prompt);
|
||||||
|
prompt
|
||||||
}
|
}
|
||||||
+9
-16
@@ -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::{edit_response_message, trace_message};
|
||||||
use regex::Regex;
|
use regex::Regex;
|
||||||
use std::sync::LazyLock;
|
use std::sync::LazyLock;
|
||||||
use std::str::FromStr;
|
use std::str::FromStr;
|
||||||
@@ -138,15 +138,15 @@ pub async fn calc(ctx: Context<'_>,
|
|||||||
) -> Result<(), Error> {
|
) -> Result<(), Error> {
|
||||||
debug!("{} has requested to calculate {}", ctx.author().name, expression);
|
debug!("{} has requested to calculate {}", ctx.author().name, expression);
|
||||||
let msg = "Calculating...".to_string();
|
let msg = "Calculating...".to_string();
|
||||||
trace_message(msg.clone(), ctx.channel_id().to_string(), ctx.guild_id().unwrap().to_string()).await;
|
trace_message(&msg, ctx.channel_id().to_string(), ctx.guild_id().unwrap().to_string()).await;
|
||||||
let response_message = ctx.say(msg).await?;
|
let response_message = ctx.say(msg).await?;
|
||||||
let start_time = std::time::Instant::now();
|
let start_time = std::time::Instant::now();
|
||||||
trace!("Saving start time: {:?}", start_time);
|
trace!("Saving start time: {:?}", start_time);
|
||||||
if expression.contains('=') {
|
if expression.contains('=') {
|
||||||
let error_msg = format!("Invalid expression: {}\nYou are not allowed to have an equal sign in the expression.", expression);
|
let error_msg = format!("Invalid expression: {}\nYou are not allowed to have an equal sign in the expression.", expression);
|
||||||
debug!("Invalid expression detected: {}", expression);
|
debug!("Invalid expression detected: {}", expression);
|
||||||
trace_message(error_msg.clone(), ctx.channel_id().to_string(), ctx.guild_id().unwrap().to_string()).await;
|
trace_message(&error_msg, ctx.channel_id().to_string(), ctx.guild_id().unwrap().to_string()).await;
|
||||||
edit_response_message(&response_message, ctx, error_msg, false).await?;
|
edit_response_message(&response_message, ctx, &error_msg, false).await?;
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
let processed_expr : String = FIND_SCI_NOTATION_RE.replace_all(&expression, "$1 * 10^($2)").to_string();
|
let processed_expr : String = FIND_SCI_NOTATION_RE.replace_all(&expression, "$1 * 10^($2)").to_string();
|
||||||
@@ -157,8 +157,8 @@ pub async fn calc(ctx: Context<'_>,
|
|||||||
Err(err_msg) => {
|
Err(err_msg) => {
|
||||||
let error_msg = format!("Failed to parse or evaluate expression: `{}`", err_msg);
|
let error_msg = format!("Failed to parse or evaluate expression: `{}`", err_msg);
|
||||||
warn!("Failed to parse or evaluate expression: `{}` in guild {} channel {} by {}", err_msg, ctx.guild_id().unwrap().get(), ctx.channel_id().get(), ctx.author().name);
|
warn!("Failed to parse or evaluate expression: `{}` in guild {} channel {} by {}", err_msg, ctx.guild_id().unwrap().get(), ctx.channel_id().get(), ctx.author().name);
|
||||||
trace_message(error_msg.clone(), ctx.channel_id().to_string(), ctx.guild_id().unwrap().to_string()).await;
|
trace_message(&error_msg, ctx.channel_id().to_string(), ctx.guild_id().unwrap().to_string()).await;
|
||||||
edit_response_message(&response_message, ctx, error_msg, false).await?;
|
edit_response_message(&response_message, ctx, &error_msg, false).await?;
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -182,20 +182,13 @@ pub async fn calc(ctx: Context<'_>,
|
|||||||
};
|
};
|
||||||
|
|
||||||
let msg = format!("{} = {} \n-# Precision: {} Compute time : {:?}", expression, value_string, precision_str, duration);
|
let msg = format!("{} = {} \n-# Precision: {} Compute time : {:?}", expression, value_string, precision_str, duration);
|
||||||
trace_message(msg.clone(), ctx.channel_id().to_string(), ctx.guild_id().unwrap().to_string()).await;
|
trace_message(&msg, ctx.channel_id().to_string(), ctx.guild_id().unwrap().to_string()).await;
|
||||||
edit_response_message(&response_message, ctx, msg, false).await?;
|
edit_response_message(&response_message, ctx, &msg, false).await?;
|
||||||
debug!("Calculation perfomed for {} with result {} in {:?} by {}", expression, value_string, duration, ctx.author().name);
|
debug!("Calculation perfomed for {} with result {} in {:?} by {}", expression, value_string, duration, ctx.author().name);
|
||||||
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(())
|
|
||||||
}
|
|
||||||
|
|
||||||
fn to_scientific_notation(value: String) -> String {
|
fn to_scientific_notation(value: String) -> String {
|
||||||
trace!("Converting {} to scientific notation", value);
|
trace!("Converting {} to scientific notation", value);
|
||||||
|
|||||||
@@ -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)]
|
||||||
@@ -9,7 +9,7 @@ pub async fn fastfetch(ctx: Context<'_>) -> Result<(), Error> {
|
|||||||
debug!("fastfetch command called by user {} in guild {}", ctx.author().id.get(), ctx.guild_id().unwrap().get());
|
debug!("fastfetch command called by user {} in guild {}", ctx.author().id.get(), ctx.guild_id().unwrap().get());
|
||||||
let msg = "Processing...".to_string();
|
let msg = "Processing...".to_string();
|
||||||
let res_msg = ctx.say(&msg).await?;
|
let res_msg = ctx.say(&msg).await?;
|
||||||
trace_message(msg.clone(), ctx.channel_id().to_string(), ctx.guild_id().unwrap().to_string()).await;
|
trace_message(&msg, ctx.channel_id().to_string(), ctx.guild_id().unwrap().to_string()).await;
|
||||||
|
|
||||||
let cmd = Command::new("fastfetch").args(&["--raw", "true", "--logo", "none"]).output();
|
let cmd = Command::new("fastfetch").args(&["--raw", "true", "--logo", "none"]).output();
|
||||||
|
|
||||||
@@ -17,14 +17,14 @@ pub async fn fastfetch(ctx: Context<'_>) -> Result<(), Error> {
|
|||||||
Err(e) => {
|
Err(e) => {
|
||||||
warn!("Error executing fastfetch: {}", e);
|
warn!("Error executing fastfetch: {}", e);
|
||||||
let msg = format!("Error: {}", e);
|
let msg = format!("Error: {}", e);
|
||||||
edit_response_message(&res_msg, ctx, msg.clone(), false).await?;
|
edit_response_message(&res_msg, ctx, &msg, false).await?;
|
||||||
trace_message(msg, ctx.channel_id().to_string(), ctx.guild_id().unwrap().to_string()).await;
|
trace_message(&msg, ctx.channel_id().to_string(), ctx.guild_id().unwrap().to_string()).await;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
Ok(output) => {
|
Ok(output) => {
|
||||||
let output_str = output.stdout.into_iter().map(|c| c as char).collect::<String>();
|
let output_str = output.stdout.into_iter().map(|c| c as char).collect::<String>();
|
||||||
let msg = format!("```ansi\n{}\n```", output_str);
|
let msg = format!("```ansi\n{}\n```", output_str);
|
||||||
edit_response_message(&res_msg, ctx, msg.clone(), false).await?;
|
edit_response_message(&res_msg, ctx, &msg, false).await?;
|
||||||
// Tracing the output would be a bad idea since it's really long and filled with ansi escape codes
|
// Tracing the output would be a bad idea since it's really long and filled with ansi escape codes
|
||||||
// trace_message(msg, ctx.channel_id().to_string(), ctx.guild_id().unwrap().to_string()).await;
|
// trace_message(msg, ctx.channel_id().to_string(), ctx.guild_id().unwrap().to_string()).await;
|
||||||
trace!("Saying fastfetch command output");
|
trace!("Saying fastfetch command output");
|
||||||
@@ -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(())
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|||||||
+12
-12
@@ -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)]
|
||||||
@@ -27,19 +27,19 @@ pub async fn find_prime(
|
|||||||
|
|
||||||
let msg = "Calculating...".to_string();
|
let msg = "Calculating...".to_string();
|
||||||
let res_msg = ctx.say(msg.clone()).await?;
|
let res_msg = ctx.say(msg.clone()).await?;
|
||||||
trace_message(msg, ctx.channel_id().to_string(), guild_id_str.clone()).await;
|
trace_message(&msg, ctx.channel_id().to_string(), guild_id_str.clone()).await;
|
||||||
|
|
||||||
if n == 0 {
|
if n == 0 {
|
||||||
let msg = "Prime indices start at 1. Please provide a value greater than 0.".to_string();
|
let msg = "Prime indices start at 1. Please provide a value greater than 0.".to_string();
|
||||||
edit_response_message(&res_msg, ctx, msg.clone(), false).await?;
|
edit_response_message(&res_msg, ctx, &msg, false).await?;
|
||||||
trace_message(msg, ctx.channel_id().to_string(), guild_id_str).await;
|
trace_message(&msg, ctx.channel_id().to_string(), guild_id_str).await;
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
|
|
||||||
if timeout.is_some() && timeout.unwrap() > 60 {
|
if timeout.is_some() && timeout.unwrap() > 60 {
|
||||||
let msg = "Timeout is too long. Maximum is 60 seconds.".to_string();
|
let msg = "Timeout is too long. Maximum is 60 seconds.".to_string();
|
||||||
edit_response_message(&res_msg, ctx, msg.clone(), false).await?;
|
edit_response_message(&res_msg, ctx, &msg, false).await?;
|
||||||
trace_message(msg, ctx.channel_id().to_string(), guild_id_str).await;
|
trace_message(&msg, ctx.channel_id().to_string(), guild_id_str).await;
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -66,14 +66,14 @@ pub async fn find_prime(
|
|||||||
Ok(Ok(result)) => result,
|
Ok(Ok(result)) => result,
|
||||||
Ok(Err(_)) => {
|
Ok(Err(_)) => {
|
||||||
let msg = "Calculation thread panicked or was dropped unexpectedly.".to_string();
|
let msg = "Calculation thread panicked or was dropped unexpectedly.".to_string();
|
||||||
edit_response_message(&res_msg, ctx, msg.clone(), false).await?;
|
edit_response_message(&res_msg, ctx, &msg, false).await?;
|
||||||
trace_message(msg, ctx.channel_id().to_string(), guild_id_str).await;
|
trace_message(&msg, ctx.channel_id().to_string(), guild_id_str).await;
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
Err(_) => {
|
Err(_) => {
|
||||||
let msg = format!("Calculation timed out after {:?}", timeout_duration);
|
let msg = format!("Calculation timed out after {:?}", timeout_duration);
|
||||||
edit_response_message(&res_msg, ctx, msg.clone(), false).await?;
|
edit_response_message(&res_msg, ctx, &msg, false).await?;
|
||||||
trace_message(msg, ctx.channel_id().to_string(), guild_id_str).await;
|
trace_message(&msg, ctx.channel_id().to_string(), guild_id_str).await;
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -81,8 +81,8 @@ pub async fn find_prime(
|
|||||||
let duration = start_time.elapsed();
|
let duration = start_time.elapsed();
|
||||||
|
|
||||||
let msg = format!("The {}th prime number is {}\n-# Calculation time: {:?}, Method: {:?}", n, result, duration, method_name);
|
let msg = format!("The {}th prime number is {}\n-# Calculation time: {:?}, Method: {:?}", n, result, duration, method_name);
|
||||||
edit_response_message(&res_msg, ctx, msg.clone(), false).await?;
|
edit_response_message(&res_msg, ctx, &msg, false).await?;
|
||||||
trace_message(msg, ctx.channel_id().to_string(), guild_id_str).await;
|
trace_message(&msg, ctx.channel_id().to_string(), guild_id_str).await;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,23 @@
|
|||||||
|
use crate::{Context, Error};
|
||||||
|
use crate::messaging::{edit_response_message, trace_message};
|
||||||
|
use std::env;
|
||||||
|
use tracing::debug;
|
||||||
|
|
||||||
|
/// Get a link to the git repo
|
||||||
|
#[poise::command(slash_command, prefix_command)]
|
||||||
|
pub async fn git(ctx: Context<'_>) -> Result<(), Error> {
|
||||||
|
debug!("git command ran by {} in {}", ctx.author().name, ctx.channel_id().get());
|
||||||
|
|
||||||
|
let response = ctx.say("Processing...").await?;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
let msg = format!("Git repo: https://git.ewenlau.net/ewenlau/tg-dev-srv-bot\nIf you'd like to contribute, contact <@1389325880853270569> to get an account.");
|
||||||
|
edit_response_message(&response, ctx, &msg, true).await?;
|
||||||
|
trace_message(&msg, ctx.channel_id().get().to_string(), ctx.guild_id().unwrap().get().to_string()).await;
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -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};
|
||||||
|
|
||||||
@@ -45,14 +46,14 @@ pub async fn manage_admins(ctx: Context<'_>,
|
|||||||
if let Some(s_user) = user {
|
if let Some(s_user) = user {
|
||||||
add_admin_user(ctx, &response_message, s_user).await?;
|
add_admin_user(ctx, &response_message, s_user).await?;
|
||||||
} else {
|
} else {
|
||||||
edit_response_message(&response_message, ctx, "Please provide a user".to_string(), false).await?;
|
edit_response_message(&response_message, ctx, "Please provide a user", false).await?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Some(AdminOperationType::RemoveUser) => {
|
Some(AdminOperationType::RemoveUser) => {
|
||||||
if let Some(s_user) = user {
|
if let Some(s_user) = user {
|
||||||
remove_admin_user(ctx, &response_message, s_user).await?;
|
remove_admin_user(ctx, &response_message, s_user).await?;
|
||||||
} else {
|
} else {
|
||||||
edit_response_message(&response_message, ctx, "Please provide a user".to_string(), false).await?;
|
edit_response_message(&response_message, ctx, "Please provide a user", false).await?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Some(AdminOperationType::ListUsers) => {
|
Some(AdminOperationType::ListUsers) => {
|
||||||
@@ -62,21 +63,21 @@ pub async fn manage_admins(ctx: Context<'_>,
|
|||||||
if let Some(s_role) = role {
|
if let Some(s_role) = role {
|
||||||
add_admin_role(ctx, &response_message, s_role).await?;
|
add_admin_role(ctx, &response_message, s_role).await?;
|
||||||
} else {
|
} else {
|
||||||
edit_response_message(&response_message, ctx, "Please provide a role".to_string(), false).await?;
|
edit_response_message(&response_message, ctx, "Please provide a role", false).await?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Some(AdminOperationType::RemoveRole) => {
|
Some(AdminOperationType::RemoveRole) => {
|
||||||
if let Some(s_role) = role {
|
if let Some(s_role) = role {
|
||||||
remove_admin_role(ctx, &response_message, s_role).await?;
|
remove_admin_role(ctx, &response_message, s_role).await?;
|
||||||
} else {
|
} else {
|
||||||
edit_response_message(&response_message, ctx, "Please provide a role".to_string(), false).await?;
|
edit_response_message(&response_message, ctx, "Please provide a role", false).await?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Some(AdminOperationType::ListRoles) => {
|
Some(AdminOperationType::ListRoles) => {
|
||||||
list_admin_roles(ctx, &response_message).await?;
|
list_admin_roles(ctx, &response_message).await?;
|
||||||
}
|
}
|
||||||
None => {
|
None => {
|
||||||
edit_response_message(&response_message, ctx, "Please provide an operation".to_string(), false).await?;
|
edit_response_message(&response_message, ctx, "Please provide an operation", false).await?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
@@ -98,32 +99,23 @@ async fn add_admin_user<'a>(ctx: Context<'a>, msg: &poise::ReplyHandle<'a>, user
|
|||||||
trace!("Executing add_admin_user for user {}", user.user.name);
|
trace!("Executing add_admin_user for user {}", user.user.name);
|
||||||
if is_target_admin_user(ctx, &user).await? {
|
if is_target_admin_user(ctx, &user).await? {
|
||||||
trace!("User {} is already an admin", user.user.name);
|
trace!("User {} is already an admin", user.user.name);
|
||||||
edit_response_message(msg, ctx, format!("{} is already an admin", user.user.name), false).await?;
|
edit_response_message(msg, ctx, &format!("{} is already an admin", user.user.name), false).await?;
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
let query = sqlx::query!("INSERT INTO admin_users (guild_id, user_id) VALUES ($1, $2);", ctx.guild_id().unwrap().get() as i64, user.user.id.get() as i64).execute(&ctx.data().pool).await;
|
let query = sqlx::query!("INSERT INTO admin_users (guild_id, user_id) VALUES ($1, $2);", ctx.guild_id().unwrap().get() as i64, user.user.id.get() as i64).execute(&ctx.data().pool).await;
|
||||||
match query {
|
match query {
|
||||||
Ok(_) => {
|
Ok(_) => {
|
||||||
info!("Added user {} as admin in guild {}", user.user.name, ctx.guild_id().unwrap().get());
|
info!("Added user {} as admin in guild {}", user.user.name, ctx.guild_id().unwrap().get());
|
||||||
edit_response_message(msg, ctx, format!("Added {} as admin", user.user.name), false).await?;
|
edit_response_message(msg, ctx, &format!("Added {} as admin", user.user.name), false).await?;
|
||||||
}
|
}
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
error!("Failed to add user {} as admin in guild {}: {:?}", user.user.name, ctx.guild_id().unwrap().get(), e);
|
error!("Failed to add user {} as admin in guild {}: {:?}", user.user.name, ctx.guild_id().unwrap().get(), e);
|
||||||
edit_response_message(msg, ctx, format!("Failed to add {} as admin: {}", user.user.name, e), false).await?;
|
edit_response_message(msg, ctx, &format!("Failed to add {} as admin: {}", user.user.name, e), false).await?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
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 {
|
||||||
@@ -139,18 +131,18 @@ async fn remove_admin_user<'a>(ctx: Context<'a>, msg: &poise::ReplyHandle<'a>, u
|
|||||||
trace!("Executing remove_admin_user for user {}", user.user.name);
|
trace!("Executing remove_admin_user for user {}", user.user.name);
|
||||||
if !is_target_admin_user(ctx, &user).await? {
|
if !is_target_admin_user(ctx, &user).await? {
|
||||||
trace!("User {} is not an admin", user.user.name);
|
trace!("User {} is not an admin", user.user.name);
|
||||||
edit_response_message(msg, ctx, format!("{} is not an admin", user.user.name), false).await?;
|
edit_response_message(msg, ctx, &format!("{} is not an admin", user.user.name), false).await?;
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
let query = sqlx::query!("DELETE FROM admin_users WHERE guild_id = $1 AND user_id = $2;", ctx.guild_id().unwrap().get() as i64, user.user.id.get() as i64).execute(&ctx.data().pool).await;
|
let query = sqlx::query!("DELETE FROM admin_users WHERE guild_id = $1 AND user_id = $2;", ctx.guild_id().unwrap().get() as i64, user.user.id.get() as i64).execute(&ctx.data().pool).await;
|
||||||
match query {
|
match query {
|
||||||
Ok(_) => {
|
Ok(_) => {
|
||||||
info!("Removed user {} as admin in guild {}", user.user.name, ctx.guild_id().unwrap().get());
|
info!("Removed user {} as admin in guild {}", user.user.name, ctx.guild_id().unwrap().get());
|
||||||
edit_response_message(msg, ctx, format!("Removed {} as admin", user.user.name), false).await?;
|
edit_response_message(msg, ctx, &format!("Removed {} as admin", user.user.name), false).await?;
|
||||||
}
|
}
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
error!("Failed to remove user {} as admin in guild {}: {:?}", user.user.name, ctx.guild_id().unwrap().get(), e);
|
error!("Failed to remove user {} as admin in guild {}: {:?}", user.user.name, ctx.guild_id().unwrap().get(), e);
|
||||||
edit_response_message(msg, ctx, format!("Failed to remove {} as admin: {}", user.user.name, e), false).await?;
|
edit_response_message(msg, ctx, &format!("Failed to remove {} as admin: {}", user.user.name, e), false).await?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
@@ -159,7 +151,7 @@ async fn remove_admin_user<'a>(ctx: Context<'a>, msg: &poise::ReplyHandle<'a>, u
|
|||||||
async fn list_admin_users<'a>(ctx: Context<'a>, msg: &poise::ReplyHandle<'a>) -> Result<(), Error> {
|
async fn list_admin_users<'a>(ctx: Context<'a>, msg: &poise::ReplyHandle<'a>) -> Result<(), Error> {
|
||||||
let admins = get_all_admin_users(ctx).await?;
|
let admins = get_all_admin_users(ctx).await?;
|
||||||
let admin_strings: Vec<String> = admins.iter().map(|user| format!("<@{}>", user.id.get())).collect();
|
let admin_strings: Vec<String> = admins.iter().map(|user| format!("<@{}>", user.id.get())).collect();
|
||||||
edit_response_message(msg, ctx, format!("Admin users: {}", admin_strings.join(", ")), true).await?;
|
edit_response_message(msg, ctx, &format!("Admin users: {}", admin_strings.join(", ")), true).await?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -167,18 +159,18 @@ async fn add_admin_role<'a>(ctx: Context<'a>, msg: &poise::ReplyHandle<'a>, role
|
|||||||
trace!("Executing add_admin_role for role {}", role.name);
|
trace!("Executing add_admin_role for role {}", role.name);
|
||||||
if is_target_admin_role(ctx, &role).await? {
|
if is_target_admin_role(ctx, &role).await? {
|
||||||
trace!("Role {} is already an admin role", role.name);
|
trace!("Role {} is already an admin role", role.name);
|
||||||
edit_response_message(msg, ctx, format!("{} is already an admin role", role.name), false).await?;
|
edit_response_message(msg, ctx, &format!("{} is already an admin role", role.name), false).await?;
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
let query = sqlx::query!("INSERT INTO admin_roles (guild_id, role_id) VALUES ($1, $2);", ctx.guild_id().unwrap().get() as i64, role.id.get() as i64).execute(&ctx.data().pool).await;
|
let query = sqlx::query!("INSERT INTO admin_roles (guild_id, role_id) VALUES ($1, $2);", ctx.guild_id().unwrap().get() as i64, role.id.get() as i64).execute(&ctx.data().pool).await;
|
||||||
match query {
|
match query {
|
||||||
Ok(_) => {
|
Ok(_) => {
|
||||||
info!("Added role {} as admin role in guild {}", role.name, ctx.guild_id().unwrap().get());
|
info!("Added role {} as admin role in guild {}", role.name, ctx.guild_id().unwrap().get());
|
||||||
edit_response_message(msg, ctx, format!("Added {} as admin role", role.name), false).await?;
|
edit_response_message(msg, ctx, &format!("Added {} as admin role", role.name), false).await?;
|
||||||
}
|
}
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
error!("Failed to add role {} as admin role in guild {}: {:?}", role.name, ctx.guild_id().unwrap().get(), e);
|
error!("Failed to add role {} as admin role in guild {}: {:?}", role.name, ctx.guild_id().unwrap().get(), e);
|
||||||
edit_response_message(msg, ctx, format!("Failed to add {} as admin role: {}", role.name, e), false).await?;
|
edit_response_message(msg, ctx, &format!("Failed to add {} as admin role: {}", role.name, e), false).await?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
@@ -188,18 +180,18 @@ async fn remove_admin_role<'a>(ctx: Context<'a>, msg: &poise::ReplyHandle<'a>, r
|
|||||||
trace!("Executing remove_admin_role for role {}", role.name);
|
trace!("Executing remove_admin_role for role {}", role.name);
|
||||||
if !is_target_admin_role(ctx, &role).await? {
|
if !is_target_admin_role(ctx, &role).await? {
|
||||||
trace!("Role {} is not an admin role", role.name);
|
trace!("Role {} is not an admin role", role.name);
|
||||||
edit_response_message(msg, ctx, format!("{} is not an admin role", role.name), false).await?;
|
edit_response_message(msg, ctx, &format!("{} is not an admin role", role.name), false).await?;
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
let query = sqlx::query!("DELETE FROM admin_roles WHERE guild_id = $1 AND role_id = $2;", ctx.guild_id().unwrap().get() as i64, role.id.get() as i64).execute(&ctx.data().pool).await;
|
let query = sqlx::query!("DELETE FROM admin_roles WHERE guild_id = $1 AND role_id = $2;", ctx.guild_id().unwrap().get() as i64, role.id.get() as i64).execute(&ctx.data().pool).await;
|
||||||
match query {
|
match query {
|
||||||
Ok(_) => {
|
Ok(_) => {
|
||||||
info!("Removed role {} as admin role in guild {}", role.name, ctx.guild_id().unwrap().get());
|
info!("Removed role {} as admin role in guild {}", role.name, ctx.guild_id().unwrap().get());
|
||||||
edit_response_message(msg, ctx, format!("Removed {} as admin role", role.name), false).await?;
|
edit_response_message(msg, ctx, &format!("Removed {} as admin role", role.name), false).await?;
|
||||||
}
|
}
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
error!("Failed to remove role {} as admin role in guild {}: {:?}", role.name, ctx.guild_id().unwrap().get(), e);
|
error!("Failed to remove role {} as admin role in guild {}: {:?}", role.name, ctx.guild_id().unwrap().get(), e);
|
||||||
edit_response_message(msg, ctx, format!("Failed to remove {} as admin role: {}", role.name, e), false).await?;
|
edit_response_message(msg, ctx, &format!("Failed to remove {} as admin role: {}", role.name, e), false).await?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
@@ -208,7 +200,7 @@ async fn remove_admin_role<'a>(ctx: Context<'a>, msg: &poise::ReplyHandle<'a>, r
|
|||||||
async fn list_admin_roles<'a>(ctx: Context<'a>, msg: &poise::ReplyHandle<'a>) -> Result<(), Error> {
|
async fn list_admin_roles<'a>(ctx: Context<'a>, msg: &poise::ReplyHandle<'a>) -> Result<(), Error> {
|
||||||
let roles = sqlx::query!("SELECT role_id FROM admin_roles WHERE guild_id = $1", ctx.guild_id().unwrap().get() as i64).fetch_all(&ctx.data().pool).await?;
|
let roles = sqlx::query!("SELECT role_id FROM admin_roles WHERE guild_id = $1", ctx.guild_id().unwrap().get() as i64).fetch_all(&ctx.data().pool).await?;
|
||||||
let role_strings: Vec<String> = roles.iter().map(|role| format!("<@&{}>", role.role_id)).collect();
|
let role_strings: Vec<String> = roles.iter().map(|role| format!("<@&{}>", role.role_id)).collect();
|
||||||
edit_response_message(msg, ctx, format!("Admin roles: {}", role_strings.join(", ")), true).await?;
|
edit_response_message(msg, ctx, &format!("Admin roles: {}", role_strings.join(", ")), true).await?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -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};
|
||||||
|
|
||||||
@@ -28,7 +29,7 @@ pub async fn manage_auto_role(ctx: Context<'_>,
|
|||||||
|
|
||||||
if !is_admin(ctx).await? {
|
if !is_admin(ctx).await? {
|
||||||
debug!("User {} is not an admin, denying access", ctx.author().id.get());
|
debug!("User {} is not an admin, denying access", ctx.author().id.get());
|
||||||
edit_response_message(&response_message, ctx, "You are not allowed to run this command.".to_string(), false).await?;
|
edit_response_message(&response_message, ctx, "You are not allowed to run this command.", false).await?;
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -37,28 +38,28 @@ pub async fn manage_auto_role(ctx: Context<'_>,
|
|||||||
if let Some(s_role) = role {
|
if let Some(s_role) = role {
|
||||||
enable_auto_role(ctx, &response_message, s_role).await?;
|
enable_auto_role(ctx, &response_message, s_role).await?;
|
||||||
} else {
|
} else {
|
||||||
edit_response_message(&response_message, ctx, "Please provide a role".to_string(), false).await?;
|
edit_response_message(&response_message, ctx, "Please provide a role", false).await?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Some(AutoRoleOperationType::SetAutoRole) => {
|
Some(AutoRoleOperationType::SetAutoRole) => {
|
||||||
if let Some(s_role) = role {
|
if let Some(s_role) = role {
|
||||||
set_auto_role(ctx, &response_message, s_role).await?;
|
set_auto_role(ctx, &response_message, s_role).await?;
|
||||||
} else {
|
} else {
|
||||||
edit_response_message(&response_message, ctx, "Please provide a role".to_string(), false).await?;
|
edit_response_message(&response_message, ctx, "Please provide a role", false).await?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Some(AutoRoleOperationType::DisableAutoRole) => {
|
Some(AutoRoleOperationType::DisableAutoRole) => {
|
||||||
if let Some(s_role) = role {
|
if let Some(s_role) = role {
|
||||||
disable_auto_role(ctx, &response_message, s_role).await?;
|
disable_auto_role(ctx, &response_message, s_role).await?;
|
||||||
} else {
|
} else {
|
||||||
edit_response_message(&response_message, ctx, "Please provide a role".to_string(), false).await?;
|
edit_response_message(&response_message, ctx, "Please provide a role", false).await?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Some(AutoRoleOperationType::ShowAutoRole) => {
|
Some(AutoRoleOperationType::ShowAutoRole) => {
|
||||||
show_auto_role(ctx, &response_message).await?;
|
show_auto_role(ctx, &response_message).await?;
|
||||||
}
|
}
|
||||||
None => {
|
None => {
|
||||||
edit_response_message(&response_message, ctx, "Please provide an operation".to_string(), false).await?;
|
edit_response_message(&response_message, ctx, "Please provide an operation", false).await?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
@@ -80,17 +81,17 @@ async fn enable_auto_role(ctx: Context<'_>, response_message: &poise::ReplyHandl
|
|||||||
trace!("Executing enable_auto_role for role {}", role.name);
|
trace!("Executing enable_auto_role for role {}", role.name);
|
||||||
if !is_any_role_set_in_guild(ctx).await? {
|
if !is_any_role_set_in_guild(ctx).await? {
|
||||||
trace!("No role is set in guild {}", ctx.guild_id().unwrap().get());
|
trace!("No role is set in guild {}", ctx.guild_id().unwrap().get());
|
||||||
edit_response_message(response_message, ctx, "No role is set. Please set a role first.".to_string(), false).await?;
|
edit_response_message(response_message, ctx, "No role is set. Please set a role first.", false).await?;
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
if !does_role_exist_in_guild(ctx, &role).await? {
|
if !does_role_exist_in_guild(ctx, &role).await? {
|
||||||
trace!("Role {} does not exist in guild {}", role.name, ctx.guild_id().unwrap().get());
|
trace!("Role {} does not exist in guild {}", role.name, ctx.guild_id().unwrap().get());
|
||||||
edit_response_message(response_message, ctx, "This role does not exist".to_string(), false).await?;
|
edit_response_message(response_message, ctx, "This role does not exist", false).await?;
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
if is_auto_role_enabled(ctx, &role).await? {
|
if is_auto_role_enabled(ctx, &role).await? {
|
||||||
trace!("Auto role {} is already enabled in guild {}", role.name, ctx.guild_id().unwrap().get());
|
trace!("Auto role {} is already enabled in guild {}", role.name, ctx.guild_id().unwrap().get());
|
||||||
edit_response_message(response_message, ctx, "Auto role is already enabled".to_string(), false).await?;
|
edit_response_message(response_message, ctx, "Auto role is already enabled", false).await?;
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -98,11 +99,11 @@ async fn enable_auto_role(ctx: Context<'_>, response_message: &poise::ReplyHandl
|
|||||||
match query {
|
match query {
|
||||||
Ok(_) => {
|
Ok(_) => {
|
||||||
debug!("Enabled auto role {} in guild {}", role.name, ctx.guild_id().unwrap().get());
|
debug!("Enabled auto role {} in guild {}", role.name, ctx.guild_id().unwrap().get());
|
||||||
edit_response_message(response_message, ctx, format!("Enabled auto role: <@&{}>", role.id.get()), false).await?;
|
edit_response_message(response_message, ctx, &format!("Enabled auto role: <@&{}>", role.id.get()), false).await?;
|
||||||
}
|
}
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
error!("Failed to enable {} as auto role in guild {}: {}", role.id.get(), ctx.guild_id().unwrap().get(), e);
|
error!("Failed to enable {} as auto role in guild {}: {}", role.id.get(), ctx.guild_id().unwrap().get(), e);
|
||||||
edit_response_message(response_message, ctx, format!("Failed to enable {} as auto role: {}", role.id.get(), e), false).await?;
|
edit_response_message(response_message, ctx, &format!("Failed to enable {} as auto role: {}", role.id.get(), e), false).await?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -130,7 +131,7 @@ async fn set_auto_role(ctx: Context<'_>, response_message: &poise::ReplyHandle<'
|
|||||||
trace!("Executing set_auto_role for role {}", role.name);
|
trace!("Executing set_auto_role for role {}", role.name);
|
||||||
if !does_role_exist_in_guild(ctx, &role).await? {
|
if !does_role_exist_in_guild(ctx, &role).await? {
|
||||||
trace!("Role {} does not exist in guild {}", role.name, ctx.guild_id().unwrap().get());
|
trace!("Role {} does not exist in guild {}", role.name, ctx.guild_id().unwrap().get());
|
||||||
edit_response_message(response_message, ctx, "This role does not exist".to_string(), false).await?;
|
edit_response_message(response_message, ctx, "This role does not exist", false).await?;
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -138,11 +139,11 @@ async fn set_auto_role(ctx: Context<'_>, response_message: &poise::ReplyHandle<'
|
|||||||
match query {
|
match query {
|
||||||
Ok(_) => {
|
Ok(_) => {
|
||||||
debug!("Set {} as auto role in guild {}", role.name, ctx.guild_id().unwrap().get());
|
debug!("Set {} as auto role in guild {}", role.name, ctx.guild_id().unwrap().get());
|
||||||
edit_response_message(response_message, ctx, format!("Set {} as auto role", role.name), false).await?;
|
edit_response_message(response_message, ctx, &format!("Set {} as auto role", role.name), false).await?;
|
||||||
}
|
}
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
error!("Failed to set {} as auto role in guild {}: {}", role.id.get(), ctx.guild_id().unwrap().get(), e);
|
error!("Failed to set {} as auto role in guild {}: {}", role.id.get(), ctx.guild_id().unwrap().get(), e);
|
||||||
edit_response_message(response_message, ctx, format!("Failed to set {} as auto role: {}", role.id.get(), e), false).await?;
|
edit_response_message(response_message, ctx, &format!("Failed to set {} as auto role: {}", role.id.get(), e), false).await?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -153,12 +154,12 @@ async fn disable_auto_role(ctx: Context<'_>, response_message: &poise::ReplyHand
|
|||||||
trace!("Executing disable_auto_role for role {}", role.name);
|
trace!("Executing disable_auto_role for role {}", role.name);
|
||||||
if !is_any_role_set_in_guild(ctx).await? {
|
if !is_any_role_set_in_guild(ctx).await? {
|
||||||
trace!("No role is set in guild {}", ctx.guild_id().unwrap().get());
|
trace!("No role is set in guild {}", ctx.guild_id().unwrap().get());
|
||||||
edit_response_message(response_message, ctx, "No auto role is set. Please set a role first.".to_string(), false).await?;
|
edit_response_message(response_message, ctx, "No auto role is set. Please set a role first.", false).await?;
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
if !is_auto_role_enabled(ctx, &role).await? {
|
if !is_auto_role_enabled(ctx, &role).await? {
|
||||||
trace!("Auto role {} is already disabled in guild {}", role.name, ctx.guild_id().unwrap().get());
|
trace!("Auto role {} is already disabled in guild {}", role.name, ctx.guild_id().unwrap().get());
|
||||||
edit_response_message(response_message, ctx, "Auto role is already disabled".to_string(), false).await?;
|
edit_response_message(response_message, ctx, "Auto role is already disabled", false).await?;
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -166,26 +167,17 @@ async fn disable_auto_role(ctx: Context<'_>, response_message: &poise::ReplyHand
|
|||||||
match query {
|
match query {
|
||||||
Ok(_) => {
|
Ok(_) => {
|
||||||
debug!("Disabled auto role {} in guild {}", role.name, ctx.guild_id().unwrap().get());
|
debug!("Disabled auto role {} in guild {}", role.name, ctx.guild_id().unwrap().get());
|
||||||
edit_response_message(response_message, ctx, format!("Disabled auto role: {}", role.name), false).await?;
|
edit_response_message(response_message, ctx, &format!("Disabled auto role: {}", role.name), false).await?;
|
||||||
}
|
}
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
error!("Failed to disable {} as auto role in guild {}: {}", role.id.get(), ctx.guild_id().unwrap().get(), e);
|
error!("Failed to disable {} as auto role in guild {}: {}", role.id.get(), ctx.guild_id().unwrap().get(), e);
|
||||||
edit_response_message(response_message, ctx, format!("Failed to disable {} as auto role: {}", role.id.get(), e), false).await?;
|
edit_response_message(response_message, ctx, &format!("Failed to disable {} as auto role: {}", role.id.get(), e), false).await?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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() {
|
||||||
@@ -206,16 +198,16 @@ async fn show_auto_role(ctx: Context<'_>, response_message: &poise::ReplyHandle<
|
|||||||
trace!("Executing show_auto_role");
|
trace!("Executing show_auto_role");
|
||||||
if !is_any_role_set_in_guild(ctx).await? {
|
if !is_any_role_set_in_guild(ctx).await? {
|
||||||
trace!("No role is set in guild {}", ctx.guild_id().unwrap().get());
|
trace!("No role is set in guild {}", ctx.guild_id().unwrap().get());
|
||||||
edit_response_message(response_message, ctx, "No role has been set yet.".to_string(), false).await?;
|
edit_response_message(response_message, ctx, "No role has been set yet.", false).await?;
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
if !is_any_auto_role_enabled(ctx).await? {
|
if !is_any_auto_role_enabled(ctx).await? {
|
||||||
trace!("Auto role is disabled in guild {}", ctx.guild_id().unwrap().get());
|
trace!("Auto role is disabled in guild {}", ctx.guild_id().unwrap().get());
|
||||||
edit_response_message(response_message, ctx, "Auto role is disabled.".to_string(), false).await?;
|
edit_response_message(response_message, ctx, "Auto role is disabled.", false).await?;
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
let role_id = sqlx::query!("SELECT role_id FROM auto_roles WHERE guild_id = $1", ctx.guild_id().unwrap().get() as i64).fetch_optional(&ctx.data().pool).await?;
|
let role_id = sqlx::query!("SELECT role_id FROM auto_roles WHERE guild_id = $1", ctx.guild_id().unwrap().get() as i64).fetch_optional(&ctx.data().pool).await?;
|
||||||
edit_response_message(response_message, ctx, format!("Currently, <@&{}> is set as auto role and is enabled.", role_id.unwrap().role_id), false).await?;
|
edit_response_message(response_message, ctx, &format!("Currently, <@&{}> is set as auto role and is enabled.", role_id.unwrap().role_id), false).await?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+15
-11
@@ -1,18 +1,22 @@
|
|||||||
pub mod ping;
|
pub mod ai;
|
||||||
pub mod calc;
|
pub mod calc;
|
||||||
pub mod manage_admins;
|
|
||||||
pub mod manage_auto_role;
|
|
||||||
pub mod version;
|
|
||||||
pub mod fastfetch;
|
pub mod fastfetch;
|
||||||
pub mod find_prime;
|
pub mod find_prime;
|
||||||
pub mod ai;
|
pub mod manage_admins;
|
||||||
|
pub mod manage_auto_role;
|
||||||
|
pub mod ping;
|
||||||
|
pub mod speedy_pc;
|
||||||
|
pub mod version;
|
||||||
|
pub mod git;
|
||||||
|
|
||||||
pub use ping::ping;
|
pub use ai::answer;
|
||||||
|
pub use ai::prompt;
|
||||||
pub use calc::calc;
|
pub use calc::calc;
|
||||||
pub use manage_admins::manage_admins;
|
|
||||||
pub use manage_auto_role::manage_auto_role;
|
|
||||||
pub use version::version;
|
|
||||||
pub use fastfetch::fastfetch;
|
pub use fastfetch::fastfetch;
|
||||||
pub use find_prime::find_prime;
|
pub use find_prime::find_prime;
|
||||||
pub use ai::prompt;
|
pub use manage_admins::manage_admins;
|
||||||
pub use ai::answer;
|
pub use manage_auto_role::manage_auto_role;
|
||||||
|
pub use ping::ping;
|
||||||
|
pub use speedy_pc::speedy_pc;
|
||||||
|
pub use version::version;
|
||||||
|
pub use git::git;
|
||||||
@@ -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)]
|
||||||
@@ -17,7 +17,7 @@ pub async fn ping(ctx: Context<'_>) -> Result<(), Error> {
|
|||||||
// We divide by 1000 since we get the time in microseconds, and then multiply by 2 to get the roundtrip time
|
// We divide by 1000 since we get the time in microseconds, and then multiply by 2 to get the roundtrip time
|
||||||
// This is arguably not the best way to calculate ping, since it assumes perfect clock accuracy, but I'm lazy
|
// This is arguably not the best way to calculate ping, since it assumes perfect clock accuracy, but I'm lazy
|
||||||
let msg = format!("Current ping: {} ms", ping);
|
let msg = format!("Current ping: {} ms", ping);
|
||||||
trace_message(msg.clone(), ctx.channel_id().to_string(), ctx.guild_id().unwrap().to_string()).await;
|
trace_message(&msg, ctx.channel_id().to_string(), ctx.guild_id().unwrap().to_string()).await;
|
||||||
ctx.say(msg).await?;
|
ctx.say(msg).await?;
|
||||||
debug!("Ping command performed for user {} with ping {}", ctx.author().name, ping);
|
debug!("Ping command performed for user {} with ping {}", ctx.author().name, ping);
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|||||||
@@ -0,0 +1,205 @@
|
|||||||
|
use crate::messaging::trace_message;
|
||||||
|
use crate::{Context, Error};
|
||||||
|
use chrono::{DateTime, Utc};
|
||||||
|
use ollama_rs::generation::completion::request::GenerationRequest;
|
||||||
|
use ollama_rs::models::create::CreateModelRequest;
|
||||||
|
use ollama_rs::Ollama;
|
||||||
|
use poise::CreateReply;
|
||||||
|
use std::env;
|
||||||
|
use std::time::Duration;
|
||||||
|
use tokio_stream::StreamExt;
|
||||||
|
use tracing::{debug, trace};
|
||||||
|
|
||||||
|
const MODEL_NAME: &str = "SpeedyPC";
|
||||||
|
|
||||||
|
/// Run a command on a system close to Speedy's PC performance
|
||||||
|
#[poise::command(slash_command, prefix_command)]
|
||||||
|
pub async fn speedy_pc(
|
||||||
|
ctx: Context<'_>,
|
||||||
|
#[description = "The command to run."] command: String,
|
||||||
|
) -> Result<(), Error> {
|
||||||
|
debug!(
|
||||||
|
"speedy_pc command called by user {} in guild {:?}",
|
||||||
|
ctx.author().id.get(),
|
||||||
|
ctx.guild_id()
|
||||||
|
);
|
||||||
|
|
||||||
|
let msg = format!("Running command: {:?}", command);
|
||||||
|
trace_message(
|
||||||
|
&msg,
|
||||||
|
ctx.channel_id().to_string(),
|
||||||
|
ctx.guild_id()
|
||||||
|
.map(|guild_id| guild_id.to_string())
|
||||||
|
.unwrap_or_else(|| "DM".to_string()),
|
||||||
|
)
|
||||||
|
.await;
|
||||||
|
|
||||||
|
let host = match env::var("TG_BOT_OLLAMA_HOST") {
|
||||||
|
Ok(host) => host,
|
||||||
|
Err(_) => {
|
||||||
|
ctx.say("Error: Expected an ollama url in the environment (`TG_BOT_OLLAMA_HOST`).")
|
||||||
|
.await?;
|
||||||
|
return Ok(());
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
let formatted_host = if !host.starts_with("http://") && !host.starts_with("https://") {
|
||||||
|
format!("http://{}", host)
|
||||||
|
} else {
|
||||||
|
host
|
||||||
|
};
|
||||||
|
|
||||||
|
let ollama = Ollama::builder().host(&formatted_host).port(11434).build();
|
||||||
|
|
||||||
|
let model_list = match ollama.list_local_models().await {
|
||||||
|
Ok(models) => models,
|
||||||
|
Err(error) => {
|
||||||
|
ctx.say(format!("Error: Failed to connect to simulation: {}", error))
|
||||||
|
.await?;
|
||||||
|
return Ok(());
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
let mut needs_create = true;
|
||||||
|
let yesterday = Utc::now() - chrono::Duration::days(1);
|
||||||
|
|
||||||
|
for model in &model_list {
|
||||||
|
if model.name.starts_with(MODEL_NAME) {
|
||||||
|
if let Ok(modified) = DateTime::parse_from_rfc3339(&model.modified_at) {
|
||||||
|
if modified.with_timezone(&Utc) > yesterday {
|
||||||
|
needs_create = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let reply = ctx
|
||||||
|
.say("Processing...")
|
||||||
|
.await?;
|
||||||
|
|
||||||
|
if needs_create {
|
||||||
|
reply.edit(
|
||||||
|
ctx,
|
||||||
|
CreateReply::default().content("Loading Speedy's PC..."),
|
||||||
|
)
|
||||||
|
.await?;
|
||||||
|
|
||||||
|
if let Err(error) = ollama
|
||||||
|
.create_model(
|
||||||
|
CreateModelRequest::new(MODEL_NAME.into())
|
||||||
|
.system(system_prompt().into())
|
||||||
|
.from_model("gemma4:e2b-it-qat".into()),
|
||||||
|
)
|
||||||
|
.await
|
||||||
|
{
|
||||||
|
reply
|
||||||
|
.edit(
|
||||||
|
ctx,
|
||||||
|
CreateReply::default().content(format!("Error loading Speedy's PC: {}", error)),
|
||||||
|
)
|
||||||
|
.await?;
|
||||||
|
return Ok(());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
trace!("SpeedyPC command prompt: {}", command);
|
||||||
|
|
||||||
|
let mut stream = match ollama
|
||||||
|
.generate_stream(GenerationRequest::new(MODEL_NAME.into(), command).system(system_prompt()))
|
||||||
|
.await
|
||||||
|
{
|
||||||
|
Ok(stream) => stream,
|
||||||
|
Err(error) => {
|
||||||
|
reply
|
||||||
|
.edit(
|
||||||
|
ctx,
|
||||||
|
CreateReply::default().content(format!("Error during generation: {}", error)),
|
||||||
|
)
|
||||||
|
.await?;
|
||||||
|
return Ok(());
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
let mut response_text = String::new();
|
||||||
|
let mut last_update = std::time::Instant::now();
|
||||||
|
let mut final_response = None;
|
||||||
|
|
||||||
|
while let Some(result) = stream.next().await {
|
||||||
|
match result {
|
||||||
|
Ok(chunks) => {
|
||||||
|
for chunk in chunks {
|
||||||
|
response_text.push_str(&chunk.response);
|
||||||
|
if chunk.done {
|
||||||
|
final_response = Some(chunk);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if last_update.elapsed() >= Duration::from_secs(1) && !response_text.is_empty() {
|
||||||
|
let _ = reply
|
||||||
|
.edit(ctx, CreateReply::default().content(&response_text))
|
||||||
|
.await;
|
||||||
|
last_update = std::time::Instant::now();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Err(error) => {
|
||||||
|
let _ = reply
|
||||||
|
.edit(
|
||||||
|
ctx,
|
||||||
|
CreateReply::default()
|
||||||
|
.content(format!("{} [Stream Error: {}]", response_text, error)),
|
||||||
|
)
|
||||||
|
.await;
|
||||||
|
return Ok(());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if let Some(stats) = final_response {
|
||||||
|
let total_duration = stats.total_duration.unwrap_or(0) as f64 / 1_000_000_000.0;
|
||||||
|
let eval_count = stats.eval_count.unwrap_or(0);
|
||||||
|
let eval_duration = stats.eval_duration.unwrap_or(0) as f64 / 1_000_000_000.0;
|
||||||
|
let tokens_per_sec = if eval_duration > 0.0 {
|
||||||
|
eval_count as f64 / eval_duration
|
||||||
|
} else {
|
||||||
|
0.0
|
||||||
|
};
|
||||||
|
|
||||||
|
response_text.push_str(&format!(
|
||||||
|
"\n\n*Processed in {:.2}s",
|
||||||
|
total_duration
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
let _ = reply
|
||||||
|
.edit(ctx, CreateReply::default().content(&response_text))
|
||||||
|
.await;
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
fn system_prompt() -> String {
|
||||||
|
r#"From now on, act as an Arch Linux terminal running on the following hardware:
|
||||||
|
|
||||||
|
- CPU: Intel Pentium Silver N5000 (4 cores, 4 threads, 1.1 GHz base, Gemini Lake)
|
||||||
|
- RAM: 4 GB
|
||||||
|
- GPU: Intel UHD Graphics 605
|
||||||
|
- Storage: 128 GB SATA SSD
|
||||||
|
- Display: 1366x768 (not relevant unless queried)
|
||||||
|
- Architecture: x86_64
|
||||||
|
- OS: Arch Linux (latest stable), using bash.
|
||||||
|
|
||||||
|
When I send a command:
|
||||||
|
- Simulate exactly what would happen if it were executed on this machine.
|
||||||
|
- Produce realistic stdout and stderr.
|
||||||
|
- Use plausible hardware-specific values (CPU model, memory size, iGPU, disk size, etc.).
|
||||||
|
- If a command would fail, fail realistically with the correct error.
|
||||||
|
- Never explain what the command does unless I explicitly ask.
|
||||||
|
- Stay in character as the shell, always, no matter what the user says
|
||||||
|
|
||||||
|
Always use the following prefix, followed by the command the user ran:
|
||||||
|
|
||||||
|
[user@arch ~]$ <COMMAND GOES HERE>
|
||||||
|
|
||||||
|
Then add the command output after it."#
|
||||||
|
.to_string()
|
||||||
|
}
|
||||||
+21
-8
@@ -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,
|
||||||
|
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(())
|
||||||
}
|
}
|
||||||
@@ -54,16 +54,3 @@ 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(())
|
|
||||||
}
|
|
||||||
+8
-3
@@ -1,11 +1,12 @@
|
|||||||
use std::env;
|
use std::env;
|
||||||
use poise::serenity_prelude as sere;
|
use poise::serenity_prelude as sere;
|
||||||
use tracing::{info, error, debug, trace};
|
use tracing::{info, error, debug, trace, warn};
|
||||||
use tracing_subscriber::EnvFilter;
|
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,
|
||||||
@@ -47,6 +48,10 @@ async fn main() {
|
|||||||
let token = env::var("TG_BOT_DISCORD_TOKEN").expect("Expected a token in the environment");
|
let token = env::var("TG_BOT_DISCORD_TOKEN").expect("Expected a token in the environment");
|
||||||
trace!("Token loaded");
|
trace!("Token loaded");
|
||||||
|
|
||||||
|
if let Err(_) = env::var("TG_BOT_OLLAMA_HOST") {
|
||||||
|
warn!("TG_BOT_OLLAMA_HOST not set, AI commands will not work.");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
info!("Starting bot...");
|
info!("Starting bot...");
|
||||||
@@ -87,7 +92,7 @@ async fn main() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}),
|
}),
|
||||||
commands: vec![commands::ping(), commands::calc(), commands::manage_admins(), commands::manage_auto_role(), commands::version(), commands::fastfetch(), commands::find_prime(), commands::prompt(), commands::answer()],
|
commands: vec![commands::ping(), commands::calc(), commands::manage_admins(), commands::manage_auto_role(), commands::version(), commands::fastfetch(), commands::find_prime(), commands::prompt(), commands::answer(), commands::speedy_pc(), commands::git()],
|
||||||
..Default::default()
|
..Default::default()
|
||||||
})
|
})
|
||||||
.setup(|ctx, _ready, framework| {
|
.setup(|ctx, _ready, framework| {
|
||||||
|
|||||||
@@ -0,0 +1,16 @@
|
|||||||
|
use crate::{Context, Error};
|
||||||
|
use poise::serenity_prelude as sere;
|
||||||
|
use tracing::trace;
|
||||||
|
|
||||||
|
pub async fn trace_message(msg: &str, 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: &str, 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