Compare commits
No commits in common. "213ecca8b9ca4f8eef9b174d29ae0c5f58571fe0" and "8453de086a446fd7eff33121448c1953d5f30c52" have entirely different histories.
213ecca8b9
...
8453de086a
4 changed files with 1 additions and 115 deletions
|
|
@ -1,71 +0,0 @@
|
||||||
use poise::serenity_prelude::{Mentionable, UserId};
|
|
||||||
use squad_quest::{SquadObject, account::Account, map::Map};
|
|
||||||
|
|
||||||
use crate::{Context, Error};
|
|
||||||
|
|
||||||
fn account_balance_string(account: &Account, map: &Map) -> String {
|
|
||||||
let rooms_value = account_rooms_value(account, map);
|
|
||||||
let full_balance = account_full_balance(account, map);
|
|
||||||
format!("{account}: **{full_balance}** points (**{balance}** on balance \
|
|
||||||
+ **{rooms_value}** unlocked rooms networth)",
|
|
||||||
account = account_user_id(&account).mention(),
|
|
||||||
balance = account.balance,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn account_rooms_value(account: &Account, map: &Map) -> u32 {
|
|
||||||
map.room.iter().filter_map(|r| {
|
|
||||||
if account.rooms_unlocked.contains(&r.id) {
|
|
||||||
Some(r.value)
|
|
||||||
} else {
|
|
||||||
None
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.sum()
|
|
||||||
}
|
|
||||||
|
|
||||||
fn account_full_balance(account: &Account, map: &Map) -> u32 {
|
|
||||||
let rooms_value = account_rooms_value(account, map);
|
|
||||||
account.balance + rooms_value
|
|
||||||
}
|
|
||||||
|
|
||||||
fn account_user_id(account: &Account) -> UserId {
|
|
||||||
UserId::new(account.id.clone().parse::<u64>().expect("automatically inserted"))
|
|
||||||
}
|
|
||||||
|
|
||||||
#[poise::command(
|
|
||||||
prefix_command,
|
|
||||||
slash_command,
|
|
||||||
guild_only,
|
|
||||||
)]
|
|
||||||
pub async fn scoreboard(
|
|
||||||
ctx: Context<'_>,
|
|
||||||
) -> Result<(), Error> {
|
|
||||||
let map_path = ctx.data().config.full_map_path();
|
|
||||||
let map = Map::load(map_path).expect("map.toml should exist");
|
|
||||||
|
|
||||||
let mut accounts = ctx.data().config.load_accounts();
|
|
||||||
accounts.sort_by(|a,b| {
|
|
||||||
let a_balance = account_full_balance(a, &map);
|
|
||||||
let b_balance = account_full_balance(b, &map);
|
|
||||||
a_balance.cmp(&b_balance)
|
|
||||||
});
|
|
||||||
|
|
||||||
let this_user = ctx.author().id;
|
|
||||||
|
|
||||||
let mut reply_string = String::new();
|
|
||||||
for account in accounts {
|
|
||||||
let user_id = account_user_id(&account);
|
|
||||||
|
|
||||||
let mut str = account_balance_string(&account, &map);
|
|
||||||
if user_id == this_user {
|
|
||||||
str = format!("__{str}__ << You");
|
|
||||||
}
|
|
||||||
|
|
||||||
reply_string.push_str(&str);
|
|
||||||
}
|
|
||||||
|
|
||||||
ctx.reply(reply_string).await?;
|
|
||||||
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
|
|
@ -6,7 +6,6 @@ pub mod quest;
|
||||||
pub mod init;
|
pub mod init;
|
||||||
pub mod answer;
|
pub mod answer;
|
||||||
pub mod social;
|
pub mod social;
|
||||||
pub mod account;
|
|
||||||
|
|
||||||
pub const ERROR_MSG: &str = "Server error :(";
|
pub const ERROR_MSG: &str = "Server error :(";
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,7 @@ use crate::{Context, Error};
|
||||||
slash_command,
|
slash_command,
|
||||||
required_permissions = "ADMINISTRATOR",
|
required_permissions = "ADMINISTRATOR",
|
||||||
guild_only,
|
guild_only,
|
||||||
subcommands("msg", "edit", "undo"),
|
subcommands("msg", "edit"),
|
||||||
)]
|
)]
|
||||||
pub async fn social( _ctx: Context<'_> ) -> Result<(), Error> {
|
pub async fn social( _ctx: Context<'_> ) -> Result<(), Error> {
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|
@ -155,44 +155,3 @@ pub async fn edit (
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[poise::command(
|
|
||||||
prefix_command,
|
|
||||||
slash_command,
|
|
||||||
required_permissions = "ADMINISTRATOR",
|
|
||||||
guild_only,
|
|
||||||
)]
|
|
||||||
pub async fn undo(
|
|
||||||
ctx: Context<'_>,
|
|
||||||
#[rename = "message"]
|
|
||||||
message_id: MessageId,
|
|
||||||
channel: Option<ChannelId>,
|
|
||||||
user: Option<UserId>,
|
|
||||||
) -> Result<(), Error> {
|
|
||||||
|
|
||||||
if channel.is_none() && user.is_none() {
|
|
||||||
let reply_string = "Please specify channel **or** user".to_string();
|
|
||||||
ctx.reply(reply_string).await?;
|
|
||||||
return Ok(());
|
|
||||||
}
|
|
||||||
|
|
||||||
if channel.is_some() && user.is_some() {
|
|
||||||
let reply_string = "Please specify **only** channel or **only** user, not both".to_string();
|
|
||||||
ctx.reply(reply_string).await?;
|
|
||||||
return Ok(());
|
|
||||||
}
|
|
||||||
|
|
||||||
if let Some(channel) = channel {
|
|
||||||
let message = channel.message(ctx, message_id).await?;
|
|
||||||
message.delete(ctx).await?;
|
|
||||||
} else if let Some(user) = user {
|
|
||||||
let channel = user.create_dm_channel(ctx).await?;
|
|
||||||
let message = channel.message(ctx, message_id).await?;
|
|
||||||
message.delete(ctx).await?;
|
|
||||||
}
|
|
||||||
|
|
||||||
let reply_string = "Successfully deleted message".to_string();
|
|
||||||
ctx.reply(reply_string).await?;
|
|
||||||
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
|
|
|
||||||
|
|
@ -41,7 +41,6 @@ async fn main() {
|
||||||
commands::init::init(),
|
commands::init::init(),
|
||||||
commands::answer::answer(),
|
commands::answer::answer(),
|
||||||
commands::social::social(),
|
commands::social::social(),
|
||||||
commands::account::scoreboard(),
|
|
||||||
],
|
],
|
||||||
..Default::default()
|
..Default::default()
|
||||||
})
|
})
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue