fixed bug in delete command message, fixed bot test button in web config

This commit is contained in:
void
2020-02-15 01:14:53 +01:00
parent 0aefe62443
commit c78900f545
4 changed files with 22 additions and 8 deletions

View File

@@ -12,7 +12,7 @@ module.exports = class BotHandler {
return new Promise((resolve) => {
const bot = this.db.webConfig.bot;
if (bot && bot.token) {
new DiscordBot(this.db, this.api).init(bot.token, bot.commandprefix).then((discordBot) => {
new DiscordBot(this.db, this.api, bot.token).init(bot.token, bot.commandprefix).then((discordBot) => {
this.bots.push(discordBot);
}).catch((err) => console.log(err));
}

View File

@@ -9,10 +9,9 @@ module.exports = class DiscordBot extends Discord.Client {
this.db = db;
this.api = api;
this.builder = MsgBuilder;
this.config = db.webConfig['bot'];
this.config.commandprefix = this.config.commandprefix || "-";
this.config = null;
this.commands = {};
this.token = token || this.config.token;
this.token = token;
}
send (msg, text) {
@@ -55,7 +54,7 @@ module.exports = class DiscordBot extends Discord.Client {
});
}
deleteCommandMessages = (msg) => {
deleteCommandMessages (msg) {
if (msg.deletable && this.config.deletecommandmessages === 'true') {
msg.delete();
}
@@ -87,9 +86,25 @@ module.exports = class DiscordBot extends Discord.Client {
});
}
test () {
return new Promise((resolve, reject) => {
try {
this.login(this.token)
.then(() => resolve(this))
.catch((err) => reject(err));
}
catch (err) {
reject(err);
}
});
}
init () {
return new Promise((resolve, reject) => {
try {
this.config = this.db.webConfig['bot'];
this.config = this.config.commandprefix || "-";
this.registerEvents();
this.registerCommands(['ombi', 'sonarr', 'radarr', 'tautulli']);

View File

@@ -5,12 +5,12 @@ const test = async (req, res) => {
const botConfig = req.body;
if (botConfig && botConfig.token) {
bot = new DiscordBot(null, null, botConfig.token);
bot.init().then((result) => {
bot.test().then(() => {
console.log("DiscordBot Test was successfull!");
bot.destroy();
res
.status(200)
.send({token: result});
.send({status: 'success'});
}).catch((err) => {
console.log('Failed initializing DiscordBot! Please check your bot configurations.');
res

View File

@@ -95,7 +95,6 @@ $(function() {
// grab bot details from the relevant form
request.token = $('#form-' + request.bot + ' input.token').val();
console.log(request.token)
// make sure that we actually have enough data to proceed first...
if (!request.token) {