mirror of
https://github.com/LBRYFoundation/lbry-wunderbot.git
synced 2025-09-02 10:15:17 +00:00
* Remade commands: price, rank, userinfo,hash,lbrylink, releasenotes, stats, supportbot. * Added modlogs and settings for modlogs. * Commands can now be locked to channels with the locktochannel module. * customCommand/triggers can be saved in mongodb and edited on the fly, the bot will always use the latest messages. This commit does not contain: * A working claimbot, the new implantation with chainquery is on the way, this will be a seperate issue. * A working webinterface, therefor, some items does not work, this will be a seperate issue. This means that this code should remain in the wunderbot-v2 branch until a working webinterface where we can control the custom triggers/commands and other settings for the bot.
90 lines
4.2 KiB
JavaScript
90 lines
4.2 KiB
JavaScript
import Commando from "discord.js-commando";
|
|
import path from "path";
|
|
import config from "config";
|
|
import { oneLine } from "common-tags";
|
|
import { MongoClient } from "mongodb";
|
|
import MongoDBProvider from "commando-provider-mongo";
|
|
import requestCacheSupport from "request-promise-cache";
|
|
import checkCustomCommands from "./helpers/customCommands";
|
|
import welcomeEvent from "./helpers/welcomeEvent";
|
|
// import controlPanel from "./web/controlPanel";
|
|
|
|
module.exports = class Wunderbot extends Commando.Client {
|
|
constructor() {
|
|
super({
|
|
owner: config.get("Wunderbot.owner"),
|
|
commandPrefix: config.get("Wunderbot.defaultPrefix")
|
|
});
|
|
// Add our own version of request with cache support :)
|
|
this.request = requestCacheSupport;
|
|
// ADD our custom commands helper :)
|
|
this.on("message", msg => {
|
|
checkCustomCommands(msg, this);
|
|
});
|
|
this.on("guildMemberAdd", member => welcomeEvent(member, this));
|
|
this.on("error", console.error)
|
|
.on("warn", console.warn)
|
|
// .on("debug", console.log)
|
|
.on("ready", () => {
|
|
console.log(`## ## ## ## ## ## ######## ######## ######## ######## ####### ########
|
|
## ## ## ## ## ### ## ## ## ## ## ## ## ## ## ## ##
|
|
## ## ## ## ## #### ## ## ## ## ## ## ## ## ## ## ##
|
|
## ## ## ## ## ## ## ## ## ## ###### ######## ######## ## ## ##
|
|
## ## ## ## ## ## #### ## ## ## ## ## ## ## ## ## ##
|
|
## ## ## ## ## ## ### ## ## ## ## ## ## ## ## ## ##
|
|
### ### ####### ## ## ######## ######## ## ## ######## ####### ##
|
|
|
|
`);
|
|
console.log(`Client ready; logged in as ${this.user.username}#${this.user.discriminator} (${this.user.id})`);
|
|
})
|
|
.on("disconnect", () => {
|
|
console.warn("Disconnected!");
|
|
})
|
|
.on("reconnecting", () => {
|
|
console.warn("Reconnecting...");
|
|
})
|
|
.on("commandError", (cmd, err) => {
|
|
if (err instanceof Commando.FriendlyError) return;
|
|
console.error(`Error in command ${cmd.groupID}:${cmd.memberName}`, err);
|
|
})
|
|
.on("commandBlocked", (msg, reason) => {
|
|
console.log(oneLine`
|
|
Command ${msg.command ? `${msg.command.groupID}:${msg.command.memberName}` : ""}
|
|
blocked; ${reason}
|
|
`);
|
|
})
|
|
.on("commandPrefixChange", (guild, prefix) => {
|
|
console.log(oneLine`
|
|
Prefix ${prefix === "" ? "removed" : `changed to ${prefix || "the default"}`}
|
|
${guild ? `in guild ${guild.name} (${guild.id})` : "globally"}.
|
|
`);
|
|
})
|
|
.on("commandStatusChange", (guild, command, enabled) => {
|
|
console.log(oneLine`
|
|
Command ${command.groupID}:${command.memberName}
|
|
${enabled ? "enabled" : "disabled"}
|
|
${guild ? `in guild ${guild.name} (${guild.id})` : "globally"}.
|
|
`);
|
|
})
|
|
.on("groupStatusChange", (guild, group, enabled) => {
|
|
console.log(oneLine`
|
|
Group ${group.id}
|
|
${enabled ? "enabled" : "disabled"}
|
|
${guild ? `in guild ${guild.name} (${guild.id})` : "globally"}.
|
|
`);
|
|
});
|
|
|
|
this.setProvider(MongoClient.connect(config.get("Wunderbot.dbUrl"), { useNewUrlParser: true }).then(client => new MongoDBProvider(client.db(config.get("Wunderbot.dbName"))))).catch(console.error);
|
|
this.registry
|
|
.registerDefaults()
|
|
.registerGroup("info", "Info")
|
|
.registerGroup("general", "General")
|
|
.registerGroup("moderation", "Moderation")
|
|
.registerGroup("lbry", "LBRY")
|
|
.registerGroup("crypto", "Crypto")
|
|
// .registerTypesIn(path.join(__dirname, "types"))
|
|
.registerCommandsIn(path.join(__dirname, "commands"));
|
|
this.login(config.get("Wunderbot.token"));
|
|
// controlPanel(this); // Lets start the control panel!
|
|
}
|
|
};
|