mirror of
https://github.com/ION606/selmerBot.git
synced 2026-05-14 21:26:54 +00:00
Added presence-changing commands to make dynamic bot moddification easier
This commit is contained in:
@@ -0,0 +1,84 @@
|
|||||||
|
const Discord = require('discord.js')
|
||||||
|
const axios = require('axios')
|
||||||
|
const cheerio = require('cheerio');
|
||||||
|
const { URL } = require("url");
|
||||||
|
|
||||||
|
function isValidUrl(s) {
|
||||||
|
try {
|
||||||
|
new URL(s);
|
||||||
|
return true;
|
||||||
|
} catch (err) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
function handleStreamInp(bot, url, customTitle) {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
if (!isValidUrl(url)) {
|
||||||
|
return reject(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
axios.get(url).then(async response => {
|
||||||
|
var title;
|
||||||
|
|
||||||
|
if (customTitle) {
|
||||||
|
title = customTitle;
|
||||||
|
} else {
|
||||||
|
const html = response.data;
|
||||||
|
const $ = cheerio.load(html);
|
||||||
|
title = $('meta[name="description"]').attr("content");
|
||||||
|
}
|
||||||
|
|
||||||
|
bot.user.setActivity({name: title, type: "STREAMING", url: url});
|
||||||
|
|
||||||
|
resolve(true);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
//Have this only visible to you.
|
||||||
|
/**
|
||||||
|
* @param {Discord.Client} bot
|
||||||
|
* @param {Discord.Interaction} interaction
|
||||||
|
*/
|
||||||
|
async function setPresence(bot, interaction) {
|
||||||
|
const command = interaction.options.data[0];
|
||||||
|
|
||||||
|
if (command.name == "setpresence") {
|
||||||
|
const txt = command.options.filter((arg) => { return(arg.name == 'pres_text'); })[0].value;
|
||||||
|
const type = command.options.filter((arg) => { return(arg.name == 'type'); })[0].value;
|
||||||
|
|
||||||
|
var sep = " ";
|
||||||
|
if (type == "LISTENING" || type == "WATCHING") {
|
||||||
|
sep = " to ";
|
||||||
|
} else if (type == "COMPETING") {
|
||||||
|
sep = " in ";
|
||||||
|
}
|
||||||
|
|
||||||
|
//Check if it's me
|
||||||
|
if (interaction.user.id == bot.guilds.cache.get(bot.home_server).ownerId) {
|
||||||
|
if (type == "STREAMING") {
|
||||||
|
const t = (command.options.length > 2) ? command.options.filter((arg) => { return(arg.name == "display_name"); })[0].value : null;
|
||||||
|
|
||||||
|
handleStreamInp(bot, txt, t, interaction).then(() => {
|
||||||
|
interaction.reply(`Set bot presence to _${type + sep + txt}_`);
|
||||||
|
}).catch(() => {
|
||||||
|
interaction.reply("Invalid URL").catch((err) => {
|
||||||
|
interaction.channel.send("Invalid URL");
|
||||||
|
});
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
bot.user.setActivity(txt, { type: type });
|
||||||
|
interaction.reply(`Set bot presence to _${type + sep + txt}_`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else if (command.name == "setactivity") {
|
||||||
|
const stat = command.options[0];
|
||||||
|
|
||||||
|
bot.user.setStatus(stat.value);
|
||||||
|
interaction.reply(`Set bot status to ${stat.value}`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
module.exports = { setPresence }
|
||||||
@@ -1,5 +1,7 @@
|
|||||||
// // @ts-check //Disabled
|
// // @ts-check //Disabled
|
||||||
|
|
||||||
|
// Maybe have the interaction type be "user" https://canary.discord.com/developers/docs/interactions/application-commands#application-command-object-application-command-types
|
||||||
|
|
||||||
const { MongoClient, ServerApiVersion } = require('mongodb');
|
const { MongoClient, ServerApiVersion } = require('mongodb');
|
||||||
let ecoimport = require("../db/econ.js");
|
let ecoimport = require("../db/econ.js");
|
||||||
|
|
||||||
@@ -20,7 +22,7 @@ const { chooseClass, presentClasses } = require('./game_classes.js');
|
|||||||
|
|
||||||
//Has a list of all games (used to change player state)
|
//Has a list of all games (used to change player state)
|
||||||
const allGames = ['battle', 'Tic Tac Toe'];
|
const allGames = ['battle', 'Tic Tac Toe'];
|
||||||
// const { NULL } = require('mysql/lib/protocol/constants/types');
|
|
||||||
|
|
||||||
|
|
||||||
//#region functions (NOT GAME SPECIFIC)
|
//#region functions (NOT GAME SPECIFIC)
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ const { devCheck } = require('./commands/dev only/devcheck.js');
|
|||||||
const { moderation_handler } = require('./commands/admin/moderation.js');
|
const { moderation_handler } = require('./commands/admin/moderation.js');
|
||||||
const { registerCommands } = require('./registerCommands.js');
|
const { registerCommands } = require('./registerCommands.js');
|
||||||
const { backupLists, loadBotBackups } = require('./commands/admin/backupBot.js');
|
const { backupLists, loadBotBackups } = require('./commands/admin/backupBot.js');
|
||||||
|
const { setPresence } = require('./commands/dev only/setPresence.js');
|
||||||
const { exit } = require('process');
|
const { exit } = require('process');
|
||||||
//#endregion
|
//#endregion
|
||||||
|
|
||||||
@@ -184,9 +185,15 @@ bot.on('ready', async () => {
|
|||||||
items = [...itemstemp];
|
items = [...itemstemp];
|
||||||
});
|
});
|
||||||
|
|
||||||
//Srt status and Activity (idle and listening to !help)
|
|
||||||
bot.user.setActivity(`${bot.prefix}help`, { type: "LISTENING" });
|
bot.user.setStatus('idle');
|
||||||
// bot.user.setStatus('idle');
|
//Why doesn't this work?
|
||||||
|
// bot.user.setPresence({
|
||||||
|
// status: 'online', activity: {
|
||||||
|
// name: "It's only logical!",
|
||||||
|
// type: "LISTENING"
|
||||||
|
// }
|
||||||
|
// });
|
||||||
});
|
});
|
||||||
|
|
||||||
//Note the xp numbers are a little wonky on levels 6, 8 and 13 (why though?)
|
//Note the xp numbers are a little wonky on levels 6, 8 and 13 (why though?)
|
||||||
@@ -216,14 +223,22 @@ bot.on('ready', async () => {
|
|||||||
//Button Section
|
//Button Section
|
||||||
bot.on('interactionCreate', async interaction => {
|
bot.on('interactionCreate', async interaction => {
|
||||||
const { commandName } = interaction;
|
const { commandName } = interaction;
|
||||||
bot.lockedChannels.set(interaction.guildId, ["NUMBERS HERE"]);
|
|
||||||
// console.log(bot.lockedChannels);
|
// console.log(bot.lockedChannels);
|
||||||
//Slash commands
|
//Slash commands
|
||||||
if (interaction.isApplicationCommand()) {
|
if (interaction.isApplicationCommand()) {
|
||||||
const logable = ['kick', 'ban', 'unban', 'mute', 'unmute', 'timeout'];
|
const logable = ['kick', 'ban', 'unban', 'mute', 'unmute', 'timeout'];
|
||||||
const econList = ["buy", 'shop', 'work', 'rank', 'inventory', 'balance', 'sell'];
|
const econList = ["buy", 'shop', 'work', 'rank', 'inventory', 'balance', 'sell'];
|
||||||
|
const adminList = ["setpresence", "setactivity"];
|
||||||
|
|
||||||
if (logable.includes(commandName)) {
|
if (commandName == "admin" && adminList.includes(interaction.options.data[0].name)) {
|
||||||
|
if (interaction.user.id == bot.guilds.cache.get(bot.home_server).ownerId) {
|
||||||
|
setPresence(bot, interaction);
|
||||||
|
} else {
|
||||||
|
return interaction.reply({ content: "HAHAHAHAHAHAHAHAHAHAHA\n\nno.", ephemeral: true }).catch((err) => {
|
||||||
|
interaction.channel.send({ content: "HAHAHAHAHAHAHAHAHAHAHA\n\nno.", ephemeral: true });
|
||||||
|
});
|
||||||
|
}
|
||||||
|
} else if (logable.includes(commandName)) {
|
||||||
moderation_handler(bot, interaction, commandName);
|
moderation_handler(bot, interaction, commandName);
|
||||||
} else if (econList.includes(commandName)) {
|
} else if (econList.includes(commandName)) {
|
||||||
bot.commands.get('econ').execute(bot, interaction, Discord, mongouri, items, xp_collection);
|
bot.commands.get('econ').execute(bot, interaction, Discord, mongouri, items, xp_collection);
|
||||||
|
|||||||
@@ -76,6 +76,40 @@ function registerCommands(bot) {
|
|||||||
// comm.setDefaultMemberPermissions(Discord.PermissionFlagsBits.KickMembers | Discord.PermissionFlagsBits.BanMembers);
|
// comm.setDefaultMemberPermissions(Discord.PermissionFlagsBits.KickMembers | Discord.PermissionFlagsBits.BanMembers);
|
||||||
// });
|
// });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//Admin commands (Home Server only)
|
||||||
|
const guild = bot.guilds.cache.get(bot.home_server);
|
||||||
|
guild.commands.create({
|
||||||
|
name: "admin",
|
||||||
|
description: "admin commands",
|
||||||
|
// type: Constants.ApplicationCommandOptionTypes.SUB_COMMAND_GROUP,
|
||||||
|
options: [
|
||||||
|
{
|
||||||
|
name: "setpresence",
|
||||||
|
description: "Change the bot's presence",
|
||||||
|
type: Constants.ApplicationCommandOptionTypes.SUB_COMMAND,
|
||||||
|
options: [
|
||||||
|
{name: "pres_text", description: "The new presence text", type: Constants.ApplicationCommandOptionTypes.STRING, required: true },
|
||||||
|
{name: "type", description: "The new presence text", type: Constants.ApplicationCommandOptionTypes.STRING, required: true, choices: [
|
||||||
|
{name: "LISTENING", value: "LISTENING"}, {name: "WATCHING", value: "WATCHING"}, {name: "COMPETING", value: "COMPETING"}, {name: "PLAYING", value: "PLAYING"}, { name: "STREAMING", value: "STREAMING"}
|
||||||
|
]},
|
||||||
|
{name: 'display_name', description: "What to display instead of the stream's title", type: Constants.ApplicationCommandOptionTypes.STRING, required: false}
|
||||||
|
],
|
||||||
|
dm_permission: false
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "setactivity",
|
||||||
|
description: "Change the bot's activity",
|
||||||
|
type: Constants.ApplicationCommandOptionTypes.SUB_COMMAND,
|
||||||
|
options: [
|
||||||
|
{name: "type", description: "The new presence text", type: Constants.ApplicationCommandOptionTypes.STRING, required: true, choices: [
|
||||||
|
{name: "Do Not Disturb", value: "dnd"}, {name: "Idle", value: "idle"}, {name: "invisible", value: "invisible"}, {name: "online", value: "online"}
|
||||||
|
]},
|
||||||
|
],
|
||||||
|
dm_permission: false
|
||||||
|
},
|
||||||
|
]
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user