[skip ci] bot up (#304)

* Add a bot startup (bro scared of circulars) (#303)

* fix(channels): correct return type of mixin functions

* feat: startup bot in test

* fix: build

* fix: ?

* fix: ??

* ci(bot-up): update conditional
This commit is contained in:
Marcos Susaña 2024-12-10 09:24:00 -04:00 committed by GitHub
parent 0a444c3e1a
commit 4bad71399a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
9 changed files with 52 additions and 16 deletions

View File

@ -46,6 +46,14 @@ jobs:
- name: Test suites
run: pnpm test
- name: Run Bot
id: bot-up
if: env.BOT_TOKEN != ''
env:
BOT_TOKEN: ${{ secrets.BOT_TOKEN }}
run: node ./tests/bot.js
- name: Publish in pkg.pr.new
run: pnpx pkg-pr-new publish

4
src/cache/index.ts vendored
View File

@ -33,8 +33,8 @@ import {
import { Messages } from './resources/messages';
import { Overwrites } from './resources/overwrites';
export { BaseResource } from './resources/default/base';
export { GuildRelatedResource } from './resources/default/guild-related';
export { GuildBasedResource } from './resources/default/guild-based';
export { GuildRelatedResource } from './resources/default/guild-related';
export type InferAsyncCache = InternalOptions extends { asyncCache: infer P } ? P : false;
export type ReturnCache<T> = If<InferAsyncCache, Promise<T>, T>;
@ -199,7 +199,7 @@ export class Cache {
}
get hasBansIntent() {
return this.hasIntent('GuildBans');
return this.hasIntent('GuildModeration');
}
async bulkGet(

View File

@ -87,9 +87,9 @@ export class BaseClient {
name: '[Seyfert]',
});
langs? = new LangsHandler(this.logger);
commands? = new CommandHandler(this.logger, this);
components? = new ComponentHandler(this.logger, this);
langs = new LangsHandler(this.logger);
commands = new CommandHandler(this.logger, this);
components = new ComponentHandler(this.logger, this);
handleCommand!: HandleCommand;
private _applicationId?: string;

View File

@ -31,7 +31,7 @@ export class Client<Ready extends boolean = boolean> extends BaseClient {
memberUpdateHandler = new MemberUpdateHandler();
presenceUpdateHandler = new PresenceUpdateHandler();
collectors = new Collectors();
events? = new EventHandler(this);
events = new EventHandler(this);
constructor(options?: ClientOptions) {
super(options);
@ -57,7 +57,7 @@ export class Client<Ready extends boolean = boolean> extends BaseClient {
async loadEvents(dir?: string) {
dir ??= await this.getRC().then(x => ('events' in x.locations ? x.locations.events : undefined));
if (dir && this.events) {
if (dir) {
await this.events.load(dir);
this.logger.info('EventHandler loaded');
}

View File

@ -63,7 +63,7 @@ export class WorkerClient<Ready extends boolean = boolean> extends BaseClient {
memberUpdateHandler = new MemberUpdateHandler();
presenceUpdateHandler = new PresenceUpdateHandler();
collectors = new Collectors();
events? = new EventHandler(this);
events = new EventHandler(this);
me!: When<Ready, ClientUserStructure>;
promises = new Map<string, { resolve: (value: any) => void; timeout: NodeJS.Timeout }>();
@ -159,7 +159,7 @@ export class WorkerClient<Ready extends boolean = boolean> extends BaseClient {
async loadEvents(dir?: string) {
dir ??= await this.getRC().then(x => ('events' in x.locations ? x.locations.events : undefined));
if (dir && this.events) {
if (dir) {
await this.events.load(dir);
this.logger.info('EventHandler loaded');
}

View File

@ -16,7 +16,7 @@ export class BanShorter extends BaseShorter {
*/
async bulkCreate(guildId: string, body: RESTPostAPIGuildBulkBanJSONBody, reason?: string) {
const bans = await this.client.proxy.guilds(guildId)['bulk-bans'].post({ reason, body });
for (const id of bans.banned_users) this.client.cache.members?.removeIfNI('GuildBans', id, guildId);
for (const id of bans.banned_users) this.client.cache.members?.removeIfNI('GuildModeration', id, guildId);
return bans;
}
@ -39,7 +39,7 @@ export class BanShorter extends BaseShorter {
*/
async create(guildId: string, memberId: string, body?: RESTPutAPIGuildBanJSONBody, reason?: string) {
await this.client.proxy.guilds(guildId).bans(memberId).put({ reason, body });
await this.client.cache.members?.removeIfNI('GuildBans', memberId, guildId);
await this.client.cache.members?.removeIfNI('GuildModeration', memberId, guildId);
}
/**

View File

@ -78,7 +78,7 @@ export class MemberShorter extends BaseShorter {
*/
async ban(guildId: string, memberId: string, body?: RESTPutAPIGuildBanJSONBody, reason?: string) {
await this.client.proxy.guilds(guildId).bans(memberId).put({ reason, body });
await this.client.cache.members?.removeIfNI('GuildBans', memberId, guildId);
await this.client.cache.members?.removeIfNI('GuildModeration', memberId, guildId);
}
/**

View File

@ -291,10 +291,6 @@ export enum GatewayIntentBits {
Guilds = 1 << 0,
GuildMembers = 1 << 1,
GuildModeration = 1 << 2,
/**
* @deprecated This is the old name for {@apilink GatewayIntentBits#GuildModeration}
*/
GuildBans = GuildModeration,
GuildExpressions = 1 << 3,
GuildIntegrations = 1 << 4,
GuildWebhooks = 1 << 5,
@ -313,6 +309,8 @@ export enum GatewayIntentBits {
AutoModerationExecution = 1 << 21,
GuildMessagePolls = 1 << 24,
DirectMessagePolls = 1 << 25,
NonPrivilaged = 53575421,
OnlyPrivilaged = 33026,
}
/**

30
tests/bot.js Normal file
View File

@ -0,0 +1,30 @@
const { Client } = require('../lib')
const { GatewayIntentBits } = require('../lib/types');
const token = process.env.BOT_TOKEN;
if (!token) process.exit(0);
const client = new Client({
getRC: () => {
return {
intents: GatewayIntentBits.NonPrivilaged,
token,
locations: {
base: '',
output: '',
},
};
},
});
client.events.onFail = (event, err) => {
client.logger.error(`${event}: ${err}`);
process.exit(1);
};
client.start().then(() => {
setTimeout(() => {
process.exit(0);
}, 15_000 * client.gateway.totalShards)
});