Skip to content

Commit

Permalink
big refacto + emoji podium almost done
Browse files Browse the repository at this point in the history
  • Loading branch information
Inspirateur committed Feb 11, 2023
1 parent 20f477c commit 6629aed
Show file tree
Hide file tree
Showing 7 changed files with 394 additions and 225 deletions.
File renamed without changes.
37 changes: 37 additions & 0 deletions src/fixed_deque.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
use std::{array::from_fn, collections::HashMap, hash::Hash};


pub struct FixedDeque<T, const N: usize = 1000> {
pub data: [T; N],
pos: usize
}

impl<T: Default, const N: usize> FixedDeque<T, N> {
pub fn new() -> Self {
FixedDeque {
data: from_fn(|_| T::default()),
pos: 0
}
}
}

impl<T, const N: usize> FixedDeque<T, N> {
pub fn push(&mut self, elem: T) {
self.data[self.pos] = elem;
self.pos += 1;
if self.pos >= N {
self.pos = 0;
}
}
}

impl<T: Hash + Eq + Clone, const N: usize> FixedDeque<T, N> {
pub fn counts(&self) -> HashMap<T, usize> {
let mut res = HashMap::new();
self.data.iter().cloned().for_each(|elem| {
let count = res.entry(elem).or_default();
*count += 1;
});
res
}
}
207 changes: 0 additions & 207 deletions src/handler.rs

This file was deleted.

12 changes: 7 additions & 5 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
mod idiom;
mod discord_emojis;
mod handler;
mod handler_util;
mod handle_events;
use handler::Handler;
mod discord_util;
mod wordy;
mod wordy_events;
mod wordy_commands;
mod fixed_deque;
use wordy::Wordy;
use env_logger;
use std::fs::read_to_string;
use log::{warn, error, LevelFilter};
Expand Down Expand Up @@ -50,7 +52,7 @@ async fn main() {
| GatewayIntents::GUILD_MEMBERS
| GatewayIntents::GUILD_PRESENCES
)
.event_handler(Handler::new())
.event_handler(Wordy::new())
.application_id(bot_id.into())
.await
.expect("Error creating client");
Expand Down
Loading

0 comments on commit 6629aed

Please sign in to comment.