Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cleanup #230

Merged
merged 3 commits into from
Dec 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,9 @@ $ pnpm run setup-files

9. Promote the Minecraft account used by the bot to Officer in-game in order for it to view the Officer chat and run privileged commands.

10. Build and run the bot.
10. On Hypixel, set the account's `Private Message Privacy` setting under `My Profile > Social Settings` to `Low` or `High`, allowing guild members to privately message the bot to see their weekly guild experience total.

11. Build and run the bot.

```bash
$ pnpm run build
Expand Down
2 changes: 1 addition & 1 deletion src/@types/command.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ declare interface Command {
}

type ExecuteCommand = (
bot: import('@classes/bot').default,
bridge: import('../bridge').default,
interaction: import('discord.js').ChatInputCommandInteraction,
args: unknown[]
) => Promise<void>;
8 changes: 3 additions & 5 deletions src/@types/event.d.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
declare interface Event {
declare interface BotEvent {
name:
| keyof typeof import('@events/regex').default
| keyof typeof import('../mineflayer/events/regex').default
| keyof import('mineflayer').BotEvents
| keyof import('discord.js').ClientEvents;
runOnce: boolean;
run: Execute;
run: (bridge: import('../bridge').default, ...params: any[]) => Promise<void>;
}

type Execute = (bot: import('@classes/bot').default, ...params: any[]) => Promise<void>;
54 changes: 54 additions & 0 deletions src/bridge.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import { ActivityType, IntentsBitField } from 'discord.js';
import winston from 'winston';
import env from '@util/env';
import Discord from '@discord/discord';
import Mineflayer from '@mineflayer/mineflayer';

export default class Bridge {
public readonly discord = new Discord({
allowedMentions: { parse: ['users', 'roles'], repliedUser: true },
intents: [
IntentsBitField.Flags.Guilds,
IntentsBitField.Flags.GuildMessages,
IntentsBitField.Flags.MessageContent,
],
});

public readonly mineflayer = new Mineflayer();
public onlineCount = 0;
public totalCount = 125;

constructor() {
try {
this.start();
} catch (error) {
winston.error(error);
}
}

public setStatus() {
const plural = this.onlineCount - 1 !== 1;

if (this.discord.isReady()) {
this.discord.user.setActivity(
`${this.onlineCount - 1} online player${plural ? 's' : ''}`,
{
type: ActivityType.Watching,
}
);
}
}

private async start() {
await Promise.all([
this.discord.loadCommands(),
this.discord.loadEvents(this),
this.mineflayer.loadEvents(this),
]);

await this.discord.login(env.DISCORD_TOKEN);
}
}

const handleError = (e: Error) => winston.error(e);
process.on('uncaughtException', handleError).on('unhandledRejection', handleError);
224 changes: 0 additions & 224 deletions src/classes/bot.ts

This file was deleted.

5 changes: 0 additions & 5 deletions src/classes/client.ts

This file was deleted.

28 changes: 0 additions & 28 deletions src/commands/reboot.ts

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export default {
},
],
},
run: async (bot, interaction, args) => {
run: async (bridge, interaction, args) => {
const type = interaction.options.getSubcommand() as 'add' | 'remove';
const mojangProfile = await fetchMojangProfile(args[0] as string);
const blacklist = _blacklist as BlacklistEntry[];
Expand Down Expand Up @@ -92,7 +92,7 @@ export default {
]);

const blacklistMessage = await (
(await bot.discord.channels.fetch(env.BLACKLIST_CHANNEL_ID)) as TextChannel
(await bridge.discord.channels.fetch(env.BLACKLIST_CHANNEL_ID)) as TextChannel
).send({
embeds: [embed],
});
Expand All @@ -109,7 +109,7 @@ export default {
blacklist.splice(blacklist.indexOf(blacklistEntry));

const message = await (
bot.discord.channels.cache.get(env.BLACKLIST_CHANNEL_ID) as TextChannel
bridge.discord.channels.cache.get(env.BLACKLIST_CHANNEL_ID) as TextChannel
).messages.fetch(blacklistEntry.messageId);
await message.delete();
}
Expand Down
4 changes: 2 additions & 2 deletions src/commands/command.ts → src/discord/commands/command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ export default {
},
],
},
run: async (bot, interaction, args) => {
run: async (bridge, interaction, args) => {
const command = (args[0] as string).startsWith('/') ? (args[0] as string) : `/${args[0]}`;
const embed = new EmbedBuilder();

try {
await bot.executeTask(command);
await bridge.mineflayer.execute(command, true);

embed
.setColor('Green')
Expand Down
Loading
Loading