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

feat: add in-game reminders #191

Merged
merged 2 commits into from
Jan 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
13 changes: 10 additions & 3 deletions .env.template
Original file line number Diff line number Diff line change
@@ -1,18 +1,25 @@
MINECRAFT_EMAIL=xxxxxxxxxxxxxxxxx@xxxx.com
MINECRAFT_PASSWORD=xxxxxxxxxxxxxxxxx

HYPIXEL_API_KEY=xxxxxxxxxxxxxxxxx
# Do `/api new` on Hypixel for this

MINECRAFT_CHAT_SEPARATOR=>
# The character that separates the author name from their message in game

USE_FIRST_WORD_OF_AUTHOR_NAME=false
# Set to true to only send the first word in the message author's name

HYPIXEL_API_KEY=xxxxxxxxxxxxxxxxx
# Do `/api new` on Hypixel for this

MINIMUM_NETWORK_LEVEL=
# The bot will warn you about players requesting to join the guild that are under this threshold

REMINDER_ENABLED=false
REMINDER_MESSAGE=
# The message to be sent in guild chat (cannot exceed 256 characters)

REMINDER_FREQUENCY=
# How often to send the reminder, in minutes

DISCORD_TOKEN=xxxxxxxxxxxxxxxxx
DISCORD_PREFIX=)
DISCORD_INVITE_LINK=discord.gg/
Expand Down
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,9 @@
- Automatic restarts and reconnections.
- Toggleable use of Discord emojis for Hypixel ranks in chat messages.
- Privileged slash commands to control bot behaviour in-game.
- Toggleable slowmode to slow and control member usage.
- Toggleable slowmode to control member usage.
- Basic filtering of extreme profanity to protect bot accounts from abuse.
- Configurable in-game reminders to spread the word about upcoming news and events.

## Installation

Expand Down Expand Up @@ -149,4 +150,4 @@ Parts of this project use code from the following repositories:

## License

This is an open-source project licensed under the [MIT License](https://github.com/MiscGuild/bridge/blob/master/LICENSE).
This is an open-source project licensed under the [MIT License](https://github.com/MiscGuild/bridge/blob/master/LICENSE).
11 changes: 9 additions & 2 deletions src/@types/environment.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,18 @@ declare global {
MINECRAFT_EMAIL: string;
MINECRAFT_PASSWORD: string;

MINECRAFT_CHAT_SEPARATOR: string;
USE_FIRST_WORD_OF_AUTHOR_NAME: boolean;
HYPIXEL_API_KEY: string;

MINECRAFT_CHAT_SEPARATOR: string;

USE_FIRST_WORD_OF_AUTHOR_NAME: "true" | "false";

MINIMUM_NETWORK_LEVEL: string;

REMINDER_ENABLED: "true" | "false";
REMINDER_MESSAGE: string;
REMINDER_FREQUENCY: string;

DISCORD_TOKEN: string;
DISCORD_PREFIX: string;
DISCORD_INVITE_LINK: `discord.gg/${string}`;
Expand Down
7 changes: 4 additions & 3 deletions src/events/discord/message.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,10 @@ export default {
`${emojis.warning} <@${message.author.id}> tried to say "${message.content}" but was blocked. This message was not sent to Hypixel.`,
);
} else {
const name = process.env.USE_FIRST_WORD_OF_AUTHOR_NAME
? message.member.displayName.split(" ")[0]
: message.member.displayName;
const name =
process.env.USE_FIRST_WORD_OF_AUTHOR_NAME === "true"
? message.member.displayName.split(" ")[0]
: message.member.displayName;

message.content = `${name} ${bot.chatSeparator} ${message.content.replace(/\r?\n|\r/g, " ")}`;
bot.sendGuildMessage(message.channel.id === bot.memberChannel?.id ? "gc" : "oc", message.content);
Expand Down
15 changes: 7 additions & 8 deletions src/events/mineflayer/handler/login.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,19 @@ export default {
`${Emojis.success} **\`${bot.mineflayer.username}\` has logged in and is now ready!**`,
);

if (process.env.REMINDER_ENABLED) {
setInterval(() => {
bot.sendGuildMessage("gc", process.env.REMINDER_MESSAGE);
}, 60_000 * parseInt(process.env.REMINDER_FREQUENCY, 10));
}

setInterval(() => {
bot.executeCommand("/g online");
}, 60_000 * 5);

setInterval(() => {
bot.sendGuildMessage(
"gc",
"Enter the new Bedwars Tournament via our Discord! 19+ rank upgrades to be won! Weekly prizes!",
);
}, 60_000 * 15);

setTimeout(async () => {
bot.executeCommand("/g online");
bot.sendToLimbo();
}, 3_000);
},
} as Event;
} as Event;