converted tabs to spaces & updated gitignore

This commit is contained in:
2026-02-27 16:51:04 +01:00
parent 4c4ff1379b
commit fcf5ffad3a
7 changed files with 79 additions and 78 deletions
+1
View File
@@ -5,6 +5,7 @@ Cargo.lock
*.pdb *.pdb
**/__pycache__/ **/__pycache__/
.vscode/ .vscode/
!.vscode/settings.json
# program-created data # program-created data
**/reddit_data.json **/reddit_data.json
+1 -1
View File
@@ -3,7 +3,7 @@
"SERVER ID": { "SERVER ID": {
"re_posts_channel": 0, "re_posts_channel": 0,
"re_disabled": false, "re_disabled": false,
"wwrps_channel": 0 "wwrps_channel": 0
} }
} }
} }
+47 -47
View File
@@ -6,60 +6,60 @@ use crate::{Context, Error, data::get_mutex_data, lang, messages::send_msg};
#[derive(poise::ChoiceParameter, PartialEq, Clone)] #[derive(poise::ChoiceParameter, PartialEq, Clone)]
#[repr(u8)] #[repr(u8)]
pub enum RPS { pub enum RPS {
Paper = 0, Paper = 0,
Rock = 1, Rock = 1,
Scissors = 2 Scissors = 2
} }
#[derive(Clone)] #[derive(Clone)]
pub struct RPSPlayer { pub struct RPSPlayer {
pub selection: RPS, pub selection: RPS,
pub user: User, pub user: User,
pub anonymous: bool pub anonymous: bool
} }
pub struct RPSGame { pub struct RPSGame {
pub players: [Option<RPSPlayer>; 2], pub players: [Option<RPSPlayer>; 2],
} }
impl RPSGame { impl RPSGame {
pub fn new() -> Self { pub fn new() -> Self {
return RPSGame { return RPSGame {
players: [None, None], players: [None, None],
} }
} }
pub fn add_player(&mut self, player: RPSPlayer) -> Result<(), Error> { pub fn add_player(&mut self, player: RPSPlayer) -> Result<(), Error> {
if let Some(p1) = &self.players[0] if let Some(p1) = &self.players[0]
{ if p1.user == player.user { return Err(Error::from("Cannot add player, it already exists!")); }} { if p1.user == player.user { return Err(Error::from("Cannot add player, it already exists!")); }}
if self.players[0].is_none() { self.players[0] = Some(player); return Ok(()); } if self.players[0].is_none() { self.players[0] = Some(player); return Ok(()); }
else if self.players[1].is_none() { self.players[1] = Some(player); return Ok(()); } else if self.players[1].is_none() { self.players[1] = Some(player); return Ok(()); }
else { return Err(Error::from("Cannot add player, list is full!")); } else { return Err(Error::from("Cannot add player, list is full!")); }
} }
pub fn clear(&mut self) pub fn clear(&mut self)
{ self.players = [None, None]; } { self.players = [None, None]; }
pub fn get_winner(&self) -> Option<i8> { pub fn get_winner(&self) -> Option<i8> {
if self.players.iter().any(|i| i.is_none()) if self.players.iter().any(|i| i.is_none())
{ return None; } { return None; }
let Some(p1) = self.players[0].clone() else { return None; }; let Some(p1) = self.players[0].clone() else { return None; };
let Some(p2) = self.players[1].clone() else { return None; }; let Some(p2) = self.players[1].clone() else { return None; };
let i1 = p1.selection as u8; let i1 = p1.selection as u8;
let i2 = p2.selection as u8; let i2 = p2.selection as u8;
if i1 == i2 { return None; } if i1 == i2 { return None; }
else if (i1 + 1) % 3 == i2 { return Some(0); } else if (i1 + 1) % 3 == i2 { return Some(0); }
else { return Some(1); } else { return Some(1); }
} }
pub fn is_full_lobby(&self) -> bool pub fn is_full_lobby(&self) -> bool
{ return self.players.iter().all(|i| i.is_some()); } { return self.players.iter().all(|i| i.is_some()); }
} }
@@ -74,32 +74,32 @@ impl RPSGame {
pub async fn cmd( pub async fn cmd(
ctx: Context<'_>, ctx: Context<'_>,
selection: RPS, selection: RPS,
#[description = "If true, replaces your username with [Anonymous]."] anonymous: bool #[description = "If true, replaces your username with [Anonymous]."] anonymous: bool
) -> Result<(), Error> ) -> Result<(), Error>
{ {
let c_o = get_wwrps_channel(ctx).await; let c_o = get_wwrps_channel(ctx).await;
if c_o.is_none() { send_msg(ctx, lang!("dc_msg_wwrps_not_in_data"), true, true).await; return Ok(()); } if c_o.is_none() { send_msg(ctx, lang!("dc_msg_wwrps_not_in_data"), true, true).await; return Ok(()); }
let c = c_o.unwrap(); let c = c_o.unwrap();
let mut game = &ctx.data().rps_game; let mut game = &ctx.data().rps_game;
if !game.is_full_lobby() { game.add_player(RPSPlayer { selection, user: ctx.author().clone(), anonymous }); } if !game.is_full_lobby() { game.add_player(RPSPlayer { selection, user: ctx.author().clone(), anonymous }); }
return Ok(()); return Ok(());
} }
async fn get_wwrps_channel(ctx: Context<'_>) -> Option<u64> { async fn get_wwrps_channel(ctx: Context<'_>) -> Option<u64> {
let d = get_mutex_data(&ctx.data().discord_data).await.unwrap(); let d = get_mutex_data(&ctx.data().discord_data).await.unwrap();
let is_guild = ctx.guild_channel().await.is_some(); let is_guild = ctx.guild_channel().await.is_some();
if !is_guild { return Some(ctx.channel_id().get()); } if !is_guild { return Some(ctx.channel_id().get()); }
let Some(servers) = d.get("servers") else { return None; }; let Some(servers) = d.get("servers") else { return None; };
let Some(s) = servers.get(ctx.guild_id().unwrap().get() as usize) else { return None; }; let Some(s) = servers.get(ctx.guild_id().unwrap().get() as usize) else { return None; };
let Some(c_id) = s.get("wwrps_channel") else { return None; }; let Some(c_id) = s.get("wwrps_channel") else { return None; };
return Some(c_id.as_u64().unwrap()); return Some(c_id.as_u64().unwrap());
} }
+2 -2
View File
@@ -183,7 +183,7 @@ pub async fn dc_bind_bk(data: &Data, server_id: u64, channel_id: u64) -> Result<
pub async fn bind_wwrps(data: &Data, server_id: u64, channel_id: u64) -> Result<(), ()> { pub async fn bind_wwrps(data: &Data, server_id: u64, channel_id: u64) -> Result<(), ()> {
let mut dc_data_lock = data.discord_data.lock().await; let mut dc_data_lock = data.discord_data.lock().await;
let dc_data = dc_data_lock.as_mut().unwrap(); let dc_data = dc_data_lock.as_mut().unwrap();
if dc_data.get("servers").is_none() { return Err(()); } if dc_data.get("servers").is_none() { return Err(()); }
@@ -191,7 +191,7 @@ pub async fn bind_wwrps(data: &Data, server_id: u64, channel_id: u64) -> Result<
let servers = dc_data["servers"].as_object_mut().unwrap(); let servers = dc_data["servers"].as_object_mut().unwrap();
if !servers.contains_key(&server_id.to_string()) if !servers.contains_key(&server_id.to_string())
{ return Err(()); } { return Err(()); }
let server = servers[&server_id.to_string()].as_object_mut().unwrap(); let server = servers[&server_id.to_string()].as_object_mut().unwrap();
+6 -6
View File
@@ -3,9 +3,9 @@ use crate::{Context, Error, db_cmds::{add_server, reddit_channel, wwrps_channel}
#[derive(poise::ChoiceParameter, PartialEq)] #[derive(poise::ChoiceParameter, PartialEq)]
pub enum Subcommands { pub enum Subcommands {
AddServer, AddServer,
RedditChannel, RedditChannel,
WWRPSChannel WWRPSChannel
} }
@@ -15,7 +15,7 @@ pub enum Subcommands {
category = "db", category = "db",
rename = "database", rename = "database",
owners_only, owners_only,
default_member_permissions = "ADMINISTRATOR", default_member_permissions = "ADMINISTRATOR",
required_bot_permissions = "SEND_MESSAGES | VIEW_CHANNEL" required_bot_permissions = "SEND_MESSAGES | VIEW_CHANNEL"
)] )]
/// Various debug utilities /// Various debug utilities
@@ -26,8 +26,8 @@ pub async fn cmd(
{ {
match subcommand { match subcommand {
Subcommands::AddServer => add_server::cmd(ctx).await?, Subcommands::AddServer => add_server::cmd(ctx).await?,
Subcommands::RedditChannel => reddit_channel::cmd(ctx).await?, Subcommands::RedditChannel => reddit_channel::cmd(ctx).await?,
Subcommands::WWRPSChannel => wwrps_channel::cmd(ctx).await?, Subcommands::WWRPSChannel => wwrps_channel::cmd(ctx).await?,
//_ => return Ok(()) //_ => return Ok(())
} }
+2 -2
View File
@@ -27,7 +27,7 @@ pub async fn gen_data(args: Args, owners: Vec<u64>) -> Data {
let data = Data { let data = Data {
owners, owners,
ball_prompts: [ball_classic, ball_quirk], ball_prompts: [ball_classic, ball_quirk],
rps_game: RPSGame::new(), rps_game: RPSGame::new(),
bk_mods: mods_vec_u64, bk_mods: mods_vec_u64,
reddit_data: None.into(), reddit_data: None.into(),
discord_data: None.into(), discord_data: None.into(),
@@ -102,7 +102,7 @@ async fn make_cmd_vec(data: &Data) -> Vec<Cmd> {
cmds::send::cmd(), cmds::send::cmd(),
debug_cmds::main_cmd::cmd(), debug_cmds::main_cmd::cmd(),
// DATABASE // DATABASE
db_cmds::main_cmd::cmd() db_cmds::main_cmd::cmd()
]; ];
let cfg = get_toml_mutex(&data.cfg).await.unwrap(); let cfg = get_toml_mutex(&data.cfg).await.unwrap();
+4 -4
View File
@@ -7,7 +7,7 @@ mod cmds {
pub mod embed; pub mod embed;
pub mod help; pub mod help;
pub mod send; pub mod send;
pub mod wwrps; pub mod wwrps;
} }
mod re_cmds { mod re_cmds {
pub mod add; pub mod add;
@@ -33,8 +33,8 @@ mod debug_cmds {
mod db_cmds { mod db_cmds {
pub mod add_server; pub mod add_server;
pub mod reddit_channel; pub mod reddit_channel;
pub mod main_cmd; pub mod main_cmd;
pub mod wwrps_channel; pub mod wwrps_channel;
} }
mod events; mod events;
mod messages; mod messages;
@@ -97,7 +97,7 @@ type Cmd = Command<Data, Box<dyn StdErr + Send + Sync>>;
struct Data { struct Data {
owners: Vec<u64>, owners: Vec<u64>,
ball_prompts: [Vec<String>; 2], ball_prompts: [Vec<String>; 2],
rps_game: RPSGame, rps_game: RPSGame,
reddit_data: Mutex<Option<Value>>, reddit_data: Mutex<Option<Value>>,
discord_data: Mutex<Option<Value>>, discord_data: Mutex<Option<Value>>,
cfg: Mutex<Option<toml::Value>>, cfg: Mutex<Option<toml::Value>>,