Skip to content

Instantly share code, notes, and snippets.

@cwebber314
Last active May 5, 2021 05:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cwebber314/da841d852b6e56300078449f243adeae to your computer and use it in GitHub Desktop.
Save cwebber314/da841d852b6e56300078449f243adeae to your computer and use it in GitHub Desktop.
discord pylon bot to copy messages which match a pattern
// Bot to copy messages which match a pattern from one channel to another
// edit the vars below
var SOURCE_CHANNEL = '830874514241749013'; // #rconlog
var DEST_CHANNEL = '804394923947851796'; // #The-Gulag
var PATTERN1 = 'do_punish';
var PATTERN2 = 'do_kick';
var PATTERN3 = 'do_perma_ban';
var PATTERN4 = 'do_temp_ban';
var PATTERN5 = 'unban';
var PATTERN6 = 'Blacklist';
// The gulag handler
discord.on('MESSAGE_CREATE', async (message) => {
console.log(message);
async function destChannelSendMessge(message_content) {
var dstChannel = await discord.getChannel(DEST_CHANNEL);
console.log(dstChannel);
await dstChannel.sendMessage({ content: message_content });
}
if (
// TODO: Edit this part to detect more phrases
(message.content.includes(PATTERN1) ||
message.content.includes(PATTERN2) ||
message.content.includes(PATTERN3) ||
message.content.includes(PATTERN4) ||
message.content.includes(PATTERN5) ||
message.content.includes(PATTERN6)) &&
message.channelId == SOURCE_CHANNEL
) {
// console.log("pattern matches")
destChannelSendMessge(message.content);
}
});
// !admin handler
// This shows how you can put the message in an embed box with a title. You can also use emoticons
// for added emphasis (see docs)
discord.on('MESSAGE_CREATE', async (message) => {
console.log(message);
async function destChannelSendMessge(message_content) {
var dstChannel = await discord.getChannel(DEST_CHANNEL);
console.log(dstChannel);
await dstChannel.sendMessage(
new discord.Embed({
title: 'Server Admin Request',
color: 0xff0000,
description: message_content
})
);
// await dstChannel.sendMessage({ content: message_content });
}
// destChannelSendMessge('dummy content');
if (
// TODO: Edit contition to detect more phrases
(message.content.toLowerCase().includes('!admin') &&
message.channelId == SOURCE_CHANNEL
) {
// console.log("pattern matches")
// Is removing the !admin in the original message causing trouble?
// Do we need to make a copy
destChannelSendMessge(message.content.replace("!admin", ""));
// let message_content = Object.assign("", message.content);
// destChannelSendMessge(message_content);
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment