Browse Source

Reformat enforcement, add sweep

master
Joshua-Gordon 4 years ago
parent
commit
dd96f393f3
  1. 43
      main.js

43
main.js

@ -46,29 +46,40 @@ function checkXMonad(msg) {
}
function checkHi(msg) {
return (msg == "hi" || msg ="Hi");
return (msg == "hi" || msg == "Hi");
}
trackedChannels = {
"572490043302871040" : msg => checkCounting(msg.content), //must be first in this object
"572497453631143936" : checkXMonad,
"572489324583452691" : msg => checkHi(msg.content)
}
function enforce(msg) {
var valid = true;
if(trackedChannels[msg.channel.id] != undefined) {
valid = trackedChannels[msg.channel.id](msg);
}
if(!valid) {
msg.delete().then(() => console.log("DELETED"));
}
}
function sweep() {
//console.log(bot.channels)
console.log(Object.keys(trackedChannels))
var channels = Object.keys(trackedChannels).map(key => bot.channels.get(key));
channels.shift(); //protects counting
channels.forEach(channel => channel.fetchMessages().then(messages => messages.forEach(enforce)));
}
bot.on("ready",() => {
logger.info("Connected");
sweep();
});
bot.on("message",msg => {
console.log(msg.content,msg.channel.name);
valid = true
switch(msg.channel.id) {
case "572490043302871040":
valid = checkCounting(msg.content);
break;
case "572497453631143936":
valid = checkXMonad(msg);
break;
case "572489324583452691":
valid = checkHi(msg.content);
break;
}
if(!valid) {
msg.delete().then(() => console.log("DELETED"));
}
enforce(msg);
});
bot.login(auth.token)

Loading…
Cancel
Save