vertbot/App.js

166 lines
6.9 KiB
JavaScript

module.exports = class App
{
constructor()
{
var secret = require("./secret.js");
this.bot = new Eris(secret.discord, { maxShards: 'auto' });
this.commands = new Commands(this);
this.version = require('./package.json').version;
this.config = JSON.parse(fs.readFileSync("./config.json"));
if(this.config.disableDBL == false)
{
setInterval(() => {
DLA.postGuilds(this.bot, secret.tokens);
}, 1800000);
}
this.db = new Database(this);
this.bot.on("ready", this.onReady.bind(this));
this.bot.on("guildCreate", this.onJoin.bind(this));
this.bot.on("guildMemberAdd", this.onMemberJoined.bind(this));
this.bot.on("messageCreate", this.onMessage.bind(this));
this.bot.on("error", this.onDisconnect.bind(this));
this.bot.connect();
}
onReady()
{
console.log("Vertbot is now online.");
this.bot.editStatus("online", {name: "v-help for info", type: 0})
var secret = require("./secret.js");
if(this.config.disableDBL == false) { DLA.postGuilds(this.bot, secret.tokens); } //Post the guild stats to bot list apon launch
//TODO: init function?
this.lavalink = new Lavalink(this);
//this.settings = new Settings(this);
}
onPosted()
{
console.log("Server count posted!");
}
onDBLError()
{
console.error("Server count could not be posted. This may be because of the fact there is no token");
}
onDisconnect(err, id)
{
//this.bot.disconnect();
//console.log("Lost connection to discord, trying to reconnect...");
//this.bot.connect();
console.log(err);
}
onJoin(guild)
{
var channel = U.getLogicalChannel(this, guild);
if(channel != null)
{
this.bot.createMessage(channel.id, U.createWelcomeEmbed(this));
}
}
onMemberJoined(guild, member)
{
if(member.username.toLowerCase().includes("h0nd"))
{
member.ban(7, "Shitty fucking spammer");
}
}
async onMessage(msg)
{
try
{
if(!msg.channel.type == 1)
{
//var prefix = (await this.db.getGuildSettings(msg.channel.guild.id)).prefix || this.config.prefix;
var prefix = (this.bot.user.id == "430118450795380736") ? "[=" : (await this.db.getGuildSettings(msg.channel.guild.id)).prefix || this.config.prefix;
var mention = msg.content.startsWith(this.bot.user.mention) ? "<@" + this.bot.user.id + ">" : "<@!" + this.bot.user.id + ">"
if((msg.content.startsWith(prefix) || msg.content.startsWith(mention)) && !msg.author.bot)
{
//the command
var text = msg.content.startsWith(prefix) ? msg.content.slice(prefix.length).trim() : msg.content.slice((mention).length).trim(); //TODO: trim?
this.commands.doCommand(msg, this, text); //Command system
}
if(msg.author.bot && msg.author.id == "817790099823525909")
{
//Scramble!
if(msg.embeds.length > 0)
{
if(msg.embeds[0].title == "Scramble!")
{
var word = msg.embeds[0].description.split("\n")[1];
console.log(word);
var words = ["bell","jail","heart","Mickey Mouse","bus","butterfly","elephant","flower","turtle","snowflake","candy","key","sun","starfish","button","leg","table","ghost","orange","house","nail","apple","football","love","ants","beak","feet","river","lemon","daisy","jar","clock","flag","snail","smile","island","inchworm","mitten","king","bench","dog","knee","horse","music","square","hair","doll","sea turtle","book","whale","arm","seashell","shirt","purse","stairs","oval","camera","truck","motorcycle","moon","fly","pillow","coat","helicopter","bowl","mouth","chicken","light","hippo","woman","chimney","grapes","jacket","float","rock","snowman","bread","snake","corn","cup","baseball","pizza","beach","bug","sunglasses","rain","robot","cherry","bunny","lamp","popsicle","ears","lollipop","socks","ladybug","triangle","zebra","broom","mouse","caterpillar","dragon","bone","door","desk","grass","car","curl","cat","ring","worm","banana","mountain","water","ball","roly poly/pill bug/doodle bug","legs","sheep","rocket","man","coin","ant","night","crayon","ocean","swimming pool","bumblebee","swing","person","blanket","bark","slide","boy","hat","star","mountains","diamond","tree","bow","computer","zigzag","dinosaur","balloon","cow","boat","bunk bed","giraffe","eyes","bird","chair","comb","circle","nose","hook","feather","bear","bee","ear","leaf","pig","drum","pie","milk","suitcase","fire","window","wheel","glasses","kite","box","cupcake","zoo","girl","pants","bed","rainbow","hamburger","jellyfish","bracelet","baby","octopus","ship","eye","lips","alive","face","dream","spider web","angel","train","egg","tail","alligator","finger","pen","bike","fish","cheese","bounce","blocks","kitten","bathroom","crack","skateboard","fork","bridge","plant","owl","branch","ice cream cone","monkey","spoon","shoe","duck","crab","lizard","lion","backpack","sea","hand","head","frog","carrot","cloud","candle","line","bat","neck","cube","family","airplane","Earth","spider","basketball","monster","pencil","cookie","rabbit"];
var scram = await unscramble(word, words);
console.log(scram);
this.bot.createMessage(msg.channel.id, U.createQuickEmbed("Word Unscrambled!", "Try: `" + scram.join(", ") + "`"));
}
//Translate!
if(msg.embeds[0].title == "Translate!")
{
var word = msg.embeds[0].description.split("\n")[1];
console.log(word);
const res = await fetch("https://libretranslate.de/translate", {
method: "POST",
body: JSON.stringify({
q: word,
source: "es",
target: "en",
format: "text",
api_key: ""
}),
headers: { "Content-Type": "application/json" }
});
var json = await res.json();
var tran = json.translatedText;
console.log(json);
console.log(tran);
this.bot.createMessage(msg.channel.id, U.createQuickEmbed("Word Translated!", "The word is: `" + tran + "`"));
}
}
}
} else {
if(!msg.author.bot && !msg.author.id == "817790099823525909")
{
this.bot.createMessage(msg.channel.id, U.createErrorEmbed("This is a DM chat", "I can't do anything in dms. If you need a gf that bad go outside"));
}
}
}
catch(e)
{
console.log(e);
//this.bot.createMessage(msg.channel.id, "" + (typeof e));
}
}
}
//var YouTube = require('youtube-node');
var Eris = require('eris');
var assert = require("assert");
//var unscramble = require('unscramble');
const unscramble = require('word-unscrambler');
//const { translate } = require('free-translate');
const fetch = require('node-fetch');
var U = require('./utils/Utils.js');
var DLA = require('./utils/Discord-List-api.js');
var Commands = require("./commands/Commands.js");
var Lavalink = require("./utils/Lavalink.js");
var Database = require("./utils/Database.js");
var Settings = require("./utils/Settings.js");
//var RestartHandler = require("./utils/RestartHandler.js");
var fs = require("fs");