Skip to content

Commit

Permalink
Added Mutual Birthday Guilds
Browse files Browse the repository at this point in the history
  • Loading branch information
beanbeanjuice committed Nov 17, 2024
1 parent b9d6f92 commit 902459e
Show file tree
Hide file tree
Showing 16 changed files with 472 additions and 163 deletions.
133 changes: 133 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
# Node/NPM
/node_modules/

# Latex Files
*.aux
*.fdb_latexmk
*.fls
*.synctex.gz

# Compiled class file
*.class

# Log file
*.log

# BlueJ files
*.ctxt

# Mobile Tools for Java (J2ME)
.mtj.tmp/

# Package Files #
*.jar
*.war
*.nar
*.ear
*.zip
*.tar.gz
*.rar

# C Files
*.o
*.out

# Maven
/target/

# Gradle
/build/
/.gradle/
/out/
gradle.properties

# JetBrains IDEA
/.idea/
/.fleet/
*.iml
*.ipr
*.iws

# VSCode
.vscode/

# Eclipse
.classpath
.project
.settings/
/bin/

# Files containing safety info
.env
beta.json
release.json

# Logging Stuff
/logs/

# Mac Stuff
.DS_Store

# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
hs_err_pid*

# GITIGNORE FOR C PROJECTS
# Prerequisites
*.d

# Object files
*.o
*.ko
*.obj
*.elf

# Linker output
*.ilk
*.map
*.exp

# Precompiled Headers
*.gch
*.pch

# Libraries
*.lib
*.a
*.la
*.lo

# Shared objects (inc. Windows DLLs)
*.dll
*.so
*.so.*
*.dylib

# Executables
*.exe
*.out
*.app
*.i*86
*.x86_64
*.hex

# Debug files
*.dSYM/
*.su
*.idb
*.pdb
/cmake-build-debug/

# Kernel Module Compile Results
*.mod*
*.cmd
.tmp_versions/
modules.order
Module.symvers
Mkfile.old
dkms.conf

# Rust Stuff
debug/
target/
**/*.rs.bk
*.pdb
133 changes: 133 additions & 0 deletions api/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
# Node/NPM
/node_modules/

# Latex Files
*.aux
*.fdb_latexmk
*.fls
*.synctex.gz

# Compiled class file
*.class

# Log file
*.log

# BlueJ files
*.ctxt

# Mobile Tools for Java (J2ME)
.mtj.tmp/

# Package Files #
*.jar
*.war
*.nar
*.ear
*.zip
*.tar.gz
*.rar

# C Files
*.o
*.out

# Maven
/target/

# Gradle
/build/
/.gradle/
/out/
gradle.properties

# JetBrains IDEA
/.idea/
/.fleet/
*.iml
*.ipr
*.iws

# VSCode
.vscode/

# Eclipse
.classpath
.project
.settings/
/bin/

# Files containing safety info
.env
beta.json
release.json

# Logging Stuff
/logs/

# Mac Stuff
.DS_Store

# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
hs_err_pid*

# GITIGNORE FOR C PROJECTS
# Prerequisites
*.d

# Object files
*.o
*.ko
*.obj
*.elf

# Linker output
*.ilk
*.map
*.exp

# Precompiled Headers
*.gch
*.pch

# Libraries
*.lib
*.a
*.la
*.lo

# Shared objects (inc. Windows DLLs)
*.dll
*.so
*.so.*
*.dylib

# Executables
*.exe
*.out
*.app
*.i*86
*.x86_64
*.hex

# Debug files
*.dSYM/
*.su
*.idb
*.pdb
/cmake-build-debug/

# Kernel Module Compile Results
*.mod*
*.cmd
.tmp_versions/
modules.order
Module.symvers
Mkfile.old
dkms.conf

# Rust Stuff
debug/
target/
**/*.rs.bk
*.pdb
3 changes: 3 additions & 0 deletions bot/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
ai.json
menu.json

# IntelliJ
./.idea/

# Compiled class file
*.class

Expand Down
16 changes: 9 additions & 7 deletions bot/src/main/java/com/beanbeanjuice/cafebot/CafeBot.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,6 @@
import net.dv8tion.jda.api.requests.RestAction;
import net.dv8tion.jda.api.sharding.DefaultShardManagerBuilder;
import net.dv8tion.jda.api.sharding.ShardManager;
import net.dv8tion.jda.api.utils.ChunkingFilter;
import net.dv8tion.jda.api.utils.MemberCachePolicy;
import org.apache.hc.client5.http.async.methods.SimpleHttpRequest;
import org.apache.hc.client5.http.impl.async.CloseableHttpAsyncClient;
import org.apache.hc.client5.http.impl.async.HttpAsyncClients;
Expand Down Expand Up @@ -130,8 +128,8 @@ public CafeBot() throws InterruptedException {
GatewayIntent.DIRECT_MESSAGES,
GatewayIntent.MESSAGE_CONTENT
)
.setMemberCachePolicy(MemberCachePolicy.ALL) // ! - Needed for mutual guilds // TODO: REMOVE?
.setChunkingFilter(ChunkingFilter.ALL) // ! - Needed for mutual guilds // TODO: REMOVE?
// .setMemberCachePolicy(MemberCachePolicy.ALL) // ! - Needed for mutual guilds // TODO: REMOVE?
// .setChunkingFilter(ChunkingFilter.ALL) // ! - Needed for mutual guilds // TODO: REMOVE?
.build();

logger.log(CafeBot.class, LogLevel.INFO, "Checking servers...");
Expand Down Expand Up @@ -331,7 +329,9 @@ private void setupListeners() {
new GoodbyeListener(this),

new WelcomeMessageModalListener(this.cafeAPI.getWelcomesEndpoint()),
new GoodbyeMessageModalListener(this.cafeAPI.getGoodbyesEndpoint())
new GoodbyeMessageModalListener(this.cafeAPI.getGoodbyesEndpoint()),

new MutualGuildsListener(this.cafeAPI.getMutualGuildsEndpoint())
);
}

Expand Down Expand Up @@ -371,19 +371,21 @@ private void startBioUpdateTimer() {
TimerTask timerTask = new TimerTask() {
@Override
public void run() {
int num = Helper.getRandomInteger(1, 4);
int num = Helper.getRandomInteger(1, 4); // (Inclusive, Exclusive)
String finalString = "";

switch (num) {
case 1 -> finalString = "Currently in " + getTotalServers() + " cafés!";
case 2 -> finalString = "Waiting " + getTotalChannels() + " tables!";
case 3 -> finalString = "Serving " + getTotalUsers() + " customers!";
case 4 -> finalString = "Hmmm... I really want to go on break but my boss will get angry...";
case 5 -> finalString = "Wow... I had to deal with " + commandsRun + " orders today...";
}

bot.getShardManager().setActivity(Activity.customStatus(initialString + finalString));
}
};
timer.scheduleAtFixedRate(timerTask, 0, TimeUnit.MINUTES.toMillis(1));
timer.scheduleAtFixedRate(timerTask, 0, TimeUnit.MINUTES.toMillis(10));
}

public MessageEmbed getUpdateEmbed(final double gatewayPing) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public void handle(SlashCommandInteractionEvent event) {
private void updateUserBirthday(final BirthdayMonth month, final int day, final TimeZone timeZone, final SlashCommandInteractionEvent event) {
User user = event.getUser();

Birthday birthday = new Birthday(month, day, timeZone.getID(), false);
Birthday birthday = new Birthday(month, day, timeZone.getID());
BirthdaysEndpoint birthdaysEndpoint = cafeBot.getCafeAPI().getBirthdaysEndpoint();

birthdaysEndpoint.createUserBirthday(user.getId(), birthday)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.beanbeanjuice.cafebot.utility.listeners;

import com.beanbeanjuice.cafeapi.wrapper.endpoints.mutualguilds.MutualGuildsEndpoint;
import lombok.RequiredArgsConstructor;
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
import net.dv8tion.jda.api.hooks.ListenerAdapter;

@RequiredArgsConstructor
public class MutualGuildsListener extends ListenerAdapter {

private final MutualGuildsEndpoint mutualGuildsEndpoint;

@Override
public void onMessageReceived(MessageReceivedEvent event) {
if (!event.isFromGuild()) return;
if (event.getAuthor().isBot()) return;

String guildID = event.getGuild().getId();
String userID = event.getAuthor().getId();

this.mutualGuildsEndpoint.addMutualGuild(userID, guildID);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,25 @@ private void sendBirthdayWish(final String userID, final Birthday birthday) {
).queue();
});

user.getMutualGuilds().forEach((guild) -> {
this.cafeBot.getLogger().log(BirthdayHelper.class, LogLevel.INFO, String.format("Sending Birthday To Guild: %s", guild.getId()), true, false);
this.cafeBot.getCafeAPI()
.getMutualGuildsEndpoint()
.getMutualGuilds(user.getId())
.thenAccept((mutualGuildIDs) -> sendBirthdayMessageToEveryServer(mutualGuildIDs, user, birthday));
});
}

cafeBot.getCafeAPI().getGuildsEndpoint().getGuildInformation(guild.getId()).thenAcceptAsync((guildInformation) -> {
handleGuildBirthday(guild, guildInformation.getSetting(GuildInformationType.BIRTHDAY_CHANNEL_ID), user, birthday);
});
});
private void sendBirthdayMessageToEveryServer(final List<String> guildIDs, final User user, final Birthday birthday) {
guildIDs.forEach((guildID) -> {
Optional<Guild> guildOptional = Optional.ofNullable(cafeBot.getShardManager().getGuildById(guildID));
if (guildOptional.isEmpty()) return;

Guild guild = guildOptional.get();

this.cafeBot.getLogger().log(BirthdayHelper.class, LogLevel.INFO, String.format("Sending Birthday To Guild: %s", guild.getId()), true, false);
this.cafeBot.getCafeAPI()
.getGuildsEndpoint()
.getGuildInformation(guild.getId())
.thenAcceptAsync((guildInformation) -> handleGuildBirthday(guild, guildInformation.getSetting(GuildInformationType.BIRTHDAY_CHANNEL_ID), user, birthday));
});
}

Expand Down
Loading

0 comments on commit 902459e

Please sign in to comment.