Created
September 13, 2020 10:22
-
-
Save flazepe/3dd1af65c1b79564324b5369975c644b to your computer and use it in GitHub Desktop.
old old old version of aeon in one file because
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// | |
// | |
// Bot Configuration | |
// | |
// | |
// | |
const beta = 1; | |
const betaToken = ""; | |
const token = ""; | |
const changelog = ``; | |
// | |
// | |
// | |
// Packages | |
// | |
// | |
// | |
const fs = require("fs"); | |
const Discord = require("discord.js"); | |
const client = new Discord.Client(); | |
const mysql = require("mysql2/promise"); | |
const OAuth = require("oauth"); | |
const fetch = require("node-fetch"); | |
const cheerio = require("cheerio"); | |
const moment = require("moment"); | |
const ytdl = require("ytdl-core"); | |
// | |
// | |
// | |
// Bot | |
// | |
// | |
// | |
// Prefix cache | |
const prefixCache = {}; | |
const cooldown = new Set(); | |
// | |
// | |
// | |
// Music Stuff | |
// | |
// | |
// | |
let node = 0; | |
const music = {}; | |
music.options = {}; | |
music.queue = {}; | |
const LavalinkHost = ""; | |
const LavalinkPassword = ""; | |
const LavalinkServer = [{ name: "default", host: LavalinkHost, port: 80, auth: LavalinkPassword }]; | |
const ShoukakuOptions = { moveOnDisconnect: false, resumable: false, resumableTimeout: 30, reconnectTries: 2, restTimeout: 10000 }; | |
const { Shoukaku } = require("shoukaku"); | |
client.shoukaku = new Shoukaku(client, LavalinkServer, ShoukakuOptions); | |
client.shoukaku.on("ready", () => console.log("Lavalink ready.")); | |
client.shoukaku.on("error", (name, error) => console.log(`Lavalink error: ${error}`)); | |
client.shoukaku.on("close", (name, code, reason) => { return; }); | |
client.shoukaku.on("disconnected", (name, reason) => { return; }); | |
// | |
// | |
// | |
// Connection | |
// | |
// | |
// | |
const conn = mysql.createPool({ | |
host: "tommy.heliohost.org", | |
user: "flazepe_aeonuser", | |
password: "aeonisnotbad!", | |
database: "flazepe_aeon", | |
connectionLimit: 2 | |
}); | |
client.on("ready", () => { | |
client.user.setActivity("aeon.now.sh | .help"); | |
console.log("Ready."); | |
}); | |
client.on("message", async msg => { | |
try { | |
// | |
// | |
// | |
// Initalize | |
// | |
// | |
// | |
if (msg.author.bot || !msg.guild) return; | |
const prefix = await (async () => { | |
try { | |
// Prefix cache | |
if (prefixCache[msg.guild.id]) return prefixCache[msg.guild.id]; | |
const [rows] = await conn.query(`SELECT * FROM prefixes WHERE server_id = ?`, msg.guild.id); | |
if (rows.length != 0) { | |
// Prefix cache | |
prefixCache[msg.guild.id] = rows[0].prefix; | |
return rows[0].prefix; | |
} | |
else { | |
// Prefix cache | |
prefixCache[msg.guild.id] = defaultPrefix; | |
return defaultPrefix; | |
} | |
} | |
catch(e) { return defaultPrefix; } | |
})(); | |
const mention = new RegExp(`^<@!?${client.user.id}>`); | |
if (msg.content.match(mention)) length = 22; | |
else if (msg.content.startsWith(prefix)) length = prefix.length; | |
else return; | |
const args = msg.content.slice(length).trim().split(/\s+/g); | |
const cmd = args.shift().toLowerCase(); | |
const authorText = msg.author.tag; | |
const authorIcon = msg.author.displayAvatarURL({ format: "png", size: 512, dynamic: 1 }); | |
// | |
// | |
// | |
// Functions | |
// | |
// | |
// | |
async function authorSend(f) { | |
return await msg.author.send(f).catch(e => { return errorEmbed("You need to allow direct messages from server members in order to use this feature."); }); | |
} | |
function successEmbed(f) { channelSend(advEmbed(successColor, 0, "Success", f)); } | |
function noticeEmbed(f) { channelSend(advEmbed(noticeColor, 0, "Notice", f)); } | |
function errorEmbed(f) { channelSend(advEmbed(errorColor, 0, "Error", f)); } | |
function loadingEmbed(f) { return channelSend(advEmbed(f ? f : 0, 0, "Loading...", "Please wait for a moment.")); } | |
async function getBody(f) { | |
const res = await fetch(f); | |
const body = await res.text(); | |
return body.trim(); | |
} | |
async function getJSON(f) { | |
const res = await fetch(f); | |
const json = await res.json().catch(e => { return; }); | |
return json; | |
} | |
async function getInput(f) { | |
let filter = m => m.author.id == msg.author.id; | |
if (f) filter = m => m.author.id == msg.author.id && m.content.includes(f); | |
const c = await msg.channel.awaitMessages(filter, { time: 10000, max: 1 }); | |
if (c.first()) return c.first().content; | |
return; | |
} | |
function resolveID(f) { | |
return f.replace(/[<@!>\\]/g, ""); | |
} | |
async function resolveMember(f1, f2) { | |
const member = await msg.guild.members.fetch(resolveID(f1)).catch(e => { return; }) || msg.guild.members.cache.find(m => | |
m.user.id == resolveID(f1) | |
|| m.user.tag == f1 | |
|| m.user.username == f1 | |
); | |
if (!member || !member.guild) return; | |
return f2 ? member.user : member; | |
} | |
function resolveEmoji(f) { | |
const emoji = client.emojis.cache.find(e => e.guild.id == "" && e.name == f) || 0; | |
return msg.channel.permissionsFor(msg.guild.me).has("USE_EXTERNAL_EMOJIS") ? emoji : "❔"; | |
} | |
// | |
// | |
// | |
// Cooldown | |
// | |
// | |
// | |
if (cooldown.has(msg.author.id)) return msg.react("🕑").catch(e => { return; }); | |
else if (msg.author.id != flazepeID) { | |
cooldown.add(msg.author.id); | |
setTimeout(() => { cooldown.delete(msg.author.id); }, 3000); | |
} | |
// | |
// | |
// | |
// Help | |
// | |
// | |
// | |
if (cmd == "help") { | |
const embed = advEmbed(0, 0, "Help", cmds); | |
embed.setDescription("Thank you for using Aeon.\n\nAll the commands must start with a prefix or @" + client.user.tag + ".\nThe current prefix " + (msg.guild ? `for **${msg.guild.name}**` : "") + " is: `" + prefix + "`\n\nBelow are the list of commands:"); | |
authorSend(embed); | |
} | |
if (cmd == "o") { | |
if (msg.author.id != flazepeID) return; | |
const act = args.shift().toLowerCase(); | |
switch(act) { | |
case "ev": { | |
try { | |
channelSend(advEmbed(0, 0, "Eval", "```js\n" + | |
JSON.stringify(eval(args.join(" ")), 0, "\t").replace(/\\n/g, "\n").slice(0, 2038) | |
+ "```")); | |
} | |
catch(e) { errorEmbed(e.message); } | |
break; | |
} | |
case "s": | |
authorSend(advEmbed(0, 0, `Servers (${client.guilds.cache.size})`, "```" + client.guilds.cache.map(g => `${g.name} (${g.id})`).join("\n").slice(0, 2042) + "```")); | |
break; | |
} | |
} | |
// | |
// | |
// | |
// General | |
// | |
// | |
// | |
if (cmd == "status") { | |
const embed = advEmbed(0, 0, "Bot Status", [ | |
`Uptime /// ${moment.duration(client.uptime, "milliseconds").humanize()}`, | |
`Music /// ${Object.keys(music.queue).length}`, | |
"Changelog /// ```" + changelog + "```" | |
]); | |
channelSend(embed); | |
} | |
if (cmd == "prefix") { | |
if (!args[0]) { | |
const [rows] = await conn.query(`SELECT * FROM prefixes WHERE server_id = ?`, msg.guild.id); | |
if (rows.length == 0) return channelSend(advEmbed(0, 0, "Prefix", `Current prefix: \`${defaultPrefix}\` (default)\n\nUse \`@${client.user.tag} prefix <new prefix>\` to change it.`)); | |
channelSend(advEmbed(0, 0, "Prefix", `Current prefix: \`${rows[0].prefix}\`\n\nUse \`@${client.user.tag} prefix default\` to reset it.`)); | |
} | |
else { | |
if (!msg.member.hasPermission("MANAGE_GUILD")) return errorEmbed("You need the permission to manage server in order to manage the prefix."); | |
if (args[0] == "default" || args[0] == defaultPrefix) { | |
await conn.query(`DELETE FROM prefixes WHERE server_id = ?`, msg.guild.id); | |
// Prefix cache | |
delete prefixCache[msg.guild.id]; | |
successEmbed("The prefix has been set to default."); | |
} | |
else { | |
const newPrefix = args.join(" "); | |
if (newPrefix.includes("`")) return errorEmbed("New prefix cannot contain `."); | |
if (newPrefix.length > 4) return errorEmbed("New prefix must be less than 4 characters."); | |
await conn.query(`DELETE FROM prefixes WHERE server_id = ?`, msg.guild.id); | |
await conn.query(`INSERT INTO prefixes (server_id, prefix) VALUES (?, ?)`, [msg.guild.id, newPrefix]); | |
// Prefix cache | |
delete prefixCache[msg.guild.id]; | |
successEmbed(`The new server prefix is now: \`${newPrefix}\``); | |
} | |
} | |
} | |
if (cmd == "ping") { | |
const embed = advEmbed(0, 0, "Ping", [ | |
`API /// ${Math.round(client.ws.ping)} ms`, | |
`Bot /// ${Date.now() - msg.createdTimestamp} ms` | |
]); | |
channelSend(embed); | |
} | |
if (cmd == "invite") { channelSend(advEmbed(0, 0, "Invite", "Refer [here](https://top.gg/bot/635833307510079490).")); } | |
// | |
// | |
// | |
// Moderation | |
// | |
// | |
// | |
if (cmd == "mute" || cmd == "m") { | |
const p = ["MANAGE_ROLES", "MANAGE_CHANNELS"]; | |
if (!msg.guild.me.hasPermission(p)) return errorEmbed(perm(1, p)); | |
if (!msg.member.hasPermission(p)) return errorEmbed(perm(2, p)); | |
if (!args[0]) return cmdEmbed("Mute", "Mutes a member.", "mute <member>", "m"); | |
const member = await resolveMember(args[0]); | |
if (!member) return errorEmbed("That user is not present in this server."); | |
if (member.id == msg.author.id) return errorEmbed("You shouldn't mute yourself."); | |
const mutedRole = msg.guild.roles.cache.find(r => r.name == "Muted"); | |
if (!mutedRole) { | |
msg.guild.roles.create({ data: { name: "Muted" }}); | |
return errorEmbed("Please try again."); | |
} | |
msg.guild.channels.cache.forEach(c => { | |
c.createOverwrite(mutedRole.id, { SEND_MESSAGES: 0, ADD_REACTIONS: 0, SPEAK: 0 }, "For the Muted role.").catch(e => { return; }); | |
}); | |
if (member.roles && member.roles.cache.has(mutedRole.id)) return errorEmbed("Member is already muted."); | |
member.roles.add(mutedRole); | |
successEmbed(`${member} (${member.user.tag}) has been muted.`); | |
logSend(new Discord.MessageEmbed().setColor(errorColor).setTitle("Muted").setDescription(`${member} (${member.user.tag})`), msg.guild); | |
} | |
if (cmd == "unmute") { | |
const p = ["MANAGE_ROLES", "MANAGE_CHANNELS"]; | |
if (!msg.guild.me.hasPermission(p)) return errorEmbed(perm(1, p)); | |
if (!msg.member.hasPermission(p)) return errorEmbed(perm(2, p)); | |
if (!args[0]) return cmdEmbed("Unmute", "Unmutes a member.", "unmute <member>"); | |
const member = await resolveMember(args[0]); | |
if (!member) return errorEmbed("That user is not present in this server."); | |
const mutedRole = msg.guild.roles.cache.find(r => r.name == "Muted"); | |
if (!mutedRole) { | |
msg.guild.roles.create({ data: { name: "Muted" }}); | |
return errorEmbed("Please try again."); | |
} | |
if (!member.roles.cache.has(mutedRole.id)) return errorEmbed("Member is not muted."); | |
member.roles.remove(mutedRole); | |
successEmbed(`${member} (${member.user.tag}) has been unmuted.`); | |
logSend(new Discord.MessageEmbed().setColor(successColor).setTitle("Unmuted").setDescription(`${member} (${member.user.tag})`), msg.guild); | |
} | |
if (cmd == "ban" || cmd == "b") { | |
const p = "BAN_MEMBERS"; | |
if (!msg.guild.me.hasPermission(p)) return errorEmbed(perm(1, p)); | |
if (!msg.member.hasPermission(p)) return errorEmbed(perm(2, p)); | |
if (!args[0]) return cmdEmbed("Ban", "Bans a member.", "ban <member> [reason]", "b"); | |
const member = await resolveMember(args[0]); | |
if (!member) return errorEmbed("Please mention a valid member."); | |
if (member.id == msg.author.id) return errorEmbed("You shouldn't ban yourself."); | |
if (!member.bannable) return errorEmbed("I cannot do that. No administrator permission? Server owner?"); | |
args.shift(); | |
let reason = args.join(" "); | |
if (!reason) reason = "No reason provided."; | |
msg.guild.members.ban(member, { reason: `Banned by ${msg.author.tag} - ${reason}` }); | |
successEmbed(`${member} (${member.user.tag}) has been banned.`); | |
} | |
if (cmd == "unban") { | |
const p = "BAN_MEMBERS"; | |
if (!msg.guild.me.hasPermission(p)) return errorEmbed(perm(1, p)); | |
if (!msg.member.hasPermission(p)) return errorEmbed(perm(2, p)); | |
if (!args[0]) return cmdEmbed("Unban", "Unbans a user.", "unban <user> [reason]"); | |
const bans = await msg.guild.fetchBans(); | |
const search = resolveID(args[0]); | |
// Search for user | |
let find = bans.find(o => o.user.id == search) || bans.find(o => o.user.tag == search); | |
if (!find) return errorEmbed("That user is not banned."); | |
find = find.user; | |
args.shift(); | |
let reason = args.join(" "); | |
if (!reason) reason = "No reason provided."; | |
msg.guild.members.unban(find, `Unbanned by ${msg.author.tag} - ${reason}`); | |
successEmbed(`@${find.username}#${find.discriminator} has been unbanned.`); | |
} | |
if (cmd == "kick" || cmd == "k") { | |
const p = "KICK_MEMBERS"; | |
if (!msg.guild.me.hasPermission(p)) return errorEmbed(perm(1, p)); | |
if (!msg.member.hasPermission(p)) return errorEmbed(perm(2, p)); | |
if (!args[0]) return cmdEmbed("Kick", "Kicks a member.", "kick <member> [reason]", "k"); | |
const member = await resolveMember(args[0]); | |
if (!member) return errorEmbed("Please mention a valid member."); | |
if (member.id == msg.author.id) return errorEmbed("You shouldn't kick yourself."); | |
if (!member.kickable) return errorEmbed("I cannot do that. No administrator permission? Server owner?"); | |
args.shift(); | |
let reason = args.join(" "); | |
if (!reason) reason = "No reason provided."; | |
member.kick(`Kicked by ${msg.author.tag} - ${reason}`); | |
successEmbed(`${member} (${member.user.tag}) has been kicked.`); | |
} | |
if (cmd == "purge" || cmd == "prune") { | |
const p = "MANAGE_MESSAGES"; | |
if (!msg.guild.me.hasPermission(p)) return errorEmbed(perm(1, p)); | |
if (!msg.member.hasPermission(p)) return errorEmbed(perm(2, p)); | |
if (!args[0]) return cmdEmbed("Purge", "Deletes messages based on the given number (2-50).", "clear <number>", "prune"); | |
const del = args[0]; | |
if (isNaN(del) || del < 2 || del > 50 || del.includes(".")) return errorEmbed("Please enter a valid number."); | |
msg.channel.bulkDelete(del); | |
successEmbed(`Deleted ${del} messages.`); | |
} | |
if (cmd == "embed") { | |
const p = "MANAGE_MESSAGES"; | |
if (!msg.member.hasPermission(p)) return errorEmbed(perm(2, p)); | |
if (!args[0]) return cmdEmbed("Embed", "Creates a basic embed.", "embed <color> <title> | <description>"); | |
const color = Discord.resolveColor(args.shift().toUpperCase()); | |
const split = args.join(" ").split("|"); | |
if (!split[0] || !split[1]) return errorEmbed(iArg); | |
const title = split[0]; | |
const description = split[1]; | |
channelSend(advEmbed(color, 0, title.slice(0, 256), description.slice(0, 600))) | |
} | |
// | |
// | |
// | |
// Discord | |
// | |
// | |
// | |
if (cmd == "user") { | |
const member = await resolveMember(args.join(" ")) || msg.member; | |
const user = member.user; | |
const created = moment(user.createdTimestamp); | |
const joined = moment(member.joinedTimestamp); | |
const roles = member.roles.cache.map(r => r).join(", ").replace(/\,? ?@everyone/, ""); | |
const embed = advEmbed(0, user.displayAvatarURL({ format: "png", dynamic: 1 }), "User", [ | |
`Name /// ${resolveEmoji(user.presence.status)} ${user} (${user.tag})`, | |
`Nickname /// ${member.nickname ? member.nickname : "-"}`, | |
`Created /// ${created.format(fmt)}`, | |
`Joined Server /// ${joined.format(fmt)}`, | |
`Bot /// ${user.bot ? "Yes" : "No"}`, | |
`Roles /// ${roles ? roles : "-"}` | |
]); | |
channelSend(embed); | |
} | |
if (cmd == "bot" || cmd == "dbl") { | |
if (!args[0]) return cmdEmbed("Discord Bot List", "Fetches a bot from Discord Bot List.", "bot <bot id/mention>", "dbl"); | |
const res = await fetch(`https://top.gg/api/bots/${resolveID(args.join(" "))}`, { | |
headers: { | |
"Authorization": "" | |
} | |
}); | |
const json = await res.json(); | |
if (json.error) return errorEmbed(nF); | |
const avatar = `https://images.discordapp.net/avatars/${json.id}/${json.avatar}.png?size=1024`; | |
const tags = json.tags.join(", "); | |
const embed = advEmbed(0, avatar, "Bot", [ | |
`Name /// ${json.certifiedBot ? resolveEmoji("dblcertified") : ""} [@${json.username}#${json.discriminator}](https://top.gg/bot/${json.clientid})`, | |
`Library /// ${json.lib}`, | |
`Description /// ${json.shortdesc}`, | |
`Prefix /// \`${json.prefix}\``, | |
`Tags /// ${tags ? tags : "-"}`, | |
`Website /// ${json.website ? json.website : "-"}` | |
]); | |
channelSend(embed); | |
} | |
if (cmd == "avatar") { | |
const user = await resolveMember(args.join(" "), 1) || msg.author; | |
const embed = advEmbed(0, 0, "Avatar", [`Name /// ${resolveEmoji(user.presence.status)} ${user} (${user.tag})`]); | |
embed.setImage(user.displayAvatarURL({ format: "png", size: 1024, dynamic: 1 })); | |
channelSend(embed); | |
} | |
if (cmd == "server") { | |
const created = moment(msg.guild.createdTimestamp); | |
const owner = await resolveMember(msg.guild.ownerID, 1); | |
const bots = msg.guild.members.cache.filter(m => m.user.bot == 1).size; | |
const embed = advEmbed(0, msg.guild.iconURL({ format: "png", dynamic: 1 }), "Server", [ | |
`Name /// ${msg.guild.name}`, | |
`Owner /// ${resolveEmoji(owner.presence.status)} ${owner} (${owner.tag})`, | |
`Created /// ${created.format(fmt)}`, | |
`Humans /// ${(msg.guild.memberCount - bots).toLocaleString()}`, | |
`Bots /// ${bots.toLocaleString()}`, | |
`Channels /// ${(msg.guild.channels.cache.size - msg.guild.channels.cache.filter(c => c.type == "category").size).toLocaleString()}`, | |
`Roles /// ${msg.guild.roles.cache.size.toLocaleString()}` | |
]); | |
channelSend(embed); | |
} | |
if (cmd == "emoji") { | |
if (!args[0]) return cmdEmbed("Emoji", "Fetches an emoji from the current server.", "emoji <name>"); | |
const emoji = msg.guild.emojis.cache.find(e => e.name.toLowerCase() == args[0].toLowerCase() || args[0].includes(e.id)); | |
if (!emoji || !emoji.available) return errorEmbed(nF); | |
const created = moment(emoji.createdTimestamp); | |
const embed = advEmbed(0, emoji.url, "Emoji", [ | |
`Name /// [${emoji.name}](${emoji.url})`, | |
`ID /// ${emoji.id}`, | |
`Animated /// ${emoji.animated ? "Yes" : "No"}`, | |
`Created /// ${created.format(fmt)}` | |
]); | |
channelSend(embed); | |
} | |
// | |
// | |
// | |
// Utility | |
// | |
// | |
// | |
if (cmd == "poll") { | |
if (!args[0]) return cmdEmbed("Poll", "Creates a poll with up to 10 choices, seperated by `|`.", "poll choice 1 | choice 2 | ... | choice 10"); | |
const choices = args.join(" ").split("|"); | |
if (choices[0] && !choices[1] || choices[10]) return errorEmbed("Minimum choices are 2 and maximum choices are 10."); | |
const numberEmojis = ["1⃣", "2⃣", "3⃣", "4⃣", "5⃣", "6⃣", "7⃣", "8⃣", "9⃣", "🔟"]; | |
let polls = ""; | |
for (let i = 0; i < choices.length; i++) { | |
polls += numberEmojis[i] + "\u00a0\u00a0" + choices[i].trim() + "\n\n"; | |
} | |
for (let i = 0; i < choices.length; i++) { | |
if (choices[i].length > 50) return errorEmbed("One of the choices is too long."); | |
} | |
const sentMsg = await channelSend(advEmbed("#a0522d", 0, "Poll", polls)) | |
for (let i = 0; i < choices.length; i++) { | |
await sentMsg.react(numberEmojis[i]).catch(e => { return; }); | |
} | |
} | |
if (cmd == "vote") { | |
if (!args[0]) return cmdEmbed("Vote", "Make people vote for something.", "vote <text>"); | |
const sentMsg = await channelSend(advEmbed(0, 0, "Vote", args.join(" "))) | |
await sentMsg.react("👍").catch(e => { return; }); | |
sentMsg.react("👎").catch(e => { return; }); | |
} | |
if (cmd == "qr") { | |
if (!args[0]) return cmdEmbed("QR Code Generator", "Sends a QR code based on the given text.", "qr <text>"); | |
const text = args.join(" "); | |
if (text.length > 500) return errorEmbed("Text is too long."); | |
const embed = imgEmbed("Success", `https://chart.googleapis.com/chart?cht=qr&chs=256x256&chl=${encodeURI(text)}&chld=|2`, 1); | |
embed.setColor(successColor); | |
channelSend(embed); | |
} | |
// | |
// | |
// | |
// Language | |
// | |
// | |
// | |
if (cmd == "urban" || cmd == "ud") { | |
if (!args[0]) return cmdEmbed("Urban Dictionary", "Defines a term from Urban Dictionary.", "urban <term>", "ud"); | |
const term = args.join(" "); | |
let json = await getJSON("http://api.urbandictionary.com/v0/define?term=" + term); | |
json = json.list[0]; | |
if (!json) return errorEmbed(nF); | |
const embed = advEmbed(0, 0, "Urban Dictionary", [ | |
`Term /// ${json.word}`, | |
`Definition /// ${json.definition.replace(/\[|\]/g, "")}`, | |
`Example /// ${json.example.replace(/\[|\]/g, "")}` | |
]); | |
msg.channel.nsfw ? channelSend(embed) : authorSend(embed); | |
} | |
// | |
// | |
// | |
// Music | |
// | |
// | |
// | |
"play": { | |
alias: "p", | |
run: async () => { | |
if (!args[0]) return cmdEmbed("Play", "Plays a music.", "play <title>", "p"); | |
if (!node) return("Try again later."); | |
const c = msg.member.voice.channel; | |
if (!c || !c.joinable) return errorEmbed(noVoice); | |
const query = encodeURI(args.join(" ")); | |
let data = await node.rest.resolve(args.join(" "), "youtube"); | |
if (!data) return errorEmbed(nF); | |
data = data.tracks[0]; | |
if (!music.queue[msg.guild.id]) music.queue[msg.guild.id] = []; | |
music.queue[msg.guild.id].push([data.track, Discord.escapeMarkdown(data.info.title), moment.duration(data.info.length, "milliseconds").format(), msg.author.id]); | |
await successEmbed(`Added "${Discord.escapeMarkdown(data.info.title)}" to the queue.`); | |
if (music.queue[msg.guild.id].length < 2 || !client.shoukaku.getPlayer(msg.guild.id)) play(c); | |
} | |
}, | |
"pause": { | |
alias: "resume", | |
run: async () => { | |
const c = msg.member.voice.channel; | |
if (!c || !c.joinable) return errorEmbed(noVoice); | |
const player = client.shoukaku.getPlayer(msg.guild.id); | |
if (!player) return errorEmbed(`There is nothing playing.`); | |
if (cmd == "pause") await player.setPaused(true); | |
else await player.setPaused(false); | |
msg.react("☑️").catch(e => { return; }); | |
} | |
}, | |
"stop": { | |
alias: "leave", | |
run: async () => { | |
const c = msg.member.voice.channel; | |
if (!c || !c.joinable) return errorEmbed(noVoice); | |
const player = client.shoukaku.getPlayer(msg.guild.id); | |
if (!player) return errorEmbed(`There is nothing playing.`); | |
await player.disconnect(); | |
msg.react("☑️").catch(e => { return; }); | |
} | |
}, | |
"volume": { | |
alias: "vol", | |
run: async () => { | |
if (!args[0]) return cmdEmbed("Volume", "Sets the music volume.", "volume <percentage>", "vol"); | |
const c = msg.member.voice.channel; | |
if (!c || !c.joinable) return errorEmbed(noVoice); | |
const volume = args[0].replace("%", ""); | |
if (isNaN(volume) || volume > 100 || volume < 0 || volume.includes(".")) return errorEmbed("Volume must be between 0 to 100 percent."); | |
const realVolume = volume * 60 / 100; | |
const player = client.shoukaku.getPlayer(msg.guild.id); | |
if (!player) return errorEmbed(`There is nothing playing.`); | |
music.options[msg.guild.id].volume = realVolume; | |
await player.setVolume(realVolume); | |
successEmbed(`Volume has been set to ${volume}%.`); | |
} | |
}, | |
"skip": { | |
run: async () => { | |
const c = msg.member.voice.channel; | |
if (!c || !c.joinable) return errorEmbed(noVoice); | |
const player = client.shoukaku.getPlayer(msg.guild.id); | |
if (!player) return errorEmbed(`There is nothing playing.`); | |
const findQueue = music.queue[msg.guild.id]; | |
if (!findQueue || !findQueue[0]) return errorEmbed("There is nothing to skip."); | |
await player.stopTrack(); | |
msg.react("☑️").catch(e => { return; }); | |
} | |
}, | |
"queue": { | |
run: async () => { | |
const c = msg.member.voice.channel; | |
if (!c || !c.joinable) return errorEmbed(noVoice); | |
const findQueue = music.queue[msg.guild.id]; | |
if (findQueue && findQueue[0]) { | |
const cleanQueue = []; | |
for (let i = 0; i < findQueue.length; i++) { | |
cleanQueue.push((i == 0 ? "" : `${i}. `) + findQueue[i][1]); | |
} | |
const embed = advEmbed(0, 0, "Queue", [ | |
`Now Playing /// ${cleanQueue.shift()}`, | |
`Queue /// ${cleanQueue && cleanQueue.length > 0 ? cleanQueue.join("\n").slice(0, 1024) : "-"}` | |
]); | |
channelSend(embed); | |
} | |
else noticeEmbed("Queue is empty."); | |
} | |
}, | |
"remove": { | |
run: async () => { | |
if (!args[0]) return cmdEmbed("Remove", "Removes a music from the queue.", "remove <number>"); | |
const c = msg.member.voice.channel; | |
if (!c || !c.joinable) return errorEmbed(noVoice); | |
const findQueue = music.queue[msg.guild.id]; | |
if (findQueue && findQueue.length > 0) { | |
if (isNaN(args[0]) || args[0].includes(".") || args[0] <= 0 || args[0] > findQueue.length - 1) return errorEmbed("Not found."); | |
const remove = [ ...findQueue[args[0]] ]; | |
findQueue.splice(args[0], 1); | |
successEmbed(`Removed "${remove[1]}" from the queue.`); | |
} | |
else noticeEmbed("Queue is empty."); | |
} | |
}, | |
"clear": { | |
run: async () => { | |
const c = msg.member.voice.channel; | |
if (!c || !c.joinable) return errorEmbed(noVoice); | |
const player = client.shoukaku.getPlayer(msg.guild.id); | |
if (player) await player.disconnect(); | |
delete music.queue[msg.guild.id]; | |
successEmbed("Queue has been cleared."); | |
} | |
}, | |
"np": { | |
run: async () => { | |
const c = msg.member.voice.channel; | |
if (!c || !c.joinable) return errorEmbed(noVoice); | |
const embed = await npEmbed(c); | |
if (embed) return channelSend(embed); | |
return errorEmbed("There is currently no music playing."); | |
} | |
}, | |
"lyrics": { | |
run: async () => { | |
if (!args[0]) return cmdEmbed("Lyrics", "Fetches lyrics of a song. Could be spammy depending on the song.", "lyrics <title>"); | |
const json = await getJSON(`https://some-random-api.ml/lyrics?title=${encodeURI(args.join(" "))}`) | |
if (json.error) return errorEmbed(nF); | |
const title = `${json.title} - ${json.author}`; | |
channelSend(advEmbed(0, json.thumbnail.genius, "Lyrics", `Found "${title}".\n\nEnter \`1\` to proceed or ignore to cancel.`)); | |
const c = await getInput("1"); | |
if (!c) return; | |
const split = json.lyrics.match(/[\s\S]{1,2048}/g); | |
for (const s of split) { | |
await authorSend({ embed: { color: primaryColor, description: s } }); | |
} | |
} | |
}, | |
"lyrics2": { | |
run: async () => { | |
if (!args[0]) return cmdEmbed("Lyrics", "Fetches lyrics of a song. Could be spammy depending on the song.", "lyrics2 <title>"); | |
let search = await getBody(`https://www.musixmatch.com/search/${encodeURI(args.join(" "))}/tracks`); | |
search = cheerio.load(search); | |
search = search("a.title").attr("href"); | |
if (!search) return errorEmbed(nF); | |
search = await getBody(`https://www.musixmatch.com${search}`); | |
const $ = cheerio.load(search); | |
const title = ($("h2 span span").text() || $("h2 span").text()) + " - " + $("h1.mxm-track-title__track").text().slice(6); | |
const lyrics = $("span.lyrics__content__ok").append("\n").text(); | |
if (!lyrics) return errorEmbed(nF); | |
channelSend(advEmbed(0, `http:${$("div.banner-album-image-desktop img").attr("src")}`, "Lyrics", `Found "${title}".\n\nEnter \`1\` to proceed or ignore to cancel.`)); | |
const c = await getInput("1"); | |
if (!c) return; | |
const split = lyrics.match(/[\s\S]{1,2048}/g); | |
for (const s of split) { | |
await authorSend({ embed: { color: primaryColor, description: s } }); | |
} | |
} | |
}, | |
// | |
// | |
// | |
// Information | |
// | |
// | |
// | |
if (cmd == "covid" || cmd == "corona" || cmd == "coronavirus") { | |
let endpoint = "https://corona.lmao.ninja/all"; | |
if (args[0]) endpoint = `https://corona.lmao.ninja/countries/${args.join(" ")}`; | |
const json = await getJSON(endpoint); | |
if (json.message) return errorEmbed(nF); | |
const fields = [ | |
`Location /// ${json.country ? json.country : "Global"}`, | |
`Cases /// ${json.cases}`, | |
`Deaths /// ${json.deaths}`, | |
`Recoveries /// ${json.recovered}` | |
]; | |
if (json.updated) { | |
const updated = moment(json.updated); | |
fields.push(`Last Updated /// ${updated.format(fmt)}`); | |
} | |
const embed = advEmbed(0, json.countryInfo ? json.countryInfo.flag : "", "COVID-19 Statistics", fields); | |
channelSend(embed); | |
} | |
if (cmd == "wikipedia" || cmd == "wiki") { | |
if (!args[0]) return cmdEmbed("Wikipedia", "Fetches summary of a Wikipedia article.", "wikipedia <article>", "wiki"); | |
const json = await getJSON(`${encodeURIComponent(args.join(" "))}`); | |
if (json.type != "standard") return errorEmbed(nF); | |
const embed = advEmbed("#eeeeee", json.thumbnail ? json.thumbnail.source : "", "Wikipedia", [`Article /// ${json.title}`, `Summary /// ${json.extract}`]); | |
msg.channel.nsfw ? channelSend(embed) : authorSend(embed); | |
} | |
if (cmd == "movie" || cmd == "tv") { | |
if (!args[0]) { | |
if (cmd == "movie") return cmdEmbed("Movie", "Fetches movie information.", "movie <title>"); | |
else return cmdEmbed("TV Show", "Fetches TV show information.", "tv <title>"); | |
} | |
const key = ""; | |
const img = ""; | |
let json = await getJSON(`${encodeURIComponent(args.join(" "))}`); | |
json = json.results[0]; | |
if (!json) return errorEmbed(nF); | |
const embed = advEmbed(0, `${img}`, cmd == "movie" ? "Movie" : "TV Show", [ | |
`Title /// ${json.title || json.name}`, | |
`Summary /// ${json.overview}` | |
]); | |
channelSend(embed); | |
} | |
if (cmd == "anime" || cmd == "manga") { | |
if (!args[0]) return cmdEmbed(flUpper(cmd), `Fetches ${cmd} information.`, `${cmd} <title>`); | |
const fetch = await getJSON(``); | |
const fetchFirst = fetch.results[0]; | |
if (!fetchFirst) return errorEmbed(nF); | |
const json = await getJSON(``); | |
const fields = [ | |
`Title /// ${json.title}`, | |
`Summary /// ${json.synopsis.slice(0, 500)}...`, | |
]; | |
if (fetchFirst.rated) fields.push(`Rating /// ${fetchFirst.rated}`); | |
const embed = advEmbed(0, json.image_url, flUpper(cmd), fields); | |
if (cmd == "anime") { | |
const R = fetchFirst.rated.includes("R"); | |
R && !msg.channel.nsfw ? authorSend(embed) : channelSend(embed); | |
} | |
else { | |
msg.channel.nsfw ? channelSend(embed) : authorSend(embed); | |
} | |
} | |
if (cmd == "weather") { | |
if (!args[0]) return cmdEmbed("Weather", "Fetches weather based on the given location.", "weather <location>"); | |
const res = new OAuth.OAuth(); | |
res.get( | |
``, | |
null, | |
null, | |
(err, data) => { | |
try { JSON.parse(data); } | |
catch(e) { return errorEmbed(nF); } | |
data = JSON.parse(data); | |
const c = data.current_observation; | |
if (!data.location.woeid || !c.condition) return errorEmbed(nF); | |
const embed = advEmbed(0, `${c.condition.code}`, "Weather", [ | |
`Location /// ${data.location.city}`, | |
`Condition /// ${c.condition.text}`, | |
`Temperature /// ${c.condition.temperature}°C`, | |
`Humidity /// ${c.atmosphere.humidity}%`, | |
`Visibility /// ${c.atmosphere.visibility} km`, | |
`Pressure /// ${c.atmosphere.pressure} millibars` | |
]); | |
channelSend(embed); | |
} | |
); | |
} | |
if (cmd == "time" || cmd == "date") { | |
if (!args[0]) return cmdEmbed("Time & Date", "Fetches time and date based on the given location.", "time <location>", "date"); | |
const key = ""; | |
let json = await getJSON(`${args.join(" ")}`); | |
json = json; // removed some properties | |
if (!json) return errorEmbed(nF); | |
const json2 = json.tz; | |
const time = moment(json2.time); | |
const embed = advEmbed("#6200d1", 0, "Time & Date", [ | |
`Location /// ${json.name}`, | |
`Timezone /// ${json2.tz}`, | |
`Time /// ${time.format("h:mma")}`, | |
`Date /// ${time.format("D MMMM YYYY")}`, | |
]); | |
channelSend(embed); | |
} | |
if (cmd == "stock") { | |
if (!args[0]) return cmdEmbed("Stock", "Fetches stock information.", "stock <name>"); | |
const search = await getBody(`https://finance.yahoo.com/lookup/equity?s=${encodeURI(args.join(" "))}`); | |
let first = cheerio.load(search); | |
first = "https://finance.yahoo.com" + first(`a[class="Fw(b)"]`).attr("href"); | |
const body = await getBody(first); | |
const $ = cheerio.load(body); | |
const name = $(`h1[class*="Fz(16px)"]`).first().text(); | |
if (!name) return errorEmbed(nF); | |
const price = $(`span[class*="Trsdu(0.3s)"]`).first().text(); | |
const stats = $(`span[class*="(0.3s) Fw(500)"]`).text(); | |
const embed = advEmbed(0, 0, "Stock", [ | |
`Name /// ${name}`, | |
`Price /// ${price}`, | |
`Statistics /// USD ${stats}` | |
]); | |
channelSend(embed); | |
} | |
// | |
// | |
// | |
// Development | |
// | |
// | |
// | |
if (cmd == "hastebin") { | |
if (!args[0]) return cmdEmbed("hastebin", "Uploads the given text to hastebin.", "hastebin <text>"); | |
const res = await fetch("https://hastebin.com/documents", { | |
"method": "POST", | |
"body": args.join(" ") | |
}) | |
.catch(e => errorEmbed(rL)); | |
const json = await res.json(); | |
successEmbed(`The text is now available at https://hastebin.com/${json.key}.`); | |
} | |
if (cmd == "npm") { | |
if (!args[0]) return cmdEmbed("npm", "Fetches an npm package information.", "npm <package>"); | |
const json = await getJSON(`https://registry.npmjs.com/${args.join(" ")}`); | |
const name = json.name; | |
if (!name) return errorEmbed(nF); | |
const embed = advEmbed("#c22129", "", "npm", [ | |
`Name /// [${name}](https://www.npmjs.com/package/${name})`, | |
`Latest Version /// ${json["dist-tags"].latest}`, | |
`Description /// ${json.description ? json.description : "-"}`, | |
`License /// ${json.license ? json.license : "-"}`, | |
]); | |
channelSend(embed); | |
} | |
// | |
// | |
// | |
// Social Media | |
// | |
// | |
// | |
if (cmd == "youtube" || cmd == "yt") { | |
if (!args[0]) return cmdEmbed("YouTube", "Fetches a YouTube video based on the top result of query.", "youtube <query>", "yt"); | |
const res = await searchYt(args.join(" ")); | |
if (!res) return errorEmbed(nF); | |
const embed = advEmbed("#c4302b", res.thumbnail, "YouTube", [ | |
`Title /// [${res.title}](${res.url})`, | |
`Channel /// [${res.channel}](${res.channelUrl})`, | |
`Duration /// ${res.duration}`, | |
`Views /// ${res.views}` | |
]); | |
msg.channel.nsfw ? channelSend(embed) : authorSend(embed); | |
} | |
// | |
// | |
// | |
// Gaming | |
// | |
// | |
// | |
if (cmd == "pokemon") { | |
if (!args[0]) return cmdEmbed("Pokémon", "Fetches information about a Pokémon.", "pokemon <name>"); | |
const body = await getBody("https://www.pokemon.com/us/pokedex/" + args[0].toLowerCase()); | |
const $ = cheerio.load(body); | |
$(".pokemon-number").remove(); | |
const name = $(".pokedex-pokemon-pagination-title div").text().trim(); | |
if (!name) return errorEmbed(nF); | |
function f(string, replace) { | |
return string.trim().replace(/[^a-zA-Z]/g, " ").replace(/ +/g, replace); | |
} | |
const type = f($(`li[class*="background-color-"]`).first().text(), ""); | |
const description = $(".version-descriptions p").first().text().replace(/\n/g, " "); | |
const weakness = f($(".dtm-weaknesses ul").first().text(), ", "); | |
const evolution = f($(".evolution-profile h3").text(), " -> "); | |
const img = $(".profile-images img").attr("src"); | |
const embed = advEmbed("#ffff00", img, "Pokémon", [ | |
`Name /// ${name} (${type})`, | |
`Description /// ${description}`, | |
`Weakness /// ${weakness}`, | |
`Evolution /// ${evolution}` | |
]); | |
channelSend(embed); | |
} | |
if (cmd == "osu") { | |
if (!args[0] || !args[1]) return cmdEmbed("osu!", "Fetches osu! user information.", "osu <standard/taiko/ctb/mania> <username>"); | |
const countries = await getJSON(""); | |
const key = ""; | |
const ms = { "standard": "0", "taiko": "1", "ctb": "2", "mania": "3" }; | |
const m = args.shift().toLowerCase(); | |
if (!ms[m]) return errorEmbed(iArg); | |
let json = await getJSON(`=${key}&m=${ms[m]}&u=${encodeURI(args.join(" "))}`); | |
if (!json[0]) return errorEmbed(nF); | |
json = json[0]; | |
const created = moment(json.join_date); | |
function osuE(f) { | |
return resolveEmoji(`osu${f}`); | |
} | |
const embed = advEmbed("#ff69b4", "https://s.ppy.sh/a/" + json.user_id, "osu!" + Object.keys(ms)[ms[m]], [ | |
`Name /// [${json.username}](https://osu.ppy.sh/users/${json.user_id}) (#${json.pp_rank})`, | |
`Country /// [${countries[json.country]}](https://osu.ppy.sh/rankings/osu/performance?country=${json.country}) (#${json.pp_country_rank})`, | |
`Created /// ${created.format(fmt)}`, | |
`Performance Points /// ${Math.floor(json.pp_raw).toLocaleString()}pp`, | |
`Level /// ${Math.floor(json.level)}`, | |
`Accuracy /// ${parseFloat(json.accuracy).toFixed(2)}%`, | |
`Play Count /// ${json.playcount.toLocaleString()}`, | |
`Rank Count /// ${osuE("a")} ${json.count_rank_a}\n${osuE("s")} ${json.count_rank_s}\n${osuE("sh")} ${json.count_rank_sh}\n${osuE("x")} ${json.count_rank_ss}\n${osuE("xh")} ${json.count_rank_ssh}`, | |
]); | |
channelSend(embed); | |
} | |
// | |
// | |
// | |
// Fun | |
// | |
// | |
// | |
if (cmd == "roll") { channelSend(advEmbed(0, 0, "Roll", "The dice landed on " + randomInt(6) + "!")); } | |
if (cmd == "fact") { | |
const json = await getJSON("https://uselessfacts.jsph.pl/random.json?language=en"); | |
channelSend(advEmbed(0, 0, "Random Fact", json.text.replace(/`/g, "'"))); | |
} | |
if (cmd == "joke") { | |
const json = await getJSON("https://official-joke-api.appspot.com/random_joke"); | |
channelSend(advEmbed(0, 0, "Random Joke", json.setup + "\n||" + json.punchline + "||")); | |
} | |
if (cmd == "gif") { | |
if (!args[0]) return cmdEmbed("GIF", "Fetches a GIF from multiple sources based on the given query. All GIFs are rated up to PG-13 only. Safe for work.", "gif <query>"); | |
let query = args.join(" "); | |
const json = await getJSON(``); | |
if (!json.result) return errorEmbed(nF); | |
imgEmbed("GIF", json.url); | |
} | |
if (cmd == "meme") { | |
const sentMsg = await loadingEmbed(); | |
const subreddits = [ | |
"AdviceAnimals", | |
"2meirl4meirl", | |
"dankmemes", | |
"me_irl", | |
"memes" | |
]; | |
const random = subreddits[randomInt(subreddits.length)]; | |
const json = await getJSON(`https://www.reddit.com/r/${random}/top/.json`); | |
const allowed = json.data.children.filter(p => !p.data.over_18); | |
const meme = allowed[randomInt(allowed.length)].data; | |
const embed = imgEmbed("Random Meme", meme.url, 1); | |
embed.addField("Title", `${meme.title}`); | |
embed.addField("Statistics", `${resolveEmoji("upvote")} ${meme.ups}`); | |
await channelSend(embed); | |
sentMsg.delete(); | |
} | |
if (cmd == "inspiro") { | |
const body = await getBody("https://inspirobot.me/api/?generate=true"); imgEmbed("InspiroBot", body); | |
} | |
if (cmd == "httpcat") { | |
if (!args[0]) return cmdEmbed("http.cat", "Fetches an image from http.cat based on the given status code (e.g. 404).", "httpcat <status code>"); | |
if (isNaN(args[0]) || args[0].length > 3 || args[0].includes(".")) return errorEmbed(iArg); | |
let url = `https://http.cat/${args[0]}`; | |
const res = await fetch(url); | |
if (!res || res.status != 200) url = "https://http.cat/404"; | |
imgEmbed("http.cat", url); | |
} | |
if (cmd == "cat") { | |
const json = await getJSON("https://api.thecatapi.com/v1/images/search"); imgEmbed("Random Cat", json[0].url); | |
} | |
if (cmd == "dog") { | |
const json = await getJSON("https://dog.ceo/api/breeds/image/random"); imgEmbed("Random Dog", json.message); | |
} | |
if (cmd == "fox") { | |
const json = await getJSON("https://randomfox.ca/floof/"); imgEmbed("Random Fox", json.image); | |
} | |
// | |
// | |
// | |
// HelioHost Addon | |
// | |
// | |
// | |
// HelioHost Python Information | |
const pyPath = "/usr/bin/python"; | |
const hhPy = { | |
"Tommy": "3.7", // krydos/flask/python/version/ | |
"pathTommy": pyPath + "3.7", | |
"djangoTommy": "2.1.13", | |
"flaskTommy": "1.1.1", // krydos/flask/flask/version/ | |
"modulesTommy": "http://krydos.heliohost.org/cgi-bin/modules37.py", | |
"Ricky": "3.6", // krydos1/flask/python/version/ | |
"pathRicky": pyPath + "3.6", | |
"djangoRicky": "1.11.4", | |
"flaskRicky": "0.12.2", // krydos1/flask/flask/version/ | |
"modulesRicky": "http://krydos1.heliohost.org/cgi-bin/modules36.py", | |
"Johnny": "3.7", // krydos2/flask/python/version/ | |
"pathJohnny": pyPath + "3.7", | |
"djangoJohnny": "2.1.13", | |
"flaskJohnny": "1.1.1", // krydos2/flask/flask/version/ | |
"modulesJohnny": "http://krydos2.heliohost.org/cgi-bin/modules37.py" | |
}; | |
const hhT = ""; | |
const hhC = "#ff9c00"; | |
function hhEmbed(title, description) { return advEmbed(hhC, hhT, title, description); } | |
const load = ".heliohost.org:2083/frontend/paper_lantern/load/index.live.php"; | |
const loadText = `**Tommy**\nhttps://tommy${load}\n\n**Ricky**\nhttps://ricky${load}\n\n**Johnny**\nhttps://johnny${load}`; | |
const hhInfo = { | |
"donate": "Donate /// https://www.heliohost.org/donate/", | |
"heliomine": "Download HelioMine /// https://www.heliohost.org/heliomine/", | |
"heliomine-scoreboard": "HelioMine Scoreboard /// https://www.heliohost.org/helioine/scoreboard/", | |
"namecheap": "Namecheap /// Buy a domain on Namecheap using our affiliate link to support us:\nhttps://www.heliohost.org/partners/namecheap", | |
"ns": "Nameservers /// `ns1.heliohost.org` and `ns2.heliohost.org`\n\n`ns1 = 65.19.143.3` and `ns2 = 64.62.211.133`", | |
"support": "Support /// **Customer Service Forum**\nhttps://www.helionet.org/index/forum/45-customer-service/" | |
+ "\n\n**Email Support**\nsupport@heliohost.org\n\n**Phone Support**\n+1 (802) 884-3546", | |
"vps": "Purchase a VPS /// https://www.heliohost.org/vps/", | |
"discord-bot": "Discord Bot Tutorial /// https://wiki.heliohost.org/tutorials/discord-bot", | |
"django": "Django Tutorial /// https://wiki.heliohost.org/tutorials/django", | |
"flask": "Flask Tutorial /// https://wiki.heliohost.org/tutorials/flask", | |
"ghost": "Ghost CMS Tutorial /// https://wiki.heliohost.org/tutorials/ghost", | |
"golang": "Golang Tutorial /// https://wiki.heliohost.org/tutorials/golang", | |
"nodejs": "Node.js Tutorial /// https://wiki.heliohost.org/tutorials/node.js", | |
"perl": "Perl Tutorial /// https://wiki.heliohost.org/tutorials/perl", | |
"ror": "Ruby on Rails Tutorial /// https://wiki.heliohost.org/tutorials/ror", | |
"ssl": "Setting up SSL on Johnny /// https://wiki.heliohost.org/management/johnny-ssl", | |
"tos": "Terms of Service /// https://wiki.heliohost.org/hosting/terms", | |
"delete": "Account Deletion Script /// http://www.heliohost.org/classic/support/scripts/delete", | |
"domain": "Domain Change Script /// http://heliohost.org/home/support/scripts/domain", | |
"monitor": "Server Monitor /// http://heliohost.grd.net.pl/monitor/", | |
"load": `Account Load /// ${loadText}`, | |
"permissions": "Permissions /// Make sure you set permission to 644 for files and 755 for folders to avoid internal server error.", | |
"signups": "Signups Reset Countdown /// http://flazepe.heliohost.org/?node=hhsignups" | |
}; | |
const hhCommands = Object.keys(hhInfo).join(", ") + ", status, heliomine-stats, python, sftp, news,\n" | |
+ "load <cody/tommy/ricky/johnny/lily>\n" | |
+ "uptime <tommy/ricky/johnny/lily>"; | |
const hhAL = ["cody", "tommy", "ricky", "johnny", "lily"]; | |
const hhAU = ["tommy", "ricky", "johnny", "lily"]; | |
if (cmd == "hh") { | |
if (!args[0]) return errorEmbed("Use `hh help`."); | |
const act = args.shift().toLowerCase(); | |
if (hhInfo[act] && !args[0]) { | |
return channelSend(hhEmbed(hhInfo[act].split("///")[0].trim(), hhInfo[act].split("///")[1].trim())); | |
} | |
args[0] ? s = args[0].toLowerCase() : s = ""; | |
switch(act) { | |
case "status": { | |
if (!args[0]) return errorEmbed(iArg); | |
const body = await getBody(`https://www.heliohost.org/status/?u=${args[0]}`); | |
const $ = cheerio.load(body); | |
const status = $("center p").text().trim(); | |
if (!status || status.includes("no account")) return errorEmbed(nF); | |
channelSend(hhEmbed("Status", `**Username**\n${args[0].toLowerCase()}\n\n**Status**\n${status}`)); | |
break; | |
} | |
case "heliomine-stats": { | |
if (!args[0]) return errorEmbed(iArg); | |
const body = await getBody("https://www.heliohost.org/heliomine/scoreboard/"); | |
const $ = cheerio.load(body); | |
const data = $("table#minetable tr:contains(" + args[1] + ") td").append(" ").text().split(" "); | |
if (!data[0]) return errorEmbed(nF); | |
const embed = new Discord.MessageEmbed() | |
.setColor(hhC) | |
.setThumbnail(hhT) | |
.setAuthor(authorText, authorIcon) | |
.setTitle("HelioMine Statistics") | |
.addField("Username", data[0], true) | |
.addField("Minutes Mining", data[7], true) | |
.addField("ETN This Month", data[1], true) | |
.addField("ETN Total", data[2], true) | |
.addField("AEON This Month", data[3], true) | |
.addField("AEON Total", data[4], true) | |
.addField("TRTL This Month", data[5], true) | |
.addField("TRTL Total", data[6], true) | |
.addField("USD This Month", data[8], true) | |
.addField("USD Total", data[9], true); | |
authorSend(embed); | |
break; | |
} | |
case "python": { | |
const embed = advEmbed(hhC, "", "Python Information", [ | |
"Tommy /// `Python version " + hhPy.Tommy + "`\n`Python path " + hhPy.pathTommy + "`\n`Django version " + hhPy.djangoTommy + "`\n`Flask version " + hhPy.flaskTommy + "`\n[Modules](" + hhPy.modulesTommy + ")", | |
"Ricky /// `Python version " + hhPy.Ricky + "`\n`Python path " + hhPy.pathRicky + "`\n`Django version " + hhPy.djangoRicky + "`\n`Flask version " + hhPy.flaskRicky + "`\n[Modules](" + hhPy.modulesRicky + ")", | |
"Johnny /// `Python version " + hhPy.Johnny + "`\n`Python path " + hhPy.pathJohnny + "`\n`Django version " + hhPy.djangoJohnny + "`\n`Flask version " + hhPy.flaskJohnny + "`\n[Modules](" + hhPy.modulesJohnny + ")", | |
]); | |
embed.setURL("https://wiki.heliohost.org/tutorials/django"); | |
channelSend(embed); | |
break; | |
} | |
case "sftp": { | |
const embed = advEmbed(hhC, hhT, "SFTP", [ | |
"Servers /// `tommy.heliohost.org`, `ricky.heliohost.org`, `johnny.heliohost.org`", | |
"Ports /// `tommy = 1342`, `ricky = 1312`, `johnny = 1373`" | |
]); | |
embed.setImage("") | |
channelSend(embed); | |
break; | |
} | |
case "load": { | |
if (hhAL.includes(s)) { | |
const body = await getBody("https://www.heliohost.org/load/load_" + s + ".html"); | |
authorSend(hhEmbed(`${flUpper(s)}'s Load`, body)); | |
} | |
break; | |
} | |
case "uptime": { | |
if (hhAU.includes(s)) { | |
const body = await getBody("https://www.heliohost.org/load/uptime_" + s + ".html"); | |
authorSend(hhEmbed(`${flUpper(s)}'s Uptime`, body + "%")); | |
} | |
break; | |
} | |
case "news": { | |
if (!msg.member.hasPermission("MANAGE_CHANNELS")) return errorEmbed("You have no permission to do that."); | |
var body = await getBody("https://www.helionet.org/index/rss/forums/1-heliohost-news/"); | |
var $ = cheerio.load(body); | |
const c = msg.guild.channels.cache.find(c => c.name == "news"); | |
if (c) c.send(`@everyone\n\n**${$("title").eq(1).text()}**\n\n${$("description").eq(1).text().replace("]]>", "")}\n\n<https://www.helionet.org/index/forum/1-news/>`, { split: 1 }) | |
.catch(e => { return; }); | |
break; | |
} | |
case "help": | |
channelSend(advEmbed(hhC, hhT, "HelioHost", [`Commands /// ${hhCommands}`])); | |
break; | |
default: channelSend(advEmbed(errorColor, 0, "Error", "Invalid HelioHost command.\n\nUse `" + prefix + "hh help` for help.")); break; | |
} | |
} | |
// Close error handler | |
} | |
catch(e) { | |
const errorID = Math.random().toString(36).slice(2, 12).toUpperCase(); | |
const log = `Aeon Error (${errorID}): ${e.message}\n${e.stack.split("\n")[1]}\n\n`; | |
fs.writeFileSync("error.log", log, { flag: "a" }); | |
console.log(log); | |
const embed = new Discord.MessageEmbed() | |
.setColor(errorColor) | |
.setTitle("Error") | |
.addField("Message", "An error occurred. Contact support server for more information.") | |
.addField("ID", errorID); | |
msg.channel.send(embed).catch(e => { return; }); | |
client.users.cache.find(u => u.id == flazepeID).send(log).catch(e => { return; }); | |
} | |
}); | |
client.on("guildDelete", async guild => { | |
await conn.query(`DELETE FROM prefixes WHERE server_id = ?`, guild.id); | |
// Prefix cache | |
delete prefixCache[guild.id]; | |
}); | |
client.on("voiceStateUpdate", (oldState, newState) => { | |
if (oldState.id != client.user.id) return; | |
const dispatcher = music.dispatchers[oldState.guild.id]; | |
if (!dispatcher) return; | |
if (!newState || !newState.connection) delete music.dispatchers[oldState.guild.id]; | |
}); | |
// | |
// | |
// | |
// Logs | |
// | |
// | |
// | |
client.on("channelCreate", channel => { | |
if (!channel.guild) return; | |
if (channel.type != "text" && channel.type != "voice") return; | |
let type = "Text"; | |
if (channel.type == "voice") type = "Voice"; | |
const embed = new Discord.MessageEmbed() | |
.setColor(successColor) | |
.setTitle(`${type} Channel Created`) | |
.setDescription(`${channel} (${channel.name})`); | |
logSend(embed, channel.guild); | |
}); | |
client.on("channelDelete", channel => { | |
if (!channel.guild) return; | |
if (channel.type != "text" && channel.type != "voice") return; | |
channel.type == "text" ? type = "Text" : type = "Voice"; | |
const embed = new Discord.MessageEmbed() | |
.setColor(errorColor) | |
.setTitle(`${type} Channel Deleted`) | |
.setDescription(`#${channel.name}`); | |
logSend(embed, channel.guild); | |
}); | |
client.on("roleCreate", role => { | |
if (!role.guild) return; | |
const embed = new Discord.MessageEmbed() | |
.setColor(successColor) | |
.setTitle("Role Created") | |
.setDescription(`${role} (${role.name})`); | |
logSend(embed, role.guild); | |
}); | |
client.on("roleDelete", role => { | |
if (!role.guild) return; | |
const embed = new Discord.MessageEmbed() | |
.setColor(errorColor) | |
.setTitle("Role Deleted") | |
.setDescription(`@${role.name}`); | |
logSend(embed, role.guild); | |
}); | |
client.on("guildBanAdd", (guild, user) => { | |
if (!guild) return; | |
const embed = new Discord.MessageEmbed() | |
.setColor(errorColor) | |
.setTitle("Banned") | |
.setDescription(`${user} (${user.tag})`); | |
logSend(embed, guild); | |
}); | |
client.on("guildBanRemove", (guild, user) => { | |
if (!guild) return; | |
const embed = new Discord.MessageEmbed() | |
.setColor(successColor) | |
.setTitle("Unbanned") | |
.setDescription(`${user} (${user.tag})`); | |
logSend(embed, guild); | |
}); | |
// | |
// | |
// | |
// Global Functions | |
// | |
// | |
// | |
function logSend(msg, guild) { | |
let c = guild.channels.cache.find(c => c.name == "logs"); | |
if (!c) return; | |
c.fetch().then(c => { | |
c.send(msg).catch(e => { return; }); | |
}) | |
.catch(e => { return; }); | |
} | |
function flUpper(string) { return string.slice(0, 1).toUpperCase() + string.slice(1); } | |
function randomInt(max) { return Math.floor(Math.random() * Math.floor(max) + 1); } | |
function perm(f1, f2) { | |
let string = "I need permission(s) below in order to make this command work:\n\n"; | |
if (f1 == 2) string = "You need permission(s) below in order to use this command:\n\n"; | |
if (Array.isArray(f2)) return string + `- ${f2.join("\n- ")}`; | |
else return string + `- ${f2}`; | |
} | |
// | |
// | |
// | |
// ? | |
// | |
// | |
// | |
const defaultPrefix = "."; | |
const primaryColor = "#007acc"; | |
const successColor = "#7ce26f"; | |
const noticeColor = "#ffa321"; | |
const errorColor = "#ca745e"; | |
const iArg = "Invalid argument."; | |
const nF = "Not found."; | |
const rL = "Rate limited."; | |
const noVoice = "Member must be connected to a voice channel that is accessible by Aeon."; | |
const fmt = "dddd, D MMMM YYYY [at] h:mma"; | |
const flazepeID = "590455379931037697"; | |
const cmds = [` | |
General /// | |
status | |
prefix | |
ping | |
invite | |
`, | |
`Moderation /// | |
mute, unmute | |
ban, unban | |
kick | |
purge | |
embed | |
`, | |
`Discord /// | |
user, bot | |
avatar | |
server | |
emoji | |
`, | |
`Utility /// | |
poll, vote | |
qr | |
shorten | |
`, | |
`Language /// | |
urban | |
`, | |
`Music /// | |
play, pause, resume, volume | |
skip, stop/leave | |
queue, remove, clear, np | |
lyrics | |
`, | |
`Information /// | |
covid | |
wikipedia | |
movie, tv | |
anime, manga | |
weather, time | |
stock | |
`, | |
`Development /// | |
hastebin | |
npm | |
`, | |
`Social Media /// | |
youtube | |
`, | |
`Gaming /// | |
pokemon | |
osu | |
`, | |
`Fun /// | |
roll | |
fact | |
joke | |
gif | |
meme | |
inspiro | |
httpcat | |
cat, dog, fox | |
`]; | |
// Log in | |
client.login(beta ? betaToken : token); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment