Added the 'poll' and 'code/repo' commands, as well as added single/multiplayer functionality to 'Minesweeper'

This commit is contained in:
ION606
2022-09-06 15:29:48 -04:00
parent af8f9f69ae
commit 27fecfffcb
8 changed files with 152 additions and 10 deletions
+32
View File
@@ -0,0 +1,32 @@
const { MessageEmbed, MessageActionRow, MessageButton, Interaction } = require('discord.js');
module.exports = {
name: 'code',
description: 'See where Selmer bot\'s code is stored! (you can also use _!repo_)',
execute(message, args, Discord, Client, bot) {
const embd = new MessageEmbed()
.setAuthor({ name: "Selmer Bot", url: bot.inviteLink, iconURL: bot.user.displayAvatarURL() })
.setThumbnail("https://github.com/ION606/selmer-bot-website/blob/main/assets/Selmer-icon.png?raw=true") // .setThumbnail('https://repository-images.githubusercontent.com/460670550/43932b23-d795-4334-838f-f33ee8f795c4')
.setDescription("Selmer Bot was created by ION606");
const row = new MessageActionRow()
.addComponents([
new MessageButton()
.setStyle("LINK")
.setURL("https://github.com/ION606/selmerBot")
.setLabel("Github Repo"),
new MessageButton()
.setStyle("LINK")
.setURL("https://www.selmerbot.com/")
.setLabel("Website"),
new MessageButton()
.setStyle("PRIMARY")
.setLabel("Tutorial")
.setCustomId("sbtutorial")
]);
message.reply({ embeds: [embd], components: [row] })
}
}
+7 -2
View File
@@ -1,6 +1,7 @@
const { convoManager } = require('./premium/chat.js');
const { handleInp } = require('./premium/stripe');
const reminders = require('./premium/reminders.js')
const reminders = require('./premium/reminders.js');
const repo = require('./Selmer Specific/repo.js');
const { MongoClient, ServerApiVersion, ConnectionClosedEvent } = require('mongodb');
function handle_dm(message, bot) {
@@ -26,7 +27,11 @@ function handle_dm(message, bot) {
handleInp(bot, message);
} else if (message.content.indexOf('!reminders') != -1) {
reminders.execute(message, null, null, null, bot);
} else {
} else if (message.content.indexOf('!repo') != -1 || message.content.indexOf('!code') != -1) {
repo.execute(message, null, null, null, bot);
}
else {
return message.reply('UNUSABLE DM COMMAND DETECTED');
}
+17 -5
View File
@@ -3,7 +3,7 @@ const { winGame, loseGame, equipItem } = require('./external_game_functions.js')
const wait = require('node:timers/promises').setTimeout;
const { STATE } = require('../db/econ.js')
function startGame(bot, channel, args) {
function startGame(bot, channel, message, args) {
let componentlist = [];
var diff;
@@ -17,6 +17,11 @@ function startGame(bot, channel, args) {
diff = 0;
}
let user = '';
if (args.length < 2 || args[1] == 'solo') {
user = message.author.id;
}
for (let i = 0; i < 5; i ++) {
const row = new MessageActionRow();
@@ -26,9 +31,9 @@ function startGame(bot, channel, args) {
const isbmb = (Math.random() > (0.70 - diff));
if (isbmb) {
btn.setCustomId(`mswpr|${i}|${j}|t`);
btn.setCustomId(`mswpr|${i}|${j}|t|${user}`);
} else {
btn.setCustomId(`mswpr|${i}|${j}|f`);
btn.setCustomId(`mswpr|${i}|${j}|f|${user}`);
}
btn.setLabel('?')
@@ -78,10 +83,17 @@ async function changeBoard(bot, interaction, xp_collection) {
interaction.deferUpdate();
const id = interaction.customId.split('|');
//"mswpr|y|x"
//"mswpr|y|x|<t/f>|[user]"
const col = id[1];
const row = id[2];
const isbmb = (id[3] === 't');
const user = id[4];
if (user && user != '') {
if (interaction.user.id != user) {
interaction.user.send(`Message from a Minesweeper game in <#${interaction.channel.id}>: ***It's not your turn!***`);
return; // interaction.reply({ content: "It's not your turn!", ephemeral: true }); //Can only reply once
}
}
var components = interaction.message.components;
var btn = components[col].components[row];
@@ -137,7 +149,7 @@ function checkAndStartGame(bot, message, channel, args) {
if (doc.game != null) { return message.reply("You're already in a game!"); }
dbo.updateOne({ "game": {$exists: true} }, { $set: { game: "minesweeper", state: STATE.FIGHTING }});
startGame(bot, channel, args);
startGame(bot, channel, message, args);
} catch (err) {
console.log(err);
const { addComplaintButton } = require('../dev only/submitcomplaint.js');
-1
View File
@@ -57,7 +57,6 @@ function startTrivia(message, m, time, bot) {
const question = obj.question;
const answer = obj.answer;
console.log(answer);
const filter = (response) => {
// return item.answers.some(answer => answer.toLowerCase() === response.content.toLowerCase());
+3
View File
@@ -88,6 +88,9 @@ async function handle_interaction(interaction, mongouri, turnManager, bot, STATE
tuto.postEmbd(bot, interaction, page, true);
} else if (interaction.customId.indexOf("mswpr|") != -1) {
mswpr.handle(bot, interaction, interaction.channel, interaction.message, null, xp_collection);
} else if (interaction.customId.indexOf("sbtutorial") != -1) {
interaction.deferUpdate();
tuto.execute(interaction.message, null, null, null, bot);
} //Button else ifs here
});
}
+2 -1
View File
@@ -1,11 +1,12 @@
const { modHelp } = require('../admin/moderation.js');
//CHANGE THIS TO FORMS?
module.exports ={
name: "help",
description: "Gets help for all of Selmer Bot's commands",
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', 'code']], ['adminCommands', [ 'setup', 'lock', 'unlock', 'serverlock' ]]]);
if (args[0] == 'econ') {
let temp = "***Selmer Bot Commands (Econ):***\n";
+89
View File
@@ -0,0 +1,89 @@
const { MessageEmbed } = require('discord.js');
//!poll <name> <option 1, option 2> [option 3...option 10]
module.exports = {
name: "poll",
description: "Create a cool poll embed (with time up to 1 hour!)",
async execute(message, args, Discord, Client, bot) {
if (args.length < 3) { return message.reply("Please provide a poll name, time (like 1:25 or 0 for not timed) and 1 - 10 options!"); }
if (args.length > 12) { return message.reply("Please specify less than 10 options!"); }
const timeList = [ '1️⃣', '2️⃣', '3️⃣', '4️⃣', '5️⃣', '6️⃣', '7️⃣', '8️⃣', '9️⃣', '🔟' ];
const author = {
name: "Selmer Bot",
url: "",
iconURL: bot.user.displayAvatarURL()
}
var time = 0;
var temp;
var isTimed = !Number.isNaN(Number(args[1].split(":")[0]));
if (!isTimed) {
temp = `This poll was created by ${message.author} and has no time limit!\n`;
} else {
time += (Number(args[1].split(':')[0]) * 60) + Number(args[1].split(':')[1]);
temp = `This poll was created by ${message.author} and ends <t:${Math.floor((new Date()).getTime()/1000) + time}:R>!\n`;
}
//args[0] is the poll name
for(let i = 2; i < args.length; i ++) {
// complist.push({ name: `${timeList[i - 1]}: ${args[i]}`, value: "" });
temp += `\n${timeList[i - 2]}: ${args[i]}\n`;
}
const embd = new MessageEmbed()
.setTimestamp()
.setTitle(`${args[0]}`)
.setDescription(temp)
.setAuthor(author)
message.channel.send({ embeds: [embd] }).then((msg) => {
for(let i = 0; i < args.length - 2; i ++) {
msg.react(timeList[i]);
}
if (!isTimed) {
return;
}
const filter = (reaction, user) => {
return timeList.includes(reaction.emoji.name);
};
let embd = msg.embeds[0];
//Replace the "and ends in <t:timestamp:R>" part with "has ended"
const collector = msg.createReactionCollector({ filter, time: time * 1000 });
collector.on('end', collected => {
let winnerC = 0;
let winners = [];
const col = Array.from(collected);
for (let i = 0; i < col.length; i++) {
const key = col[i][0];
const val = col[i][1];
if (val.count > winnerC) {
winners = [key];
winnerC = val.count;
} else if (val.count == winnerC) {
winners.push(key);
}
}
let temp;
if (winners.length > 1) {
temp = `The winners are: \`${winners.join(", ")}\` with \`${winnerC}\` votes each!`;
} else {
temp = `The winner is: \`${winners.join(", ")}\` with \`${winnerC}\` votes!`;
}
embd.description = embd.description.substr(0, 50) + ` has ended!\n${temp}` + embd.description.substr(embd.description.indexOf("!") + 1);
msg.edit({ embeds: [embd] });
msg.reply(temp);
});
});
}
}
+1
View File
@@ -73,6 +73,7 @@ bot.prefix = prefix;
bot.inDebugMode = IDM;
bot.home_server = home_server;
bot.debug_channel = debug_channel;
bot.inviteLink = 'https://discord.com/oauth2/authorize?client_id=944046902415093760&scope=applications.commands+bot&permissions=549755289087';
const configuration = new Configuration({
apiKey: MLAIKEY,