-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* Fix working of voice experience system. * Update src/main/java/com/eternalcode/discordapp/leveling/experience/voice/ExperienceLeaveVoiceController.java Co-authored-by: DMK <[email protected]> --------- Co-authored-by: Krzysztof Haller <[email protected]> Co-authored-by: DMK <[email protected]>
- Loading branch information
1 parent
81277d7
commit 8f509b9
Showing
5 changed files
with
106 additions
and
98 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
89 changes: 0 additions & 89 deletions
89
...java/com/eternalcode/discordapp/leveling/experience/listener/ExperienceVoiceListener.java
This file was deleted.
Oops, something went wrong.
35 changes: 35 additions & 0 deletions
35
...a/com/eternalcode/discordapp/leveling/experience/voice/ExperienceJoinVoiceController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package com.eternalcode.discordapp.leveling.experience.voice; | ||
|
||
import com.eternalcode.discordapp.config.ConfigManager; | ||
import net.dv8tion.jda.api.events.guild.voice.GuildVoiceUpdateEvent; | ||
import net.dv8tion.jda.api.hooks.ListenerAdapter; | ||
|
||
import java.time.Instant; | ||
|
||
public class ExperienceJoinVoiceController extends ListenerAdapter { | ||
|
||
private final ExperienceVoiceActivityData experienceVoiceActivityData; | ||
private final ConfigManager configManager; | ||
|
||
public ExperienceJoinVoiceController(ExperienceVoiceActivityData experienceVoiceActivityData, ConfigManager configManager) { | ||
this.experienceVoiceActivityData = experienceVoiceActivityData; | ||
this.configManager = configManager; | ||
} | ||
|
||
@Override | ||
public void onGuildVoiceUpdate(GuildVoiceUpdateEvent event) { | ||
long userId = event.getMember().getIdLong(); | ||
|
||
if (this.experienceVoiceActivityData.usersOnVoiceChannel.containsKey(userId)) { | ||
return; | ||
} | ||
|
||
if (event.getChannelJoined() == null) { | ||
return; | ||
} | ||
|
||
this.experienceVoiceActivityData.usersOnVoiceChannel.put(userId, Instant.now()); | ||
this.configManager.save(this.experienceVoiceActivityData); | ||
} | ||
|
||
} |
58 changes: 58 additions & 0 deletions
58
.../com/eternalcode/discordapp/leveling/experience/voice/ExperienceLeaveVoiceController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package com.eternalcode.discordapp.leveling.experience.voice; | ||
|
||
import com.eternalcode.discordapp.config.ConfigManager; | ||
import com.eternalcode.discordapp.leveling.experience.ExperienceConfig; | ||
import com.eternalcode.discordapp.leveling.experience.ExperienceService; | ||
import net.dv8tion.jda.api.events.guild.voice.GuildVoiceUpdateEvent; | ||
import net.dv8tion.jda.api.hooks.ListenerAdapter; | ||
|
||
import java.time.Duration; | ||
import java.time.Instant; | ||
import java.util.function.LongSupplier; | ||
|
||
public class ExperienceLeaveVoiceController extends ListenerAdapter { | ||
|
||
private final ExperienceVoiceActivityData experienceVoiceActivityData; | ||
private final ConfigManager configManager; | ||
private final ExperienceConfig experienceConfig; | ||
private final ExperienceService experienceService; | ||
|
||
public ExperienceLeaveVoiceController(ExperienceVoiceActivityData experienceVoiceActivityData, ConfigManager configManager, | ||
ExperienceConfig experienceConfig, ExperienceService experienceService) { | ||
this.experienceVoiceActivityData = experienceVoiceActivityData; | ||
this.configManager = configManager; | ||
this.experienceConfig = experienceConfig; | ||
this.experienceService = experienceService; | ||
} | ||
|
||
@Override | ||
public void onGuildVoiceUpdate(GuildVoiceUpdateEvent event) { | ||
if (event.getChannelLeft() == null) { | ||
return; | ||
} | ||
|
||
long userId = event.getMember().getIdLong(); | ||
|
||
LongSupplier voiceLeftChannelId = () -> event.getChannelLeft().getIdLong(); | ||
this.experienceService.modifyPoints(userId, this.calculatePoints(event), true, voiceLeftChannelId).whenComplete((experience, throwable) -> { | ||
if (throwable != null) { | ||
throwable.printStackTrace(); | ||
} | ||
}); | ||
|
||
this.experienceVoiceActivityData.usersOnVoiceChannel.remove(userId); | ||
this.configManager.save(this.experienceVoiceActivityData); | ||
} | ||
|
||
|
||
private double calculatePoints(GuildVoiceUpdateEvent event) { | ||
long userId = event.getMember().getIdLong(); | ||
|
||
Instant joined = this.experienceVoiceActivityData.usersOnVoiceChannel.get(userId); | ||
long minutes = Duration.between(joined, Instant.now()).toMinutes(); | ||
|
||
double basePoints = this.experienceConfig.basePoints * this.experienceConfig.voiceExperience.multiplier; | ||
return basePoints * minutes / this.experienceConfig.voiceExperience.howLongTimeSpendInVoiceChannel; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters