Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added /quote command #860

Merged
merged 21 commits into from
Jul 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion commands/api/dictionary.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export default async (interaction, ephemeral) => {
} catch (e) {
// console.log(e);
let errorEmbed = new EmbedBuilder()
.setColor('#FF0000')
.setColor(globalVars.embedColorError)
.setTitle("Error")
.setDescription("Word not found.");
return sendMessage({ interaction: interaction, embeds: errorEmbed, ephemeral: ephemeral });
Expand Down
70 changes: 70 additions & 0 deletions commands/other/quote.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
import {
EmbedBuilder,
SlashCommandBuilder
} from "discord.js";
import sendMessage from "../../util/sendMessage.js";
import logger from "../../util/logger.js";
import randomNumber from "../../util/randomNumber.js";
import quotes from "../../objects/quotes.json" with { type: "json" };
import globalVars from "../../objects/globalVars.json" with { type: "json" };
import config from "../../config.json" with { type: "json" };

let previousQuoteTime = null;
let allMessages = [];
for (const [key, value] of Object.entries(quotes)) {
value.forEach(messageID => allMessages.push({ channnelID: key, messageID: messageID }));
};

export default async (interaction, ephemeral) => {
try {
ephemeral = false;
let quoteEmbed = new EmbedBuilder()
.setColor(globalVars.embedColor);
const now = Date.now();
const cooldownAmount = 6 * 60 * 60 * 1000; // 6 hours in ms

if (previousQuoteTime) {
const expirationTime = previousQuoteTime + cooldownAmount;
if (now < expirationTime) {
const timeLeft = Math.floor((expirationTime - now) / 1000 / 60); // time left in min
return sendMessage({ interaction: interaction, content: `Please wait ${timeLeft} more minutes before trying to achieve even more wisdom.` });
};
};
let randomMessage = allMessages[randomNumber(0, allMessages.length - 1)];
let messageURL = `https://discord.com/channels/${globalVars.ShinxServerID}/${randomMessage.channelID}/${randomMessage.messageID}`;
let channel, message;
try {
channel = interaction.guild.channels.fetch(randomMessage.channelID);
message = channel.messages.fetch(randomMessage.messageID);
} catch (e) {
quoteEmbed
.setAuthor("Error")
.setColor(globalVars.embedColorError)
.setDescription(`Failed to fetch the selected message.\nChannel ID: ${randomMessage.channelID}\nMessage ID: ${randomMessage.messageID}`);
return sendMessage({ interaction: interaction, embeds: quoteEmbed, ephemeral: ephemeral });
};

let messageImage = null;
if (message.attachments.size > 0) messageImage = message.attachments.first().url;

quoteEmbed
.setAuthor({ name: "Quote" })
.setTitle(message.author.username)
.setURL(messageURL)
.setDescription(message.content)
.setImage(messageImage)
.setFooter(`Channel: ${channel.id} | Message: ${message.id}`);
previousQuoteTime = now;
return sendMessage({ interaction: interaction, embeds: quoteEmbed, ephemeral: ephemeral });

} catch (e) {
logger({ exception: e, interaction: interaction });
};
};

export const guildIDs = [config.devServerID, globalVars.ShinxServerID];

export const commandObject = new SlashCommandBuilder()
.setName("quote")
.setDescription("Let someone's wisdom guide you.")
.setDMPermission(false);
6 changes: 4 additions & 2 deletions events/ready.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@ export default async (client) => {
await client.commands.forEach(async (command) => {
try {
let commandServerIDs = null;
if (command.guildIDs) commandServerIDs = command.guildIDs;
// if (client.user.id != module.exports.NinigiID) commandServerID = client.guildIDs; // set to test server for test build
if (command.guildIDs) {
commandServerIDs = command.guildIDs;
if (client.user.id != globalVars.NinigiID) commandServerIDs = commandServerIDs.filter(ID => ID != globalVars.ShinxServerID);
};
await client.application.commands.create(command.commandObject, commandServerIDs);
} catch (e) {
console.log(e);
Expand Down
1 change: 1 addition & 0 deletions objects/globalVars.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"subscriptionSKUID": "1164974692889808999",
"currency": "💰",
"embedColor": "#219DCD",
"embedColorError": "#FF0000",
"lackPermsString": "You do not have the required permissions to do this.",
"ephemeralOptionDescription": "Whether the reply will be private.",
"starboardLimit": 3,
Expand Down
153 changes: 153 additions & 0 deletions objects/quotes.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
{
"549217627365441566": [
"778390611388137472",
"1165061943934066770",
"1113368396457840691",
"1233431544169758752",
"1235705614857146509",
"1235298798146682911",
"973552750338146394",
"982249751242244097",
"1009591004149596332",
"1011262768906784779",
"1011419118219571322",
"1012353757582999622",
"1028033491021070376",
"1030098191586168902",
"1030152490559225887",
"1031632178796298310",
"1033860923259097148",
"1034199638489706588",
"1034200531113099264",
"1051554460599599155",
"1056181914874155079",
"1057605537845489704",
"1060217005820612618",
"1069589806234992660",
"1071447371076075630",
"1072999169603686591",
"1077917671355588608",
"1079474487151562853",
"1080225428486234162",
"1110933190614458489",
"1116011247738028192",
"1141765698583019691",
"1165591236187537418",
"1167338661549977600",
"1169614414354337822",
"1174006300779221022",
"1174059730482757633",
"1175881474415788053",
"1177335888250945607",
"1184771509043068988",
"1184992247813513296",
"1187774667432415295",
"1189242833878650941",
"1190019952661512222",
"1190349724230881363",
"1191056093074436108",
"1191060012978667690",
"1191509287319650385",
"1192890518238142494",
"1193324828850143313",
"1201271723174146248",
"1217895146113470474",
"1226941731342123142",
"1228042718547021915",
"1233429378516516985",
"742886654204838078",
"832384880738172938",
"1122319130377322507",
"1239875209406845018",
"933138585106935898",
"1230900642399387758",
"1150545454761783437",
"729158135620567051",
"730380749139607572",
"775558626244558848"
],
"748873664308576337": [
"1125169489797972232",
"1129371296925491271"
],
"730808051266748437": [
"1080615232428331108"
],
"747878956434325626": [
"1007758700150280262"
],
"1098285734496043118": [
"1098285734496043118"
],
"722113630153343076": [
"733067749252923463"
],
"665274079397281835": [
"671735953970298902"
],
"815249117303406602": [
"1002144404716404806"
],
"656557551755853844": [
"1004499744233627768",
"1014896686096728064",
"1049033029860995083",
"1081256635747549224",
"1172132432451993601",
"1186408087402328305"
],
"761961657169477660": [
"1007378627589066762"
],
"551132163438018575": [
"1028218546066563133",
"1032413732380348468",
"1043909278739746906",
"1137162836250992722",
"1189343243687694406",
"746021971468353556"
],
"974238847900717066": [
"1045113117639708695"
],
"1043833369340944396": [
"1058979522084601967"
],
"677598636707938335": [
"1059134530440679487"
],
"705372420718198795": [
"1073554749481308230"
],
"1078298069067645050": [
"1079116198882590921",
"1079116128854474803"
],
"1059151082045063300": [
"1129407474110304389"
],
"717841246101700709": [
"1150886767877169272"
],
"769949605139578900": [
"1155529073183961178"
],
"705601772785238080": [
"1166088494234488882",
"1167770443541917747"
],
"1045353775893852160": [
"1168497455642456105"
],
"752626723345924157": [
"1180647604137242755",
"1180648304988655626",
"1227357596273348679"
],
"1212052738335051839": [
"1212350913919057940"
],
"549214833858576399": [
"1191054304711278733"
]
}