Skip to content

Commit

Permalink
Last Percy stuff (#730)
Browse files Browse the repository at this point in the history
* Add in percy badge

* Percy stuff
  • Loading branch information
vck3000 authored Jan 4, 2025
1 parent ae59b9d commit 57fb338
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 6 deletions.
3 changes: 3 additions & 0 deletions assets/scripts/lobby/chat.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
}
Expand Down
6 changes: 6 additions & 0 deletions src/routes/mod.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down Expand Up @@ -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);
Expand Down
38 changes: 38 additions & 0 deletions src/sockets/commands/admin/adiscordmessage.ts
Original file line number Diff line number Diff line change
@@ -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 <admin|mod> <ping (true|false)> <message>: 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.');
},
};
2 changes: 2 additions & 0 deletions src/sockets/commands/admin/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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,
Expand Down
10 changes: 4 additions & 6 deletions src/sockets/sockets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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';
Expand Down

0 comments on commit 57fb338

Please sign in to comment.