From 62eb21e77e6eddc99a3bd09a3261da1ca0cddc7d Mon Sep 17 00:00:00 2001 From: RyGuy Date: Wed, 29 Mar 2023 16:06:53 -0400 Subject: [PATCH 1/3] Ensure you're updating end instant, fixes #227, partially helps #228 --- src/main/java/com/jagrosh/giveawaybot/GiveawayManager.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/main/java/com/jagrosh/giveawaybot/GiveawayManager.java b/src/main/java/com/jagrosh/giveawaybot/GiveawayManager.java index 0aad9b1c..1e9fd014 100644 --- a/src/main/java/com/jagrosh/giveawaybot/GiveawayManager.java +++ b/src/main/java/com/jagrosh/giveawaybot/GiveawayManager.java @@ -36,6 +36,7 @@ import com.jagrosh.interactions.requests.Route; import com.jagrosh.interactions.util.JsonUtil; import java.awt.Color; +import java.time.Clock; import java.time.Instant; import java.time.temporal.ChronoUnit; import java.util.ArrayList; @@ -137,6 +138,7 @@ public boolean endGiveaway(Giveaway giveaway) List all = new ArrayList<>(entries); List winners = GiveawayUtil.selectWinners(all, giveaway.getWinners()); CachedUser host = database.getUser(giveaway.getUserId()); + giveaway.setEndInstant(Instant.now(Clock.systemDefaultZone())); try { JSONObject summary = createGiveawaySummary(giveaway, host, entries, winners); From 97c37b390450368953b43164e857c6642aa53432 Mon Sep 17 00:00:00 2001 From: RyGuy Date: Wed, 29 Mar 2023 16:22:56 -0400 Subject: [PATCH 2/3] impl log channel capabilities (#228) --- .../com/jagrosh/giveawaybot/commands/SettingsCmd.java | 9 ++++++++- .../java/com/jagrosh/giveawaybot/data/Database.java | 11 +++++++++++ .../com/jagrosh/giveawaybot/data/GuildSettings.java | 11 +++++++++++ .../giveawaybot/entities/LocalizedMessage.java | 2 ++ src/main/resources/localization/messages.properties | 4 +++- 5 files changed, 35 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/jagrosh/giveawaybot/commands/SettingsCmd.java b/src/main/java/com/jagrosh/giveawaybot/commands/SettingsCmd.java index b3076792..86a35dc6 100644 --- a/src/main/java/com/jagrosh/giveawaybot/commands/SettingsCmd.java +++ b/src/main/java/com/jagrosh/giveawaybot/commands/SettingsCmd.java @@ -50,11 +50,13 @@ public SettingsCmd(GiveawayBot bot) ApplicationCommandOption group = new ApplicationCommandOption(ApplicationCommandOption.Type.SUB_COMMAND_GROUP, "set", "set settings", false); ApplicationCommandOption colorCmd = new ApplicationCommandOption(ApplicationCommandOption.Type.SUB_COMMAND, "color", "set giveaway embed color", false); colorCmd.addOptions(new ApplicationCommandOption(ApplicationCommandOption.Type.STRING, "hex", "hex code or standard color name", true)); + ApplicationCommandOption logCmd = new ApplicationCommandOption(ApplicationCommandOption.Type.SUB_COMMAND, "logchannel", "sets the log channel", false); + logCmd.addOptions(new ApplicationCommandOption(ApplicationCommandOption.Type.CHANNEL, "channel", "channel to log to", true)); ApplicationCommandOption buttonCmd = new ApplicationCommandOption(ApplicationCommandOption.Type.SUB_COMMAND, "emoji", "set giveaway button emoji and text", false); buttonCmd.addOptions(new ApplicationCommandOption(ApplicationCommandOption.Type.STRING, "emoji", "emoji or button text", true, 1, 64, false)); //ApplicationCommandOption roleCmd = new ApplicationCommandOption(ApplicationCommandOption.Type.SUB_COMMAND, "role", "set giveaway manager role", false); //roleCmd.addOptions(new ApplicationCommandOption(ApplicationCommandOption.Type.ROLE, "role", "role that can create and manage giveaways", true)); - group.addOptions(colorCmd, buttonCmd/*, roleCmd*/); + group.addOptions(colorCmd, buttonCmd/*, roleCmd*/, logCmd); this.app = new ApplicationCommand.Builder() .setType(ApplicationCommand.Type.CHAT_INPUT) .setName(bot.getCommandPrefix() + "settings") @@ -104,6 +106,10 @@ protected InteractionResponse gbExecute(Interaction interaction) throws Giveaway return respondSuccess(LocalizedMessage.SUCCESS_SETTINGS_EMOJI.getLocalizedMessage(wl, pe.render())); } else return respondError(LocalizedMessage.ERROR_INVALID_EMOJI_CHOICE.getLocalizedMessage(wl, bot.getGiveawayManager().getEmojiManager().getFreeEmoji())); + case "logchannel": + long channel = cmd.getOptionByName("channel").getIdValue(); + bot.getDatabase().setGuildLogChannel(interaction.getGuildId(), channel); + return respondSuccess(LocalizedMessage.SUCCESS_SETTINGS_LOGCHANNEL.getLocalizedMessage(wl, "<#" + channel + ">")); default: return respondError("Unknown settings command."); } @@ -113,6 +119,7 @@ protected InteractionResponse gbExecute(Interaction interaction) throws Giveaway + LocalizedMessage.INFO_SETTINGS_PREMIUM.getLocalizedMessage(wl) + ": **" + bot.getDatabase().getPremiumLevel(gs.getGuildId(), gs.getOwnerId()) + "**\n" //+ LocalizedMessage.INFO_SETTINGS_ROLE.getLocalizedMessage(wl) + ": " + (gs.getManagerRoleId() == 0L ? "N/A" : "<@&" + gs.getManagerRoleId() + ">") + "\n" + LocalizedMessage.INFO_SETTINGS_EMOJI.getLocalizedMessage(wl) + ": " + gs.getEmoji() + "\n" + + LocalizedMessage.INFO_SETTINGS_LOGCHANNEL.getLocalizedMessage(wl) + ": <#" + gs.getLogChannelId() + ">\n" + LocalizedMessage.INFO_SETTINGS_LOCALE.getLocalizedMessage(wl) + ": " + gs.getLocale().getTextualName() + "\n\n" + LocalizedMessage.INFO_SETTINGS_ETC.getLocalizedMessage(wl); return new MessageCallback(new SentMessage.Builder() diff --git a/src/main/java/com/jagrosh/giveawaybot/data/Database.java b/src/main/java/com/jagrosh/giveawaybot/data/Database.java index c73518ca..560fe242 100644 --- a/src/main/java/com/jagrosh/giveawaybot/data/Database.java +++ b/src/main/java/com/jagrosh/giveawaybot/data/Database.java @@ -118,6 +118,17 @@ public synchronized void setGuildColor(long guildId, Color color) gs.setColor(color); em.getTransaction().commit(); } + + public synchronized void setGuildLogChannel(long guildId, long logChannel) { + GuildSettings gs = em.find(GuildSettings.class, guildId); + em.getTransaction().begin(); + if(gs == null) { + gs = new GuildSettings(); + gs.setGuildId(guildId); + em.persist(guildId); + } + + } public synchronized void setGuildEmoji(long guildId, String emoji) { diff --git a/src/main/java/com/jagrosh/giveawaybot/data/GuildSettings.java b/src/main/java/com/jagrosh/giveawaybot/data/GuildSettings.java index 340a344d..b0a0390d 100644 --- a/src/main/java/com/jagrosh/giveawaybot/data/GuildSettings.java +++ b/src/main/java/com/jagrosh/giveawaybot/data/GuildSettings.java @@ -43,6 +43,8 @@ public class GuildSettings private String emoji; @Column(name = "OWNER") private long ownerId; + @Column(name = "LOG") + private long logChannelId; @Column(name = "LOCALE") private String locale; @Column(name = "LAST_FETCH") @@ -62,6 +64,7 @@ public GuildSettings(long guildId) this.ownerId = 0L; this.locale = null; this.latestRetrieval = 0L; + this.logChannelId = 0L; } public long getGuildId() @@ -124,6 +127,14 @@ public void setOwnerId(long ownerId) this.ownerId = ownerId; } + public long getLogChannelId() { + return logChannelId; + } + + public void setLogChannelId(long logChannelId) { + this.logChannelId = logChannelId; + } + public WebLocale getLocale() { return WebLocale.of(locale); diff --git a/src/main/java/com/jagrosh/giveawaybot/entities/LocalizedMessage.java b/src/main/java/com/jagrosh/giveawaybot/entities/LocalizedMessage.java index 0494049d..d5e51652 100644 --- a/src/main/java/com/jagrosh/giveawaybot/entities/LocalizedMessage.java +++ b/src/main/java/com/jagrosh/giveawaybot/entities/LocalizedMessage.java @@ -77,6 +77,7 @@ public enum LocalizedMessage SUCCESS_SETTINGS_ROLE("success.settings.role"), SUCCESS_SETTINGS_COLOR("success.settings.color"), SUCCESS_SETTINGS_EMOJI("success.settings.emoji"), + SUCCESS_SETTINGS_LOGCHANNEL("success.settings.logchannel"), SUCCESS_GIVEAWAY_ENDED("success.giveaway_ended"), SUCCESS_GIVEAWAY_REROLL("success.giveaway_reroll"), SUCCESS_GIVEAWAY_DELETE("success.giveaway_delete"), @@ -99,6 +100,7 @@ public enum LocalizedMessage INFO_SETTINGS_EMOJI("info.settings.emoji"), INFO_SETTINGS_ROLE("info.settings.role"), INFO_SETTINGS_COLOR("info.settings.color"), + INFO_SETTINGS_LOGCHANNEL("info.settings.logchannel"), INFO_SETTINGS_LOCALE("info.settings.locale"), INFO_SETTINGS_ETC("info.settings.etc"), INFO_HELP_GENERAL("info.help.general"), diff --git a/src/main/resources/localization/messages.properties b/src/main/resources/localization/messages.properties index 82e3ff19..f0c222a1 100644 --- a/src/main/resources/localization/messages.properties +++ b/src/main/resources/localization/messages.properties @@ -43,7 +43,8 @@ success.ping = Pong! success.winner = Congratulations {0}! You won the **{1}**! success.settings.role = Users with the {0} role can now manage giveaways! success.settings.color = The embed color for giveaways has been changed to `{0}`. -success.settings.emoji = The custom button emoji as been changed to `{0}`. +success.settings.emoji = The custom button emoji has been changed to `{0}`. +success.settings.logchannel = The log channel has been changed to `{0}`. success.giveaway_ended = Successfully ended giveaway {0}! success.giveaway_reroll = {0} rerolled the giveaway! Congratulations {1}! success.giveaway_delete = Successfully deleted giveaway {0}! @@ -69,6 +70,7 @@ info.settings.role = Manager Role info.settings.color = Embed Color info.settings.locale = Language info.settings.etc = To control which roles can manage giveaways, head to **Server Settings** > **Integrations** > **GiveawayBot** +info.settings.logchannel = Log Channel info.help.general = General Commands info.help.creation = Giveaway Creation Commands info.help.manipulation = Giveaway Manipulation Commands From 0532d38c8c02be78eb075ec1ed814cf8e818d2ac Mon Sep 17 00:00:00 2001 From: RyGuy Date: Wed, 29 Mar 2023 16:27:03 -0400 Subject: [PATCH 3/3] handle the java side of #210 - needs pages update to account --- src/main/java/com/jagrosh/giveawaybot/GiveawayManager.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/java/com/jagrosh/giveawaybot/GiveawayManager.java b/src/main/java/com/jagrosh/giveawaybot/GiveawayManager.java index 1e9fd014..a122b894 100644 --- a/src/main/java/com/jagrosh/giveawaybot/GiveawayManager.java +++ b/src/main/java/com/jagrosh/giveawaybot/GiveawayManager.java @@ -302,6 +302,7 @@ private JSONObject createGiveawaySummary(Giveaway giveaway, CachedUser host, Lis .put("giveaway", new JSONObject() .put("id", Long.toString(giveaway.getMessageId())) .put("prize", giveaway.getPrize()) + .put("desc", giveaway.getDescription()) .put("num_winners", giveaway.getWinners()) .put("host", host.toJson()) .put("end", giveaway.getEndTime()))