Skip to content

Commit

Permalink
Merge pull request #110 from xp-bot/dev
Browse files Browse the repository at this point in the history
dev build
  • Loading branch information
crnvl authored Sep 24, 2023
2 parents fd442d7 + 110fa2c commit c1ac18d
Show file tree
Hide file tree
Showing 24 changed files with 809 additions and 187 deletions.
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ FROM rust:latest
WORKDIR /usr/src
COPY . .

RUN cargo install --path xp-bot
RUN cargo build --release
EXPOSE 80

CMD ["cargo", "run", "--release"]
CMD ["./target/release/xp-bot"]
12 changes: 0 additions & 12 deletions vmng/Cargo.toml

This file was deleted.

74 changes: 0 additions & 74 deletions vmng/src/main.rs

This file was deleted.

10 changes: 8 additions & 2 deletions xp-bot/src/commands/admin/add.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ use serenity::{
},
prelude::Context,
};
use xp_db_connector::guild_member::GuildMember;
use xp_db_connector::{guild_member::GuildMember, guild::Guild};

use crate::{commands::XpCommand, utils::{colors, utils::format_number}};
use crate::{commands::XpCommand, utils::{colors, utils::{format_number, handle_level_roles}, math::calculate_level}};

pub struct AddCommand;

Expand Down Expand Up @@ -80,6 +80,9 @@ impl XpCommand for AddCommand {

let new_amount = guild_member.xp + amount;

let guild = Guild::from_id(guild_id).await?;
let new_level = calculate_level(&new_amount);

let _ = GuildMember::set_xp(guild_id, user, &new_amount, &guild_member).await?;

command
Expand All @@ -100,6 +103,9 @@ impl XpCommand for AddCommand {
})
.await?;

handle_level_roles(&guild, &user, &new_level, &ctx, command.guild_id.clone().unwrap().0).await;


Ok(())
}
}
9 changes: 7 additions & 2 deletions xp-bot/src/commands/admin/remove.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ use serenity::{
},
prelude::Context,
};
use xp_db_connector::guild_member::GuildMember;
use xp_db_connector::{guild_member::GuildMember, guild::Guild};

use crate::{commands::XpCommand, utils::{colors, utils::format_number}};
use crate::{commands::XpCommand, utils::{colors, utils::{format_number, handle_level_roles}, math::calculate_level}};

pub struct RemoveCommand;

Expand Down Expand Up @@ -79,6 +79,9 @@ impl XpCommand for RemoveCommand {

let new_amount = guild_member.xp - amount;

let guild = Guild::from_id(guild_id).await?;
let new_level = calculate_level(&new_amount);

let _ = GuildMember::set_xp(guild_id, user, &new_amount, &guild_member).await?;

command
Expand All @@ -99,6 +102,8 @@ impl XpCommand for RemoveCommand {
})
.await?;

handle_level_roles(&guild, &user, &new_level, &ctx, command.guild_id.clone().unwrap().0).await;

Ok(())
}
}
9 changes: 7 additions & 2 deletions xp-bot/src/commands/admin/set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ use serenity::{
},
prelude::Context,
};
use xp_db_connector::guild_member::GuildMember;
use xp_db_connector::{guild_member::GuildMember, guild::Guild};

use crate::{commands::XpCommand, utils::{colors, utils::format_number}};
use crate::{commands::XpCommand, utils::{colors, utils::{format_number, handle_level_roles}, math::calculate_level}};

pub struct SetCommand;

Expand Down Expand Up @@ -78,6 +78,9 @@ impl XpCommand for SetCommand {

let guild_member = GuildMember::from_id(guild_id, user).await?;

let guild = Guild::from_id(guild_id).await?;
let new_level = calculate_level(&amount);

let _ = GuildMember::set_xp(guild_id, user, &amount, &guild_member).await?;

command
Expand All @@ -98,6 +101,8 @@ impl XpCommand for SetCommand {
})
.await?;

handle_level_roles(&guild, &user, &new_level, &ctx, command.guild_id.clone().unwrap().0).await;

Ok(())
}
}
10 changes: 8 additions & 2 deletions xp-bot/src/commands/admin/setlevel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ use serenity::{
},
prelude::Context,
};
use xp_db_connector::guild_member::GuildMember;
use xp_db_connector::{guild_member::GuildMember, guild::Guild};

use crate::{
commands::XpCommand,
utils::{colors, math::get_required_xp},
utils::{colors, math::{get_required_xp, calculate_level}, utils::handle_level_roles},
};

pub struct SetLevelCommand;
Expand Down Expand Up @@ -82,6 +82,10 @@ impl XpCommand for SetLevelCommand {
let required_xp = get_required_xp(level as i32);

let guild_member = GuildMember::from_id(command.guild_id.unwrap().into(), user_id).await?;

let guild = Guild::from_id(command.guild_id.unwrap().into()).await?;
let new_level = calculate_level(&(required_xp as u64));

let _ = GuildMember::set_xp(
command.guild_id.unwrap().into(),
user_id,
Expand Down Expand Up @@ -109,6 +113,8 @@ impl XpCommand for SetLevelCommand {
})
.await;

handle_level_roles(&guild, &user_id, &new_level, &ctx, command.guild_id.clone().unwrap().0).await;

Ok(())
}
}
45 changes: 32 additions & 13 deletions xp-bot/src/commands/games/daily.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ impl XpCommand for DailyCommand {
return Ok(());
}

if !eligibility_helper(command.user.id.0).await {
if !eligibility_helper(command.user.id.0, &command.guild_id.unwrap().0).await {
command
.create_interaction_response(ctx, |response| {
response
Expand Down Expand Up @@ -121,19 +121,37 @@ impl XpCommand for DailyCommand {

let daily_xp = 250;

let mut old_streak_msg = String::new();
// reset streak if last daily was claimed more than 48 hours ago
let streak =
if time_now - guild_member.timestamps.game_daily.unwrap_or(0) as i64 > 86400 * 1000 * 2 {
1
} else {
guild_member.streaks.game_daily.unwrap_or(0) + 1
};

guild_member.xp += daily_xp * streak;
let streak = if time_now - guild_member.timestamps.game_daily.unwrap_or(0) as i64
> 86400 * 1000 * 2
{
old_streak_msg = format!(
"Your old streak was **{}**.",
guild_member.streaks.game_daily.unwrap_or(0)
);
1
} else {
guild_member.streaks.game_daily.unwrap_or(0) + 1
};

let member_xp = daily_xp * streak;
let xp_to_add = if member_xp > guild.values.maximumdailyxp as u64 {
guild.values.maximumdailyxp as u64
} else {
member_xp
};
guild_member.xp += xp_to_add;

guild_member.timestamps.game_daily = Some(time_now as u64);
guild_member.streaks.game_daily = Some(streak);

let _ = GuildMember::set_guild_member(command.guild_id.unwrap().0, command.user.id.0, guild_member).await?;
let _ = GuildMember::set_guild_member(
command.guild_id.unwrap().0,
command.user.id.0,
guild_member,
)
.await?;

command
.create_interaction_response(ctx, |response| {
Expand All @@ -142,9 +160,10 @@ impl XpCommand for DailyCommand {
.interaction_response_data(|message| {
message.embed(|embed| {
embed.description(format!(
"You claimed **{}** xp. Your streak is now **{}**.",
format_number(daily_xp * streak),
streak
"You claimed **{}** xp. Your streak is now **{}**.\n\n{}",
format_number(xp_to_add),
streak,
old_streak_msg
));
embed.color(colors::green())
})
Expand Down
13 changes: 8 additions & 5 deletions xp-bot/src/commands/games/fish.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use crate::{
commands::XpCommand,
utils::{
colors,
utils::{eligibility_helper, is_cooldowned, format_number},
utils::{eligibility_helper, is_cooldowned, format_number, game_fish},
},
};

Expand Down Expand Up @@ -58,7 +58,7 @@ impl XpCommand for FishCommand {
return Ok(());
}

if !eligibility_helper(command.user.id.0).await {
if !eligibility_helper(command.user.id.0, &command.guild_id.unwrap().0).await {
command
.create_interaction_response(ctx, |response| {
response
Expand Down Expand Up @@ -115,8 +115,10 @@ impl XpCommand for FishCommand {
return Ok(());
}

let game_result = game_fish(guild.values.fishXP as i64);

// assign xp
guild_member.xp += guild.values.fishXP as u64;
guild_member.xp += game_result.xp as u64;

// set new cooldown
guild_member.timestamps.game_fish = Some(time_now as u64);
Expand All @@ -134,8 +136,9 @@ impl XpCommand for FishCommand {
.interaction_response_data(|message| {
message.embed(|embed| {
embed.description(format!(
":fishing_pole_and_fish: | You caught a fish and gained **{}** xp!",
format_number(guild.values.fishXP as u64)
":fishing_pole_and_fish: | You got **{}** xp for finding **{}**.",
format_number(game_result.xp as u64),
game_result.item
));
embed.color(colors::green())
})
Expand Down
13 changes: 8 additions & 5 deletions xp-bot/src/commands/games/loot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use crate::{
commands::XpCommand,
utils::{
colors,
utils::{eligibility_helper, format_number, is_cooldowned},
utils::{eligibility_helper, format_number, game_loot, is_cooldowned},
},
};

Expand Down Expand Up @@ -58,7 +58,7 @@ impl XpCommand for LootCommand {
return Ok(());
}

if !eligibility_helper(command.user.id.0).await {
if !eligibility_helper(command.user.id.0, &command.guild_id.unwrap().0).await {
command
.create_interaction_response(ctx, |response| {
response
Expand Down Expand Up @@ -117,8 +117,10 @@ impl XpCommand for LootCommand {
return Ok(());
}

let game_result = game_loot(guild.values.lootXP as i64);

// assign xp
guild_member.xp += guild.values.lootXP as u64;
guild_member.xp += game_result.xp as u64;

// set new cooldown
guild_member.timestamps.game_loot = Some(time_now as u64);
Expand All @@ -136,8 +138,9 @@ impl XpCommand for LootCommand {
.interaction_response_data(|message| {
message.embed(|embed| {
embed.description(format!(
":package: | You looted a crate and got **{}** xp!",
format_number(guild.values.lootXP as u64),
":package: | You found **{}** crate and got **{}** xp!",
game_result.item,
format_number(game_result.xp as u64),
));
embed.color(colors::green())
})
Expand Down
3 changes: 2 additions & 1 deletion xp-bot/src/commands/games/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ pub mod fish;
pub mod roll;
pub mod loot;
pub mod daily;
pub mod trivia;
pub mod trivia;
pub mod party;
Loading

0 comments on commit c1ac18d

Please sign in to comment.