-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #262 from KittyBot-Org/development
voting rewards
- Loading branch information
Showing
33 changed files
with
688 additions
and
137 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
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
28 changes: 28 additions & 0 deletions
28
src/main/java/de/kittybot/kittybot/commands/info/VoteCommand.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,28 @@ | ||
package de.kittybot.kittybot.commands.info; | ||
|
||
import de.kittybot.kittybot.objects.enums.BotList; | ||
import de.kittybot.kittybot.slashcommands.application.Category; | ||
import de.kittybot.kittybot.slashcommands.application.RunCommand; | ||
import de.kittybot.kittybot.slashcommands.interaction.Interaction; | ||
import de.kittybot.kittybot.slashcommands.interaction.Options; | ||
import de.kittybot.kittybot.utils.MessageUtils; | ||
|
||
import java.util.Arrays; | ||
import java.util.stream.Collectors; | ||
|
||
@SuppressWarnings("unused") | ||
public class VoteCommand extends RunCommand{ | ||
|
||
public VoteCommand(){ | ||
super("vote", "Displays all info about voting for kitty", Category.INFORMATION); | ||
} | ||
|
||
@Override | ||
public void run(Options options, Interaction ia){ | ||
ia.reply("You can vote on following sites for KittyBot:\n" + Arrays.stream(BotList.values()). | ||
filter(BotList::canVote) | ||
.map(botList -> MessageUtils.maskLink(botList.getName(), botList.getBotUrl())).collect(Collectors.joining(", ")) | ||
); | ||
} | ||
|
||
} |
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
62 changes: 0 additions & 62 deletions
62
src/main/java/de/kittybot/kittybot/modules/BotListsModule.java
This file was deleted.
Oops, something went wrong.
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
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
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
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
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
74 changes: 74 additions & 0 deletions
74
src/main/java/de/kittybot/kittybot/modules/VoteModule.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,74 @@ | ||
package de.kittybot.kittybot.modules; | ||
|
||
import de.kittybot.kittybot.objects.enums.BotList; | ||
import de.kittybot.kittybot.objects.module.Module; | ||
import de.kittybot.kittybot.utils.Config; | ||
import de.kittybot.kittybot.utils.MessageUtils; | ||
import net.dv8tion.jda.api.events.guild.GuildReadyEvent; | ||
import org.jetbrains.annotations.NotNull; | ||
import org.jooq.types.YearToSecond; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import java.time.Duration; | ||
import java.time.LocalDateTime; | ||
import java.util.concurrent.TimeUnit; | ||
|
||
import static de.kittybot.kittybot.jooq.Tables.VOTERS; | ||
|
||
public class VoteModule extends Module{ | ||
|
||
private static final Logger LOG = LoggerFactory.getLogger(VoteModule.class); | ||
|
||
@Override | ||
public void onGuildReady(@NotNull GuildReadyEvent event){ | ||
if(event.getGuild().getIdLong() == Config.SUPPORT_GUILD_ID){ | ||
this.modules.scheduleAtFixedRate(this::checkVoters, 0, 30, TimeUnit.MINUTES); | ||
} | ||
} | ||
|
||
private void checkVoters(){ | ||
var guild = this.modules.getGuildById(Config.SUPPORT_GUILD_ID); | ||
if(guild == null){ | ||
return; | ||
} | ||
var role = guild.getRoleById(Config.VOTER_ROLE_ID); | ||
if(role == null){ | ||
return; | ||
} | ||
var result = this.modules.get(DatabaseModule.class).getCtx().deleteFrom(VOTERS).where(VOTERS.VOTE_EXPIRY.lessOrEqual(LocalDateTime.now())).returning().fetch(); | ||
for(var r : result){ | ||
guild.removeRoleFromMember(r.getUserId(), role).reason("vote expired").queue(); | ||
} | ||
} | ||
|
||
public void addVote(long userId, BotList botList, int voteMultiplier){ | ||
var voteDuration = Duration.of(botList.getVoteCooldown(), botList.getTimeUnit()).multipliedBy(voteMultiplier); | ||
|
||
this.modules.get(DatabaseModule.class).getCtx().insertInto(VOTERS) | ||
.columns(VOTERS.USER_ID, VOTERS.VOTE_EXPIRY) | ||
.values(userId, LocalDateTime.now().plus(voteDuration)) | ||
.onConflict(VOTERS.USER_ID) | ||
.doUpdate() | ||
.set(VOTERS.VOTE_EXPIRY, VOTERS.VOTE_EXPIRY.add(YearToSecond.valueOf(voteDuration))) | ||
.execute(); | ||
|
||
var jda = this.modules.getJDA(); | ||
jda.retrieveUserById(userId).queue(user -> this.modules.get(EventLogModule.class).send(jda, "Vote", "´" + user.getAsTag() + "`(`" + user.getId() + "`) voted on " + MessageUtils.maskLink("`" + botList.getName() + "`", botList.getUrl()))); | ||
|
||
var guild = this.modules.getGuildById(Config.SUPPORT_GUILD_ID); | ||
if(guild == null){ | ||
return; | ||
} | ||
var role = guild.getRoleById(Config.VOTER_ROLE_ID); | ||
if(role == null){ | ||
return; | ||
} | ||
if(!guild.getSelfMember().canInteract(role)){ | ||
LOG.error("I can't interact with the provided voter role: {}", role.getId()); | ||
return; | ||
} | ||
guild.addRoleToMember(userId, role).reason("voted on " + botList.getName()).queue(); | ||
} | ||
|
||
} |
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
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
Oops, something went wrong.