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