diff --git a/assets/scripts/lobby/chat.js b/assets/scripts/lobby/chat.js index b48a5039..e0337e1b 100644 --- a/assets/scripts/lobby/chat.js +++ b/assets/scripts/lobby/chat.js @@ -571,6 +571,9 @@ function generateBadgeString(badge) { else if (badge === 'M') { title = 'Moderator'; } + else if (badge === 'P') { + title = 'Percy'; + } else if (badge === 'D') { title = 'Developer'; } diff --git a/src/routes/mod.js b/src/routes/mod.js index 2387660b..06910a78 100644 --- a/src/routes/mod.js +++ b/src/routes/mod.js @@ -21,6 +21,7 @@ import { MongoClient } from 'mongodb'; import { SESSIONS_COLLECTION_NAME } from '../constants'; import { isMod } from '../modsadmins/mods'; import { isPercival } from '../modsadmins/percivals'; +import { sendToDiscordMods } from '../clients/discord'; const router = new Router(); @@ -217,6 +218,11 @@ router.post('/ban', async (req, res) => { dateCreated: new Date(), }); + sendToDiscordMods(`${userIsMod ? "Moderator" : "Percival"} "${req.user.usernameLower}" banned "${banUser.usernameLower}" for \ +${req.body['duration']} ${req.body['duration_units']} for reason "${req.body.reason}" with description \ +"${req.body['descriptionByMod']}".` + , false); + // Delete all the sessions associated with this username const dbResult = await MongoClient.connect(process.env.DATABASEURL); const mySessions = dbResult.db().collection(SESSIONS_COLLECTION_NAME); diff --git a/src/sockets/commands/admin/adiscordmessage.ts b/src/sockets/commands/admin/adiscordmessage.ts new file mode 100644 index 00000000..3c17b39a --- /dev/null +++ b/src/sockets/commands/admin/adiscordmessage.ts @@ -0,0 +1,38 @@ +import { sendReplyToCommand } from '../../sockets'; +import { SocketUser } from '../../types'; +import { Command } from '../types'; +import { sendToDiscordAdmins, sendToDiscordMods } from '../../../clients/discord'; + +export const adiscordmessage: Command = { + command: 'adiscordmessage', + help: '/adiscordmessage : Sends a discord message to the admin or mod channel.', + run: async (args: string[], socket: SocketUser) => { + + if (args.length < 4) { + sendReplyToCommand(socket, 'Need at least 3 args.'); + return; + } + + const channel = args[1]; + const ping = args[2] === "true"; + const message = args.slice(3).join(' '); + + switch(channel) + { + case "admin": { + sendToDiscordAdmins(message, ping); + break; + } + case "mod": { + sendToDiscordMods(message, ping); + break; + } + default: { + sendToDiscordAdmins(`Invalid channel. Expected "admin" or "mod", got ${channel}.`); + return; + } + } + + sendReplyToCommand(socket, 'Message sent.'); + }, +}; diff --git a/src/sockets/commands/admin/index.ts b/src/sockets/commands/admin/index.ts index d160528d..300a3d9f 100644 --- a/src/sockets/commands/admin/index.ts +++ b/src/sockets/commands/admin/index.ts @@ -4,6 +4,7 @@ import { aip } from './aip'; import { aresetpassword } from './aresetpassword'; import { Commands } from '../types'; import { atestgame } from './atestgame'; +import { adiscordmessage } from './adiscordmessage'; import { acreatetestaccounts } from './acreatetestaccounts'; import { aresettournamentaccounts } from './aresettournamentaccounts'; import { ausernametoemail } from './ausernametoemail'; @@ -12,6 +13,7 @@ import { asessions } from './asessions'; export const adminCommands: Commands = { [a.command]: a, [acreatetestaccounts.command]: acreatetestaccounts, + [adiscordmessage.command]: adiscordmessage, [aemailtousername.command]: aemailtousername, [aip.command]: aip, [aresettournamentaccounts.command]: aresettournamentaccounts, diff --git a/src/sockets/sockets.ts b/src/sockets/sockets.ts index ea9877f0..fa207ef8 100644 --- a/src/sockets/sockets.ts +++ b/src/sockets/sockets.ts @@ -15,12 +15,7 @@ import { isAdmin } from '../modsadmins/admins'; import { isMod } from '../modsadmins/mods'; import { isPercival } from '../modsadmins/percivals'; import { isTO } from '../modsadmins/tournamentOrganizers'; -import { - GAME_MODE_NAMES, - GameMode, - isGameMode, - strToGameMode, -} from '../gameplay/gameModes'; +import { GAME_MODE_NAMES, GameMode, isGameMode, strToGameMode } from '../gameplay/gameModes'; import { ChatSpamFilter } from './filters/chatSpamFilter'; import { MessageWithDate, Quote } from './quote'; @@ -777,6 +772,9 @@ const applyApplicableRewards = function (socket) { else if (socket.rewards.includes(REWARDS.MOD_BADGE)) { socket.request.badge = 'M'; } + else if (isPercival(socket.request.user.username)) { + socket.request.badge = 'P'; + } // TO badge else if (socket.rewards.includes(REWARDS.TO_BADGE)) { socket.request.badge = 'T';