123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125 |
- const db = require("../db.js");
- const util = require("../util.js");
- const client = require("../client.js");
- const pattern = /^react to\s+"([^"]+)"\s+with\s+\<:[^:]+:([^\>]+)\>$/i;
- const documentation = {
- "react to \"<message>\" with <emote>": {
- auth: true,
- description: "React to <message> with <emote>."
- },
- "remove reaction to <message>": {
- auth: true,
- description: "Stops reacting to <message>."
- },
- "reactions": {
- auth: false,
- description: "Lists all known messages this bot can react to."
- }
- };
- const commands = {
- "react to": (msg, s) => {
- if (!util.isAuthorised(msg.member)) return;
- let contents = pattern.exec(s);
- if (contents != null) {
- let reactable = contents[1].trim().toLowerCase();
- let reactionEmoji = contents[2];
- if (!client.emojis.has(reactionEmoji)) {
- msg.channel.send(`${msg.author.toString()} I cannot react with this emoji :(`);
- return;
- }
- db.get("messageReactions").set(reactable, reactionEmoji).write();
- msg.channel.send(`${msg.author.toString()} Added reaction!`);
- }
- },
- "remove reaction to": (msg, s) => {
- if (!util.isAuthorised(msg.member)) return;
- let content = s.substring("remove reaction to ".length).trim().toLowerCase();
- if (!db.get("messageReactions").has(content).value()) {
- msg.channel.send(`${msg.author.toString()} No such reaction available!`);
- return;
- }
- db.get("messageReactions").unset(content).write();
- msg.channel.send(`${msg.author.toString()} Removed reaction!`);
- },
- "reactions": msg => {
- let reactions = db.get("messageReactions").keys().value().reduce((p, c) => `${p}\n${c}`, "");
- msg.channel.send(`I'll react to the following messages:\n\`\`\`${reactions}\`\`\``);
- }
- };
- const onMessage = (msg, content, actionsDone) => {
- if (actionsDone)
- return false;
- let lowerContent = content.toLowerCase();
- if (db.get("messageReactions").has(lowerContent).value()) {
- msg.react(client.emojis.get(db.get("messageReactions").get(lowerContent).value()));
- return true;
- }
- if (msg.mentions.users.size == 0)
- return false;
- if (!db.get("reactableMentionedUsers").intersectionWith(msg.mentions.users.map(u => u.id)).isEmpty().value()) {
- const emoteId = db
- .get("emotes")
- .get("angery")
- .randomElement()
- .value();
- msg.react(client.emojis.find(e => e.id == emoteId));
- return true;
- }
- return false;
- };
- const onIndirectMention = (msg, actionsDone) => {
- if(actionsDone)
- return false;
- let emoteType = "angery";
- if (db.get("specialUsers").includes(msg.author.id).value())
- emoteType = "hug";
- else if (db.get("bigUsers").includes(msg.author.id).value())
- emoteType = "big";
- else if (db.get("dedUsers").includes(msg.author.id).value())
- emoteType = "ded";
- let id = db
- .get("emotes")
- .get(emoteType)
- .randomElement()
- .value();
- let emote = client.emojis.find(e => e.id == id);
- if(!emote) {
- console.log(`WARNING: Emote ${id} no longer is valid. Deleting invalid emojis from the list...`);
- db.get("emotes")
- .get(emoteType)
- .remove(id => !client.emojis.has(id))
- .write();
- id = db
- .get("emotes")
- .get(emoteType)
- .randomElement()
- .value();
- emote = client.emojis.find(e => e.id == id);
- }
- if(!emote)
- return false;
- msg.channel.send(emote.toString());
- return true;
- };
- module.exports = {
- commands: commands,
- onMessage: onMessage,
- onIndirectMention: onIndirectMention,
- documentation: documentation
- };
|