mirror of
https://github.com/SrIzan10/femboybot.git
synced 2026-06-06 00:56:50 +00:00
asdf
This commit is contained in:
54
.github/workflows/docker.yml
vendored
Normal file
54
.github/workflows/docker.yml
vendored
Normal 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
|
||||
22
Dockerfile
22
Dockerfile
@@ -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"]
|
||||
16
index.ts
16
index.ts
@@ -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
4758
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@@ -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"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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,41 +24,32 @@ 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
|
||||
if (ctx.guild === null) {
|
||||
await ctx.reply({ content: onFail, ephemeral });
|
||||
return controller.stop();
|
||||
}
|
||||
//channel is thread (not supported by nsfw)
|
||||
if (isGuildText(ctx.channel) == true) {
|
||||
await ctx.reply({ content: onFail, ephemeral });
|
||||
return controller.stop();
|
||||
}
|
||||
if (!(ctx.channel! as TextChannel).nsfw) {
|
||||
//channel is not nsfw
|
||||
await ctx.reply({ content: onFail, ephemeral });
|
||||
return controller.stop();
|
||||
}
|
||||
//continues to command if nsfw
|
||||
return controller.next();
|
||||
},
|
||||
};
|
||||
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();
|
||||
}
|
||||
//channel is thread (not supported by nsfw)
|
||||
if (isGuildText(ctx.channel) == true) {
|
||||
await ctx.reply({ content: onFail, ephemeral });
|
||||
return controller.stop();
|
||||
}
|
||||
if (!(ctx.channel! as TextChannel).nsfw) {
|
||||
//channel is not nsfw
|
||||
await ctx.reply({ content: onFail, ephemeral });
|
||||
return controller.stop();
|
||||
}
|
||||
//continues to command if nsfw
|
||||
return controller.next();
|
||||
});
|
||||
}
|
||||
|
||||
@@ -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,176 +17,172 @@
|
||||
* }
|
||||
* })
|
||||
* ```
|
||||
* @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
|
||||
| CommandType.Both
|
||||
| CommandType.CtxUser
|
||||
| CommandType.CtxMsg
|
||||
> {
|
||||
return {
|
||||
type: PluginType.Command,
|
||||
description: "Manage Application Commands",
|
||||
name: "slash-auto-publish",
|
||||
async execute({ mod: module }, controller) {
|
||||
// Users need to provide their own useContainer function.
|
||||
const [client] = useContainer("@sern/client");
|
||||
const defaultOptions = {
|
||||
guildIds: [],
|
||||
dmPermission: undefined,
|
||||
defaultMemberPermissions: null,
|
||||
};
|
||||
|
||||
options = { ...defaultOptions, ...options } as PublishOptions &
|
||||
ValidPublishOptions;
|
||||
let { defaultMemberPermissions, dmPermission, guildIds } =
|
||||
options as unknown as ValidPublishOptions;
|
||||
|
||||
function c(e: unknown) {
|
||||
console.error("publish command didnt work for", module.name);
|
||||
console.error(e);
|
||||
}
|
||||
const log =
|
||||
(...message: any[]) =>
|
||||
() =>
|
||||
console.log(...message);
|
||||
const logged = (...message: any[]) => log(message);
|
||||
/**
|
||||
* a local function that returns either one value or the other,
|
||||
* depending on {t}'s CommandType. If the commandtype of
|
||||
* this module is CommandType.Both or CommandType.Text or CommandType.Slash,
|
||||
* return 'is', else return 'els'
|
||||
* @param t
|
||||
* @returns S | T
|
||||
*/
|
||||
const appCmd = <V extends CommandType, S, T>(t: V) => {
|
||||
return (is: S, els: T) =>
|
||||
(t & CommandType.Both) !== 0 ? is : els;
|
||||
};
|
||||
const curAppType = CommandTypeRaw[module.type];
|
||||
const createCommandData = () => {
|
||||
const cmd = appCmd(module.type);
|
||||
return {
|
||||
name: module.name,
|
||||
type: curAppType,
|
||||
description: cmd(module.description, ""),
|
||||
options: cmd(
|
||||
optionsTransformer(
|
||||
(module as SlashCommand).options ?? []
|
||||
),
|
||||
[]
|
||||
),
|
||||
defaultMemberPermissions,
|
||||
dmPermission,
|
||||
} as ApplicationCommandData;
|
||||
};
|
||||
|
||||
try {
|
||||
const commandData = createCommandData();
|
||||
|
||||
if (!guildIds.length) {
|
||||
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}`
|
||||
);
|
||||
cmd.edit(commandData).then(
|
||||
log(
|
||||
`${module.name} updated with new data successfully!`
|
||||
)
|
||||
);
|
||||
}
|
||||
return controller.next();
|
||||
}
|
||||
client
|
||||
.application!.commands.create(commandData)
|
||||
.then(log("Command created", module.name))
|
||||
.catch(c);
|
||||
return controller.next();
|
||||
}
|
||||
|
||||
for (const id of guildIds) {
|
||||
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
|
||||
);
|
||||
if (guildCmd) {
|
||||
if (!guildCmd.equals(commandData, true)) {
|
||||
logged(
|
||||
`Found differences in command ${module.name}`
|
||||
);
|
||||
guildCmd
|
||||
.edit(commandData)
|
||||
.then(
|
||||
log(
|
||||
`${module.name} updated with new data successfully!`
|
||||
)
|
||||
)
|
||||
.catch(c);
|
||||
continue;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
guild.commands
|
||||
.create(commandData)
|
||||
.then(
|
||||
log(
|
||||
"Guild Command created",
|
||||
module.name,
|
||||
guild.name
|
||||
)
|
||||
)
|
||||
.catch(c);
|
||||
}
|
||||
return controller.next();
|
||||
} catch (e) {
|
||||
logged("Command did not register" + module.name);
|
||||
logged(e);
|
||||
return controller.stop();
|
||||
}
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
export function optionsTransformer(ops: Array<SernOptionsData>) {
|
||||
return ops.map((el) =>
|
||||
el.autocomplete ? (({ command, ...el }) => el)(el) : el
|
||||
);
|
||||
}
|
||||
|
||||
export const CommandTypeRaw = {
|
||||
[CommandType.Both]: ApplicationCommandType.ChatInput,
|
||||
[CommandType.CtxUser]: ApplicationCommandType.Message,
|
||||
[CommandType.CtxMsg]: ApplicationCommandType.User,
|
||||
[CommandType.CtxUser]: ApplicationCommandType.User,
|
||||
[CommandType.CtxMsg]: ApplicationCommandType.Message,
|
||||
[CommandType.Slash]: ApplicationCommandType.ChatInput,
|
||||
} as const;
|
||||
|
||||
export function publish<
|
||||
T extends
|
||||
| CommandType.Both
|
||||
| CommandType.Slash
|
||||
| CommandType.CtxMsg
|
||||
| CommandType.CtxUser,
|
||||
>(options?: PublishOptions) {
|
||||
return CommandInitPlugin<T>(async ({ module }) => {
|
||||
// Users need to provide their own useContainer function.
|
||||
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,
|
||||
defaultMemberPermissions: null,
|
||||
};
|
||||
|
||||
options = { ...defaultOptions, ...options } as PublishOptions &
|
||||
ValidPublishOptions;
|
||||
let { defaultMemberPermissions, dmPermission, guildIds } =
|
||||
options as unknown as ValidPublishOptions;
|
||||
|
||||
function c(e: unknown) {
|
||||
console.error("publish command didnt work for", module.name);
|
||||
console.error(e);
|
||||
}
|
||||
|
||||
const log =
|
||||
(...message: any[]) =>
|
||||
() =>
|
||||
console.log(...message);
|
||||
const logged = (...message: any[]) => log(message);
|
||||
/**
|
||||
* a local function that returns either one value or the other,
|
||||
* depending on {t}'s CommandType. If the commandtype of
|
||||
* this module is CommandType.Both or CommandType.Text or CommandType.Slash,
|
||||
* return 'is', else return 'els'
|
||||
* @param t
|
||||
* @returns S | T
|
||||
*/
|
||||
const appCmd = <V extends CommandType, S, T>(t: V) => {
|
||||
return (is: S, els: T) => ((t & CommandType.Both) !== 0 ? is : els);
|
||||
};
|
||||
const curAppType = CommandTypeRaw[module.type];
|
||||
const createCommandData = () => {
|
||||
const cmd = appCmd(module.type);
|
||||
return {
|
||||
name: module.name,
|
||||
type: curAppType,
|
||||
description: cmd(module.description, ""),
|
||||
options: cmd(
|
||||
optionsTransformer((module as SlashCommand).options ?? []),
|
||||
[],
|
||||
),
|
||||
defaultMemberPermissions,
|
||||
dmPermission,
|
||||
} as ApplicationCommandData;
|
||||
};
|
||||
|
||||
try {
|
||||
const commandData = createCommandData();
|
||||
|
||||
if (!guildIds.length) {
|
||||
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}`,
|
||||
);
|
||||
cmd.edit(commandData).then(
|
||||
log(
|
||||
`${module.name} updated with new data successfully!`,
|
||||
),
|
||||
);
|
||||
}
|
||||
return controller.next();
|
||||
}
|
||||
client
|
||||
.application!.commands.create(commandData)
|
||||
.then(log("Command created", module.name))
|
||||
.catch(c);
|
||||
return controller.next();
|
||||
}
|
||||
|
||||
for (const id of guildIds) {
|
||||
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,
|
||||
);
|
||||
if (guildCmd) {
|
||||
if (!guildCmd.equals(commandData, true)) {
|
||||
logged(`Found differences in command ${module.name}`);
|
||||
guildCmd
|
||||
.edit(commandData)
|
||||
.then(
|
||||
log(
|
||||
`${module.name} updated with new data successfully!`,
|
||||
),
|
||||
)
|
||||
.catch(c);
|
||||
continue;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
guild.commands
|
||||
.create(commandData)
|
||||
.then(log("Guild Command created", module.name, guild.name))
|
||||
.catch(c);
|
||||
}
|
||||
return controller.next();
|
||||
} catch (e) {
|
||||
logged("Command did not register" + module.name);
|
||||
logged(e);
|
||||
return controller.stop();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
export function optionsTransformer(ops: Array<SernOptionsData>) {
|
||||
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 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;
|
||||
|
||||
Reference in New Issue
Block a user