Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Misc bug / feature changes (#227 #228 #210) #231

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/main/java/com/jagrosh/giveawaybot/GiveawayManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -137,6 +138,7 @@ public boolean endGiveaway(Giveaway giveaway)
List<CachedUser> all = new ArrayList<>(entries);
List<CachedUser> 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);
Expand Down Expand Up @@ -300,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()))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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.");
}
Expand All @@ -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()
Expand Down
11 changes: 11 additions & 0 deletions src/main/java/com/jagrosh/giveawaybot/data/Database.java
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
11 changes: 11 additions & 0 deletions src/main/java/com/jagrosh/giveawaybot/data/GuildSettings.java
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -62,6 +64,7 @@ public GuildSettings(long guildId)
this.ownerId = 0L;
this.locale = null;
this.latestRetrieval = 0L;
this.logChannelId = 0L;
}

public long getGuildId()
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand All @@ -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"),
Expand Down
4 changes: 3 additions & 1 deletion src/main/resources/localization/messages.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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}!
Expand All @@ -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
Expand Down