adding stuffs
This commit is contained in:
parent
d701e1bdff
commit
9157728723
11 changed files with 1453 additions and 0 deletions
84
combo-handler.js
Executable file
84
combo-handler.js
Executable file
|
@ -0,0 +1,84 @@
|
|||
const {seperators, multipliers, comboMax, comboMin, disabledSymbols} = require ('./const.js');
|
||||
const verifyPlay = require ('./verify.js');
|
||||
var comboModule = require('./combo.js');
|
||||
const comboFun = comboModule.combine;
|
||||
|
||||
|
||||
sortHelper = (a,b) => {
|
||||
return (a > b) - (a < b);
|
||||
}
|
||||
|
||||
module.exports = (message) => {
|
||||
if (message.author.bot) return;
|
||||
|
||||
if (!verifyPlay(message)) {
|
||||
return;
|
||||
}
|
||||
|
||||
var seperator = "(none)";
|
||||
var multiplier = "(none)";
|
||||
|
||||
for (var i = 0; i < seperators.length; i++) {
|
||||
if (message.content.indexOf(seperators[i]) != -1) {
|
||||
seperator = seperators[i];
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
for (var i = 0; i < multipliers.length; i++) {
|
||||
if (message.content.indexOf(multipliers[i]) != -1) {
|
||||
multiplier = multipliers[i];
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (seperator == "(none)" && multiplier == "(none)") return;
|
||||
|
||||
var comboTemp = message.content.split(seperator);
|
||||
var combo = [];
|
||||
|
||||
for (var i = 0; i < comboTemp.length; i++) {
|
||||
if (multiplier == "(none)") {
|
||||
var split = [comboTemp[i]];
|
||||
} else {
|
||||
var split = comboTemp[i].split(multiplier);
|
||||
}
|
||||
|
||||
if (split[0].replace(/\s+/,' ').replace(/^\s+|\s+$/g,'') == "") split[0] = comboModule.getLastCombined(message.author.id);
|
||||
|
||||
if (split.length == 1) {
|
||||
combo.push(split[0].replace(/\s+/,' ').replace(/^\s+|\s+$/g,'').toLowerCase().replace(/(\b[a-z](?!\s))/g,(c) => c.toUpperCase()));
|
||||
} else {
|
||||
var times = parseInt(split[1]);
|
||||
if (Number.isNaN(times) || times < 1 || times > comboMax) {
|
||||
message.channel.send(":x: You can't multiply by non-numbers");
|
||||
return;
|
||||
}
|
||||
for (var j = 0; j < parseInt(split[1]); j++) {
|
||||
combo.push(split[0].replace(/\s+/,' ').replace(/^\s+|\s+$/g,'').toLowerCase().replace(/(\b[a-z](?!\s))/g,(c) => c.toUpperCase()));
|
||||
}
|
||||
}
|
||||
}
|
||||
if (combo.length > comboMax) {
|
||||
message.channel.send(':x: Too long of a combo');
|
||||
return;
|
||||
}
|
||||
if (combo.length < (comboMin + 1)) {
|
||||
message.channel.send(':x: Combo is empty');
|
||||
return;
|
||||
}
|
||||
for (var i = 0; i < combo.length; i++) {
|
||||
if (combo[i] == "") {
|
||||
message.channel.send(':x: An element is empty');
|
||||
return;
|
||||
}
|
||||
for (var j = 0; j < disabledSymbols.length; j++) {
|
||||
if (combo[i].indexOf(disabledSymbols[j]) != -1) {
|
||||
message.channel.send(`:x: You are using the illegal character ${disabledSymbols[j]}`);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
comboFun(combo.sort(), message.channel, message.author.id);
|
||||
}
|
23
commands.js
Executable file
23
commands.js
Executable file
|
@ -0,0 +1,23 @@
|
|||
module.exports.commands = [
|
||||
{
|
||||
"name": "inv",
|
||||
"description": "Get your inventory",
|
||||
},
|
||||
{
|
||||
"name": "sugg",
|
||||
"description": "Suggest an element",
|
||||
"options": [
|
||||
{
|
||||
"name": "element",
|
||||
"description": "Element to be suggested",
|
||||
"required": true,
|
||||
"type": 3
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
|
||||
module.exports.commandHandlers = {
|
||||
"inv": require("./inv.js"),
|
||||
"sugg": require("./sugg.js")
|
||||
};
|
17
const.js
Executable file
17
const.js
Executable file
|
@ -0,0 +1,17 @@
|
|||
module.exports = {
|
||||
"clientId": "880926181791240202",
|
||||
"token": "",
|
||||
"defaultGuild": "895763120172175380",
|
||||
"playChannels": [
|
||||
/play.*/
|
||||
],
|
||||
"pollChannel": "896003582866903050",
|
||||
"newsChannel": "896003590768951348",
|
||||
"seperators": "\n+,",
|
||||
"multipliers": ["**","^^"],
|
||||
"comboMax": 20,
|
||||
"comboMin": 1,
|
||||
"disabledSymbols": ["**","^^","\n","```"],
|
||||
"maxElemLength": 50,
|
||||
"voteThreshold": 2,
|
||||
};
|
44
index.js
Executable file
44
index.js
Executable file
|
@ -0,0 +1,44 @@
|
|||
const { REST } = require('@discordjs/rest');
|
||||
const { Routes } = require('discord-api-types/v9');
|
||||
|
||||
const {clientId, token, defaultGuild} = require ('./const.js');
|
||||
const {commands,commandHandlers} = require('./commands.js');
|
||||
const comboHandler = require("./combo-handler.js");
|
||||
const elementInfo = require("./info.js");
|
||||
const vote = require('./vote.js');
|
||||
|
||||
const rest = new REST({ version: '9' }).setToken(token);
|
||||
|
||||
(async () => {
|
||||
try {
|
||||
console.log('Started refreshing application (/) commands.');
|
||||
|
||||
await rest.put(
|
||||
Routes.applicationGuildCommands(clientId, defaultGuild),
|
||||
{ body: commands },
|
||||
);
|
||||
|
||||
console.log('Successfully reloaded application (/) commands.');
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
}
|
||||
})();
|
||||
|
||||
const { Client, Intents } = require('discord.js');
|
||||
const client = new Client({ intents: [Intents.FLAGS.GUILDS, 'GUILD_MESSAGES', 'GUILD_MESSAGE_REACTIONS'] });
|
||||
|
||||
client.on('ready', () => {
|
||||
console.log(`Logged in as ${client.user.tag}!`);
|
||||
});
|
||||
|
||||
client.on('interactionCreate', async interaction => {
|
||||
if (!interaction.isCommand()) return;
|
||||
|
||||
|
||||
commandHandlers[interaction.commandName](interaction);
|
||||
});
|
||||
|
||||
client.on('messageCreate', comboHandler);
|
||||
client.on('messageCreate', elementInfo);
|
||||
|
||||
client.login(token);
|
43
info.js
Normal file
43
info.js
Normal file
|
@ -0,0 +1,43 @@
|
|||
const {seperators, multipliers, comboMax, comboMin, disabledSymbols} = require ('./const.js');
|
||||
const verifyPlay = require ('./verify.js');
|
||||
var combo = require('./combo.js');
|
||||
|
||||
|
||||
sortHelper = (a,b) => {
|
||||
return (a > b) - (a < b);
|
||||
}
|
||||
|
||||
module.exports = (message) => {
|
||||
if (message.author.bot) return;
|
||||
|
||||
if (!verifyPlay(message)) return;
|
||||
|
||||
msg = message.content;
|
||||
|
||||
if(!msg.startsWith("?")) return;
|
||||
|
||||
element=msg.replace("?", "").toLowerCase();
|
||||
|
||||
out = "";
|
||||
|
||||
if(combo.getUserInv(message.author.id).join("**").toLowerCase().split("**").includes(element.toLowerCase())) {
|
||||
out+=":green_circle: **You have this element!**\n";
|
||||
} else {
|
||||
out+=":red_circle: **You don't have this element.**\n";
|
||||
}
|
||||
|
||||
// https://stackoverflow.com/questions/5667888/counting-the-occurrences-frequency-of-array-elements
|
||||
const map = combo.getInv().join("**").toLowerCase().split("**").reduce((acc, e) => acc.set(e, (acc.get(e) || 0) + 1), new Map());
|
||||
|
||||
var am;
|
||||
try {
|
||||
var el = [...map.values()][[...map.keys()].indexOf(element)];
|
||||
am = (el!==undefined ? el : 0);
|
||||
} catch(err) {
|
||||
am = err;
|
||||
}
|
||||
//out+="Users with this element: "+JSON.stringify([...map.keys()]);
|
||||
|
||||
message.reply("Element info:"+"\n"+out);
|
||||
|
||||
};
|
11
inv.js
Executable file
11
inv.js
Executable file
|
@ -0,0 +1,11 @@
|
|||
const verifyPlay = require('./verify.js');
|
||||
const combo = require('./combo.js');
|
||||
|
||||
module.exports = async interaction => {
|
||||
|
||||
interaction.reply({embeds: [{
|
||||
color: 0x0099ff,
|
||||
description: combo.getUserInv(interaction.user.id).join('\n'),
|
||||
title: `${interaction.user.username}'s Inventory (${combo.getUserInv(interaction.user.id).length} elements)`
|
||||
}]});
|
||||
};
|
1125
package-lock.json
generated
Executable file
1125
package-lock.json
generated
Executable file
File diff suppressed because it is too large
Load diff
42
poll.js
Executable file
42
poll.js
Executable file
|
@ -0,0 +1,42 @@
|
|||
const { MessageButton, MessageActionRow } = require("discord.js")
|
||||
|
||||
const { pollChannel } = require('./const.js');
|
||||
const vote = require('./vote.js');
|
||||
|
||||
var collectors = [];
|
||||
|
||||
module.exports = (combo,result,channel,id,interaction) => {
|
||||
result = result.replace(/\s+/,' ').replace(/^\s+|\s+$/g,'').toLowerCase().replace(/(\b[a-z](?!\s))/g,(c) => c.toUpperCase());
|
||||
var comboString = combo.join(' + ') + ' = ' + result;
|
||||
const comboArrayString = combo.join('**') + '**' + result;
|
||||
|
||||
const row = new MessageActionRow()
|
||||
.addComponents(
|
||||
new MessageButton()
|
||||
.setCustomId(comboString + '**0')
|
||||
.setLabel('Upvote')
|
||||
.setStyle('PRIMARY'),
|
||||
new MessageButton()
|
||||
.setCustomId(comboString + '**1')
|
||||
.setLabel('Downvote')
|
||||
.setStyle('PRIMARY')
|
||||
)
|
||||
|
||||
interaction.reply(`Suggested ${comboString}`);
|
||||
|
||||
channel.guild.channels.fetch(pollChannel).then(channel => {channel.send({
|
||||
embeds: [{
|
||||
color: 0x0099ff,
|
||||
description: comboString,
|
||||
title: 'Vote'
|
||||
}]
|
||||
}).then(message => {
|
||||
message.react('⬆️')
|
||||
.then(() => {
|
||||
message.react('⬇️').then(() => {
|
||||
collectors.push(message.createReactionCollector());
|
||||
collectors[collectors.length-1].on('collect', (reaction,user) => {vote(reaction,user,combo,result)});
|
||||
})
|
||||
})
|
||||
})});
|
||||
}
|
27
sugg.js
Executable file
27
sugg.js
Executable file
|
@ -0,0 +1,27 @@
|
|||
const combo = require('./combo.js');
|
||||
const poll = require('./poll.js');
|
||||
const {disabledSymbols, maxElemLength} = require('./const.js');
|
||||
|
||||
module.exports = async interaction => {
|
||||
var comboLast = combo.getSuggestion(interaction.user.id);
|
||||
var suggestion = interaction.options.getString('element');
|
||||
|
||||
if (comboLast.length === 0) {
|
||||
interaction.reply(":x: You haven't combined anything");
|
||||
return;
|
||||
}
|
||||
|
||||
if (suggestion.length > maxElemLength) {
|
||||
interaction.reply(':x: Too long of a suggestion');
|
||||
return;
|
||||
}
|
||||
|
||||
for (var i = 0; i < disabledSymbols.length; i++) {
|
||||
if (suggestion.indexOf(disabledSymbols[i]) != -1) {
|
||||
interaction.reply(`:x: You are using the illegal character ${disabledSymbols[j]}!`);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
poll(comboLast,suggestion,interaction.channel,interaction.user.id,interaction);
|
||||
}
|
12
verify.js
Executable file
12
verify.js
Executable file
|
@ -0,0 +1,12 @@
|
|||
const {playChannels} = require ('./const.js');
|
||||
|
||||
module.exports = interaction => {
|
||||
var playChannel = false;
|
||||
for (var i = 0; i < playChannels.length; i++) {
|
||||
if (interaction.channel.name.match(playChannels[i])) {
|
||||
playChannel = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return playChannel;
|
||||
}
|
25
vote.js
Executable file
25
vote.js
Executable file
|
@ -0,0 +1,25 @@
|
|||
const { voteThreshold, newsChannel } = require('./const.js');
|
||||
|
||||
const { pushCombo } = require('./combo.js');
|
||||
|
||||
votes = {};
|
||||
|
||||
module.exports = (reaction, user, combo, result) => {
|
||||
if (reaction.message.author != '880926181791240202') return;
|
||||
if (reaction.emoji.name != '⬆️' && reaction.emoji.name != '⬇️') return;
|
||||
|
||||
if (votes[reaction.message.id] == null) votes[reaction.message.id] = {'⬆️':1,'⬇️':1};
|
||||
|
||||
votes[reaction.message.id][reaction.emoji.name] = reaction.count;
|
||||
|
||||
if (votes[reaction.message.id]['⬆️'] - votes[reaction.message.id]['⬇️'] >= voteThreshold) {
|
||||
reaction.message.guild.channels.fetch(newsChannel)
|
||||
.then(channel => {
|
||||
reaction.message.delete();
|
||||
pushCombo([...combo,result],channel,reaction.message.author.id);
|
||||
});
|
||||
}
|
||||
else if (votes[reaction.message.id]['⬆️'] - votes[reaction.message.id]['⬇️'] <= -voteThreshold) {
|
||||
reaction.message.delete();
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue