Skip to content

Commit

Permalink
Add logging for ingame chat/commandsand createMessage
Browse files Browse the repository at this point in the history
  • Loading branch information
alexemanuelol committed Sep 3, 2023
1 parent 362d0ac commit 08b06fd
Show file tree
Hide file tree
Showing 9 changed files with 83 additions and 9 deletions.
22 changes: 22 additions & 0 deletions src/discordEvents/messageCreate.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
*/

const DiscordCommandHandler = require('../handlers/discordCommandHandler.js');
const DiscordTools = require('../discordTools/discordTools');

module.exports = {
name: 'messageCreate',
Expand All @@ -28,10 +29,31 @@ module.exports = {

if (message.author.bot || !rustplus || (rustplus && !rustplus.isOperational)) return;

if (instance.blacklist['discordIds'].includes(message.author.id) &&
Object.values(instance.channelId).includes(message.channelId)) {
const guild = DiscordTools.getGuild(message.guild.id);
const channel = DiscordTools.getTextChannelById(guild.id, message.channelId);
client.log(client.intlGet(null, 'infoCap'), client.intlGet(null, `userPartOfBlacklistDiscord`, {
guild: `${guild.name} (${guild.id})`,
channel: `${channel.name} (${channel.id})`,
user: `${message.author.username} (${message.author.id})`,
message: message.cleanContent
}));
return;
}

if (message.channelId === instance.channelId.commands) {
await DiscordCommandHandler.discordCommandHandler(rustplus, client, message);
}
else if (message.channelId === instance.channelId.teamchat) {
const guild = DiscordTools.getGuild(message.guild.id);
const channel = DiscordTools.getTextChannelById(guild.id, message.channelId);
client.log(client.intlGet(null, 'infoCap'), client.intlGet(null, `logDiscordMessage`, {
guild: `${guild.name} (${guild.id})`,
channel: `${channel.name} (${channel.id})`,
user: `${message.author.username} (${message.author.id})`,
message: message.cleanContent
}));
await rustplus.sendTeamMessageAsync(`${message.author.username}: ${message.cleanContent}`);
}
},
Expand Down
10 changes: 10 additions & 0 deletions src/handlers/discordCommandHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
*/

const DiscordMessages = require('../discordTools/discordMessages.js');
const DiscordTools = require('../discordTools/discordTools');

module.exports = {
discordCommandHandler: async function (rustplus, client, message) {
Expand Down Expand Up @@ -178,6 +179,15 @@ module.exports = {
await DiscordMessages.sendDiscordCommandResponseMessage(rustplus, client, message, response);
}

const guild = DiscordTools.getGuild(message.guild.id);
const channel = DiscordTools.getTextChannelById(guild.id, message.channelId);
client.log(client.intlGet(null, 'infoCap'), client.intlGet(null, `logDiscordCommand`, {
guild: `${guild.name} (${guild.id})`,
channel: `${channel.name} (${channel.id})`,
user: `${message.author.username} (${message.author.id})`,
message: message.cleanContent
}));

return true;
},
};
5 changes: 5 additions & 0 deletions src/handlers/inGameCommandHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -182,20 +182,25 @@ module.exports = {
/* Maybe a custom command? */

if (SmartAlarmHandler.smartAlarmCommandHandler(rustplus, client, command)) {
rustplus.logInGameCommand('Smart Alarm', message);
return true;
}

if (await SmartSwitchHandler.smartSwitchCommandHandler(rustplus, client, command)) {
rustplus.logInGameCommand('Smart Switch', message);
return true;
}

if (await SmartSwitchGroupHandler.smartSwitchGroupCommandHandler(rustplus, client, command)) {
rustplus.logInGameCommand('Smart Switch Group', message);
return true;
}

return false;
}

rustplus.logInGameCommand('Default', message);

return true;
},
};
4 changes: 4 additions & 0 deletions src/handlers/smartSwitchGroupHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,10 @@ module.exports = {
status: active ? onCap : offCap
});

rustplus.log(client.intlGet(null, 'infoCap'), client.intlGet(null, `logSmartSwitchGroupValueChange`, {
value: active
}));

if (timeSeconds === null) {
rustplus.printCommandOutput(str);
await module.exports.TurnOnOffGroup(client, rustplus, guildId, serverId, groupId, active);
Expand Down
4 changes: 4 additions & 0 deletions src/handlers/smartSwitchHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,10 @@ module.exports = {

const timeSeconds = Timer.getSecondsFromStringTime(rest);

rustplus.log(client.intlGet(null, 'infoCap'), client.intlGet(null, `logSmartSwitchValueChange`, {
value: active
}));

module.exports.smartSwitchCommandTurnOnOff(rustplus, client, entityId, active);

if (!switches[entityId].reachable) return true;
Expand Down
24 changes: 16 additions & 8 deletions src/languages/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,6 @@
"broadcaster": "Broadcaster",
"buttonReconnecting": "RECONNECTING",
"buttonValueChange": "Button Interaction - VerifyId: {id}, Value: {value}.",
"slashCommandValueChange": "Slash Command Interaction - VerifyId: {id}, Value: {value}.",
"selectMenuValueChange": "Select Menu Interaction - VerifyId: {id}, Value: {value}.",
"modalValueChange": "Modal Interaction - VerifyId: {id}, Value: {value}.",
"buy": "buy",
"cargoAt": "At {location}.",
"cargoLeavingMapAt": "Cargo Ship is leaving the map at {location}.",
Expand Down Expand Up @@ -394,6 +391,12 @@
"lockedCrateLargeOilRigUnlocked": "Locked Crate at Large Oil Rig at {location} has been unlocked.",
"lockedCrateOilRigUnlockedSetting": "When a Locked Crate at Oil Rig is unlocked, send a notification.",
"lockedCrateSmallOilRigUnlocked": "Locked Crate at Small Oil Rig at {location} has been unlocked.",
"logDiscordCommand": "Discord Command - Guild: {guild}, Channel: {channel}, User: {user}, Message: {message}.",
"logDiscordMessage": "Discord Message - Guild: {guild}, Channel: {channel}, User: {user}, Message: {message}.",
"logInGameCommand": "{type} - Command: {command}, User: {user}.",
"logInGameMessage": "Message: {message}, User: {user}",
"logSmartSwitchGroupValueChange": "Smart Switch Group - Value: {}.",
"logSmartSwitchValueChange": "Smart Switch - Value: {value}.",
"loggedInAs": "LOGGED IN AS: {name}",
"makeSureApplicationsCommandsEnabled": "Make sure applications.commands is checked when creating the invite URL.",
"map": "Map",
Expand All @@ -417,6 +420,7 @@
"missingArguments": "Missing arguments.",
"missingPermission": "You don't have permission to do this.",
"missingTimerMessage": "Missing timer message.",
"modalValueChange": "Modal Interaction - VerifyId: {id}, Value: {value}.",
"more": "more",
"morePlayers": "{players} ...{number} more.",
"mutedCap": "MUTED",
Expand Down Expand Up @@ -532,6 +536,7 @@
"selectInGamePrefixSetting": "Select what in-game command prefix that should be used:",
"selectLanguageExtendSetting": "Make sure you run **/reset discord** to successfully load the new language.",
"selectLanguageSetting": "Select what language the bot uses:",
"selectMenuValueChange": "Select Menu Interaction - VerifyId: {id}, Value: {value}.",
"selectTrademarkSetting": "Select which trademark that should be shown in every in-game message.",
"sell": "sell",
"semicolon": "Semicolon",
Expand Down Expand Up @@ -559,6 +564,8 @@
"sirenLight": "Siren Light",
"six": "Six",
"slash": "Slash",
"slashCommandInteraction": "Slash Command Interaction - Guild: {guild}, Channel: {channel}, User: {user}, Command: {command}, VerifyId: {id}.",
"slashCommandValueChange": "Slash Command Interaction - VerifyId: {id}, Value: {value}.",
"slashCommandsSuccessRegister": "Successfully registered application commands for guild: {guildId}.",
"slots": "Slots",
"smallOilRig": "Small Oil Rig",
Expand Down Expand Up @@ -659,18 +666,19 @@
"userAddedToBlacklist": "{user} was added to blacklist.",
"userAlreadyInBlacklist": "{user} already in blacklist.",
"userButtonInteraction": "Button Interaction - Guild: {guild}, Channel: {channel}, User: {user}, CustomId: {customid}, VerifyId: {id}.",
"slashCommandInteraction": "Slash Command Interaction - Guild: {guild}, Channel: {channel}, User: {user}, Command: {command}, VerifyId: {id}.",
"userModalInteraction": "Modal Interaction - Guild: {guild}, Channel: {channel}, User: {user}, CustomId: {customid}, VerifyId: {id}.",
"userSelectMenuInteraction": "Select Menu Interaction - Guild: {guild}, Channel: {channel}, User: {user}, CustomId: {customid}, VerifyId: {id}.",
"userButtonInteractionSuccess": "Button Interaction - VerifyId: {id} SUCCESS",
"userSelectMenuInteractionSuccess": "Select Menu Interaction - VerifyId: {id} SUCCESS",
"userModalInteractionSuccess": "Modal Interaction - VerifyId: {id} SUCCESS",
"userJustConnected": "{name} just connected.",
"userModalInteraction": "Modal Interaction - Guild: {guild}, Channel: {channel}, User: {user}, CustomId: {customid}, VerifyId: {id}.",
"userModalInteractionSuccess": "Modal Interaction - VerifyId: {id} SUCCESS",
"userNotInBlacklist": "{user} not in blacklist.",
"userNotRegistered": "{user} is not registered.",
"userPartOfBlacklist": "VerifyId: {id}, {user} is part of the blacklist.",
"userPartOfBlacklistDiscord": "Blacklisted User! Guild: {guild}, Channel: {channel}, User: {user}, Message: {message}.",
"userPartOfBlacklistInGame": "Blacklisted User! User: {user}, Message: {message}.",
"userRemovedFromBlacklist": "{user} was removed from blacklist.",
"userSaid": "{user} said, {text}",
"userSelectMenuInteraction": "Select Menu Interaction - Guild: {guild}, Channel: {channel}, User: {user}, CustomId: {customid}, VerifyId: {id}.",
"userSelectMenuInteractionSuccess": "Select Menu Interaction - VerifyId: {id} SUCCESS",
"vendingMachine": "Vending Machine",
"vendingMachineDetectedSetting": "When a new Vending Machine is detected, send a notification.",
"voiceCap": "VOICE",
Expand Down
11 changes: 11 additions & 0 deletions src/rustplusEvents/message.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,11 @@ async function messageBroadcastTeamMessage(rustplus, client, message) {
message.broadcast.teamMessage.message.message.replace(/^<color.+?<\/color>/g, '');

if (instance.blacklist['steamIds'].includes(`${message.broadcast.teamMessage.message.steamId}`)) {
rustplus.log(client.intlGet(null, 'infoCap'), client.intlGet(null, `userPartOfBlacklistInGame`, {
user: `${message.broadcast.teamMessage.message.name}` +
` (${message.broadcast.teamMessage.message.steamId.toString()})`,
message: message.broadcast.teamMessage.message.message
}));
TeamChatHandler(rustplus, client, message.broadcast.teamMessage.message);
return;
}
Expand All @@ -83,6 +88,12 @@ async function messageBroadcastTeamMessage(rustplus, client, message) {
const isCommand = await CommandHandler.inGameCommandHandler(rustplus, client, message);

if (!isCommand && !startsWithTrademark) {
rustplus.log(client.intlGet(null, 'infoCap'), client.intlGet(null, `logInGameMessage`, {
message: message.broadcast.teamMessage.message.message,
user: `${message.broadcast.teamMessage.message.name}` +
` (${message.broadcast.teamMessage.message.steamId.toString()})`
}));

TeamChatHandler(rustplus, client, message.broadcast.teamMessage.message);
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/structures/DiscordBot.js
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ class DiscordBot extends Discord.Client {
args['guild'] = `${interaction.member.guild.name} (${interaction.member.guild.id})`;
args['channel'] = `${channel.name} (${interaction.channelId})`;
args['user'] = `${interaction.user.username} (${interaction.user.id})`;
args[(type === 'slashCommand') ? 'command' : 'customId'] = (type === 'slashCommand') ?
args[(type === 'slashCommand') ? 'command' : 'customid'] = (type === 'slashCommand') ?
`${interaction.commandName}` : `${interaction.customId}`;
args['id'] = `${verifyId}`;

Expand Down
10 changes: 10 additions & 0 deletions src/structures/RustPlus.js
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,16 @@ class RustPlus extends RustPlusLib {
this.logger.log(title, text, level);
}

logInGameCommand(type = 'Default', message) {
const args = new Object();
args['type'] = type;
args['command'] = message.broadcast.teamMessage.message.message;
args['user'] = `${message.broadcast.teamMessage.message.name}`;
args['user'] += ` (${message.broadcast.teamMessage.message.steamId.toString()})`;

this.log(Client.client.intlGet(null, 'infoCap'), Client.client.intlGet(null, `logInGameCommand`, args));
}

async printCommandOutput(str, type = 'COMMAND') {
if (str === null) return;

Expand Down

0 comments on commit 08b06fd

Please sign in to comment.