-
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.
* dailies need to use usersV2 * WIP: achievemnts v1 * added pagination action row * achievementslist, achievemnt commands. Make achievements work when a test is submitted. * chore: gitignore cache, unhide ZBotData * bugfix: fix name of button * chore: docs, code style fixes * chore: more docs * chore: even more docs * chore: remove logs * bugfix: fix up file paths
- Loading branch information
1 parent
9da7f23
commit a2e93d5
Showing
15 changed files
with
471 additions
and
22 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
File renamed without changes.
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,51 @@ | ||
package asynchronous.typing; | ||
|
||
import net.dv8tion.jda.api.events.message.MessageReceivedEvent; | ||
import net.dv8tion.jda.api.EmbedBuilder; | ||
import net.dv8tion.jda.api.entities.MessageChannel; | ||
import zyenyo.Database; | ||
|
||
import java.awt.Color; | ||
import java.io.File; | ||
import java.util.Arrays; | ||
|
||
import dataStructures.AchievementDetails; | ||
import dataStructures.streakStatusResult; | ||
|
||
public class Achievement implements Runnable { | ||
private MessageReceivedEvent event; | ||
private String idStr; | ||
private MessageChannel channel; | ||
private String[] args; | ||
|
||
public Achievement(MessageReceivedEvent event, String[] args) { | ||
this.event = event; | ||
this.idStr = event.getAuthor().getId(); | ||
this.channel = event.getChannel(); | ||
this.args = args; | ||
} | ||
|
||
@Override | ||
public void run() { | ||
event.getChannel().sendTyping().queue(); | ||
try { | ||
AchievementDetails achievement = Database.getAchievement(String.join(" ", Arrays.copyOfRange(args, 1, args.length))); | ||
EmbedBuilder embed = new EmbedBuilder().setColor(Color.black); | ||
|
||
embed.setTitle(achievement.title()); | ||
|
||
embed.setThumbnail(String.format("attachment://thumbnail.png")); | ||
embed.setDescription(achievement.description()); | ||
|
||
File file = new File(achievement.thumbnail()); | ||
|
||
|
||
channel.sendMessageEmbeds(embed.build()).addFile(file, "thumbnail.png").queue(); | ||
|
||
} catch (Exception e) { | ||
System.err.println(e); | ||
} | ||
|
||
} | ||
|
||
} |
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,101 @@ | ||
package asynchronous.typing; | ||
|
||
import net.dv8tion.jda.api.events.interaction.ButtonClickEvent; | ||
import net.dv8tion.jda.api.events.message.MessageReceivedEvent; | ||
import net.dv8tion.jda.api.interactions.components.Button; | ||
import net.dv8tion.jda.api.EmbedBuilder; | ||
import net.dv8tion.jda.api.entities.Emoji; | ||
import net.dv8tion.jda.api.entities.MessageChannel; | ||
import zyenyo.Database; | ||
|
||
import java.awt.Color; | ||
import java.util.Arrays; | ||
|
||
import org.bson.Document; | ||
|
||
import com.mongodb.client.AggregateIterable; | ||
|
||
public class AchievementList implements Runnable { | ||
// limit on the number button clicks allowed, so that users don't keep bumping old messages and send unnecessary calls to the bot | ||
private static final Integer BUTTONCLICK_MAX = 50; | ||
private MessageReceivedEvent event; | ||
private MessageChannel channel; | ||
// TODO: using a static variable for pages causes problems when a user interacts with multiple messages of the same command. | ||
static Integer page; | ||
static Integer buttonClickCount; | ||
|
||
public AchievementList(MessageReceivedEvent event, String[] args) { | ||
this.event = event; | ||
this.channel = event.getChannel(); | ||
} | ||
|
||
@Override | ||
public void run() { | ||
event.getChannel().sendTyping().queue(); | ||
page = 1; | ||
buttonClickCount = 0; | ||
|
||
try { | ||
|
||
EmbedBuilder embed = makeAchievementList(); | ||
|
||
channel.sendMessageEmbeds(embed.build()) | ||
.setActionRow( | ||
Button.secondary("achievementListPrev", Emoji.fromUnicode("U+25C0")).asDisabled(), // arrow backward | ||
Button.secondary("achievementListNext", Emoji.fromUnicode("U+25B6")) // arrow forward | ||
) | ||
.queue(); | ||
|
||
} catch (Exception e) { | ||
System.err.println(e); | ||
} | ||
|
||
} | ||
|
||
private static EmbedBuilder makeAchievementList() { | ||
|
||
AggregateIterable<Document> achievementList = Database.getAchievementList(page); | ||
final int initialPosition = (page -1) * 10; | ||
|
||
EmbedBuilder embed = new EmbedBuilder().setColor(Color.black); | ||
embed.setTitle("Zyenyo Achievements"); | ||
|
||
int index = initialPosition; | ||
|
||
for (Document doc : achievementList) { | ||
embed.addField(String.format("[%d] %s", ++index, doc.getString("title")), doc.getString("description"), false); | ||
} | ||
|
||
embed.setFooter( | ||
String.format("Showing achievements %d to %d on page %d.", | ||
initialPosition+1, initialPosition+10, page) | ||
); | ||
|
||
return embed; | ||
} | ||
|
||
public static void onNextPage(ButtonClickEvent event) { | ||
page++; | ||
buttonClickCount++; | ||
|
||
event.editMessageEmbeds(makeAchievementList().build()) | ||
.setActionRow( | ||
Button.secondary("achievementListPrev", Emoji.fromUnicode("U+25C0")).withDisabled(page <=1 || buttonClickCount >= BUTTONCLICK_MAX), // arrow backward | ||
Button.secondary("achievementListNext", Emoji.fromUnicode("U+25B6")).withDisabled(page >= 20 || buttonClickCount >= BUTTONCLICK_MAX) // arrow forward | ||
) | ||
.queue(); | ||
} | ||
|
||
public static void onPrevPage(ButtonClickEvent event) { | ||
page--; | ||
buttonClickCount++; | ||
|
||
event.editMessageEmbeds(makeAchievementList().build()) | ||
.setActionRow( | ||
Button.secondary("achievementListPrev", Emoji.fromUnicode("U+25C0")).withDisabled(page <=1 || buttonClickCount >= BUTTONCLICK_MAX), // arrow backward | ||
Button.secondary("achievementListNext", Emoji.fromUnicode("U+25B6")).withDisabled(page >= 20 || buttonClickCount >= BUTTONCLICK_MAX) // arrow forward | ||
) | ||
.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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package dataStructures; | ||
|
||
/** | ||
* Data about a specific achievement. | ||
* @param title : name of achievement | ||
* @param description : Description of the achievment | ||
* @param thumbnail : the achievement icon, that will be displayed in the embed. | ||
*/ | ||
public record AchievementDetails(String title, String description, String thumbnail ) {} |
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 |
---|---|---|
@@ -1,3 +1,5 @@ | ||
package dataStructures; | ||
|
||
public record AddTestResult(double rawTp, Integer dailyStreak ) {} | ||
import java.util.List; | ||
|
||
public record AddTestResult(double rawTp, Integer dailyStreak, List<AchievementDetails> achievements ) {} |
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
Oops, something went wrong.