Merge branch 'dev' into 'main'
Dev See merge request illegitimate/illegitimate-bot!143
This commit is contained in:
@@ -8,5 +8,6 @@
|
|||||||
"hypixelGuildID": "5a353a170cf2e529044f2935",
|
"hypixelGuildID": "5a353a170cf2e529044f2935",
|
||||||
"onlineLogChannel": "1101144489306886226",
|
"onlineLogChannel": "1101144489306886226",
|
||||||
"botLogChannel": "1174403585149243472",
|
"botLogChannel": "1174403585149243472",
|
||||||
|
"guildLogChannel": "1183733282534326322",
|
||||||
"instructionsgif": "https://cdn.discordapp.com/attachments/838716950723952640/1188211176300089384/4DMu513uNxbM.gif?ex=6599b2e4&is=65873de4&hm=e727c7a39aacbc47d6a5453f4b5f792a45679983c30d662cd258a311381b6df0&"
|
"instructionsgif": "https://cdn.discordapp.com/attachments/838716950723952640/1188211176300089384/4DMu513uNxbM.gif?ex=6599b2e4&is=65873de4&hm=e727c7a39aacbc47d6a5453f4b5f792a45679983c30d662cd258a311381b6df0&"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,18 +0,0 @@
|
|||||||
import { Cron } from "../../interfaces";
|
|
||||||
|
|
||||||
export = {
|
|
||||||
time: {
|
|
||||||
seconds: 0,
|
|
||||||
minutes: 0,
|
|
||||||
hours: 12,
|
|
||||||
dayOfMonth: 10,
|
|
||||||
month: 5,
|
|
||||||
dayOfWeek: 5
|
|
||||||
},
|
|
||||||
execute: () => {
|
|
||||||
console.log("Test cron executed!")
|
|
||||||
},
|
|
||||||
onComplete: null,
|
|
||||||
start: true,
|
|
||||||
timeZone: "Europe/Zagreb"
|
|
||||||
} as Cron
|
|
||||||
137
src/events/cron/weeklyGexp.ts
Normal file
137
src/events/cron/weeklyGexp.ts
Normal file
@@ -0,0 +1,137 @@
|
|||||||
|
import {
|
||||||
|
hypixelGuildID,
|
||||||
|
guildLogChannel,
|
||||||
|
color,
|
||||||
|
devMessage
|
||||||
|
} from "../../../config/options.json"
|
||||||
|
import { getGuild, getIGN } from "../../utils/Hypixel"
|
||||||
|
import { Cron, GuildData } from "../../interfaces"
|
||||||
|
import Illegitimate from "../../utils/Illegitimate"
|
||||||
|
import { GuildTextBasedChannel } from "discord.js"
|
||||||
|
const client = Illegitimate.client
|
||||||
|
|
||||||
|
async function guildWeekly() {
|
||||||
|
const channel = client.channels.cache.get(
|
||||||
|
guildLogChannel,
|
||||||
|
) as GuildTextBasedChannel
|
||||||
|
|
||||||
|
if (!channel) {
|
||||||
|
console.log("Guild log channel not found")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
const embedColor = Number(color.replace("#", "0x"))
|
||||||
|
|
||||||
|
const message = await channel.send({
|
||||||
|
embeds: [{
|
||||||
|
description: "Starting to fetch guild data...",
|
||||||
|
color: embedColor
|
||||||
|
}]
|
||||||
|
})
|
||||||
|
|
||||||
|
const guild = (await getGuild(hypixelGuildID, "id")) as GuildData
|
||||||
|
const guildMembersList: string[] = []
|
||||||
|
const topWeeklyMembers: { name: string; value: string; inline: boolean }[] =
|
||||||
|
[]
|
||||||
|
|
||||||
|
const guildName = guild.name
|
||||||
|
const guildMembers = guild.members
|
||||||
|
|
||||||
|
const sliceSize = guildMembers.length / 4
|
||||||
|
|
||||||
|
// top weekly members
|
||||||
|
const allMembersGexpSorted = guildMembers
|
||||||
|
.map(member => {
|
||||||
|
return {
|
||||||
|
uuid: member.uuid,
|
||||||
|
exp: Object.values(member.expHistory).reduce(
|
||||||
|
(a, b) => a + b,
|
||||||
|
0,
|
||||||
|
),
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.sort((a, b) => b.exp - a.exp)
|
||||||
|
|
||||||
|
for (let i = 0; i < allMembersGexpSorted.length; i++) {
|
||||||
|
const ign = await getIGN(allMembersGexpSorted[i].uuid)
|
||||||
|
const gexp = new Intl.NumberFormat("en-US").format(
|
||||||
|
allMembersGexpSorted[i].exp,
|
||||||
|
)
|
||||||
|
const position = i + 1
|
||||||
|
guildMembersList.push(
|
||||||
|
"**#" + position + " " + ign + ":** `" + gexp + "`",
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
const list = Array.from({ length: sliceSize }, (_, i) =>
|
||||||
|
guildMembersList.slice(i * sliceSize, (i + 1) * sliceSize),
|
||||||
|
)
|
||||||
|
|
||||||
|
list.forEach((item, index) => {
|
||||||
|
if (item.length === 0) return
|
||||||
|
|
||||||
|
topWeeklyMembers[index] = {
|
||||||
|
name: "",
|
||||||
|
value: item.join("\n"),
|
||||||
|
inline: false,
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
// combined weekly gexp
|
||||||
|
const allGuildMembersWeeklyXP = guildMembers.map(
|
||||||
|
member => member.expHistory,
|
||||||
|
)
|
||||||
|
const guildMembersWeeklyXP = allGuildMembersWeeklyXP.map(member => {
|
||||||
|
return Object.values(member).reduce((a, b) => a + b, 0)
|
||||||
|
})
|
||||||
|
const totalGuildMembersWeeklyXPUnformatted = guildMembersWeeklyXP.reduce(
|
||||||
|
(a, b) => a + b,
|
||||||
|
0,
|
||||||
|
)
|
||||||
|
const averageGuildMembersDailyXPUnformatted =
|
||||||
|
totalGuildMembersWeeklyXPUnformatted / 7
|
||||||
|
|
||||||
|
// final values
|
||||||
|
const totalGuildMembersWeeklyXP = new Intl.NumberFormat("en-US").format(
|
||||||
|
totalGuildMembersWeeklyXPUnformatted,
|
||||||
|
)
|
||||||
|
const averageGuildMembersWeeklyXP = new Intl.NumberFormat("en-US").format(
|
||||||
|
averageGuildMembersDailyXPUnformatted,
|
||||||
|
)
|
||||||
|
|
||||||
|
await message.edit({
|
||||||
|
embeds: [
|
||||||
|
{
|
||||||
|
title: "**Weekly Guild XP for " + guildName + "**",
|
||||||
|
description:
|
||||||
|
"**Total weekly guild XP:** `" +
|
||||||
|
totalGuildMembersWeeklyXP +
|
||||||
|
"`\n**Average daily guild XP:** `" +
|
||||||
|
averageGuildMembersWeeklyXP +
|
||||||
|
"`",
|
||||||
|
color: embedColor,
|
||||||
|
fields: topWeeklyMembers,
|
||||||
|
timestamp: new Date().toISOString(),
|
||||||
|
footer: {
|
||||||
|
text: channel.guild.name + " | " + devMessage,
|
||||||
|
icon_url: channel.guild.iconURL({ forceStatic: false })!,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
export = {
|
||||||
|
time: {
|
||||||
|
seconds: 0,
|
||||||
|
minutes: 0,
|
||||||
|
hours: 21,
|
||||||
|
dayOfWeek: 7,
|
||||||
|
dayOfMonth: "*",
|
||||||
|
month: "*",
|
||||||
|
},
|
||||||
|
execute: guildWeekly,
|
||||||
|
onComplete: null,
|
||||||
|
start: true,
|
||||||
|
timeZone: "Europe/Zagreb",
|
||||||
|
} as Cron
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
import Illegitimate from "./utils/Illegitimate"
|
import Illegitimate from "./utils/Illegitimate"
|
||||||
const illegitimate = new Illegitimate()
|
const illegitimate = new Illegitimate.Bot()
|
||||||
|
|
||||||
illegitimate.start()
|
illegitimate.start()
|
||||||
|
|||||||
@@ -75,7 +75,7 @@ async function autoDeployCommands() {
|
|||||||
console.log(
|
console.log(
|
||||||
color.colorize("Commands are the same, skipping deploy.", "green"),
|
color.colorize("Commands are the same, skipping deploy.", "green"),
|
||||||
)
|
)
|
||||||
console.log(color.colorize(currentCmds, "green"))
|
console.log(color.colorize(newCmds, "green"))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ import init from "./Init"
|
|||||||
import { loadCronEvents } from "./Cron"
|
import { loadCronEvents } from "./Cron"
|
||||||
const client = new Client()
|
const client = new Client()
|
||||||
|
|
||||||
export default class Illegitimate {
|
class Bot {
|
||||||
constructor() {}
|
constructor() {}
|
||||||
|
|
||||||
async start() {
|
async start() {
|
||||||
@@ -21,3 +21,5 @@ export default class Illegitimate {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export default { Bot, client }
|
||||||
@@ -9,6 +9,7 @@ const mojanguuid = "https://sessionserver.mojang.com/session/minecraft/profile/"
|
|||||||
const hypixel = "https://api.hypixel.net/player"
|
const hypixel = "https://api.hypixel.net/player"
|
||||||
const guild = "https://api.hypixel.net/guild"
|
const guild = "https://api.hypixel.net/guild"
|
||||||
const minotar = "https://minotar.net/helm/"
|
const minotar = "https://minotar.net/helm/"
|
||||||
|
type GuildQuerqType = "player" | "name" | "id"
|
||||||
|
|
||||||
async function getUUID(ign: string): Promise<string | null> {
|
async function getUUID(ign: string): Promise<string | null> {
|
||||||
try {
|
try {
|
||||||
@@ -45,7 +46,7 @@ async function getPlayer(uuid: string): Promise<PlayerData | null> {
|
|||||||
|
|
||||||
async function getGuild(
|
async function getGuild(
|
||||||
query: string,
|
query: string,
|
||||||
type?: string,
|
type?: GuildQuerqType,
|
||||||
): Promise<GuildData | null> {
|
): Promise<GuildData | null> {
|
||||||
const reqType = type ? type : "player"
|
const reqType = type ? type : "player"
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user