Skip to content
This repository has been archived by the owner on Mar 18, 2024. It is now read-only.

Bot Update #107

Open
SocketSomeone opened this issue Feb 13, 2022 · 0 comments
Open

Bot Update #107

SocketSomeone opened this issue Feb 13, 2022 · 0 comments

Comments

@SocketSomeone
Copy link
Member

SocketSomeone commented Feb 13, 2022

		super(token, {
			allowedMentions: {
				everyone: false,
				roles: true,
				users: true
			},
			firstShardID: firstShard,
			lastShardID: lastShard,
			maxShards: shardCount,
			disableEvents: {
				TYPING_START: true,
				PRESENCE_UPDATE: true,
				USER_UPDATE: true
			},
			restMode: true,
			messageLimit: 2,
			getAllUsers: false,
			compress: true,
			guildCreateTimeout: 60000
		});
	private async onClientReady() {
		if (this.hasStarted) {
			console.error('BOT HAS ALREADY STARTED, IGNORING EXTRA READY EVENT');
			return;
		}

		await Promise.all([...this.services.values()].map((s) => s.onClientReady()));

		this.hasStarted = true;
		this.startedAt = moment();

		console.log(chalk.green(`Client ready! Serving ${chalk.blue(this.guilds.size)} guilds.`));

		await Promise.all([...this.caches.values()].map((c) => c.init()));
		await BaseGuild.saveGuilds(this.guilds.map((g) => g));
	}

	private async onGuildCreate(guild: Guild) {
		await BaseGuild.saveGuilds([guild], {
			joinedAt: moment(),
			deletedAt: null
		});

		const { locale } = await this.guildsCache.get(guild);
		const ownerDM = await this.getDMChannel(guild.ownerID);

		const t: TranslateFunc = (phrase, replacements) => i18n.__({ phrase, locale }, replacements);

		const modules = [...this.modules.values()]
			.sort((a, b) => a.names[locale].localeCompare(b.names[locale]))
			.filter((m) => !(m instanceof FrameworkModule))
			.map((m) => m.names[locale])
			.join('\n');

		const embed = this.messageService.createEmbed({
			author: { name: t('others.onBotAdd.title', { guild: guild.name }), icon_url: Images.HELP },
			description: t('others.onBotAdd.desc', { modules }),
			thumbnail: { url: this.user.dynamicAvatarURL('png', 4096) },
			fields: [
				{
					name: '\u200b',
					value: t('others.onBotAdd.field'),
					inline: false
				}
			],
			footer: {
				icon_url: this.user.dynamicAvatarURL('png', 4096),
				text: t('others.onBotAdd.footer')
			}
		});

		await ownerDM.createMessage({ embed }).catch(() => undefined);
	}

	private async onGuildDelete(guild: Guild) {
		await BaseGuild.saveGuilds([guild], {
			deletedAt: moment()
		});
	}

	private async onShardReady(shardId: number) {
		console.log(chalk.green(`Shard ${chalk.blue(shardId + 1)} is ready`));
	}

	private async onShardConnect(shardId: number) {
		console.log(chalk.green(`Shard ${chalk.blue(shardId + 1)} is connected to the gateway`));

		this.shardsConnected.add(shardId + 1);
		this.stats.shardConnects++;
	}

	private async onShardResume(shardId: number) {
		console.log(chalk.green(`Shard ${chalk.blue(shardId + 1)} has resumed`));
		this.shardsConnected.add(shardId + 1);
		this.stats.shardResumes++;
	}

	private async onShardDisconnect(err: Error, shardId: number) {
		console.error(chalk.red(`Shard ${chalk.blue(shardId + 1)} was disconnected: ${err}`));

		this.shardsConnected.delete(shardId + 1);
		this.stats.shardDisconnects++;
	}

	private async onGuildUnavailable(guild: Guild) {
		console.error('DISCORD GUILD_UNAVAILABLE:', guild.id);
	}

	private async onWarn(warn: string) {
		console.error('DISCORD WARNING:', warn);
		this.stats.wsWarnings++;
	}

	private async onError(error: Error) {
		console.error('DISCORD ERROR:', error);
		this.stats.wsErrors++;
	}

	private async onRawWS() {
		this.stats.wsEvents++;
	}
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant