Skip to content

Commit

Permalink
[Update]: Add stuffs + fix bugs
Browse files Browse the repository at this point in the history
- Add time format in timeout with carefully checked error cases!
- Change from "userinfo" to "infouser"
- Spacing + fixing bugs in /infouser
  • Loading branch information
harshfeudal committed Dec 3, 2022
1 parent ea8a571 commit de75006
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,11 @@ inline void EmbedInfoBuild(dpp::embed& embed, std::string avatar, std::string us
.set_timestamp(time(nullptr));
}

void userInfo(dpp::cluster& client, const dpp::slashcommand_t& event);

inline std::string StringFormatter(std::string &str)
{
str.erase(remove(str.begin(), str.end(), ' '), str.end());
return str;
}

void infouser(dpp::cluster& client, const dpp::slashcommand_t& event);
6 changes: 3 additions & 3 deletions handler/builder.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
#include "../commands/moderation/disconnect.h"

#include "../commands/information/ping.h"
#include "../commands/information/userinfo.h"
#include "../commands/information/infouser.h"
#include "../commands/information/about.h"

void SlashCommandCreate(dpp::cluster& client);
Expand Down Expand Up @@ -71,9 +71,9 @@ inline std::map<std::string, commandDef> commands
}
},
{
"userinfo",
"infouser",
{
"Show mentioned user info", userInfo,
"Show mentioned user info", infouser,
{
dpp::command_option(dpp::co_user, "user", "User you would like to know", false)
}
Expand Down
17 changes: 11 additions & 6 deletions src/information/userInfo.cpp → src/information/infouser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@

#include <spdlog/spdlog.h>
#include <dpp/dpp.h>
#include "../../commands/information/userinfo.h"
#include "../../commands/information/infouser.h"
#include "../../handler/handler.h"

// TO DO
// 1. Try hard to fix the pointer, since it is getting error
// 2. Make the code "shorter" if possible

void userInfo(dpp::cluster& client, const dpp::slashcommand_t& event)
void infouser(dpp::cluster& client, const dpp::slashcommand_t& event)
{
dpp::embed embed;

Expand All @@ -35,7 +35,7 @@ void userInfo(dpp::cluster& client, const dpp::slashcommand_t& event)

const auto StaffBadge = "<:BadgeStaff:1043810278564970568>";
const auto PartnerBadge = "<:BadgePartner:1043810326862381078>";
const auto CertifiedMod = "<:BadgeCertifiedMod:1043811850925658162>";
const auto CertifiedMod = "<:ModProgramsAlu:1048550817608761384>";

const auto EventBadge = "<:BadgeHypeSquadEvents:1043817210499584050>";
const auto EarlyVerifiedBotDev = "<:BadgeEarlyVerifiedBotDeveloper:1043820046318846062>";
Expand All @@ -49,7 +49,7 @@ void userInfo(dpp::cluster& client, const dpp::slashcommand_t& event)
const auto HypesquadBalance = "<:BadgeBalance:1043797533060767835>";
const auto HypesquadBrilliance = "<:BadgeBrilliance:1043798261137408060>";

const auto ActiveDeveloper = "<:BadgeActiveDeveloper:1047528637013962792>";
const auto ActiveDeveloper = "<:BadgeActiveDeveloper:1048550931966468106>";

auto hasStaffBadge = "";
auto hasPartnerBadge = "";
Expand Down Expand Up @@ -107,21 +107,26 @@ void userInfo(dpp::cluster& client, const dpp::slashcommand_t& event)

// Cannot get nitro badge, probably, I read doc again
// Working with another way
// Nitro and boost badge will be soon added when I know some methods!

const auto avatar = tgtId.get_avatar_url();
const auto usrID = fmt::format("{}", tgtId.id);
const auto created = fmt::format("<t:{}:R>", round(tgtId.get_creation_time()));
const auto usrName = fmt::format("{}", tgtId.format_username());

// The badge cannot show now because the pointer is error ... will fix it ASAP
auto BadgeShow = fmt::format("{}{}{}{}{}{}{}{}{}{}{}",
auto BadgeShow = fmt::format("{} {} {} {} {} {} {} {} {} {} {}",
hasStaffBadge, hasPartnerBadge, hasModBadge, hasEventBadge, hasHouseBadge,
hasBugHunterBadge, hasActiveDev, hasBotDevBadge, hasEarlySupBadge, hasNitroBadge,
hasBoostBadge
);

// Create a copy memory
auto CopyBadgeShow = BadgeShow;
const auto CheckFormatter = StringFormatter(CopyBadgeShow);

// Check if the user doesn't have any badge
if (BadgeShow == "")
if (CheckFormatter == "")
BadgeShow = "No badge found!";

// Add view profile linking button
Expand Down
48 changes: 43 additions & 5 deletions src/moderation/timeout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,11 +117,16 @@ void timeout(dpp::cluster& client, const dpp::slashcommand_t& event)

std::string input = duration;

uint64_t sec = 0;
uint64_t temp = 0;
uint64_t sec = 0;
uint64_t temp = 0;

bool bSyntax = 0;
bool error = 0;
bool bSyntax = 0;
bool error = 0;

int DayCount = 0;
int HourCount = 0;
int MinuteCount = 0;
int SecondCount = 0;

// Automatically convert if no day format
if (isNumber(input))
Expand Down Expand Up @@ -168,8 +173,31 @@ void timeout(dpp::cluster& client, const dpp::slashcommand_t& event)
error = true;
}

for (int i = 0; i < input.size(); i++)
{
if (isdigit(input[i]))
if (input[i + 1] == 'd')
DayCount++;
else if (input[i + 1] == 'h')
HourCount++;
else if (input[i + 1] == 'm')
MinuteCount++;
else if (input[i + 1] == 's')
SecondCount++;
else
break;
}

std::cout << DayCount << std::endl;
std::cout << HourCount << std::endl;
std::cout << MinuteCount << std::endl;
std::cout << SecondCount << std::endl;

// Check all error cases occur
if (std::isdigit(input[input.size() - 1]))
if (std::isdigit(input[input.size() - 1]) && sec > 0)
error = true;

if (DayCount > 1 || HourCount > 1 || MinuteCount > 1 || SecondCount > 1)
error = true;

if (error)
Expand All @@ -182,6 +210,16 @@ void timeout(dpp::cluster& client, const dpp::slashcommand_t& event)
return;
}

if (sec > 2419200)
{
EmbedBuild(embed, 0xFF7578, errorTitle, warnTitle, "Cannot timeout user over 28 days!", event.command.usr);
event.reply(
dpp::message(event.command.channel_id, embed).set_flags(dpp::m_ephemeral)
);

return;
}

auto toutContent = fmt::format("<@{}> has been timeouted until <t:{}:F>!", usr, time(nullptr) + sec);
std::string tout_Reason = "No reason provided";

Expand Down

0 comments on commit de75006

Please sign in to comment.