Added the 'tuto' command and fixed some bugs

This commit is contained in:
ION606
2022-08-17 20:21:19 -07:00
parent b7d51c2d14
commit 9de7eecdd9
7 changed files with 166 additions and 19 deletions
+82
View File
@@ -0,0 +1,82 @@
// @ts-check
const { MessageActionRow, MessageButton, MessageEmbed, Interaction } = require('discord.js');
//Intro, setup/logging, Econ, Moderation, anime/manga, games, Selmer Specific, Misc, DMS/Premium
const tutoText = [
"__**Hello, and welcome to the Selmer Bot tutorial!**__\nIn this tutorial, I will walk you through the various commands and features of Selmer Bot!\n\nTo progress to the next page, click the right arrow at the bottom of this message.\nTo go back to the previous page, click the left arrow",
"__**SETUP AND LOGGING**__\nSet up your server to take full advantage of Selmer Bot's features, this includes moderation logging, custom welcome messages, calendar event pings and more!\n_Note: Most of these commands are only available to the server owner_\n\n__***COMMANDS***__\n!setup help welcome, !setup help logs, !setup help announcement, !setup welcome_channel, !setup welcome_message, !setup keep_logs, !setup log_channel, !setup log_severity, !setup announcement_channel, !setup announcement_role",
"__**ECONOMY**__\nThese commands have to do with the inventory and currency system Selmer Bot uses, although I should note that as of now Selmer Coin holds no IRL value ;-;\n\n__***COMMANDS***__\n!inventory, !buy, !sell, !shop, !work, !rank, !balance",
"__**MODERATION**__\nI mean....\n\n***__COMMANDS__***\n!help admin, !warn, !mute, !unmute, !kick, !ban, !unban, !lock, !unlock, !serverlock",
"__**AMIME AND MANGA**__\nGet info on your favorite Anime or Manga as a stat-sheet, a fancy embed, or have Selmer Bot describe it to you!\n\n__***COMMANDS***__\n!asearch, !msearch",
"__**GAMES**__\nAt the moment Selmer Bot only offers two games: Trivia and Tic Tac Toe. Both games can be played with other people, but only Trivia can be played solo. Selmer Bot also has a battle game where you can use weapons, potions, attack and defend, but this is still in beta\n\n__***COMMANDS***__\n!help game, !game battle !game tictactoe, !game trivia, !game equip, !game status, !game hp, !game classes, !game quit",
"__**SELMER SPECIFIC**__\nThese commands will probably be found nowhere else!\nThese include quotes (For legal reasons I have to state they aren't real quotes, mostly), as well as varius other things I based on good old Selmer\n\n__***COMMANDS***__\n!arrow, !extracredit, !tuto, !profile, !quotes",
"__**MISCELLANEOUS**__\nThese are the commands that are not really in any of the other categories. Don't be fooled, these are actually some of the most useful commands Selmer Bot has to offer. From playing music to web scraping to memes, I'm sure Selmer Bot has what you're looking for!\n\n__***COMMANDS***__\n!help, !kareoke, !link, !meme, !pickupline, !audio, !react, !scrape",
"__**DM COMMANDS**__\nThese commands will only work in DM's. All these commands will only work with Selmer Bot Premium (it's on the next page).\nThese features include Reminders (AKA a calendar) and Selmer Bot's own chat AI!\n\n__***COMMANDS***__\n!chat, !startconvo, !endconvo, !premium",
"__**SELMER BOT PREMIUM**__\nUse an AI chat, complete with semi-accurate IRL data, have Selmer Bot remind you of events with an easy-to-use interface and even a clickable calendar on the Selmer Bot website (_www.selmerbot.com_)\n\n__***COMMANDS***__\n!premium, !premium buy, !premium manage, !reminders",
"__**Thank you for completing the Selmer Bot Tutorial!**__\n\nTry out all Selmer Bot's features, play the games and most importantly, have fun!\n\n-The Selmer Bot Team AKA ION606"
];
//If the page number == 0 and refered == false, then interaction will be a Message
function postEmbd(bot, interaction, page, refered) {
const author = {
name: "Selmer Bot",
url: "",
iconURL: bot.user.displayAvatarURL()
};
//Tutorial Embed
const te = new MessageEmbed();
te.setAuthor(author)
.setTitle("Selmer Bot Tutorial")
.setDescription(tutoText[page])
.setURL('https://www.selmerbot.com/')
.setFooter({ text: `Page ${page + 1}` });
if (tutoText[page].indexOf('Thank you for completing the Selmer Bot Tutorial') != -1) {
te.setImage('https://github.com/ION606/selmerBot/blob/main/assets/Sleemer_Bringsjorgend.png?raw=true');
}
const row = new MessageActionRow();
//Make sure the page is never < 1
const prevbtn = new MessageButton()
.setCustomId(`tutoQueue|`)
.setLabel('⬅️')
.setStyle('SECONDARY');
if (page <= 0) {
prevbtn.customId += `0`;
prevbtn.setDisabled(true);
} else {
prevbtn.customId += `${page - 1}`;
}
const nextbtn = new MessageButton()
.setCustomId(`tutoQueue|`)
.setLabel('➡️')
.setStyle('SECONDARY');
if ((page + 1) >= tutoText.length) {
nextbtn.customId += `${tutoText.length}`;
nextbtn.setDisabled(true);
} else {
nextbtn.customId += `${page + 1}`;
}
row.addComponents(prevbtn, nextbtn);
if (page > 0 || refered) {
interaction.update({ content: '_Note: To see a full list of reminder stats visit www.selmerbot.com _', embeds: [te], components: [row] });
} else {
interaction.reply({ content: '_Note: To see a full list of reminder stats visit www.selmerbot.com _', embeds: [te], components: [row] });
}
}
module.exports = {
name: 'tuto',
description: 'An introduction command to Selmer Bot',
async execute(message, args, Discord, Client, bot) {
postEmbd(bot, message, 0, false);
}, postEmbd
}
+11 -3
View File
@@ -1,8 +1,16 @@
function checkRole(bot, guild, userId) { function checkRole(bot, guild, userId, cal = false) {
const role = guild.roles.cache.find((role) => { return (role.name == 'Selmer Bot Commands'); }) var roleName;
if (cal) {
roleName = "Selmer Bot Calendar";
} else {
roleName = "Selmer Bot Commands";
}
const role = guild.roles.cache.find((role) => { return (role.name == roleName); })
const user = guild.members.cache.get(userId); const user = guild.members.cache.get(userId);
return (user.roles.cache.get(role.id) || user.id == guild.ownerId || bot.inDebugMode); return (role != undefined && user.roles.cache.has(role.id)); // || user.id == guild.ownerId || bot.inDebugMode
/*Maybe implement this later, useless for now /*Maybe implement this later, useless for now
+3 -2
View File
@@ -141,6 +141,7 @@ function hpmp(message, command, dbo) {
function equip(message, args, command, dbo, bot, shop) { function equip(message, args, command, dbo, bot, shop) {
const inp = args[1]; const inp = args[1];
if (!inp) { return message.reply("Please provide input (either a weapon for main or shield for secondary)")}
//Check if the user is already in a game //Check if the user is already in a game
dbo.find({'game': {$exists: true}}).toArray(function(err, docs) { dbo.find({'game': {$exists: true}}).toArray(function(err, docs) {
@@ -370,14 +371,14 @@ module.exports ={
//Handle sending the request and making sure the user exists here //Handle sending the request and making sure the user exists here
let other_discord = message.mentions.users.first(); let other_discord = message.mentions.users.first();
if (other_discord == undefined) { if (other_discord == undefined) {
return message.reply(`${args[1]} is not a valid user!`); return message.reply(`"${args[1]}" is not a valid user (use _!game battle @user_)`);
} }
message.channel.send(`${other_discord}, <@${message.author.id}> has invited you to play _"battle"_. To accept, please reply to this message with _!game accept_`); message.channel.send(`${other_discord}, <@${message.author.id}> has invited you to play _"battle"_. To accept, please reply to this message with _!game accept_`);
} else if (game == 'Tic Tac Toe' || command == 'Tic Tac Toe') { } else if (game == 'Tic Tac Toe' || command == 'Tic Tac Toe') {
let other_discord = message.mentions.users.first(); let other_discord = message.mentions.users.first();
if (other_discord == undefined) { if (other_discord == undefined) {
return message.reply(`${args[1]} is not a valid user!`); return message.reply(`"${args[1]}" is not a valid user (use _!game tictactoe @user_)`);
} }
message.channel.send(`${other_discord}, <@${message.author.id}> has invited you to play _"Tic Tac Toe"_. To accept, please reply to this message with _!game accept_`); message.channel.send(`${other_discord}, <@${message.author.id}> has invited you to play _"Tic Tac Toe"_. To accept, please reply to this message with _!game accept_`);
+4
View File
@@ -3,6 +3,7 @@ const { createSubscriptionManual } = require('./premium/stripe.js');
const { pause_start_stop, playNext, showQueue } = require('./misc/playAudio.js'); const { pause_start_stop, playNext, showQueue } = require('./misc/playAudio.js');
const { resolveComplaint } = require('./dev only/submitcomplaint.js'); const { resolveComplaint } = require('./dev only/submitcomplaint.js');
const reminders = require('./premium/reminders.js'); const reminders = require('./premium/reminders.js');
const tuto = require('../commands/Selmer Specific/intro');
// const { RSSInteractionHandler } = require('./premium/rssFeed.js'); // const { RSSInteractionHandler } = require('./premium/rssFeed.js');
const { Interaction } = require('discord.js') const { Interaction } = require('discord.js')
@@ -81,6 +82,9 @@ async function handle_interaction(interaction, mongouri, turnManager, bot, STATE
reminders.modalHandle(bot, interaction); reminders.modalHandle(bot, interaction);
} else if (interaction.customId.indexOf('reminderQueue') != -1) { } else if (interaction.customId.indexOf('reminderQueue') != -1) {
reminders.turnPage(bot, interaction); reminders.turnPage(bot, interaction);
} else if (interaction.customId.indexOf("tutoQueue") != -1){
const page = Number(interaction.customId.split('|')[1]);
tuto.postEmbd(bot, interaction, page, true);
} //Button else ifs here } //Button else ifs here
}); });
} }
+1 -1
View File
@@ -5,7 +5,7 @@ module.exports ={
description: "Gets help for all of Selmer Bot's commands", description: "Gets help for all of Selmer Bot's commands",
execute(message, args, Discord, Client, bot) { execute(message, args, Discord, Client, bot) {
const groups = new Map([['SBspec', ['arrow', 'extracredit', 'profile', 'quotes']], ['adminCommands', [ 'setup', 'lock', 'unlock', 'serverLock' ]]]); const groups = new Map([['SBspec', ['arrow', 'extracredit', 'profile', 'quotes']], ['adminCommands', [ 'setup', 'lock', 'unlock', 'serverlock' ]]]);
if (args[0] == 'econ') { if (args[0] == 'econ') {
let temp = "***Selmer Bot Commands (Econ):***\n"; let temp = "***Selmer Bot Commands (Econ):***\n";
+17 -12
View File
@@ -1,4 +1,5 @@
const { Modal, TextInputComponent, MessageActionRow, MessageButton, MessageEmbed, Interaction } = require('discord.js'); const { Modal, TextInputComponent, MessageActionRow, MessageButton, MessageEmbed, Interaction } = require('discord.js');
const { checkRole } = require('../admin/verify');
/** /**
@@ -126,26 +127,27 @@ async function postForm(interaction, isGuild = false) {
//#region DATABASE PROCESSING //#region DATABASE PROCESSING
//ADD SERVER SUPPORT
function addEvent(obj, connection, interaction, embd) { function addEvent(obj, connection, interaction, embd) {
try { try {
// console.log(obj.time, typeof obj.time); return; var Id;
if (obj.event.userId != null) { Id = obj.event.userId }
else { Id = obj.event.guildId; }
connection.then((client) => { connection.then((client) => {
// Update the Key object first to check if the time is already there // Update the Key object first to check if the time is already there
const kbo = client.db('main').collection('reminderKeys'); const kbo = client.db('main').collection('reminderKeys');
kbo.findOne(({ 'userId': obj.event.userId })).then((doc) => { kbo.findOne(({ 'userId': Id })).then((doc) => {
const t = obj.time.toString(); const t = obj.time.toString();
try { try {
if (doc) { if (doc) {
if (doc.times.indexOf(obj.time) == -1) { if (doc.times.indexOf(obj.time) == -1) {
kbo.updateOne({ 'userId': obj.event.userId }, { $push: { times: t } }) kbo.updateOne({ 'userId': Id }, { $push: { times: t } })
} else { } else {
//Event already exists at this time //Event already exists at this time
return interaction.reply("An event already exists at this time!"); return interaction.reply("An event already exists at this time!");
} }
} else { } else {
doc = { userId: obj.event.userId, times: [t] } doc = { userId: Id, times: [t] }
kbo.insertOne(doc); kbo.insertOne(doc);
} }
@@ -201,7 +203,7 @@ function getEvents(bot, interaction, id, jpage = 0, isGuild = false, refered = f
} }
bot.mongoconnection.then((client) => { bot.mongoconnection.then((client) => {
try { try {
var times; var times;
const dbo = client.db('main').collection('reminderKeys'); const dbo = client.db('main').collection('reminderKeys');
@@ -247,13 +249,16 @@ function getEvents(bot, interaction, id, jpage = 0, isGuild = false, refered = f
//fields: [<name>, <description>, <date>, <time>, [offset], [url], [location]] //fields: [<name>, <description>, <date>, <time>, [offset], [url], [location]]
function processForm(bot, interaction) { function processForm(bot, interaction) {
try { try {
var guildId = null; var guildId = null;
var userId = null; var userId = null;
if (interaction.channel.type == 'DM') { var isGuild = false;
if (interaction.customId.toLowerCase().indexOf('user') != -1) {
userId = interaction.user.id; userId = interaction.user.id;
} else { } else {
guildId = interaction.guildId; guildId = interaction.guildId;
isGuild = true;
} }
@@ -315,7 +320,7 @@ function processForm(bot, interaction) {
); );
const obj = { time: timeUTC, event: { guildId: guildId, userId: userId, name: name, description: desc, offset: 0, link: url, location: loc } } const obj = { time: timeUTC, event: { guildId: guildId, userId: userId, name: name, description: desc, offset: 0, link: url, location: loc } }
addEvent(obj, bot.mongoconnection, interaction, embd); addEvent(obj, bot.mongoconnection, interaction, embd, isGuild);
} catch (err) { } catch (err) {
console.error(err); console.error(err);
} }
@@ -379,7 +384,7 @@ module.exports = {
.setStyle('SUCCESS'), .setStyle('SUCCESS'),
new MessageButton() new MessageButton()
.setCustomId('getEvents') .setCustomId('getEvents')
.setLabel('See Reminders') .setLabel('See Personal Reminders')
.setStyle('PRIMARY'), .setStyle('PRIMARY'),
); );
} else { } else {
@@ -394,12 +399,12 @@ module.exports = {
.setStyle('SUCCESS'), .setStyle('SUCCESS'),
new MessageButton() new MessageButton()
.setCustomId('getEvents') .setCustomId('getEvents')
.setLabel('See Reminders') .setLabel('See Guild Reminders')
.setStyle('PRIMARY'), .setStyle('PRIMARY'),
); );
} }
return message.channel.send({ content: 'Please select an action (note that adding offset to an event is only supported on the website)', components: [row] }); return message.channel.send({ content: 'Please select an action\n_Notes: Adding offset to an event is only supported on the website and personal reminders can be viewed in DM\'s_', components: [row] });
} else { } else {
message.reply("You have to be a premium subscriber to use this feature!\n_support coming soon_"); message.reply("You have to be a premium subscriber to use this feature!\n_support coming soon_");
} }
+48 -1
View File
@@ -201,11 +201,15 @@ bot.on("guildCreate", guild => {
guild.roles.create({ name: 'Selmer Bot Commands' }); guild.roles.create({ name: 'Selmer Bot Commands' });
} }
if (guild.roles.cache.find((role) => { return (role.name == 'Selmer Bot Calendar'); }) == undefined) {
guild.roles.create({ name: 'Selmer Bot Calendar' });
}
//const role = guild.roles.cache.find((role) => role.name === 'Selmer Bot Mod'); // member.roles.cache.has('role-id-here'); //const role = guild.roles.cache.find((role) => role.name === 'Selmer Bot Mod'); // member.roles.cache.has('role-id-here');
const server = bot.guilds.cache.get(guild.id); const server = bot.guilds.cache.get(guild.id);
const owner = server.members.fetch(guild.ownerId).then(function(owner) { const owner = server.members.fetch(guild.ownerId).then(function(owner) {
owner.send('Thank you for adding Selmer Bot to your server!\nPlease give people you want to have access to Selmer Bot\'s restricted commands the "_Selmer Bot Commands_" role.'); owner.send('Thank you for adding Selmer Bot to your server!\nPlease give people you want to have access to Selmer Bot\'s restricted commands the "_Selmer Bot Commands_" role and people you want to access set the calendar the "Selmer Bot Calendar" role');
owner.send('To help set up Selmer Bot to work better with your server, use _!setup help_ in a channel Selmer Bot is in!'); owner.send('To help set up Selmer Bot to work better with your server, use _!setup help_ in a channel Selmer Bot is in!');
}); });
@@ -218,6 +222,49 @@ bot.on("guildCreate", guild => {
}); });
bot.on("guildDelete", guild => {
bot.mongoconnection.then((client) => {
//Insufficient Permission????
// db.dropDatabase();
try {
const db = client.db(guild.id);
db.listCollections().forEach(function(x) { db.collection(x.name).drop(); });
var times;
const dbo = client.db('main').collection('reminderKeys');
//ReminderKeys are all stored as userId, the reminders themselves are not
dbo.findOne({userId: guild.id}).then((doc) => {
times = doc.times;
const tbo = client.db('main').collection('reminders');
tbo.find({time: {$in: times}}).toArray((err, docs) => {
for (let i = 0; i < docs.length; i ++) {
for (let j in docs[i]) {
if (!isNaN(j) && (docs[i][j].guildId == guild.id)) {
delete docs[i][j];
docs[i].amt --;
}
}
if (docs.amt > 0) {
tbo.replaceOne({ time: docs[i].time }, docs[i]);
} else {
tbo.deleteOne({ time: docs[i].time });
}
}
});
});
dbo.deleteOne({ userId: guild.id });
} catch (err) {
console.log(err);
}
})
});
//Welcome new members //Welcome new members
bot.on('guildMemberAdd', async (member) => { bot.on('guildMemberAdd', async (member) => {