Merge branch 'main' into develop
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
commit
cca34a476c
16 changed files with 95 additions and 11 deletions
4
.dev.env
4
.dev.env
|
@ -7,7 +7,7 @@
|
||||||
# any secret values.
|
# any secret values.
|
||||||
|
|
||||||
BOT_TOKEN=
|
BOT_TOKEN=
|
||||||
BOT_VER=3.2 DEV
|
BOT_VER=3.2.1
|
||||||
BOT_AUTHOR=Vylpes
|
BOT_AUTHOR=Vylpes
|
||||||
BOT_OWNERID=147392775707426816
|
BOT_OWNERID=147392775707426816
|
||||||
BOT_CLIENTID=682942374040961060
|
BOT_CLIENTID=682942374040961060
|
||||||
|
@ -15,6 +15,8 @@ BOT_CLIENTID=682942374040961060
|
||||||
ABOUT_FUNDING=https://ko-fi.com/vylpes
|
ABOUT_FUNDING=https://ko-fi.com/vylpes
|
||||||
ABOUT_REPO=https://gitea.vylpes.xyz/RabbitLabs/vylbot-app
|
ABOUT_REPO=https://gitea.vylpes.xyz/RabbitLabs/vylbot-app
|
||||||
|
|
||||||
|
CACHE_INTERVAL=1800000 # 30 minutes
|
||||||
|
|
||||||
DB_HOST=127.0.0.1
|
DB_HOST=127.0.0.1
|
||||||
DB_PORT=3101
|
DB_PORT=3101
|
||||||
DB_NAME=vylbot
|
DB_NAME=vylbot
|
||||||
|
|
|
@ -7,7 +7,7 @@
|
||||||
# any secret values.
|
# any secret values.
|
||||||
|
|
||||||
BOT_TOKEN=
|
BOT_TOKEN=
|
||||||
BOT_VER=3.2
|
BOT_VER=3.2.1
|
||||||
BOT_AUTHOR=Vylpes
|
BOT_AUTHOR=Vylpes
|
||||||
BOT_OWNERID=147392775707426816
|
BOT_OWNERID=147392775707426816
|
||||||
BOT_CLIENTID=680083120896081954
|
BOT_CLIENTID=680083120896081954
|
||||||
|
@ -15,6 +15,8 @@ BOT_CLIENTID=680083120896081954
|
||||||
ABOUT_FUNDING=https://ko-fi.com/vylpes
|
ABOUT_FUNDING=https://ko-fi.com/vylpes
|
||||||
ABOUT_REPO=https://gitea.vylpes.xyz/RabbitLabs/vylbot-app
|
ABOUT_REPO=https://gitea.vylpes.xyz/RabbitLabs/vylbot-app
|
||||||
|
|
||||||
|
CACHE_INTERVAL=1800000 # 30 minutes
|
||||||
|
|
||||||
DB_HOST=127.0.0.1
|
DB_HOST=127.0.0.1
|
||||||
DB_PORT=3121
|
DB_PORT=3121
|
||||||
DB_NAME=vylbot
|
DB_NAME=vylbot
|
||||||
|
|
|
@ -7,7 +7,7 @@
|
||||||
# any secret values.
|
# any secret values.
|
||||||
|
|
||||||
BOT_TOKEN=
|
BOT_TOKEN=
|
||||||
BOT_VER=3.2 BETA
|
BOT_VER=3.2.1
|
||||||
BOT_AUTHOR=Vylpes
|
BOT_AUTHOR=Vylpes
|
||||||
BOT_OWNERID=147392775707426816
|
BOT_OWNERID=147392775707426816
|
||||||
BOT_CLIENTID=1016767908740857949
|
BOT_CLIENTID=1016767908740857949
|
||||||
|
@ -15,6 +15,8 @@ BOT_CLIENTID=1016767908740857949
|
||||||
ABOUT_FUNDING=https://ko-fi.com/vylpes
|
ABOUT_FUNDING=https://ko-fi.com/vylpes
|
||||||
ABOUT_REPO=https://gitea.vylpes.xyz/RabbitLabs/vylbot-app
|
ABOUT_REPO=https://gitea.vylpes.xyz/RabbitLabs/vylbot-app
|
||||||
|
|
||||||
|
CACHE_INTERVAL=1800000 # 30 minutes
|
||||||
|
|
||||||
DB_HOST=127.0.0.1
|
DB_HOST=127.0.0.1
|
||||||
DB_PORT=3111
|
DB_PORT=3111
|
||||||
DB_NAME=vylbot
|
DB_NAME=vylbot
|
||||||
|
|
|
@ -0,0 +1,2 @@
|
||||||
|
ALTER TABLE server
|
||||||
|
ADD LastCached datetime NOT NULL DEFAULT '2024-03-01 18:10:04';
|
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "vylbot-app",
|
"name": "vylbot-app",
|
||||||
"version": "3.2.0",
|
"version": "3.2.1",
|
||||||
"description": "A discord bot made for Vylpes' Den",
|
"description": "A discord bot made for Vylpes' Den",
|
||||||
"main": "./dist/vylbot",
|
"main": "./dist/vylbot",
|
||||||
"typings": "./dist",
|
"typings": "./dist",
|
||||||
|
@ -11,6 +11,7 @@
|
||||||
"test": "echo true",
|
"test": "echo true",
|
||||||
"db:up": "typeorm migration:run -d dist/database/dataSources/appDataSource.js",
|
"db:up": "typeorm migration:run -d dist/database/dataSources/appDataSource.js",
|
||||||
"db:down": "typeorm migration:revert -d dist/database/dataSources/appDataSource.js",
|
"db:down": "typeorm migration:revert -d dist/database/dataSources/appDataSource.js",
|
||||||
|
"db:create": "typeorm migration:create ./src/database/migrations",
|
||||||
"release": "np --no-publish"
|
"release": "np --no-publish"
|
||||||
},
|
},
|
||||||
"repository": {
|
"repository": {
|
||||||
|
@ -41,7 +42,8 @@
|
||||||
"typeorm": "0.3.20"
|
"typeorm": "0.3.20"
|
||||||
},
|
},
|
||||||
"resolutions": {
|
"resolutions": {
|
||||||
"**/semver": "^7.5.2"
|
"**/semver": "^7.5.2",
|
||||||
|
"**/undici": "^5.28.3"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@types/node": "^20.0.0",
|
"@types/node": "^20.0.0",
|
||||||
|
|
|
@ -11,6 +11,7 @@ import { Util } from "./util";
|
||||||
import AppDataSource from "../database/dataSources/appDataSource";
|
import AppDataSource from "../database/dataSources/appDataSource";
|
||||||
import ButtonEventItem from "../contracts/ButtonEventItem";
|
import ButtonEventItem from "../contracts/ButtonEventItem";
|
||||||
import { ButtonEvent } from "../type/buttonEvent";
|
import { ButtonEvent } from "../type/buttonEvent";
|
||||||
|
import CacheHelper from "../helpers/CacheHelper";
|
||||||
|
|
||||||
export class CoreClient extends Client {
|
export class CoreClient extends Client {
|
||||||
private static _commandItems: ICommandItem[];
|
private static _commandItems: ICommandItem[];
|
||||||
|
@ -59,6 +60,10 @@ export class CoreClient extends Client {
|
||||||
|
|
||||||
await super.login(process.env.BOT_TOKEN);
|
await super.login(process.env.BOT_TOKEN);
|
||||||
|
|
||||||
|
this.guilds.cache.forEach(async (guild) => {
|
||||||
|
await CacheHelper.UpdateServerCache(guild);
|
||||||
|
});
|
||||||
|
|
||||||
this._util.loadEvents(this, CoreClient._eventItems);
|
this._util.loadEvents(this, CoreClient._eventItems);
|
||||||
this._util.loadSlashCommands(this);
|
this._util.loadSlashCommands(this);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
import { Entity, OneToMany } from "typeorm";
|
import { Column, Entity, OneToMany } from "typeorm";
|
||||||
import BaseEntity from "../../contracts/BaseEntity";
|
import BaseEntity from "../../contracts/BaseEntity";
|
||||||
import Role from "./Role";
|
import Role from "./Role";
|
||||||
import Setting from "./Setting";
|
import Setting from "./Setting";
|
||||||
|
@ -9,14 +9,22 @@ export default class Server extends BaseEntity {
|
||||||
super();
|
super();
|
||||||
|
|
||||||
this.Id = serverId;
|
this.Id = serverId;
|
||||||
|
this.LastCached = new Date();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Column({ default: "2024-03-01 18:10:04" })
|
||||||
|
LastCached: Date;
|
||||||
|
|
||||||
@OneToMany(() => Setting, x => x.Server)
|
@OneToMany(() => Setting, x => x.Server)
|
||||||
Settings: Setting[];
|
Settings: Setting[];
|
||||||
|
|
||||||
@OneToMany(() => Role, x => x.Server)
|
@OneToMany(() => Role, x => x.Server)
|
||||||
Roles: Role[];
|
Roles: Role[];
|
||||||
|
|
||||||
|
public UpdateLastCached(lastCached: Date) {
|
||||||
|
this.LastCached = lastCached;
|
||||||
|
}
|
||||||
|
|
||||||
public AddSettingToServer(setting: Setting) {
|
public AddSettingToServer(setting: Setting) {
|
||||||
this.Settings.push(setting);
|
this.Settings.push(setting);
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,15 @@
|
||||||
|
import { MigrationInterface, QueryRunner } from "typeorm"
|
||||||
|
import MigrationHelper from "../../../helpers/MigrationHelper"
|
||||||
|
|
||||||
|
export class AddServerCacheDate1709316734401 implements MigrationInterface {
|
||||||
|
|
||||||
|
public async up(queryRunner: QueryRunner): Promise<void> {
|
||||||
|
MigrationHelper.Up('1709316734401-AddServerCacheDate', '3.2.1', [
|
||||||
|
"01-Server",
|
||||||
|
], queryRunner);
|
||||||
|
}
|
||||||
|
|
||||||
|
public async down(queryRunner: QueryRunner): Promise<void> {
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -1,10 +1,13 @@
|
||||||
import { EmbedBuilder, GuildMember, TextChannel } from "discord.js";
|
import { EmbedBuilder, GuildMember, TextChannel } from "discord.js";
|
||||||
import EmbedColours from "../../constants/EmbedColours";
|
import EmbedColours from "../../constants/EmbedColours";
|
||||||
import SettingsHelper from "../../helpers/SettingsHelper";
|
import SettingsHelper from "../../helpers/SettingsHelper";
|
||||||
|
import CacheHelper from "../../helpers/CacheHelper";
|
||||||
|
|
||||||
export default async function GuildMemberAdd(member: GuildMember) {
|
export default async function GuildMemberAdd(member: GuildMember) {
|
||||||
if (!member.guild) return;
|
if (!member.guild) return;
|
||||||
|
|
||||||
|
await CacheHelper.UpdateServerCache(member.guild);
|
||||||
|
|
||||||
const enabled = await SettingsHelper.GetSetting("event.member.add.enabled", member.guild.id);
|
const enabled = await SettingsHelper.GetSetting("event.member.add.enabled", member.guild.id);
|
||||||
if (!enabled || enabled.toLowerCase() != "true") return;
|
if (!enabled || enabled.toLowerCase() != "true") return;
|
||||||
|
|
||||||
|
|
|
@ -1,10 +1,13 @@
|
||||||
import { EmbedBuilder, GuildMember, TextChannel } from "discord.js";
|
import { EmbedBuilder, GuildMember, TextChannel } from "discord.js";
|
||||||
import EmbedColours from "../../constants/EmbedColours";
|
import EmbedColours from "../../constants/EmbedColours";
|
||||||
import SettingsHelper from "../../helpers/SettingsHelper";
|
import SettingsHelper from "../../helpers/SettingsHelper";
|
||||||
|
import CacheHelper from "../../helpers/CacheHelper";
|
||||||
|
|
||||||
export default async function GuildMemberRemove(member: GuildMember) {
|
export default async function GuildMemberRemove(member: GuildMember) {
|
||||||
if (!member.guild) return;
|
if (!member.guild) return;
|
||||||
|
|
||||||
|
await CacheHelper.UpdateServerCache(member.guild);
|
||||||
|
|
||||||
const enabled = await SettingsHelper.GetSetting("event.member.remove.enabled", member.guild.id);
|
const enabled = await SettingsHelper.GetSetting("event.member.remove.enabled", member.guild.id);
|
||||||
if (!enabled || enabled.toLowerCase() != "true") return;
|
if (!enabled || enabled.toLowerCase() != "true") return;
|
||||||
|
|
||||||
|
|
|
@ -1,8 +1,11 @@
|
||||||
import { GuildMember } from "discord.js";
|
import { GuildMember } from "discord.js";
|
||||||
import NicknameChanged from "./GuildMemberUpdate/NicknameChanged";
|
import NicknameChanged from "./GuildMemberUpdate/NicknameChanged";
|
||||||
|
import CacheHelper from "../../helpers/CacheHelper";
|
||||||
|
|
||||||
export default async function GuildMemberUpdate(oldMember: GuildMember, newMember: GuildMember) {
|
export default async function GuildMemberUpdate(oldMember: GuildMember, newMember: GuildMember) {
|
||||||
if (oldMember.nickname != newMember.nickname) { // Nickname change
|
await CacheHelper.UpdateServerCache(newMember.guild);
|
||||||
|
|
||||||
|
if (oldMember.nickname !== newMember.nickname) { // Nickname change
|
||||||
await NicknameChanged(oldMember, newMember);
|
await NicknameChanged(oldMember, newMember);
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,11 +1,14 @@
|
||||||
import { Message } from "discord.js";
|
import { Message } from "discord.js";
|
||||||
import SettingsHelper from "../../helpers/SettingsHelper";
|
import SettingsHelper from "../../helpers/SettingsHelper";
|
||||||
import VerificationCheck from "./MessageCreate/VerificationCheck";
|
import VerificationCheck from "./MessageCreate/VerificationCheck";
|
||||||
|
import CacheHelper from "../../helpers/CacheHelper";
|
||||||
|
|
||||||
export default async function MessageCreate(message: Message) {
|
export default async function MessageCreate(message: Message) {
|
||||||
if (!message.guild) return;
|
if (!message.guild) return;
|
||||||
if (message.author.bot) return;
|
if (message.author.bot) return;
|
||||||
|
|
||||||
|
await CacheHelper.UpdateServerCache(message.guild);
|
||||||
|
|
||||||
const isVerificationEnabled = await SettingsHelper.GetSetting("verification.enabled", message.guild.id);
|
const isVerificationEnabled = await SettingsHelper.GetSetting("verification.enabled", message.guild.id);
|
||||||
|
|
||||||
if (isVerificationEnabled && isVerificationEnabled.toLocaleLowerCase() == "true") {
|
if (isVerificationEnabled && isVerificationEnabled.toLocaleLowerCase() == "true") {
|
||||||
|
|
|
@ -2,11 +2,14 @@ import { EmbedBuilder, Message, TextChannel } from "discord.js";
|
||||||
import EmbedColours from "../../constants/EmbedColours";
|
import EmbedColours from "../../constants/EmbedColours";
|
||||||
import IgnoredChannel from "../../database/entities/IgnoredChannel";
|
import IgnoredChannel from "../../database/entities/IgnoredChannel";
|
||||||
import SettingsHelper from "../../helpers/SettingsHelper";
|
import SettingsHelper from "../../helpers/SettingsHelper";
|
||||||
|
import CacheHelper from "../../helpers/CacheHelper";
|
||||||
|
|
||||||
export default async function MessageDelete(message: Message) {
|
export default async function MessageDelete(message: Message) {
|
||||||
if (!message.guild) return;
|
if (!message.guild) return;
|
||||||
if (message.author.bot) return;
|
if (message.author.bot) return;
|
||||||
|
|
||||||
|
await CacheHelper.UpdateServerCache(message.guild);
|
||||||
|
|
||||||
const enabled = await SettingsHelper.GetSetting("event.message.delete.enabled", message.guild.id);
|
const enabled = await SettingsHelper.GetSetting("event.message.delete.enabled", message.guild.id);
|
||||||
if (!enabled || enabled.toLowerCase() != "true") return;
|
if (!enabled || enabled.toLowerCase() != "true") return;
|
||||||
|
|
||||||
|
|
|
@ -2,10 +2,14 @@ import { EmbedBuilder, Message, TextChannel } from "discord.js";
|
||||||
import EmbedColours from "../../constants/EmbedColours";
|
import EmbedColours from "../../constants/EmbedColours";
|
||||||
import IgnoredChannel from "../../database/entities/IgnoredChannel";
|
import IgnoredChannel from "../../database/entities/IgnoredChannel";
|
||||||
import SettingsHelper from "../../helpers/SettingsHelper";
|
import SettingsHelper from "../../helpers/SettingsHelper";
|
||||||
|
import CacheHelper from "../../helpers/CacheHelper";
|
||||||
|
|
||||||
export default async function MessageUpdate(oldMessage: Message, newMessage: Message) {
|
export default async function MessageUpdate(oldMessage: Message, newMessage: Message) {
|
||||||
if (!newMessage.guild) return;
|
if (!newMessage.guild) return;
|
||||||
if (newMessage.author.bot) return;
|
if (newMessage.author.bot) return;
|
||||||
|
|
||||||
|
await CacheHelper.UpdateServerCache(newMessage.guild);
|
||||||
|
|
||||||
if (oldMessage.content == newMessage.content) return;
|
if (oldMessage.content == newMessage.content) return;
|
||||||
|
|
||||||
const enabled = await SettingsHelper.GetSetting("event.message.update.enabled", newMessage.guild.id);
|
const enabled = await SettingsHelper.GetSetting("event.message.update.enabled", newMessage.guild.id);
|
||||||
|
|
27
src/helpers/CacheHelper.ts
Normal file
27
src/helpers/CacheHelper.ts
Normal file
|
@ -0,0 +1,27 @@
|
||||||
|
import { Guild } from "discord.js";
|
||||||
|
import Server from "../database/entities/Server";
|
||||||
|
|
||||||
|
export default class CacheHelper {
|
||||||
|
public static async UpdateServerCache(guild: Guild) {
|
||||||
|
const cacheInterval = process.env.CACHE_INTERVAL;
|
||||||
|
|
||||||
|
if (!cacheInterval) return;
|
||||||
|
|
||||||
|
let server = await Server.FetchOneById(Server, guild.id);
|
||||||
|
|
||||||
|
if (!server) {
|
||||||
|
server = new Server(guild.id);
|
||||||
|
await server.Save(Server, server);
|
||||||
|
|
||||||
|
await CacheHelper.UpdateCache(guild);
|
||||||
|
} else if (server.LastCached.getTime() + Number(cacheInterval) < Date.now()) {
|
||||||
|
await CacheHelper.UpdateCache(guild);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static async UpdateCache(guild: Guild) {
|
||||||
|
console.log(`Updating cache for ${guild.name} (${guild.id})`);
|
||||||
|
|
||||||
|
await guild.members.fetch();
|
||||||
|
}
|
||||||
|
}
|
|
@ -4777,10 +4777,10 @@ undici-types@~5.26.4:
|
||||||
resolved "https://registry.yarnpkg.com/undici-types/-/undici-types-5.26.5.tgz#bcd539893d00b56e964fd2657a4866b221a65617"
|
resolved "https://registry.yarnpkg.com/undici-types/-/undici-types-5.26.5.tgz#bcd539893d00b56e964fd2657a4866b221a65617"
|
||||||
integrity sha512-JlCMO+ehdEIKqlFxk6IfVoAUVmgz7cU7zD/h9XZ0qzeosSHmUJVOzSQvvYSYWXkFXC+IfLKSIffhv0sVZup6pA==
|
integrity sha512-JlCMO+ehdEIKqlFxk6IfVoAUVmgz7cU7zD/h9XZ0qzeosSHmUJVOzSQvvYSYWXkFXC+IfLKSIffhv0sVZup6pA==
|
||||||
|
|
||||||
undici@5.27.2:
|
undici@5.27.2, undici@^5.28.3:
|
||||||
version "5.27.2"
|
version "5.28.3"
|
||||||
resolved "https://registry.yarnpkg.com/undici/-/undici-5.27.2.tgz#a270c563aea5b46cc0df2550523638c95c5d4411"
|
resolved "https://registry.yarnpkg.com/undici/-/undici-5.28.3.tgz#a731e0eff2c3fcfd41c1169a869062be222d1e5b"
|
||||||
integrity sha512-iS857PdOEy/y3wlM3yRp+6SNQQ6xU0mmZcwRSriqk+et/cwWAtwmIGf6WkoDN2EK/AMdCO/dfXzIwi+rFMrjjQ==
|
integrity sha512-3ItfzbrhDlINjaP0duwnNsKpDQk3acHI3gVJ1z4fmwMK31k5G9OVIAMLSIaP6w4FaGkaAkN6zaQO9LUvZ1t7VA==
|
||||||
dependencies:
|
dependencies:
|
||||||
"@fastify/busboy" "^2.0.0"
|
"@fastify/busboy" "^2.0.0"
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue