Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const Discord = require('discord.js')
- const mineflayer = require('mineflayer')
- const fetch = require('node-fetch')
- const credentials = require("./settings/credentials.json")
- const config = require("./settings/config.json")
- const embeds = require("./modules/sendEmbeds")
- const client = new Discord.Client()
- var botOnline = false
- var botLockDown = true
- client.on("ready", () => {
- console.log(`[D] - Logged in as ${client.user.tag}`)
- client.user.setStatus('idle', 'Idling')
- })
- client.on("message", async message => {
- if (message.author.bot) return
- if (message.channel.type !== "text") return
- if (message.content.toLowerCase() === config.prefix) {
- message.delete()
- embeds.sendMainHelpEmbed(message.channel, message.author)
- return
- } else {
- if (message.content.startsWith(config.prefix)) {
- message.delete()
- var args = message.content.split(" ").slice(1)
- switch (args[0].toLowerCase()) {
- case "help":
- if (!args[1]) {
- embeds.sendMainHelpEmbed(message.channel, message.author)
- return
- } else {
- switch (args[1].toLowerCase()) {
- case "start":
- embeds.sendSingleHelpEmbed(message.channel, message.author, "Start", "/housing start", '/housing start', 'Housing')
- break
- case "stop":
- embeds.sendSingleHelpEmbed(message.channel, message.author, "Stop", "/housing stop", '/housing stop', 'Housing')
- break
- case "restart":
- embeds.sendSingleHelpEmbed(message.channel, message.author, 'Restart', '/housing restart', '/housing restart', 'Housing')
- case "say":
- embeds.sendSingleHelpEmbed(message.channel, message.author, "Say", "/housing say <message>", '/housing say monkaS', 'Karaoke Leaders')
- break
- case "privacy":
- embeds.sendSingleHelpEmbed(message.channel, message.author, "Privacy", "/housing privacy <private | party | public>", '/housing privacy public', 'Event Advisers')
- break
- case "invite":
- embeds.sendSingleHelpEmbed(message.channel, message.author, "Invite", "/housing invite <username>", '/housing invite FunnyFungi', 'Housing')
- break
- default:
- embeds.sendMainHelpEmbed(message.channel, message.author)
- }
- }
- break
- case "start":
- if (botOnline === false) {
- createBot()
- global.workingEmbed = await embeds.sendEmbed('working', message.channel, 'Starting the housing bot . . .', message.author, null)
- setTimeout(function() {
- bot.chat("/home")
- }, 5 * 1000)
- botOnline = true
- } else {
- embeds.sendEmbed('error', message.channel, 'Housing bot already in housing', message.author, 5)
- return
- }
- break
- case "stop":
- if (botOnline === false) {
- embeds.sendEmbed('error', message.channel, 'Housing bot already offline', message.author, 5)
- return
- } else {
- embeds.sendEmbed('success', message.channel, 'Housing bot logged off', message.author, null)
- botOnline = false
- killBot()
- }
- break
- case "restart":
- if (botOnline === false) {
- embeds.sendEmbed('error', message.channel, 'Housing bot offline', message.author, 3)
- return
- } else {
- killBot()
- var restartEmbed = await embeds.sendEmbed('working', message.channel, 'Restarting housing bot . . . ', message.author, null)
- setTimeout(function() {
- embeds.editEmbed('success', restartEmbed, 'Restarted housing bot, logging back in', message.author, null)
- createBot()
- }, 3 * 1000)
- }
- break
- case "privacy":
- if (botOnline === false) {
- embeds.sendEmbed('error', message.channel, 'Housing bot offline', message.author, 3)
- return
- } else {
- if (botLockDown === true) {
- embeds.sendEmbed('error', message.channel, 'Housing bot not in Housing', message.author, 4)
- return
- } else {
- if (!args[1]) {
- embeds.sendEmbed('error', message.channel, 'Try `PUBLIC`, `PARTY` or `PRIVATE`', message.author, 5)
- return
- } else {
- if (!message.member.roles.has(message.guild.roles.find(role => role.name === config.roles.advisers)) && !message.member.roles.has(message.guild.roles.find(role => role.name === config.roles.leaders))) {
- embeds.sendEmbed('error', message.channel, 'You need the role \`EVENT ADVISERS\` to run that command', message.author, 5)
- return
- } else {
- switch (args[1].toLowerCase()) {
- case "party":
- bot.chat("/visitingrule PARTY")
- embeds.sendEmbed('success', message.channel, 'The housing is now set to **PARTY** - Only party members can join', message.author, null)
- break
- case "public":
- bot.chat("/visitingrule PUBLIC")
- embeds.sendEmbed('success', message.channel, 'The housing is now set to **PUBLIC** - Anyone can join', message.author, null)
- break
- case "private":
- bot.chat('/visitingrule PRIVATE')
- embeds.sendEmbed('success', message.channel, 'The housing is now set to **PRIVATE** - No one can join', message.author, null)
- break
- default:
- embeds.sendEmbed('error', message.channel, 'Try `PUBLIC`, `PARTY` or `PRIVATE`', message.author, 5)
- }
- }
- }
- }
- }
- break
- case "invite":
- if (botOnline === false) {
- embeds.sendEmbed('error', message.channel, 'Housing bot offline', message.author, 3)
- return
- } else {
- if (!args[1]) return embeds.sendEmbed('error', message.channel, 'You haven\'t supplied a username to invite', message.author, 5)
- var personToInvite = args[1]
- if (personToInvite.match("[A-Za-z0-9_]")) {
- if (personToInvite === "HypixelKaraoke") {
- embeds.sendEmbed('error', message.channel, 'You can\'t invite me to my own house ', message.author, 5)
- return
- }
- var inviteEmbed = await embeds.sendEmbed('working', message.channel, `Attempting to invite \`${personToInvite}\` to the plot`, message.author, null)
- bot.chat('/p invite ' + personToInvite)
- bot.on("message", msg => {
- var msgToString = msg.toString().toLowerCase()
- if (msgToString.startsWith("can't find a player by the name of '" + personToInvite.toLowerCase() +"'")) {
- embeds.editEmbed('error', inviteEmbed, `Can't find a player by the name of \`${personToInvite}\``, message.author, 7)
- return
- } else if (msgToString.startsWith("you can't invite") && msgToString.endsWith(personToInvite.toLowerCase() + " to the party because they're not online!")) {
- embeds.editEmbed('error', inviteEmbed, `Can't invite \`${personToInvite}\` to the party because they're not online`, message.author, 7)
- return
- } else if (msgToString.startsWith("[vip] apskull invited") && msgToString.endsWith(personToInvite.toLowerCase() + " to the party! they have 60 seconds to accept.")) {
- embeds.editEmbed('success', inviteEmbed, `Invited \`${personToInvite}\` to the party`, message.author, null)
- }
- })
- } else {
- embeds.editEmbed('error', inviteEmbed, `\`${personToInvite}\` is not a valid username`, message.author, 5)
- return
- }
- }
- break
- case "say":
- if (botOnline === false) {
- embeds.sendEmbed('error', message.channel, 'Housing bot offline', message.author, 3)
- return
- } else {
- if (!message.member.roles.has(message.guild.roles.find(role => role.name === config.roles.leaders))) {
- embeds.sendEmbed('error', message.channel, 'You need the role \`KARAOKE LEADERS\` to run that command', message.author, 5)
- return
- } else {
- if (args[1].toLowerCase() === "/resetplot" || args[1].toLowerCase() === "/settheme") {
- embeds.sendEmbed('error', message.channel, "This command cannot be run from the bot", message.author, 5)
- return
- } else {
- if (args.slice(1).length === 0) {
- embeds.sendEmbed('error', message.channel, "Please supply a message to send as the housing bot", message.author, 5)
- return
- } else {
- embeds.sendEmbed('success', message.channel, `Sending chat message \`${args.slice(1).join(" ")}\` as the housing bot`, message.author, null)
- bot.chat(args.slice(1).join(" "))
- }
- }
- }
- }
- break
- default:
- embeds.sendMainHelpEmbed(message.channel, message.author)
- }
- }
- }
- })
- function urlcustomencode(str) {
- var symbols = {
- '@': '%40',
- '*': '%2A',
- '+': '%2B',
- '/': '%2F',
- '%26lt%3B': '%3C',
- '%26gt%3B': '%3E'
- }
- return escape(str).replace(/([@*+/]|%26(amp|lt|gt)%3B)/g, function(m) {
- return symbols[m]
- })
- }
- client.login(credentials.botToken).catch(err => console.error(err))
- function createBot() {
- client.user.setStatus('online', 'Chilling in Housing')
- try {
- bot = mineflayer.createBot({
- host: "mc.hypixel.net",
- port: 25565,
- version: '1.9',
- username: credentials.username,
- password: credentials.password
- })
- bot.on('error', err => {
- console.error(err)
- embeds.sendEmbed('error', client.guilds.find(guild => guild.name === config.guild).channels.find(channel => channel.name === config.channels.housingCommands), "Minecraft bot failed to connect, check console for details", null, null)
- killBot()
- return
- })
- bot.on('message', message => {
- if (bot == null) return
- let plainText = message.toString()
- let colourText = message.toMotd()
- if (plainText.match(new RegExp("^(?:\\[[A-Z]+\\+?\\] ?)?" + bot.username + " entered the world\.$"))) {
- bot.look((Math.PI), 0, false)
- bot.setControlState("back", true)
- setTimeout(() => bot.setControlState("back", false), 1000)
- } else if (plainText.toLowerCase() === "welcome to the housing beta!") {
- embeds.editEmbed('success', workingEmbed, 'Housing bot logged into housing', message.author, null)
- botLockDown = false
- } else if (plainText.includes(":") || plainText.includes('entered the world') || plainText.includes('left the world')) {
- // fetch('https://kipli.ng/karaoke/submithousingchat', { method: 'POST', body: `key=${credentials.kiplingAPIKey}&message=${urlcustomencode(colourText)}`})
- // .then(res => console.log(res))
- } else {
- if (plainText.toLowerCase().startsWith("you are currently vanished")) {
- botLockDown = true
- return
- }
- client.guilds.find(guild => guild.name === config.guild).channels.find(channel => channel.name === config.channels.housingLog).send('`' + plainText + '`')
- }
- })
- var homeInterval = setInterval(function() {
- if (bot == null) {
- clearInterval(homeInterval)
- } else {
- bot.chat("/home")
- }
- }, 15000)
- } catch (e) {
- console.error(e)
- embeds.sendEmbed('error', client.guilds.find(guild => guild.name === config.guild).channels.find(channel => channel.name === config.channels.housingCommands), "Minecraft bot failed to connect, check console for details", null, null)
- killBot()
- }
- }
- var macroString
- var macroTimeoutMs = 10000
- var macroTimeout = createTimeout(macroTimeoutMs)
- function createTimeout(ms) {
- return setTimeout(function(){
- kiplingMacroRequest()
- }, parseInt(ms))
- }
- function killBot() {
- if (bot == null) {
- botOnline = false
- botLockDown = true
- } else {
- bot.quit()
- bot = null
- botOnline = false
- botLockDown = true
- client.user.setStatus('idle', 'Idling')
- }
- }
- function mcChat(macroString) {
- if (botOnline === true && bot !== null && botLockDown !== true) {
- bot.chat(macroString)
- }
- }
- function kiplingMacroRequest() {
- fetch("https://kipli.ng/api/karaoke/housingmacro")
- .then(res => res.text())
- .then(body => {
- if (!body.startsWith("/")) {
- mcChat(body)
- body = body
- } else {
- embeds.sendEmbed('warning', client.guilds.find(guild => guild.name === config.guild).channels.find(channel => channel.name === config.channels.housingCommands), "A macro sourced from Kipling was a command", null, null)
- return
- }
- })
- fetch("https://kipli.ng/api/karaoke/housingmacrointerval")
- .then(res => res.text())
- .then(body => {
- macroTimeout = createTimeout(body)
- })
- }
- // function kiplingNotifications() {
- // if(housingState == true){
- // https.get("KIPLING_LINK_REVOKED", response => {
- // var notification = ''
- // response.setEncoding('utf8');
- // response.on('data', function(d) {
- // notification = d
- // })
- // response.on('end', function() {
- // if(notification.startsWith("/resetplot") || notification.startsWith("/settheme") || notification.startsWith("resetparkour")) {
- // discordBot.channels.get("534109440165675009").send(discordBot.emojis.get("544943638157852695") + " A chat message sourced from Kipling was a command that is banned.")
- // mcChat(notification)
- // } else {
- // mcChat(notification)
- // }
- // })
- // })
- // }
- // }
- // setInterval(kiplingNotifications, 3000)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement