Skip to content

Instantly share code, notes, and snippets.

@midknightmare666
Last active September 20, 2020 20:54
Show Gist options
  • Save midknightmare666/0a2b35e351fee844fa068beba62cc9af to your computer and use it in GitHub Desktop.
Save midknightmare666/0a2b35e351fee844fa068beba62cc9af to your computer and use it in GitHub Desktop.
/* eslint-disable no-param-reassign */
/**
* Creates a short unique id from a string of numbers.
*
* @param {String} inputNumber The number to hash
* @return {String} hash The hashed string
*/
module.exports = (inputNumber) => {
let hash = '';
const alphabet = '23456789abcdefghijklmnopqrstuvwxyz';
const length = alphabet.length;
do {
hash = alphabet[inputNumber % length] + hash;
inputNumber = parseInt(inputNumber / length, 10);
} while (inputNumber);
return hash;
};
const { RichEmbed } = require('discord.js');
const cap = require('../../utils/capitalizeFirstLetter');
/**
* Dev suggestion edit command
* get suggestion id,
* fetch suggestion channel messages,
* verify dev's id against fetched messages footer id
* if match edit suggestion
*
*/
module.exports = {
config: {
name: 'edit',
aliases: ['sedit', 'edits'],
des: 'Edit User Suggestions',
usage: '<suggestionID> <dev note>',
guildOnly: true,
ownerOnly: false,
category: 'admin',
cooldown: 0,
isDisabled: false,
userPerm: ['MANAGE_GUILD', 'ADMINISTRATOR'],
clientPerm: ['MANAGE_GUILD', 'ADMINISTRATOR']
},
run: async (soa, message, args, settings) => {
const isSuggestionsBot = settings.suggestionMain === 'not set' ? 'not set' : settings.suggestionMain;
const isSuggestionsUser = settings.suggestionUsers === 'not set' ? 'not set' : settings.suggestionUsers;
if (isSuggestionsBot === 'not set') return message.reply('There Are No Configured Suggestion Channels. Please Ask An Admin For Set Up');
if (isSuggestionsUser === 'not set') return message.reply('There Are No Configured Suggestion Channels. Please Ask An Admin For Set Up');
await message.delete()
/**
* Get Suggestion Channels
* ideally instead of hardcoding the suggestion channels, we'd put them in the database
*
* suggestionsBotChannel = bot channel for suggestions
* suggestionsChat = user's channel for suggestions
*/
const suggestionsBotChannel = message.guild.channels.find(c => c.id === isSuggestionsBot);
const suggestionsChat = message.guild.channels.find(c => c.id === isSuggestionsUser);
/**
* suggestionID
* the id to check for
* @type {String}
*/
const suggestionID = args[0];
if (!suggestionID) return message.reply('no suggestion id provided').then(e => e.delete(5000));
/**
* devNote
* everything after the suggestionID
* @type {String}
*
*/
const devNote = args.slice(1).join(' ')
if (!devNote) return message.reply('Please provide a note').then(e => e.delete(5000));
const devNoteAndName = `${devNote} - ${message.author}`;
try {
/**
* fetch suggestions channel messages and verify against suggestionID
* {@link https://discord.js.org/#/docs/main/stable/class/TextChannel?scrollTo=fetchMessages}
* @type {Object}
* @returns {Promise} Collection of messages, using await so we don't need that gay ass promise syntax
*/
const fetched = await suggestionsBotChannel.fetchMessages({limit: 20});
const fetchedEmbed = fetched.filter(m => m.embeds[0].footer.text.split(' ')[4] === suggestionID);
if (!fetchedEmbed || fetchedEmbed.size === 0) return message.channel.send(`Unable to edit suggestion with the id \`${suggestionID}\``).then(m => m.delete(8000));
const embedSID = fetchedEmbed.first().embeds[0].footer.text.split(' ')[4];
const embedUserID = fetchedEmbed.first().embeds[0].footer.text.split(' ')[1];
if (suggestionID !== embedSID) return message.reply('Invalid Suggestion Id, Try Again').then(m => m.delete(8000));
/**
* data
* the main fetched embed message data we need
* @type {Object}
*/
const data = {
channelID: fetchedEmbed.first().channel.id,
guildID: fetchedEmbed.first().channel.guild.id,
messageID: fetchedEmbed.first().id,
};
/**
* devEmbed
* the embed that'll replace the user's suggestion with dev note etc.
* @type {RichEmbed}
*/
const devEmbed = new RichEmbed(fetchedEmbed.first().embeds[0])
.setColor('#ffa500')
.addField('Dev Note', devNoteAndName);
const suggestionLINK = `https://discordapp.com/channels/${data.guildID}/${data.channelID}`;
const userEmbed = new RichEmbed()
.setColor('#ffa500')
.setTitle('Dev Note')
.setDescription(`${devNote}`)
.setAuthor(`Suggestion Edited By ${cap(message.author.username)}`, message.author.avatarURL)
.addField('Link', `[Click Here](${suggestionLINK}/${data.messageID})`)
.addField('Suggestion ID', `\`${suggestionID}\``)
return fetchedEmbed.first().edit(devEmbed) && suggestionsChat.send(`<@${embedUserID}>`, userEmbed);
} catch (err) {
return message.channel.send(`Invalid ID: \`${suggestionID}\``).then(e => e.delete(6000));
};
}
};
const { RichEmbed } = require('discord.js');
const matchURL = new RegExp(/(http(s?):)([/|.|\w|\s|-])*\.(?:jpg|gif|png|svg|jpeg)/)
module.exports = {
config: {
name: 'edituser',
aliases: ['useredit'],
des: 'Edit Your Suggestion',
usage: '<SuggestionID> <UpdatedSuggestion>',
guildOnly: true,
ownerOnly: false,
category: 'public',
cooldown: 30,
isDisabled: false,
userPerm: ['SEND_MESSAGES'],
clientPerm: ['SEND_MESSAGES']
},
run: async (soa, message, args, settings) => {
const isSuggestionsBot = settings.suggestionMain === 'not set' ? 'not set' : settings.suggestionMain;
const isSuggestionsUser = settings.suggestionUsers === 'not set' ? 'not set' : settings.suggestionUsers;
if (isSuggestionsBot === 'not set') return message.reply('There Are No Configured Suggestion Channels. Please Ask An Admin For Set Up');
if (isSuggestionsUser === 'not set') return message.reply('There Are No Configured Suggestion Channels. Please Ask An Admin For Set Up');
await message.delete(3000)
const userSuggestionID = args[0];
if (!userSuggestionID) return message.reply('Please Provide A Suggestion ID (located at the bottom of your suggestion)');
// TEST server suggestion channel
const suggestionsBotChannel = message.guild.channels.find(c => c.id === isSuggestionsBot);
const suggestionsChat = message.guild.channels.find(c => c.id === isSuggestionsUser);
const userSuggestionUpdate = args.slice(1).join(' ');
if (!userSuggestionUpdate) return message.reply('Please Provide A New Suggestion');
const imageAttach = message.attachments.first();
const regexImage = matchURL.exec(message.content);
try {
const fetched = await suggestionsBotChannel.fetchMessages({limit: 5});
const fetchedEmbed = fetched.first();
if (!fetchedEmbed) return message.channel.send(`Unable to edit suggestion with the id \`${userSuggestionID}\``).then(m => m.delete(8000));
const embedSID = fetched.first().embeds[0].footer.text.split(' ')[4];
const embedUserID = fetched.first().embeds[0].footer.text.split(' ')[1];
if (userSuggestionID !== embedSID) return message.reply('Invalid Suggestion Id, Try Again').then(m => m.delete(8000));
const data = {
channelID: fetchedEmbed.channel.id,
guildID: fetchedEmbed.guild.id,
messageID: fetchedEmbed.id,
embedDes: fetchedEmbed.embeds[0].description,
embedAuthorID: fetchedEmbed.embeds[0].author.name
};
const emoji = [ `<a:sharkDance:630513114265419810>`, `<a:lick:551140066140094474>`, `<a:thanosdance:577533347002056744>`,
`<a:ricardoFlick:565689151853428776>`, `<:waaa:562161105246355505>`, `<:Good_Boy_2:408467747517890571>`,
`<:Shy_Boy_1:408467765427699722>`
];
const random = emoji[Math.floor(Math.random() * emoji.length)];
const userEmbedUpdate = new RichEmbed(fetchedEmbed.embeds[0])
.setColor('#1f89a3')
.setDescription(`${userSuggestionUpdate}`)
if (regexImage !== null) {
const img = regexImage[0].toString();
userEmbedUpdate.setImage(img);
} else if (imageAttach !== undefined) {
userEmbedUpdate.setImage(imageAttach.proxyURL);
};
const suggestionLINK = `https://discordapp.com/channels/${data.guildID}/${data.channelID}`;
const updatedEmbed = new RichEmbed()
.setColor('#338a53')
.setAuthor(`${message.member.user.username.toUpperCase()}`, message.member.user.displayAvatarURL)
.setDescription(`${random} Success! Updated Suggestion`)
.addField('Link:', `[Click Here](${suggestionLINK}/${data.messageID})`)
.setFooter(`Suggestion ID: ${userSuggestionID}`)
return fetchedEmbed.edit(userEmbedUpdate) && suggestionsChat.send(`<@${embedUserID}>`, updatedEmbed);
} catch (err) {
console.log({ ok: false, status: err.message, stack: err.stack});
};
}
}
const { RichEmbed } = require('discord.js');
const hash = require('../../utils/hash');
const matchURL = new RegExp(/(http(s?):)([/|.|\w|\s|-])*\.(?:jpg|gif|png|svg|jpeg)/)
module.exports = {
config: {
name: 'suggest',
aliases: ['suggestion', 'sug', 'sugg'],
des: 'Suggest Ideas For SoA',
usage: '<suggestion> (image)',
guildOnly: true,
ownerOnly: false,
category: 'public',
cooldown: 12000,
isDisabled: true,
userPerm: ['SEND_MESSAGES'],
clientPerm: ['SEND_MESSAGES']
},
run: async (soa, message, args, settings) => {
const isSuggestionsBot = settings.suggestionMain === 'not set' ? 'not set' : settings.suggestionMain;
const isSuggestionsUser = settings.suggestionUsers === 'not set' ? 'not set' : settings.suggestionUsers;
if (isSuggestionsBot === 'not set') return message.reply('There Are No Configured Suggestion Channels. Please Ask An Admin For Set Up');
if (isSuggestionsUser === 'not set') return message.reply('There Are No Configured Suggestion Channels. Please Ask An Admin For Set Up');
await message.delete(3000);
const userSuggestion = args.join(' ');
if (!userSuggestion) return message.reply(`Error: No Suggestion Found.\nType \`${settings.prefix}help suggest\` for more info on this command.`);
const emojiY = soa.emojis.find(e => e.name === 'greenwhitecheck');
const emojiX = soa.emojis.find(e => e.name === 'redwhitex');
// const bannedRole = message.guild.roles.find(r => r.id === settings.bannedrole);
// if (!bannedRole) return new Error('unable to find banned role');
const userHash = hash(parseInt(message.member.id) + Date.now());
// main suggestions channel. For now: 630922038898327552 = suggestion channel in TEST server
const suggestionChannel = message.guild.channels.find(ch => ch.id === isSuggestionsBot);
// suggestions channel for user. For now 630922063070363684 = suggestion chat in TEST serve
const suggestionChannelUsers = message.guild.channels.find(ch => ch.id === isSuggestionsUser);
if (message.channel !== suggestionChannelUsers) return message.reply(`Please use ${suggestionChannelUsers} to execute this command`)
const imageAttach = message.attachments.first();
const regexImage = matchURL.exec(message.content);
const suggUser = message.member;
const validUser = {
mid: '394540642987933707',
simply: '123541929123119104',
elyMain: '143539319221518336',
elyAlt: '431615205915754497',
suggUser: `${suggUser.id}`,
};
const validUserArray = Object.values(validUser);
const filter = (reaction, user) => {
return reaction.emoji.name === '🗑' && validUserArray.includes(user.id);
};
const suggestionEmbed = new RichEmbed()
.setColor('#0000')
.setAuthor(`${suggUser.displayName}`, suggUser.user.displayAvatarURL)
.setTitle('Suggestion')
.setFooter(`UserID: ${suggUser.id} • sID: ${userHash}`)
.setDescription(userSuggestion)
const botMsg = await message.reply('processing suggestion...');
if (regexImage !== null) {
const img = regexImage[0].toString();
suggestionEmbed.setImage(img);
} else if (imageAttach !== undefined) {
suggestionEmbed.setImage(imageAttach.proxyURL);
};
const userEmbed = new RichEmbed()
.setColor('#389644')
.setAuthor(message.member.displayName, message.member.user.displayAvatarURL)
.setTitle('Suggestion Posted!')
.setDescription(`React with 🗑 to delete your own suggestion\n*Timeout: 2 mins*\n\nUse \`${settings.prefix}edituser <suggestionID> <New Suggestion>\` to edit your own suggestion\n*Do Not Include Angle Brackets <>*`)
.addField('Suggestion Id', `${userHash}`)
try {
const msg = await suggestionChannel.send(suggestionEmbed)
await msg.react(emojiY)
await msg.react(emojiX)
await msg.react('🗑')
const suggestionLINK = `https://discordapp.com/channels/${msg.guild.id}/${msg.channel.id}/${msg.id}`;
userEmbed.addField('Link', `[Click Here](${suggestionLINK})`)
await botMsg.edit(`<@${message.author.id}>`, userEmbed)
const reacted = await msg.awaitReactions(filter, { max: 1, time: 120000, errors: ['time'] });
const reaction = reacted.first();
if (reaction.emoji.name === '🗑') {
if (reaction.users.map(user => validUserArray.includes(user.id))) {
return msg.delete() && message.reply('Suggestion Deleted')
}
}
} catch (isGay) {
console.error(isGay)
};
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment