Skip to content

Commit

Permalink
fix: stats
Browse files Browse the repository at this point in the history
  • Loading branch information
Googlefan256 committed Oct 30, 2023
1 parent bf0f084 commit 88c2df0
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 14 deletions.
7 changes: 5 additions & 2 deletions bin/bot/src/component.rs
Original file line number Diff line number Diff line change
Expand Up @@ -173,8 +173,11 @@ pub fn create_components(
let format = CreateActionRow::SelectMenu(format);
let button = CreateActionRow::Buttons(vec![
CreateButton::new_link(format!("https://enka.network/u/{}", uid)).label("Enka Network"),
CreateButton::new_link(format!("https://ag.neody.land/generate?uid={}", uid))
.label(t!(locale, "main:general.webapp")),
CreateButton::new_link(format!(
"https://ag.neody.land/generate?uid={}&game=genshin",
uid
))
.label(t!(locale, "main:general.webapp")),
/*CreateButton::new("end")
.style(ButtonStyle::Danger)
.label(t!(locale, "main:general.close")),*/
Expand Down
13 changes: 10 additions & 3 deletions bin/bot/src/events/ready.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::sync::{atomic::Ordering, Arc};
use std::sync::Arc;

use poise::serenity_prelude as serenity;
use serenity::{ActivityData, Context, Ready};
Expand All @@ -15,8 +15,15 @@ pub async fn handler(
) -> Result<(), Error> {
log::info!("{} is connected!", ready.user.name);
let ctx = Arc::new(ctx.to_owned());
if !state.started.load(Ordering::Relaxed) {
state.started.store(true, Ordering::Relaxed);
let started = {
let mut started = state.started.lock().await;
if let Some(s) = ready.shard {
started.insert(s.id.0)
} else {
false
}
};
if started {
tokio::spawn(async move {
loop {
let activity =
Expand Down
9 changes: 6 additions & 3 deletions bin/bot/src/hsr_components.rs
Original file line number Diff line number Diff line change
Expand Up @@ -173,9 +173,12 @@ pub fn create_components(
.placeholder(t!(locale, "main:general.selectBaseImage"));
let base_img = CreateActionRow::SelectMenu(base_img);
let button = CreateActionRow::Buttons(vec![
CreateButton::new_link(format!("https://enka.network/u/{}", uid)).label("Enka Network"),
CreateButton::new_link(format!("https://ag.neody.land/generate?uid={}", uid))
.label(t!(locale, "main:general.webapp")),
CreateButton::new_link(format!("https://enka.network/hsr/{}", uid)).label("Enka Network"),
CreateButton::new_link(format!(
"https://ag.neody.land/generate?uid={}&game=hsr",
uid
))
.label(t!(locale, "main:general.webapp")),
/*CreateButton::new("end")
.style(ButtonStyle::Danger)
.label(t!(locale, "main:general.close")),*/
Expand Down
7 changes: 4 additions & 3 deletions bin/bot/src/state.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::sync::{atomic::AtomicBool, Arc};
use std::{collections::BTreeSet, sync::Arc};

use tokio::sync::Mutex;

Expand All @@ -11,7 +11,7 @@ use crate::{
#[derive(Clone)]
pub struct State {
pub db: PgPool,
pub started: Arc<AtomicBool>,
pub started: Arc<Mutex<BTreeSet<u32>>>,
pub api: Api,
pub cache: Arc<Mutex<Cache>>,
pub hsr_cache: Arc<Mutex<HsrCache>>,
Expand All @@ -20,9 +20,10 @@ pub struct State {
impl State {
pub async fn new() -> Self {
let db = connect().await;
let set = BTreeSet::new();
Self {
db,
started: Arc::new(AtomicBool::new(false)),
started: Arc::new(Mutex::new(set)),
api: Api::new(),
cache: Arc::new(Mutex::new(Cache::new())),
hsr_cache: Arc::new(Mutex::new(HsrCache::new())),
Expand Down
6 changes: 3 additions & 3 deletions lib/gen/src/gen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -620,7 +620,7 @@ pub async fn generate(
&mut image,
white,
1820,
235,
240,
scale,
&font,
&format!("{}", set_count),
Expand All @@ -629,7 +629,7 @@ pub async fn generate(
&mut image,
white,
1820,
280,
285,
scale,
&font,
&format!("{}", second_set_count),
Expand All @@ -650,7 +650,7 @@ pub async fn generate(
&mut image,
first_key_color,
1520,
255,
260,
scale,
&font,
&set_name,
Expand Down

0 comments on commit 88c2df0

Please sign in to comment.