remove modules

This commit is contained in:
Daniel afx 2022-03-23 05:22:00 +02:00
parent c752b95490
commit e299e0d330
15 changed files with 0 additions and 1433 deletions

View file

@ -1,29 +0,0 @@
const discord = require("discord.js");
class AutoReactModule
{
constructor(config, client, bot)
{
this.config = config;
/** @type {discord.Client} */
this.client = client;
this.bot = bot;
}
/**
* @param {discord.Message} msg
* @param {Boolean} edited
*/
onMessage(msg, edited)
{
if (edited) {
return;
}
if (msg.content.match(new RegExp(this.config.match, "i"))) {
msg.react(this.config.emoji);
}
}
}
module.exports = AutoReactModule;

View file

@ -1,513 +0,0 @@
var fs = require("fs");
var moment = require("moment");
var cmdsplit = require("./../cmdsplit");
class EventSchedule
{
constructor(config, client, bot)
{
this.event = config;
this.client = client;
this.bot = bot;
this.lastNotFound = new Date(1970, 1, 1);
this.lastNow = new Date(1970, 1, 1);
this.loadSchedule(this.event.file);
}
loadSchedule(filename)
{
console.log('Loading schedule: "' + filename + '"');
this.schedule = JSON.parse(fs.readFileSync(filename));
for (var i = 0; i < this.schedule.length; i++) {
let stage = this.schedule[i];
console.log("Event channel: " + stage.channel);
this.client.channels.fetch(stage.channel).then(channel => {
stage.channel = channel;
this.updateChannel(stage);
}).catch(() => {
console.error("Unable to find channel for stage \"" + stage.stage + "\"");
});
var newResponses = [];
for (var expression in stage.responses) {
let newResponse = {
match: new RegExp(expression, "i"),
msg: stage.responses[expression]
};
newResponses.push(newResponse);
}
stage.responses = newResponses;
stage.channelExtra = null;
if (stage.extra_channel !== undefined) {
this.client.channels.fetch(stage.extra_channel).then(channel => {
stage.channelExtra = channel;
}).catch(() => {
console.error("Unable to find channel for stage \"" + stage.stage + "\"");
});
}
var streamDelay = stage.streamdelay;
for (var j = 0; j < stage.sets.length; j++) {
var set = stage.sets[j];
var dateArray = set.slice(0, 5);
dateArray[1] -= 1; // months are 0-indexed, for some reason. even in the moment library!
var setDate = moment(dateArray).add(streamDelay, 'm');
var newSet = {
date: setDate,
name: set[5],
report: moment() > setDate,
report_5min: moment().add(5, 'm') > setDate,
nothing: (set[5] === undefined || set[5] == "Nothing"),
who: set[6]
};
stage.sets[j] = newSet;
}
}
}
getStage(stage)
{
for (var i = 0; i < this.schedule.length; i++) {
var s = this.schedule[i];
if (s.stage == stage) {
return s;
}
}
return null;
}
getStageByChannel(channel)
{
for (var i = 0; i < this.schedule.length; i++) {
var s = this.schedule[i];
if (s.channel == channel) {
return s;
}
}
return null;
}
findSets(query)
{
query = query.toLowerCase();
var ret = [];
for (var i = 0; i < this.schedule.length; i++) {
var stage = this.schedule[i];
for (var j = 0; j < stage.sets.length; j++) {
var set = stage.sets[j];
if (set.nothing) {
continue;
}
if (set.name.toLowerCase().indexOf(query) != -1 || (set.who && set.who.toLowerCase().indexOf(query) != -1)) {
ret.push({
set: set,
stage: stage
});
}
}
}
return ret;
}
getCurrentSet(stage)
{
var date = new Date();
for (var i = 0; i < stage.sets.length; i++) {
var set = stage.sets[i];
if (date < set.date) {
if (i == 0) {
// Happens if no set has started yet on this stage
return null;
}
return stage.sets[i - 1];
}
}
// Happens if the last set has been played
return stage.sets[stage.sets.length - 1];
}
getNextSet(stage)
{
var date = new Date();
for (var i = 0; i < stage.sets.length; i++) {
var set = stage.sets[i];
if (date < set.date) {
return set;
}
}
// Happens if this is the final set on this stage
return null;
}
getNextLiveSet(stage)
{
var date = new Date();
for (var i = 0; i < stage.sets.length; i++) {
var set = stage.sets[i];
if (date < set.date && !set.nothing) {
return set;
}
}
// Happens if this is the final set on this stage
return null;
}
onTick()
{
var date = moment();
for (var i = 0; i < this.schedule.length; i++) {
var stage = this.schedule[i];
var current = this.getCurrentSet(stage);
if (current !== null) {
if (!current.report) {
current.report = true;
if (!current.nothing) {
console.log("Starting now: " + current.name);
var msg = ":red_circle: STARTING NOW: **" + current.name + "**";
stage.channel.send(msg);
if (stage.channelExtra) {
stage.channelExtra.send(msg);
}
} else {
console.log("Stream is not live anymore.");
var next = this.getNextSet(stage);
if (next !== null && !next.nothing) {
var msg = ":no_entry_sign: Stream is no longer live. Next set is at **" + this.getTimeString(next.date) + "**!";
stage.channel.send(msg);
if (stage.channelExtra) {
stage.channelExtra.send(msg);
}
} else {
var msg = ":tada: This is the end of the livestream. Thanks for watching.";
stage.channel.send(msg);
if (stage.channelExtra) {
stage.channelExtra.send(msg);
}
}
}
this.updateChannel(stage);
}
}
var next = this.getNextSet(stage);
if (next !== null && !next.nothing) {
if (date.clone().add(5, 'm') > next.date && !next.report_5min) {
next.report_5min = true;
console.log("Starting in 5 minutes: " + next.name);
var msg = ":warning: **" + next.name + "** starts in 5 minutes!";
stage.channel.send(msg);
if (stage.channelExtra) {
stage.channelExtra.send(msg);
}
}
}
}
}
onCmdCurrent(msg) { this.onCmdNp(msg); }
onCmdNow(msg) { this.onCmdNp(msg); }
onCmdNp(msg)
{
var stage = this.getStageByChannel(msg.channel);
if (!stage) {
return;
}
var current = this.getCurrentSet(stage);
if (current !== null && !current.nothing) {
if (current.who) {
msg.channel.send(":red_circle: Now playing: **" + current.name + "**, started <t:" + current.date.unix() + ":R>! (" + current.who + ")");
} else {
msg.channel.send(":red_circle: Now playing: **" + current.name + "**, started <t:" + current.date.unix() + ":R>!");
}
} else {
msg.channel.send("Nobody's playing right now.");
}
}
onCmdNext(msg)
{
var stage = this.getStageByChannel(msg.channel);
if (!stage) {
return;
}
var next = this.getNextSet(stage);
if (next) {
var localTime = "**" + this.getTimeString(next.date) + "**";
localTime += " (<t:" + next.date.unix() + ":R>)";
if (next.name) {
if (next.who) {
msg.channel.send(":arrow_forward: Next up: **" + next.name + "**, at " + localTime + " (" + next.who + ")");
} else {
msg.channel.send(":arrow_forward: Next up: **" + next.name + "**, at " + localTime);
}
} else {
msg.channel.send(":arrow_forward: The stream ends at " + localTime);
}
} else {
msg.channel.send("There's nothing playing next.");
}
}
getScheduleString(stage, limit, starttime)
{
var ret = "";
if (stage.unconfirmed) {
ret = ":warning: **Note:** Set times are not confirmed!\n";
}
if (!starttime) {
starttime = moment(stage.sets[0].date).clone().subtract(1, 'm');
}
var lines = 0;
for (var i = 0; i < stage.sets.length; i++) {
var set = stage.sets[i];
if (starttime > set.date) {
continue;
}
if (limit && lines == limit) {
ret += "(limited, use `.fullschedule` for the full schedule)\n";
break;
}
lines++;
if (set.nothing) {
ret += "- <t:" + set.date.unix() + ":t> (<t:" + set.date.unix() + ":R>), the stream will be offline :no_entry_sign:\n";
} else {
if (set.who) {
ret += "- <t:" + set.date.unix() + ":t> (<t:" + set.date.unix() + ":R>): **" + set.name + "** (" + set.who + ")\n";
} else {
ret += "- <t:" + set.date.unix() + ":t> (<t:" + set.date.unix() + ":R>): **" + set.name + "**\n";
}
}
}
if (lines == 0) {
ret = "We have nothing left! :frowning:";
} else if (limit) {
ret = ":calendar_spiral: Next " + limit + " sets are:\n" + ret.trim();
} else {
ret = ":calendar_spiral: The full schedule:\n" + ret.trim();
}
return ret;
}
onCmdTimetable(msg) { this.onCmdSchedule(msg); }
onCmdSched(msg) { this.onCmdSchedule(msg); }
onCmdSchedule(msg)
{
var stage = this.getStageByChannel(msg.channel);
if (!stage) {
return;
}
msg.channel.send(this.getScheduleString(stage, 5, moment()));
}
onCmdFullSched(msg) { this.onCmdFullSchedule(msg); }
onCmdFullSchedule(msg)
{
var stage = this.getStageByChannel(msg.channel);
if (!stage) {
return;
}
var text = this.getScheduleString(stage);
while (text.length > 0) {
msg.author.send(text.substr(0, 2000)).catch(console.error);
text = text.substr(2000);
}
msg.reply("I've DM'd you the full schedule.");
}
onCmdFind(msg)
{
var query = Array.from(arguments).slice(1).join(" ").trim();
if (query.length < 3) {
return;
}
var results = this.findSets(query);
var ret = "";
if (results.length == 0) {
ret = "I found nothing :frowning:";
// Avoid spamming "I found nothing" when jokers do .find a meaning of life
var now = new Date();
if ((now - this.lastNotFound) < 60 * 1000) {
return;
}
this.lastNotFound = now;
} else {
var date = new Date();
for (var i = 0; i < results.length; i++) {
var res = results[i];
var localTime = "**" + this.getTimeString(res.set.date) + "**";
localTime += " (<t:" + res.set.date.unix() + ":R>)";
var stageMessage = "";
if (this.schedule.length > 1) {
stageMessage = " on **" + res.stage.stage + "** " + res.stage.emoji + " stage!";
}
if (date > res.date) {
ret += res.set.name + " already played on <t:" + res.set.date.unix() + ":F>\n";
} else {
ret += res.set.name + " plays on <t:" + res.set.date.unix() + ":F>\n";
}
}
}
msg.channel.send(":calendar_spiral: " + ret.trim());
}
onCmdReloadSchedule(msg)
{
if (!this.bot.isAdmin(msg.member)) {
return;
}
this.loadSchedule(this.event.file);
msg.reply("schedule reloaded!");
}
onMessage(msg)
{
var inStage = false;
for (var i = 0; i < this.schedule.length; i++) {
var stage = this.schedule[i];
if (stage.channel.id != msg.channel.id) {
continue;
}
inStage = true;
for (var j = 0; j < stage.responses.length; j++) {
var r = stage.responses[j];
var match = msg.content.match(r.match);
if (match) {
var sendMessage = r.msg;
for (var k = 0; k < match.length; k++) {
sendMessage = sendMessage.replace("$" + k, match[k]);
}
msg.channel.send(sendMessage);
return true;
}
}
}
var isCommand = msg.content.startsWith(".");
var parse = [];
if (isCommand) {
parse = cmdsplit(msg.content);
}
// Outside-channel schedule command
if (isCommand && this.schedule.length > 1 && !inStage && (parse[0] == ".schedule" || parse[0] == ".timetable" || parse[0] == ".sched" || parse[0] == ".current" || parse[0] == ".now")) {
// Avoid spamming long .now message when jokers spam .now
var now = new Date();
if ((now - this.lastNow) < 60 * 1000) {
return true;
}
this.lastNow = now;
var ret = "**LIVE**\n";
for (var i = 0; i < this.schedule.length; i++) {
var stage = this.schedule[i];
var current = this.getCurrentSet(stage);
var next = this.getNextSet(stage);
if (current === null && next !== null && next.date.date() != moment(now).date()) {
continue;
}
if (current !== null && !current.nothing) {
ret += stage.emoji + " " + stage.stage + ": **" + current.name + "**";
} else {
ret += stage.emoji + " " + stage.stage + ": Not live";
}
if (next !== null && !next.nothing) {
ret += ", next: " + next.name;
} else {
ret += ".";
}
ret += " " + stage.channel.toString() + "\n";
}
msg.channel.send(ret.trim());
return true;
}
return false;
}
getTimeString(date)
{
return "<t:" + date.unix() + ":t>";
}
updateChannel(stage)
{
if (typeof(stage.channel) == "string") {
return;
}
var line = "";
var current = this.getCurrentSet(stage);
var next = this.getNextLiveSet(stage);
if ((current === null || current.nothing) && next === null) {
line += " :tada: Thanks for watching.";
} else {
if (current !== null && !current.nothing) {
line += " __" + current.name + "__ <t:" + current.date.unix() + ":R>";
} else {
line += " :no_entry_sign: __Not currently live__.";
}
if (next !== null) {
line += " :arrow_forward: Next: __" + next.name + "__ <t:" + next.date.unix() + ":R>";
} else {
line += " :warning: This is the last set!";
}
line += " :link: " + stage.url;
}
stage.channel.setTopic(stage.emoji + " " + line, "Automated bot action for event");
}
}
module.exports = EventSchedule;

View file

@ -1,133 +0,0 @@
class EventQuickModule
{
constructor(config, client, bot)
{
this.event = config;
this.client = client;
this.bot = bot;
this.current = '';
this.ended = false;
if (this.event.current !== undefined) {
this.current = this.event.current;
}
this.channel = client.channels.resolve(this.event.channel);
this.updateChannel();
}
onCmdIlink(msg, link)
{
if (!this.bot.isMod(msg.member)) {
return;
}
this.event.link = link;
console.log("New impromptu event link: " + this.event.link);
msg.channel.send(":link: The livestream can be found here: <" + this.event.link + ">");
msg.delete();
this.updateChannel();
}
onCmdInow(msg)
{
if (!this.bot.isMod(msg.member)) {
return;
}
if (arguments.length == 1) {
return;
}
this.current = Array.from(arguments).slice(1).join(" ").trim();
this.ended = false;
console.log("Starting now: " + this.current);
msg.channel.send(":red_circle: STARTING NOW: **" + this.current + "**");
msg.delete();
this.updateChannel();
}
onCmdIoffline(msg)
{
if (!this.bot.isMod(msg.member)) {
return;
}
this.current = "";
this.ended = false;
console.log("Stream is offline!");
msg.channel.send(":no_entry_sign: Stream is temporarily offline.");
msg.delete();
this.updateChannel();
}
onCmdIend(msg)
{
if (!this.bot.isMod(msg.member)) {
return;
}
this.current = "";
this.ended = true;
console.log("End of event!");
msg.channel.send(":tada: Thank you for tuning in.");
msg.delete();
this.updateChannel();
}
onCmdCurrent(msg) { this.onCmdNp(msg); }
onCmdNow(msg) { this.onCmdNp(msg); }
onCmdNp(msg)
{
if (this.current != "") {
msg.channel.send(":red_circle: Now playing: **" + this.current + "**");
} else {
msg.channel.send(":robot: There's currently no set playing.");
}
}
onCmdNext(msg)
{
msg.channel.send(":robot: This is an event without a timetable.");
}
onCmdLink(msg)
{
msg.channel.send(":link: The livestream can be found here: <" + this.event.link + ">");
}
updateChannel()
{
var line = "";
if (this.ended) {
line = ":tada: Thank you for tuning in.";
} else {
if (this.current == "") {
line = ":no_entry_sign: Not currently live.";
} else {
line = "__" + this.current + "__";
}
if (this.event.link !== undefined) {
line += " :link: " + this.event.link;
}
}
if (this.event.emoji) {
line = this.event.emoji + " " + line;
}
this.channel.setTopic(line);
}
}
module.exports = EventQuickModule;

View file

@ -1,70 +0,0 @@
const discord = require("discord.js");
const RedditRadio = require("../RedditRadio");
class FilterModule
{
constructor(config, client, bot)
{
this.config = config;
/** @type {discord.Client} */
this.client = client;
/** @type {RedditRadio} */
this.bot = bot;
if (this.config.channel) {
if (!this.config.channels) {
this.config.channels = [];
}
this.config.channels.push(this.config.channel);
}
}
/**
* @param {discord.Message} msg
* @param {Boolean} edited
*/
onMessage(msg, edited)
{
if (this.bot.isMod(msg.member)) {
return;
}
var shouldDelete = false;
// Only filter if we're in the right channel
if (this.config.channels) {
var isInChannel = false;
for (const channelID of this.config.channels) {
if (msg.channel.id == channelID) {
isInChannel = true;
break;
}
}
if (!isInChannel) {
return;
}
}
// Check for bad words (case insensitive)
if (this.config.words && msg.content.toLowerCase().match(this.config.words)) {
shouldDelete = true;
}
// Check for bad tokens (case sensitive)
if (this.config.tokens && msg.content.match(this.config.tokens)) {
shouldDelete = true;
}
if (shouldDelete) {
var usermessage = this.config.usermessage || "Your recent message has been automatically deleted. Please take another look at the rules in #info. We automatically delete messages for things like piracy and advertising.";
msg.delete();
this.bot.addLogMessage("Deleted unwanted message from " + msg.author.toString() + " in " + msg.channel.toString() + ": `" + msg.content.replace('`', '\\`') + "`");
msg.author.send(usermessage).catch(console.error);
}
}
}
module.exports = FilterModule;

View file

@ -1,34 +0,0 @@
const discord = require("discord.js");
const RedditRadio = require("../RedditRadio");
class FilterEmotesModule
{
constructor(config, client, bot)
{
this.config = config;
/** @type {discord.Client} */
this.client = client;
/** @type {RedditRadio} */
this.bot = bot;
}
/**
* @param {discord.Message} msg
* @param {Boolean} edited
*/
onMessage(msg, edited)
{
var limit = this.config.limit || 14;
var emotes = msg.content.toLowerCase().match(/(<a?:[^:]+:[0-9]+>|\u00a9|\u00ae|[\u2000-\u3300]|\ud83c[\ud000-\udfff]|\ud83d[\ud000-\udfff]|\ud83e[\ud000-\udfff])/g);
if (emotes && emotes.length > limit) {
msg.delete();
this.bot.addLogMessage("Deleted message from " + msg.member.toString() + " in " + msg.channel.toString() + " that contained " + emotes.length + " emotes");
msg.author.send("You posted too many emojis. Calm down a little bit!").catch(console.error);
}
}
}
module.exports = FilterEmotesModule;

View file

@ -1,45 +0,0 @@
const discord = require("discord.js");
const RedditRadio = require("../RedditRadio");
class FilterInviteModule
{
constructor(config, client, bot)
{
this.config = config;
/** @type {discord.Client} */
this.client = client;
/** @type {RedditRadio} */
this.bot = bot;
}
/**
* @param {discord.Message} msg
* @param {Boolean} edited
*/
onMessage(msg, edited)
{
if (this.bot.isMod(msg.member)) {
return;
}
var inviteLinks = msg.content.matchAll(/(discord\.gg|discord\.com\/invite|discordapp\.com\/invite)\/([A-Za-z0-9]+)/gi);
for (const link of inviteLinks) {
var inviteCode = link[2];
var isWhitelisted = false;
if (this.config.whitelist) {
isWhitelisted = (this.config.whitelist.indexOf(inviteCode) != -1);
}
if (!isWhitelisted) {
msg.delete();
this.bot.addLogMessage("Deleted Discord invite link from " + msg.author.toString() + " in " + msg.channel.toString() + ": `" + msg.content.replace('`', '\\`') + "`");
msg.author.send("Your recent message has been automatically deleted. Please do not post Discord invite links without prior permission from a moderator or admin.").catch(console.error);
}
}
}
}
module.exports = FilterInviteModule;

View file

@ -1,92 +0,0 @@
const discord = require("discord.js");
const RedditRadio = require("../RedditRadio");
var moment = require("moment");
class FilterLinkModule
{
constructor(config, client, bot)
{
this.config = config;
/** @type {discord.Client} */
this.client = client;
/** @type {RedditRadio} */
this.bot = bot;
/** @type {String[]} */
this.permitted = [];
}
isPermitted(member)
{
var delay = this.config.minutes || 60;
var minutes = moment().diff(member.joinedTimestamp, "minutes");
if (minutes >= delay) {
return true;
}
// Check the list of permitted users with .permit
var permittedIndex = this.permitted.indexOf(member.id);
if (permittedIndex != -1) {
if (minutes >= delay) {
this.permitted.splice(permittedIndex, 1);
}
return true;
}
return false;
}
/**
* @param {discord.Message} msg
* @param {Boolean} edited
*/
onMessage(msg, edited)
{
if (msg.content.match(/https?:\/\//i) || msg.content.match(/\.[a-z]{2,3}\//i) || msg.content.match(/(bit.ly|shorturl.at|tiny.cc)/i)) {
msg.guild.members.fetch(msg.author).then((member) => {
if (this.isPermitted(member)) {
return;
}
msg.delete();
msg.author.send("Your recent message has been automatically deleted. Brand new members can't post links for a short while, to combat spam. Check #info for more information about the rules. If you think this message is in error, please DM one of the mods.").catch(console.error);
var minutes = moment().diff(member.joinedTimestamp, "minutes");
this.bot.addLogMessage("Deleted link from " + member.toString() + " in " + msg.channel.toString() + " who joined " + minutes + " minutes ago. Deleted message:\n```" + msg.content + "```");
});
}
}
/**
* @param {discord.Message} msg
* @param {String} user
*/
onCmdPermit(msg, user)
{
if (!this.bot.isMod(msg.member)) {
return;
}
var mentions = "";
var num = 0;
msg.mentions.members.each(member => {
if (this.isPermitted(member)) {
return;
}
this.permitted.push(member.id);
mentions += member.toString() + " ";
num++;
});
if (num > 0) {
msg.channel.send(mentions + "A moderator has permitted you to post links!");
this.bot.addLogMessage(msg.member.toString() + " has permitted " + mentions + "to post links");
}
}
}
module.exports = FilterLinkModule;

View file

@ -1,55 +0,0 @@
const discord = require("discord.js");
const RedditRadio = require("../RedditRadio");
class FunModule
{
constructor(config, client, bot)
{
this.config = config;
/** @type {discord.Client} */
this.client = client;
/** @type {RedditRadio} */
this.bot = bot;
}
/**
* @param {discord.Message} msg
* @param {Boolean} edited
*/
onMessage(msg, edited)
{
if (msg.content.toLowerCase() == "good bot") {
msg.channel.send(msg.member.toString() + " Thanks");
return;
}
if (msg.content.toLowerCase() == "bad bot") {
msg.channel.send(msg.member.toString() + " I'm sorry :sob: If I did something wrong, you can report a bug! <https://github.com/codecat/reddit-radio/issues>");
return;
}
if (msg.content.toLowerCase() == "kut bot") {
msg.channel.send(msg.member.toString() + " nou sorry hoor");
return;
}
if (msg.content.toLowerCase().indexOf("am i the only one") != -1 && msg.member !== null) {
msg.channel.send(msg.member.toString() + " Probably not.");
return;
}
if (msg.content.toLowerCase().indexOf(".shrug") != -1) {
msg.channel.send("\xaf\\\\\\_<:headykappa:330110432209797123>\\_/\xaf");
return;
}
if (msg.content.toLowerCase() == "<@!327816989114630145> <a:catjam150:760555281414881380>") {
msg.channel.send("<a:catjam150:760555281414881380>");
return;
}
}
}
module.exports = FunModule;

View file

@ -1,29 +0,0 @@
const discord = require("discord.js");
class JoinReactModule
{
constructor(config, client, bot)
{
this.config = config;
/** @type {discord.Client} */
this.client = client;
this.bot = bot;
}
/**
* @param {discord.Message} msg
* @param {Boolean} edited
*/
onMessage(msg, edited)
{
if (msg.system && msg.type == "GUILD_MEMBER_JOIN") {
setTimeout(() => {
try {
msg.react(this.config.emoji || "👋");
} catch (err) { console.error(err); }
}, 2000);
}
}
}
module.exports = JoinReactModule;

View file

@ -1,29 +0,0 @@
const discord = require("discord.js");
const RedditRadio = require("../RedditRadio");
class PollModule
{
constructor(config, client, bot)
{
this.config = config;
/** @type {discord.Client} */
this.client = client;
/** @type {RedditRadio} */
this.bot = bot;
}
/**
* @param {discord.Message} msg
*/
onCmdPoll(msg)
{
(async () => {
await msg.react("👍");
await msg.react("👎");
})();
}
}
module.exports = PollModule;

View file

@ -1,212 +0,0 @@
var colors = require("colors");
var moment = require("moment");
const ffmpeg = require('fluent-ffmpeg');
class ProducingModule
{
constructor(config, client, bot)
{
this.config = config;
this.client = client;
this.bot = bot;
this.client.on("messageReactionAdd", (r, user) => { this.onMessageReactionAdd(r, user); });
this.client.on("messageReactionRemove", (r, user) => { this.onMessageReactionRemove(r, user); });
if (!this.bot.mongodb) {
console.error("The producing module requires MongoDB to be connected to a database!");
return;
}
this.collUsers = this.bot.mongodb.collection("users");
this.collFiles = this.bot.mongodb.collection("files");
this.collFilesFeedback = this.bot.mongodb.collection("files_feedback");
}
async getOrCreateUser(id)
{
var user = await this.collUsers.findOne({ id: id });
if (!user) {
user = {
id: id,
files_uploaded: 0,
feedback_given: 0
};
await this.collUsers.insertOne(user);
}
return user;
}
async getNumberOfFeedbackGiven(userId)
{
var result = await this.collFilesFeedback.aggregate([
{ $match: { user: userId } },
{ $group: { _id: "$msg", count: { $sum: 1 } } },
{ $count: "count" }
]).next();
if (!result) {
return 0;
}
return result.count;
}
onMessageReactionAdd(r, user)
{
if (user == this.client.user) {
return;
}
var msg = r.message;
if (msg.channel.id != this.config.channel) {
return;
}
if (user == msg.author) {
return;
}
if (this.config.reactions.indexOf(r.emoji.name) == -1) {
return;
}
this.collFilesFeedback.insertOne({
time: new Date(),
msg: msg.id,
msg_user: msg.author.id,
user: user.id,
emoji: r.emoji.name
});
}
onMessageReactionRemove(r, user)
{
if (user == this.client.user) {
return;
}
var msg = r.message;
if (msg.channel.id != this.config.channel) {
return;
}
if (user == msg.author) {
return;
}
if (this.config.reactions.indexOf(r.emoji.name) == -1) {
return;
}
this.collFilesFeedback.deleteOne({
msg: msg.id,
user: user.id,
emoji: r.emoji.name
});
}
onMessage(msg, edited)
{
if (msg.channel.id != this.config.channel) {
return false;
}
if (edited) {
return false;
}
(async () => {
var user = await this.getOrCreateUser(msg.author.id);
var filenames = "";
var numFiles = 0;
msg.attachments.each(async a => {
if (!a.name.match(/.*\.(wav|mp3|ogg|flac)/)) {
return;
}
filenames += a.name + " ";
numFiles++;
var logUsername = msg.author.username + '#' + msg.author.discriminator;
console.log(logUsername + " uploaded " + a.name.red.underline);
this.collUsers.updateOne({ id: user.id }, {
$inc: { files_uploaded: 1 }
});
/*
statsmessage = false
feedbackmessage = false
spectrumpic = false
*/
if (this.config.spectrumpic) {
new Promise((resolve, reject) => {
let path = '/tmp/waveform-' + msg.id + '.png';
let cmd = ffmpeg(a.url);
cmd.complexFilter([
'[0:a] showspectrumpic=s=400x70:color=nebulae:legend=false [tmp1]',
//'[0:a] showwavespic=s=400x70:colors=0xFFFFFFFF:filter=peak [tmp2]',
//'[tmp1][tmp2] overlay=y=0:format=rgb:alpha=premultiplied [tmp3]',
'[tmp1] drawbox=0:0:400:70:black',
]);
cmd.frames(1);
cmd.on('error', err => {
reject(err);
});
cmd.on('end', () => {
msg.channel.send({
files: [{
attachment: path,
name: 'waveform.png',
}],
}).then(resolve).catch(reject);
});
cmd.save(path);
}).catch(err => {
console.error('ffmpeg waveform failed!', err);
});
}
for (var i = 0; i < this.config.reactions.length; i++) {
await msg.react(this.config.reactions[i]);
}
});
if (numFiles > 0) {
var numFeedbackGiven = await this.getNumberOfFeedbackGiven(user.id);
if (this.config.statsmessage) {
msg.channel.send("**Give " + msg.member.displayName + " your feedback!** :outbox_tray: " + (user.files_uploaded + 1) + " / :bulb: " + numFeedbackGiven);
}
if (this.config.feedbackmessage) {
if (numFeedbackGiven < user.files_uploaded) {
msg.channel.send(msg.member.toString() + " Remember to give others feedback, too! :ok_hand:");
}
}
}
})();
return false;
}
async onCmdStats(msg)
{
if (msg.channel.id != this.config.channel) {
return;
}
var user = await this.getOrCreateUser(msg.author.id);
var numFeedbackReceived = await this.collFilesFeedback.countDocuments({ msg_user: user.id });
var numFeedbackGiven = await this.getNumberOfFeedbackGiven(user.id);
msg.channel.send(":bar_chart: " + msg.member.toString() + ", you have uploaded **" + (user.files_uploaded || 0) + "** files, given **" + numFeedbackGiven + "** feedback reactions, and received **" + numFeedbackReceived + "**.");
}
}
module.exports = ProducingModule;

View file

@ -1,65 +0,0 @@
var discord = require("discord.js");
var http = require("https");
class QdanceModule
{
get(dir)
{
return new Promise((resolve, reject) => {
http.get("https://feed.q-dance.com/onair", function(res) {
var data = "";
res.setEncoding("utf8");
res.on("data", function(chunk) { data += chunk; });
res.on("end", function() {
var obj = JSON.parse(data);
if (dir == -1) {
resolve(obj.TrackData.PreviousPlaying);
} else if (dir == 0) {
resolve(obj.TrackData.NowPlaying);
} else if (dir == 1) {
resolve(obj.TrackData.NextPlaying);
}
reject('Unknown track direction!');
});
});
});
}
makeEmbed(track, title)
{
var embed = new discord.MessageEmbed({
title: title,
description: track.Artist + " - " + track.Title,
hexColor: "#D26F1C"
});
embed.setAuthor("Q-dance Radio", "https://4o4.nl/20170908JHxVy.png");
embed.setThumbnail(track.CoverImage);
return embed;
}
async onCmdQdnp(msg)
{
var track = await this.get(0);
msg.channel.send({
embeds: [ this.makeEmbed(track, "Q-dance Radio is now playing:") ],
});
}
async onCmdQdnext(msg)
{
var track = await this.get(1);
msg.channel.send({
embeds: [ this.makeEmbed(track, "Next track on Q-dance Radio:") ],
});
}
async onCmdQdprev(msg)
{
var track = await this.get(-1);
msg.channel.send({
embeds: [ this.makeEmbed(track, "Previous track on Q-dance Radio:") ],
});
}
}
module.exports = QdanceModule;

View file

@ -1,27 +0,0 @@
const discord = require("discord.js");
var moment = require("moment");
class SusModule
{
constructor(config, client, bot)
{
this.config = config;
/** @type {discord.Client} */
this.client = client;
this.bot = bot;
}
/**
* @param {discord.GuildMember} member
*/
onMemberJoin(member)
{
if (moment().diff(member.user.createdAt, "hours") < 48) {
this.bot.addLogMessage("<:skepticalpepe:743455915935662133> Brand new user account joined: " + member.user.toString()
+ " (account created <t:" + moment(member.user.createdAt).unix() + ":R>)");
}
}
}
module.exports = SusModule;

View file

@ -1,60 +0,0 @@
var moment = require("moment");
class ToolsModule
{
constructor(config, client, bot)
{
this.client = client;
this.bot = bot;
}
onCmdJoinTime(msg) { this.onCmdJoinDate(msg); }
onCmdJoinDate(msg)
{
msg.guild.members.fetch(msg.author).then((member) => {
var joinedAt = moment(member.joinedTimestamp);
msg.reply("you joined this server **<t:" + joinedAt.unix() + ":R>** - <t:" + joinedAt.unix() + ":F>");
});
}
onCmdSlow(msg, seconds)
{
if (!this.bot.isMod(msg.member)) {
return;
}
msg.channel.setRateLimitPerUser(parseInt(seconds));
msg.delete();
}
async onCmdUserInfo(msg, user)
{
if (!this.bot.isMod(msg.member)) {
return;
}
try {
var member = await msg.guild.members.fetch(user);
} catch {
var fetcheduser = await this.client.users.fetch(user);
var createdAt = moment(fetcheduser.createdTimestamp);
msg.channel.send(
"**Info for non-member " + fetcheduser.tag + "**:\n" +
":alarm_clock: Account age: **<t:" + createdAt.unix() + ":R>** - <t:" + createdAt.unix() + ":F>"
);
return;
}
var joinedAt = moment(member.joinedTimestamp);
var createdAt = moment(member.user.createdTimestamp);
msg.channel.send(
"**Info for member " + member.toString() + "**:\n" +
":alarm_clock: Join time: **<t:" + joinedAt.unix() + ":R>** - <t:" + joinedAt.unix() + ":F>\n" +
":alarm_clock: Account age: **<t:" + createdAt.unix() + ":R>** - <t:" + createdAt.unix() + ":F>"
);
}
}
module.exports = ToolsModule;

View file

@ -1,40 +0,0 @@
const discord = require("discord.js");
class WelcomeModule
{
constructor(config, client, bot)
{
this.config = config;
/** @type {discord.Client} */
this.client = client;
this.bot = bot;
}
/**
* @param {discord.GuildMember} member
*/
async onMemberJoin(member)
{
var msg = this.config.messageprefix;
var msgIndex = Math.floor(Math.random() * this.config.messages.length);
msg += ' ' + this.config.messages[msgIndex];
msg = msg.replace('<name>', '**' + member.user.username + '**');
//msg = msg.replace('<name>', member.toString());
//^ Commented out because mentions for newly joined members are broken on the client
var channel = await this.client.channels.fetch(this.config.channel);
var message = await channel.send(msg);
/*
var message = await channel.send({
content: msg,
allowedMentions: {
users: []
}
});
*/
message.react(this.config.emoji || "👋");
}
}
module.exports = WelcomeModule;