1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889 |
- 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 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";
- const id = db
- .get("emotes")
- .get(emoteType)
- .randomElement()
- .value();
- console.log(id);
- msg.channel.send(client.emojis.find(e => e.id == id).toString());
- return true;
- };
- module.exports = {
- commands: commands,
- onMessage: onMessage,
- onIndirectMention: onIndirectMention
- };
|