Skip to content
This repository was archived by the owner on Dec 5, 2021. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.env
node_modules
build
build
logs
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
"axios": "^0.21.1",
"discord.js": "^12.5.1",
"dotenv": "^8.2.0",
"mongoose": "^5.11.6"
"mongoose": "^5.11.6",
"winston": "^3.3.3"
},
"devDependencies": {
"rimraf": "^3.0.2",
Expand Down
3 changes: 3 additions & 0 deletions src/commands/admin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import adminfindsuggestor from "../handlers/admin/adminfindsuggestor";
import adminsay from "../handlers/admin/adminsay";

import Roles from "../data/calm/roles.json";
import Logger from "../utils/logger/Logger";
module.exports = {
name: "admin",
aliases: ["administrator"],
Expand Down Expand Up @@ -46,6 +47,8 @@ module.exports = {
return;
}

Logger.verbose(`Admin command ran by ${message.author.id}. ${message.content}`);

args[0] = args[0].toLowerCase();
if (args[0] === "manualchallenge") {
adminmanualchallenge.run(client, message, args);
Expand Down
2 changes: 1 addition & 1 deletion src/commands/annonsuggestion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ module.exports = {
secondReaction = "❎";
}

if (suggestionChannel === undefined) {
if (!suggestionChannel) {
message.channel.send("Uh oh! We could not find a channel to put the suggestion in!");
return;
}
Expand Down
3 changes: 2 additions & 1 deletion src/commands/help.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Message, MessageEmbed } from "discord.js";
import Client from "../structures/Client";
import logger from "../utils/logger/Logger";

module.exports = {
name: "help",
Expand Down Expand Up @@ -72,7 +73,7 @@ module.exports = {
}
} catch (err) {
message.channel.send("Sorry, we have encountered an error :sob:");
console.log(err);
logger.error(err);
}
},
};
11 changes: 5 additions & 6 deletions src/commands/lockdown.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { Message, Role, TextChannel } from "discord.js";
import Client from "../structures/Client";
import channels from "../data/calm/channels.json";
import roles from "../data/calm/roles.json";
import logger from "../utils/logger/Logger";

module.exports = {
name: "lockdown",
Expand Down Expand Up @@ -32,14 +33,12 @@ module.exports = {
newsChannel = message.guild.channels.cache.find((chan) => chan.name === channels.IMPORTANT.NEWS.name) as TextChannel;
}

if(guildMemberRole === undefined || nitroBoosterRole === undefined) {
return message.channel.send("Unable to find one or more roles. Please make sure the Guild Member role exists and the Nitro Booster role exists")
if (guildMemberRole === undefined || nitroBoosterRole === undefined) {
return message.channel.send("Unable to find one or more roles. Please make sure the Guild Member role exists and the Nitro Booster role exists");
}

if (newsChannel) {
await newsChannel.send(
`**Attention,** \n<@${message.author.id}> has **initiated** a _server lockdown_. \nYou are **not muted**, but will not be able to talk until a server admin does \`c!unlock\``
);
await newsChannel.send(`**Attention,** \n<@${message.author.id}> has **initiated** a _server lockdown_. \nYou are **not muted**, but will not be able to talk until a server admin does \`c!unlock\``);
}

for (const categoryName in channels) {
Expand All @@ -54,7 +53,7 @@ module.exports = {
}

if (!channel) {
console.log(`Channel ${channelProperties.name} wasn't found`);
logger.verbose(`Channel ${channelProperties.name} wasn't found`);
} else if (channelProperties.membersOnly && fullLock) {
channel.updateOverwrite(guildMemberRole, { SEND_MESSAGES: false, ADD_REACTIONS: false });
} else if (channelProperties.public && fullLock) {
Expand Down
87 changes: 47 additions & 40 deletions src/commands/staff.ts
Original file line number Diff line number Diff line change
@@ -1,57 +1,64 @@
import { GuildEmoji, Message, MessageEmbed } from "discord.js";
import Client from "../structures/Client";
import HypixelApi from "../utils/api/HypixelApi";
import { IPlayer } from "../utils/api/Interfaces"
import { IPlayer } from "../utils/api/Interfaces";
import logger from "../utils/logger/Logger";

module.exports = {
name: "staff",
description: "Displays all online Calm Guild Staff",
category: "Utility",
usage: "staff",
run: async function run(client: Client, message: Message) {
const guildStaff = await HypixelApi.getGuildStaff();
if (!guildStaff) {
return message.channel.send("Error: To prevent ratelimiting this command is on cooldown. Please wait a little bit and then try again.");
}
HypixelApi.getGuildStaff()
.then(async (guildStaff) => {
let onlineEmote: GuildEmoji | string, offlineEmote: GuildEmoji | string;
if (message.guild.id === "501501905508237312") {
onlineEmote = client.emojis.cache.find((e) => e.id === "805656441704546324");
offlineEmote = client.emojis.cache.find((e) => e.id === "805656538127401000");
} else {
onlineEmote = "🟢";
offlineEmote = "🔴";
}

let onlineEmote: GuildEmoji | string, offlineEmote: GuildEmoji | string;
if(message.guild.id === "501501905508237312") {
onlineEmote = client.emojis.cache.find(e => e.id === "805656441704546324")
offlineEmote = client.emojis.cache.find(e => e.id === "805656538127401000");
} else {
onlineEmote = "🟢";
offlineEmote = "🔴";
}
const tmp = await message.channel.send("Please wait while we fetch data from the api. This could take some time.");

const tmp = await message.channel.send("Please wait while we fetch data from the api. This could take some time.");

let online = Array<IPlayer>();
let offline = Array<IPlayer>();
let online = Array<IPlayer>();
let offline = Array<IPlayer>();

for (const member in guildStaff) {
const player = await HypixelApi.getPlayerFromUUID(guildStaff[member].uuid);

if (player.lastLogin > player.lastLogout) {
online.push(player);
} else {
offline.push(player);
}
}
for (const member in guildStaff) {
let player: IPlayer;
try {
player = await HypixelApi.getPlayerFromUUID(guildStaff[member].uuid);
} catch (err) {
logger.error(err);
return message.channel.send("An error happened while trying to perform this command! Please contact a developer.");
}

let embedDesc = "";
online.forEach((player) => {
embedDesc += "`" + player.displayname + "` " + onlineEmote + "\n";
})
offline.forEach((player) => {
embedDesc += "`" + player.displayname + "` " + offlineEmote + "\n";
})
if (player.lastLogin > player.lastLogout) {
online.push(player);
} else {
offline.push(player);
}
}


const embed = new MessageEmbed();
embed.setTitle("Guild Staff");
embed.setDescription(embedDesc);
await tmp.delete();
await message.channel.send(embed)
let embedDesc = "";
online.forEach((player) => {
embedDesc += "`" + player.displayname + "` " + onlineEmote + "\n";
});
offline.forEach((player) => {
embedDesc += "`" + player.displayname + "` " + offlineEmote + "\n";
});

const embed = new MessageEmbed();
embed.setTitle("Guild Staff");
embed.setDescription(embedDesc);
await tmp.delete();
await message.channel.send(embed);
})
.catch((err) => {
message.channel.send("That command could not be performed at this time. (this may be due to a cooldown). Please try again later!");
logger.warn(err);
});
},
};

3 changes: 2 additions & 1 deletion src/commands/unlock.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Message, Role, TextChannel } from "discord.js";
import Client from "../structures/Client";
import channels from "../data/calm/channels.json";
import logger from "../utils/logger/Logger";

module.exports = {
name: "unlock",
Expand Down Expand Up @@ -47,7 +48,7 @@ module.exports = {
}

if (!channel) {
console.log(`Channel ${channelProperties.name} wasn't found`);
logger.verbose(`Channel ${channelProperties.name} wasn't found`);
} else if (channelProperties.membersOnly && fullLock) {
channel.updateOverwrite(guildMemberRole, { SEND_MESSAGES: true, ADD_REACTIONS: null });
} else if (channelProperties.public && fullLock) {
Expand Down
14 changes: 0 additions & 14 deletions src/data/calm/staffuuids.ts

This file was deleted.

3 changes: 3 additions & 0 deletions src/events/message.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { Message, TextChannel } from "discord.js";
import { loggers } from "winston";
import DiscordClient from "../structures/Client";
import Database from "../utils/database/Database";
import Logger from "../utils/logger/Logger";
module.exports = async function message(client: DiscordClient, message: Message) {
if (message.author.bot || message.channel.type === "dm") return;

Expand Down Expand Up @@ -54,6 +56,7 @@ module.exports = async function message(client: DiscordClient, message: Message)
missingPerms = cmd.permissions.filter((permission) => !message.member.hasPermission(permission));
if (missingPerms.length) return message.channel.send(`You are missing the following permissions required to run this command: ${missingPerms.map((x) => `\`${x}\``).join(", ")}`);
}
Logger.verbose(`Running the ${cmd.name} commands for ${message.author.id}`);
cmd.run(client, message, args);
}
};
5 changes: 2 additions & 3 deletions src/events/ready.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import Client from "../structures/Client";
import Logger from "../utils/logger/Logger";

module.exports = async function ready(client: Client) {
console.log(" ");
console.log(`${client.user.tag} is now serving in ${client.guilds.cache.size} guilds!`);
console.log(" ");
Logger.info(`${client.user.tag} is now serving in ${client.guilds.cache.size} guilds!`);
};
4 changes: 3 additions & 1 deletion src/handlers/admin/admincommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ if (process.env.NODE_ENV !== "production") require("dotenv").config();
import { Message } from "discord.js";
import Client from "../../structures/Client";
import axios from "axios";
import Logger from "../../utils/logger/Logger";

export default {
run: async function run(client: Client, message: Message, args: Array<String>) {
Expand Down Expand Up @@ -30,8 +31,9 @@ export default {
message.channel.send(`StatusCode: ${response.status} | StatusMessage: ${response.statusText}`);
},
(error) => {
console.log(error);
message.channel.send("There was an error making that request!");
Logger.error(`Error making request to ${"http://" + ip + ":" + port + "/chat"}!!`);
Logger.error(error);
}
);
},
Expand Down
2 changes: 2 additions & 0 deletions src/handlers/admin/admindisablecommand.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Message } from "discord.js";
import GuildSettings from "../../schemas/GuildSettings";
import Client from "../../structures/Client";
import Logger from "../../utils/logger/Logger";
export default {
run: async function run(client: Client, message: Message, args: Array<String>) {
if (args.length < 2) {
Expand Down Expand Up @@ -33,5 +34,6 @@ export default {
guildSettings.disabledCommands.push(cmdname as string);
await guildSettings.save();
message.channel.send(`Disabled \`${cmdname}\``);
Logger.info(`Disabled \`${cmdname}\``);
},
};
2 changes: 2 additions & 0 deletions src/handlers/admin/adminenablecommand.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Message } from "discord.js";
import GuildSettings from "../../schemas/GuildSettings";
import Client from "../../structures/Client";
import Logger from "../../utils/logger/Logger";
export default {
run: async function run(client: Client, message: Message, args: Array<String>) {
if (args.length < 2) {
Expand Down Expand Up @@ -33,5 +34,6 @@ export default {
}
await guildSettings.save();
message.channel.send(`Enabled \`${cmdname}\``);
Logger.info(`Enabled \`${cmdname}\``);
},
};
4 changes: 4 additions & 0 deletions src/handlers/admin/adminmanualchallenge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { Message, User } from "discord.js";
import Client from "../../structures/Client";
import Challenges from "../../data/calm/challenges/DecemberChallenges.json";
import ChallengeParticipant from "../../schemas/ChallengeParticipant";
import Logger from "../../utils/logger/Logger";

export default {
run: async function run(client: Client, message: Message, args: Array<String>) {
Expand Down Expand Up @@ -40,10 +41,12 @@ export default {
participant.completedChallenges.delete(args[2]);
await participant.save();
message.channel.send(`Sucsess! Set ${args[1]}'s challenge #${args[2]} to __FALSE__`);
Logger.verbose(`Set ${args[1]}'s challenge #${args[2]} to FALSE`);
if (participant.completedChallenges.size === 0) {
let participant = await ChallengeParticipant.findOne({ discordID: args[1] as string });
await participant.delete();
message.channel.send("Document in database for that user has been marked for deletion due to that challenge being the user's last TRUE challenge");
Logger.verbose(`Deleting ${args[1]}'s challenge participant document as the last entry was manually deleted by ${message.author.id}`);
return;
}
return;
Expand All @@ -52,6 +55,7 @@ export default {
participant.completedChallenges.set(args[2], "true");
await participant.save();
message.channel.send(`Sucsess! Set ${args[1]}'s challenge #${args[2]} to __TRUE__`);
Logger.verbose(`Set ${args[1]}'s challenge #${args[2]} to TRUE`);
return;
}
},
Expand Down
2 changes: 2 additions & 0 deletions src/handlers/admin/adminsay.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Message, TextChannel } from "discord.js";
import Client from "../../structures/Client";
import Logger from "../../utils/logger/Logger";

export default {
run: async function run(client: Client, message: Message, args: Array<String>) {
Expand All @@ -15,5 +16,6 @@ export default {

const txtchannel = channel as TextChannel;
txtchannel.send(text);
Logger.verbose(`Sent message (${text}) in ${txtchannel.name} at request from ${message.author.id}`);
},
};
5 changes: 4 additions & 1 deletion src/handlers/admin/adminsleep.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,21 @@
import { Message } from "discord.js";
import Database from "../../utils/database/Database";
import Client from "../../structures/Client";
import Logger from "../../utils/logger/Logger";

export default {
run: async function run(client: Client, message: Message, args: Array<String>) {
let settings = await Database.getGuildSettings(message.guild.id);
if (settings.sleep) {
settings.sleep = false;
settings.save();
message.channel.send("Turned off sleep mode");
message.channel.send("Turned off sleep mode.");
Logger.info("Turned off sleep mode");
} else {
settings.sleep = true;
settings.save();
message.channel.send("Turned on sleep mode. Run c!admin sleep to turn it off");
Logger.info("Turned on sleep mode.");
}
},
};
Loading