Skip to content

Commit

Permalink
Add support for user apps (#473)
Browse files Browse the repository at this point in the history
* fix: add woobly code

* Add more support :)

* Possible pagination fix

* fix: no any type

* fix: split button/command handler

* fix: rework interaction create

* fix: run formatter

* fix: button cooldown

* fix: format

* fix: button + command support

* add: game buttons support

* add: even more button support

* chore(app commands): finished

---------

Co-authored-by: ForGetFulSkyBro <[email protected]>
  • Loading branch information
mezotv and forgetfulskybro authored Mar 22, 2024
1 parent 50d8a41 commit 048750b
Show file tree
Hide file tree
Showing 66 changed files with 1,692 additions and 1,006 deletions.
476 changes: 476 additions & 0 deletions json.json

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {
EmbedBuilder,
MessageActionRowComponentBuilder,
} from "discord.js";
import { Button } from "../interfaces";
import { Button } from "../../interfaces";

const button: Button = {
name: "wycustom_accept",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {
EmbedBuilder,
MessageActionRowComponentBuilder,
} from "discord.js";
import { Button } from "../interfaces";
import { Button } from "../../interfaces";

const button: Button = {
name: "wycustom_add",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {
EmbedBuilder,
MessageActionRowComponentBuilder,
} from "discord.js";
import { Button } from "../interfaces";
import { Button } from "../../interfaces";

const button: Button = {
name: "wycustom_decline",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
MessageActionRowComponentBuilder,
ButtonStyle,
} from "discord.js";
import { Button } from "../interfaces";
import { Button } from "../../interfaces";

const button: Button = {
name: "wycustom_remove",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {
ChannelSelectMenuBuilder,
MessageActionRowComponentBuilder,
} from "discord.js";
import { Button } from "../interfaces";
import { Button } from "../../interfaces";

const button: Button = {
name: "dailyChannel",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
ButtonStyle,
MessageActionRowComponentBuilder,
} from "discord.js";
import { Button } from "../interfaces";
import { Button } from "../../interfaces";

const button: Button = {
name: "deleteDailyRole",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
ButtonStyle,
MessageActionRowComponentBuilder,
} from "discord.js";
import { Button } from "../interfaces";
import { Button } from "../../interfaces";

const modalObject = {
title: "Daily Post Time",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
ButtonStyle,
MessageActionRowComponentBuilder,
} from "discord.js";
import { Button } from "../interfaces";
import { Button } from "../../interfaces";

const button: Button = {
name: "dailyMsg",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
MessageActionRowComponentBuilder,
ButtonStyle,
} from "discord.js";
import { Button } from "../interfaces";
import { Button } from "../../interfaces";

const button: Button = {
name: "dailyRole",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
ButtonStyle,
MessageActionRowComponentBuilder,
} from "discord.js";
import { Button } from "../interfaces";
import { Button } from "../../interfaces";

const button: Button = {
name: "dailyThread",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
ButtonStyle,
} from "discord.js";
import { captureException } from "@sentry/node";
import { Button } from "../interfaces";
import { Button } from "../../interfaces";

const modalObject = {
title: "Daily Message Timezone",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {
MessageActionRowComponentBuilder,
StringSelectMenuBuilder,
} from "discord.js";
import { Button } from "../interfaces";
import { Button } from "../../interfaces";

const button: Button = {
name: "dailyType",
Expand Down
90 changes: 51 additions & 39 deletions src/buttons/dare.ts → src/buttons/gamesActivities/dare.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,56 +8,68 @@ import {
ButtonInteraction,
} from "discord.js";
import { captureException } from "@sentry/node";
import shuffle from "../util/shuffle";
import { Button } from "../interfaces";
import { getDare } from "../util/Functions/jsonImport";
import shuffle from "../../util/shuffle";
import { Button } from "../../interfaces";

import { getDare } from "../../util/Functions/jsonImport";

const button: Button = {
name: "dare",
execute: async (interaction: any, client, guildDb) => {
if (interaction.channel.isThread()) {
if (
!interaction.channel
?.permissionsFor(interaction.user.id)
.has(PermissionFlagsBits.SendMessagesInThreads)
) {
return interaction.reply({
content:
"You don't have permission to use this button in this channel!",
ephemeral: true,
});
}
} else {
if (
!interaction.channel
?.permissionsFor(interaction.user.id)
.has(PermissionFlagsBits.SendMessages)
) {
return interaction.reply({
content:
"You don't have permission to use this button in this channel!",
ephemeral: true,
});
if (interaction.guild) {
if (interaction.channel.isThread()) {
if (
!interaction.channel
?.permissionsFor(interaction.user.id)
.has(PermissionFlagsBits.SendMessagesInThreads)
) {
return interaction.reply({
content:
"You don't have permission to use this button in this channel!",
ephemeral: true,
});
}
} else {
if (
!interaction.channel
?.permissionsFor(interaction.user.id)
.has(PermissionFlagsBits.SendMessages)
) {
return interaction.reply({
content:
"You don't have permission to use this button in this channel!",
ephemeral: true,
});
}
}
}

let Dare = await getDare(guildDb.language);
const dbquestions = guildDb.customMessages.filter((c) => c.type === "dare");
let Dare = await getDare(
guildDb?.language != null ? guildDb.language : "en_EN",
);

let dbquestions;

let truthordare = [] as string[];

if (!dbquestions.length) guildDb.customTypes = "regular";
if (guildDb != null) {
dbquestions = guildDb.customMessages.filter((c) => c.type === "dare");

switch (guildDb.customTypes) {
case "regular":
truthordare = shuffle([...Dare]);
break;
case "mixed":
truthordare = shuffle([...Dare, ...dbquestions.map((c) => c.msg)]);
break;
case "custom":
truthordare = shuffle(dbquestions.map((c) => c.msg));
break;
if (!dbquestions.length) guildDb.customTypes = "regular";

switch (guildDb.customTypes) {
case "regular":
truthordare = shuffle([...Dare]);
break;
case "mixed":
truthordare = shuffle([...Dare, ...dbquestions.map((c) => c.msg)]);
break;
case "custom":
truthordare = shuffle(dbquestions.map((c) => c.msg));
break;
}
} else {
truthordare = shuffle([...Dare]);
}

const Random = Math.floor(Math.random() * truthordare.length);
Expand Down
40 changes: 25 additions & 15 deletions src/buttons/higher.ts → src/buttons/gamesActivities/higher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@ import {
AttachmentBuilder,
MessageActionRowComponentBuilder,
} from "discord.js";
import { HigherlowerModel } from "../util/Models/higherlowerModel";
import LOSE from "../util/Classes/generateLOSE";
import HOR from "../util/Classes/generateHOR";
import { Button } from "../interfaces";
import { getHigherLower } from "../util/Functions/jsonImport";
import { HigherlowerModel } from "../../util/Models/higherlowerModel";
import LOSE from "../../util/Classes/generateLOSE";
import HOR from "../../util/Classes/generateHOR";
import { Button } from "../../interfaces";

import { getHigherLower } from "../../util/Functions/jsonImport";

const button: Button = {
name: "higher",
Expand Down Expand Up @@ -83,14 +84,20 @@ const button: Button = {
const gameEmbed = new EmbedBuilder()

.setDescription(
client.translation.get(guildDb?.language, "HigherLower.description", {
keyword: game.items.current.keyword,
history: game.items.history[game.items.history.length - 1].keyword,
source: game.items.current.link || "https://wouldyoubot.gg/nolink",
source2:
game.items.history[game.items.history.length - 1].link ||
"https://wouldyoubot.gg/nolink",
}),
client.translation.get(
guildDb?.language != null ? guildDb.language : "en_EN",
"HigherLower.description",
{
keyword: game.items.current.keyword,
history:
game.items.history[game.items.history.length - 1].keyword,
source:
game.items.current.link || "https://wouldyoubot.gg/nolink",
source2:
game.items.history[game.items.history.length - 1].link ||
"https://wouldyoubot.gg/nolink",
},
),
)
.setColor("Green")
.setImage("attachment://game.png")
Expand Down Expand Up @@ -127,11 +134,14 @@ const button: Button = {
} else {
const loseEmbed = new EmbedBuilder()
.setTitle(
client.translation.get(guildDb?.language, "HigherLower.game.title"),
client.translation.get(
guildDb?.language != null ? guildDb.language : "en_EN",
"HigherLower.game.title",
),
)
.setDescription(
`${client.translation.get(
guildDb?.language,
guildDb?.language != null ? guildDb.language : "en_EN",
"HigherLower.game.description",
{
score: game?.score,
Expand Down
42 changes: 26 additions & 16 deletions src/buttons/lower.ts → src/buttons/gamesActivities/lower.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,20 @@ import {
AttachmentBuilder,
MessageActionRowComponentBuilder,
} from "discord.js";
import { HigherlowerModel } from "../util/Models/higherlowerModel";
import LOSE from "../util/Classes/generateLOSE";
import HOR from "../util/Classes/generateHOR";
import { Button } from "../interfaces";
import { getHigherLower } from "../util/Functions/jsonImport";
import { HigherlowerModel } from "../../util/Models/higherlowerModel";
import LOSE from "../../util/Classes/generateLOSE";
import HOR from "../../util/Classes/generateHOR";
import { Button } from "../../interfaces";

import { getHigherLower } from "../../util/Functions/jsonImport";

const button: Button = {
name: "lower",
execute: async (interaction, client, guildDb) => {
if (interaction.message.interaction?.user.id !== interaction.user.id) {
interaction.reply({
content: client.translation.get(
guildDb?.language,
guildDb?.language != null ? guildDb.language : "en_EN",
"HigherLower.error.user",
{
user: interaction.message.interaction?.user.username,
Expand Down Expand Up @@ -83,14 +84,20 @@ const button: Button = {
const gameEmbed = new EmbedBuilder()

.setDescription(
client.translation.get(guildDb?.language, "HigherLower.description", {
keyword: game.items.current.keyword,
history: game.items.history[game.items.history.length - 1].keyword,
source: game.items.current.link || "https://wouldyoubot.gg/nolink",
source2:
game.items.history[game.items.history.length - 1].link ||
"https://wouldyoubot.gg/nolink",
}),
client.translation.get(
guildDb?.language != null ? guildDb.language : "en_EN",
"HigherLower.description",
{
keyword: game.items.current.keyword,
history:
game.items.history[game.items.history.length - 1].keyword,
source:
game.items.current.link || "https://wouldyoubot.gg/nolink",
source2:
game.items.history[game.items.history.length - 1].link ||
"https://wouldyoubot.gg/nolink",
},
),
)
.setColor("Green")
.setImage("attachment://game.png")
Expand Down Expand Up @@ -127,11 +134,14 @@ const button: Button = {
} else {
const loseEmbed = new EmbedBuilder()
.setTitle(
client.translation.get(guildDb?.language, "HigherLower.game.title"),
client.translation.get(
guildDb?.language != null ? guildDb.language : "en_EN",
"HigherLower.game.title",
),
)
.setDescription(
`${client.translation.get(
guildDb?.language,
guildDb?.language != null ? guildDb.language : "en_EN",
"HigherLower.game.description",
{
score: game?.score,
Expand Down
Loading

0 comments on commit 048750b

Please sign in to comment.