This commit is contained in:
2023-10-18 21:41:56 +02:00
parent 580b712496
commit 75f8681a5e
8 changed files with 1691 additions and 4966 deletions

54
.github/workflows/docker.yml vendored Normal file
View File

@@ -0,0 +1,54 @@
# This workflow uses actions that are not certified by GitHub.
# They are provided by a third-party and are governed by
# separate terms of service, privacy policy, and support
# documentation.
# GitHub recommends pinning actions to a commit SHA.
# To get a newer version, you will need to update the SHA.
# You can also reference a tag or branch, but the action may change without warning.
name: Publish Docker image
on:
push:
branches:
- main
jobs:
push_to_registry:
name: Push Docker image to Docker Hub
runs-on: ubuntu-latest
steps:
- name: Check out the repo
uses: actions/checkout@v3
- name: Log in to Sr Izan's container registry
uses: docker/login-action@f4ef78c080cd8ba55a85445d5b36e214a81df20a
with:
registry: containers.srizan.dev
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@9ec57ed1fcdbf14dcef7dfbe97b2010124a938b7
with:
images: containers.srizan.dev/femboy
tags: latest
- name: Build and push Docker image
uses: docker/build-push-action@3b5e8027fcad23fda98b2e3ac259d8d67585f671
with:
context: .
file: ./Dockerfile
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
- name: Emit a webhook to the server
env:
AUTH_HEADER: ${{ secrets.WHSERVER_TOKEN }}
run: |
curl -X POST \
-H "Authorization: Bearer $AUTH_HEADER" \
https://webhooks.srizan.dev/hooks/femboy

View File

@@ -1,13 +1,23 @@
FROM node:lts-alpine
# Build stage
FROM node:lts-alpine AS build
WORKDIR /app
COPY package.json ./
RUN npm i
COPY package.json yarn.lock ./
RUN yarn
COPY . .
RUN yarn build
RUN npm run build
# Final stage
FROM node:lts-alpine AS final
CMD node ./dist/index.js
WORKDIR /app
COPY --from=build /app/dist ./dist
COPY --from=build /app/plugins ./plugins
COPY --from=build /app/schemas ./schemas
COPY --from=build /app/node_modules ./node_modules
COPY --from=build /app/package.json ./package.json
CMD ["node", "dist/index.js"]

View File

@@ -1,5 +1,5 @@
import { Client, GatewayIntentBits } from 'discord.js';
import { DefaultLogging, Dependencies, Sern, SernEmitter, single, Singleton } from '@sern/handler';
import { makeDependencies, Sern, single } from '@sern/handler';
import 'dotenv/config'
import mongoose from 'mongoose';
@@ -13,22 +13,14 @@ const client = new Client({
],
});
interface MyDependencies extends Dependencies {
'@sern/client' : Singleton<Client>;
'@sern/logger' : Singleton<DefaultLogging>
}
export const useContainer = Sern.makeDependencies<MyDependencies>({
build: root => root
.add({ '@sern/client': single(client) })
.add({ '@sern/logger': single(new DefaultLogging()) })
await makeDependencies({
build: root => root.add({ '@sern/client': single(() => client) })
});
Sern.init({
commands: './dist/commands/',
events: './dist/events/',
defaultPrefix: 'fmb!',
containerConfig: {
get: useContainer
}
});
mongoose.connect(process.env.MONGODB!)

4758
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@@ -16,15 +16,15 @@
],
"license": "UNLICENSED",
"dependencies": {
"@sern/handler": "^2.1.1",
"@sern/handler": "^3.1.0",
"axios": "^0.27.2",
"discord.js": "^14.2.0",
"discord.js": "^14.13.0",
"dotenv": "^16.0.3",
"mongoose": "^6.7.2"
},
"devDependencies": {
"@types/node": "^17.0.25",
"tsc-watch": "^5.0.3",
"typescript": "^4.6.3"
"typescript": "^5.2.2"
}
}

View File

@@ -1,8 +1,9 @@
//@ts-nocheck
/**
* @plugin
* This plugin checks if the channel is nsfw and responds to user with a specified response if not nsfw
*
* @author @NeoYaBoi [<@762918086349029386>]
* @author @Benzo-Fury [<@762918086349029386>]
* @version 1.0.0
* @example
* ```ts
@@ -15,6 +16,7 @@
* }
* })
* ```
* @end
*/
import {
ChannelType,
@@ -22,25 +24,17 @@ import {
TextBasedChannel,
TextChannel,
} from "discord.js";
import { CommandType, EventPlugin, Nullish, PluginType } from "@sern/handler";
import { CommandControlPlugin, CommandType, controller } from "@sern/handler";
function isGuildText(
channel: Nullish<TextBasedChannel>
channel: TextBasedChannel | null,
): channel is GuildTextBasedChannel {
return (
channel?.type == ChannelType.GuildPublicThread ||
channel?.type == ChannelType.GuildPrivateThread
channel?.type == ChannelType.PublicThread ||
channel?.type == ChannelType.PrivateThread
);
}
export function nsfwOnly(
onFail: string,
ephemeral: boolean
): EventPlugin<CommandType.Both> {
return {
type: PluginType.Event,
description: "Checks if the channel is nsfw or not.",
async execute(event, controller) {
const [ctx] = event;
//checking if command was executed in dms
export function nsfwOnly(onFail: string, ephemeral: boolean) {
return CommandControlPlugin<CommandType.Both>(async (ctx, _) => {
if (ctx.guild === null) {
await ctx.reply({ content: onFail, ephemeral });
return controller.stop();
@@ -57,6 +51,5 @@ export function nsfwOnly(
}
//continues to command if nsfw
return controller.next();
},
};
});
}

View File

@@ -1,6 +1,7 @@
// @ts-nocheck
/**
* This is publish plugin, it allows you to publish your application commands using the discord.js library with ease.
* @plugin
* [DEPRECATED] It allows you to publish your application commands using the discord.js library with ease.
*
* @author @EvolutionX-10 [<@697795666373640213>]
* @version 2.0.0
@@ -16,40 +17,46 @@
* }
* })
* ```
* @end
*/
import {
CommandPlugin,
CommandInitPlugin,
CommandType,
PluginType,
controller,
SernOptionsData,
SlashCommand,
Service,
} from "@sern/handler";
import {
ApplicationCommandData,
ApplicationCommandType,
ApplicationCommandOptionType,
PermissionResolvable,
} from "discord.js";
/**
* This is the dependency getter that is created from Sern.makeDependencies.
* import it here so that this plugin has access to your bot's dependencies
*/
import { useContainer } from "../index.js";
export function publish(
options?: PublishOptions
): CommandPlugin<
| CommandType.Slash
export const CommandTypeRaw = {
[CommandType.Both]: ApplicationCommandType.ChatInput,
[CommandType.CtxUser]: ApplicationCommandType.User,
[CommandType.CtxMsg]: ApplicationCommandType.Message,
[CommandType.Slash]: ApplicationCommandType.ChatInput,
} as const;
export function publish<
T extends
| CommandType.Both
| CommandType.CtxUser
| CommandType.Slash
| CommandType.CtxMsg
> {
return {
type: PluginType.Command,
description: "Manage Application Commands",
name: "slash-auto-publish",
async execute({ mod: module }, controller) {
| CommandType.CtxUser,
>(options?: PublishOptions) {
return CommandInitPlugin<T>(async ({ module }) => {
// Users need to provide their own useContainer function.
const [client] = useContainer("@sern/client");
let client;
try {
client = (await import("@sern/handler")).Service("@sern/client");
} catch {
const { useContainer } = await import("../index.js");
client = useContainer("@sern/client")[0];
}
const defaultOptions = {
guildIds: [],
dmPermission: undefined,
@@ -65,6 +72,7 @@ export function publish(
console.error("publish command didnt work for", module.name);
console.error(e);
}
const log =
(...message: any[]) =>
() =>
@@ -79,8 +87,7 @@ export function publish(
* @returns S | T
*/
const appCmd = <V extends CommandType, S, T>(t: V) => {
return (is: S, els: T) =>
(t & CommandType.Both) !== 0 ? is : els;
return (is: S, els: T) => ((t & CommandType.Both) !== 0 ? is : els);
};
const curAppType = CommandTypeRaw[module.type];
const createCommandData = () => {
@@ -90,10 +97,8 @@ export function publish(
type: curAppType,
description: cmd(module.description, ""),
options: cmd(
optionsTransformer(
(module as SlashCommand).options ?? []
),
[]
optionsTransformer((module as SlashCommand).options ?? []),
[],
),
defaultMemberPermissions,
dmPermission,
@@ -104,20 +109,18 @@ export function publish(
const commandData = createCommandData();
if (!guildIds.length) {
const cmd = (
await client.application!.commands.fetch()
).find(
(c) => c.name === module.name && c.type === curAppType
const cmd = (await client.application!.commands.fetch()).find(
(c) => c.name === module.name && c.type === curAppType,
);
if (cmd) {
if (!cmd.equals(commandData, true)) {
logged(
`Found differences in global command ${module.name}`
`Found differences in global command ${module.name}`,
);
cmd.edit(commandData).then(
log(
`${module.name} updated with new data successfully!`
)
`${module.name} updated with new data successfully!`,
),
);
}
return controller.next();
@@ -133,19 +136,17 @@ export function publish(
const guild = await client.guilds.fetch(id).catch(c);
if (!guild) continue;
const guildCmd = (await guild.commands.fetch()).find(
(c) => c.name === module.name && c.type === curAppType
(c) => c.name === module.name && c.type === curAppType,
);
if (guildCmd) {
if (!guildCmd.equals(commandData, true)) {
logged(
`Found differences in command ${module.name}`
);
logged(`Found differences in command ${module.name}`);
guildCmd
.edit(commandData)
.then(
log(
`${module.name} updated with new data successfully!`
)
`${module.name} updated with new data successfully!`,
),
)
.catch(c);
continue;
@@ -154,13 +155,7 @@ export function publish(
}
guild.commands
.create(commandData)
.then(
log(
"Guild Command created",
module.name,
guild.name
)
)
.then(log("Guild Command created", module.name, guild.name))
.catch(c);
}
return controller.next();
@@ -169,23 +164,25 @@ export function publish(
logged(e);
return controller.stop();
}
},
};
});
}
export function optionsTransformer(ops: Array<SernOptionsData>) {
return ops.map((el) =>
el.autocomplete ? (({ command, ...el }) => el)(el) : el
);
return ops.map((el) => {
switch (el.type) {
case ApplicationCommandOptionType.String:
case ApplicationCommandOptionType.Number:
case ApplicationCommandOptionType.Integer: {
return el.autocomplete && "command" in el
? (({ command, ...el }) => el)(el)
: el;
}
default:
return el;
}
});
}
export const CommandTypeRaw = {
[CommandType.Both]: ApplicationCommandType.ChatInput,
[CommandType.CtxUser]: ApplicationCommandType.Message,
[CommandType.CtxMsg]: ApplicationCommandType.User,
[CommandType.Slash]: ApplicationCommandType.ChatInput,
} as const;
export type NonEmptyArray<T extends `${number}` = `${number}`> = [T, ...T[]];
export interface ValidPublishOptions {
@@ -193,11 +190,13 @@ export interface ValidPublishOptions {
dmPermission: boolean;
defaultMemberPermissions: PermissionResolvable;
}
interface GuildPublishOptions {
guildIds?: NonEmptyArray;
defaultMemberPermissions?: PermissionResolvable;
dmPermission?: never;
}
interface GlobalPublishOptions {
defaultMemberPermissions?: PermissionResolvable;
dmPermission?: false;

1435
yarn.lock Normal file

File diff suppressed because it is too large Load Diff