wip
This commit is contained in:
@@ -0,0 +1,26 @@
|
||||
import { Routes } from "discord.js";
|
||||
import { REST } from "@discordjs/rest";
|
||||
import config from "config";
|
||||
import getCommands from "components/commands.component";
|
||||
|
||||
export default class DiscordService {
|
||||
rest: REST;
|
||||
|
||||
constructor() {
|
||||
this.rest = new REST({ version: "10" }).setToken(config.discord.token);
|
||||
}
|
||||
|
||||
async init() {
|
||||
try {
|
||||
await this.rest.put(
|
||||
Routes.applicationCommands(config.discord.applicationId),
|
||||
{
|
||||
body: getCommands(),
|
||||
},
|
||||
);
|
||||
console.log("Successfully added commands");
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
import config from "config";
|
||||
import client from "lib/client";
|
||||
|
||||
export class GreetingService {
|
||||
async greet() {
|
||||
const channels = client.channels;
|
||||
|
||||
const channel = channels.cache.get(config.discord.channelId);
|
||||
|
||||
if (channel?.isTextBased && channel?.isSendable()) {
|
||||
await channel.send({ content: "HALLOOOO" });
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
import config from "config";
|
||||
import client from "lib/client";
|
||||
|
||||
export class GreetingService {
|
||||
async greet() {
|
||||
const channels = client.channels;
|
||||
|
||||
const channel = channels.cache.get(config.discord.channelId);
|
||||
|
||||
if (channel?.isTextBased && channel?.isSendable()) {
|
||||
await channel.send({ content: "HALLOOOO" });
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,98 @@
|
||||
import { CronJob } from "cron";
|
||||
import { getRandomInt } from "lib/utils";
|
||||
import config from "config";
|
||||
import client from "lib/client";
|
||||
import {
|
||||
ActionRowBuilder,
|
||||
ButtonBuilder,
|
||||
ButtonStyle,
|
||||
type CacheType,
|
||||
type Interaction,
|
||||
} from "discord.js";
|
||||
|
||||
export class WaterMeService {
|
||||
waterLevel: number;
|
||||
|
||||
private thirsty = 3 as const;
|
||||
private enough = 10 as const;
|
||||
|
||||
constructor() {
|
||||
this.waterLevel = 0;
|
||||
}
|
||||
|
||||
getReply() {
|
||||
const thirstyReplies = [
|
||||
"... wow das wars schon???",
|
||||
"dankeeeee!!!! ich waer fast verdurstet :(((",
|
||||
"*roelpssssss*",
|
||||
];
|
||||
|
||||
const fullReplies = [
|
||||
"langsam reicht es :o",
|
||||
"poah, das hat gut getan",
|
||||
"das ist krass :3",
|
||||
];
|
||||
|
||||
const tooMuchReplies = [
|
||||
"ES REICHT!!!!",
|
||||
"bitte hoer auf, ich platze gleich :(",
|
||||
];
|
||||
|
||||
if (this.waterLevel <= this.thirsty) {
|
||||
return thirstyReplies[getRandomInt(0, thirstyReplies.length - 1)];
|
||||
}
|
||||
if (this.waterLevel > this.thirsty && this.waterLevel <= this.enough) {
|
||||
return fullReplies[getRandomInt(0, fullReplies.length - 1)];
|
||||
}
|
||||
if (this.waterLevel > this.enough) {
|
||||
return tooMuchReplies[getRandomInt(0, tooMuchReplies.length - 1)];
|
||||
}
|
||||
}
|
||||
|
||||
async isThirsty() {
|
||||
const channels = client.channels;
|
||||
|
||||
const channel = channels.cache.get(config.discord.channelId);
|
||||
|
||||
if (
|
||||
channel?.isTextBased &&
|
||||
channel?.isSendable() &&
|
||||
this.waterLevel <= this.thirsty
|
||||
) {
|
||||
await channel.send({ content: "ich brauche wasser :(" });
|
||||
}
|
||||
}
|
||||
|
||||
waterMe() {
|
||||
const reply = this.getReply();
|
||||
|
||||
this.waterLevel++;
|
||||
|
||||
return {
|
||||
reply,
|
||||
};
|
||||
}
|
||||
|
||||
async handleInteraction(interaction: Interaction<CacheType>) {
|
||||
const result = this.waterMe();
|
||||
|
||||
const moreButton = new ButtonBuilder()
|
||||
.setCustomId("more")
|
||||
.setLabel("mehr")
|
||||
.setStyle(ButtonStyle.Secondary);
|
||||
|
||||
const row = new ActionRowBuilder().addComponents(moreButton);
|
||||
|
||||
if (interaction.isChatInputCommand()) {
|
||||
await interaction.reply({
|
||||
content: result.reply,
|
||||
// biome-ignore lint/suspicious/noExplicitAny: <explanation>
|
||||
components: [row as any],
|
||||
});
|
||||
} else if (interaction.isButton()) {
|
||||
await interaction.reply({
|
||||
content: result.reply,
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user