From 9a70ac37cc4f523df81fd74ee611149f10cbdedd Mon Sep 17 00:00:00 2001 From: NovaFox161 Date: Mon, 9 Aug 2021 14:10:38 -0500 Subject: [PATCH] Add json for settings command --- .../client/message/EventMessageFormatter.java | 61 ------------- .../src/main/resources/commands/settings.json | 87 +++++++++++++++++++ .../i18n/command/discal/discal.properties | 25 ------ .../i18n/command/settings/settings.properties | 19 ++++ 4 files changed, 106 insertions(+), 86 deletions(-) create mode 100644 core/src/main/resources/commands/settings.json create mode 100644 core/src/main/resources/i18n/command/settings/settings.properties diff --git a/client/src/main/java/org/dreamexposure/discal/client/message/EventMessageFormatter.java b/client/src/main/java/org/dreamexposure/discal/client/message/EventMessageFormatter.java index a354d287..dacfc75c 100644 --- a/client/src/main/java/org/dreamexposure/discal/client/message/EventMessageFormatter.java +++ b/client/src/main/java/org/dreamexposure/discal/client/message/EventMessageFormatter.java @@ -16,8 +16,6 @@ import org.dreamexposure.discal.core.object.event.PreEvent; import org.dreamexposure.discal.core.utils.GlobalVal; import org.dreamexposure.discal.core.utils.ImageUtils; import org.dreamexposure.discal.core.wrapper.google.CalendarWrapper; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import reactor.core.publisher.Mono; import reactor.function.TupleUtils; @@ -34,8 +32,6 @@ import java.time.temporal.ChronoUnit; */ @SuppressWarnings("MagicNumber") public class EventMessageFormatter { - private final static Logger LOGGER = LoggerFactory.getLogger(EventMessageFormatter.class); - public static Mono getEventEmbed(Event event, int calNum, GuildSettings settings) { final Mono guild = DisCalClient.getClient().getGuildById(settings.getGuildID()); Mono data = DatabaseManager.INSTANCE.getEventData(settings.getGuildID(), event.getId()) @@ -120,63 +116,6 @@ public class EventMessageFormatter { })); } - public static Mono getCondensedEventEmbed(Event event, int calNum, GuildSettings settings) { - Mono guild = DisCalClient.getClient().getGuildById(settings.getGuildID()); - Mono data = DatabaseManager.INSTANCE.getEventData(settings.getGuildID(), event.getId()) - .defaultIfEmpty(new EventData()) - .cache(); - Mono date = getHumanReadableDate(event.getStart(), calNum, false, settings); - Mono time = getHumanReadableTime(event.getStart(), 1, false, settings); - Mono img = data.filter(EventData::shouldBeSaved) - .flatMap(d -> ImageUtils.validate(d.getImageLink(), settings.getPatronGuild())) - .defaultIfEmpty(false); - - return Mono.zip(guild, data, date, time, img) - .map(TupleUtils.function((g, ed, startData, startTime, hasImg) -> { - var builder = EmbedCreateSpec.builder(); - - if (settings.getBranded()) - builder.author(g.getName(), BotSettings.BASE_URL.get(), - g.getIconUrl(Image.Format.PNG).orElse(GlobalVal.getIconUrl())); - else - builder.author("DisCal", BotSettings.BASE_URL.get(), GlobalVal.getIconUrl()); - - builder.title(Messages.getMessage("Embed.Event.Condensed.Title", settings)); - if (hasImg) - builder.thumbnail(ed.getImageLink()); - - if (event.getSummary() != null) { - String summary = event.getSummary(); - if (summary.length() > 250) { - summary = summary.substring(0, 250); - summary = summary + " (continues on Google Calendar View)"; - } - builder.addField(Messages.getMessage("Embed.Event.Condensed.Summary", settings), summary, false); - } - builder.addField(Messages.getMessage("Embed.Event.Condensed.Date", settings), startData, true); - builder.addField(Messages.getMessage("Embed.Event.Condensed.Time", settings), startTime, true); - if (event.getLocation() != null && !"".equalsIgnoreCase(event.getLocation())) { - if (event.getLocation().length() > 300) { - final String location = event.getLocation().substring(0, 300).trim() + "... (cont. on Google Cal)"; - builder.addField(Messages.getMessage("Embed.Event.Confirm.Location", settings), location, false); - } else { - builder.addField(Messages.getMessage("Embed.Event.Confirm.Location", settings), event.getLocation(), false); - } - } - builder.addField(Messages.getMessage("Embed.Event.Condensed.ID", settings), event.getId(), false); - builder.url(event.getHtmlLink()); - - if (event.getColorId() != null) { - final EventColor ec = EventColor.Companion.fromId(Integer.parseInt(event.getColorId())); - builder.color(ec.asColor()); - } else { - builder.color(GlobalVal.getDiscalColor()); - } - - return builder.build(); - })); - } - public static Mono getPreEventEmbed(PreEvent event, GuildSettings settings) { Mono guild = DisCalClient.getClient().getGuildById(settings.getGuildID()); Mono sDate = getHumanReadableDate(event.getStartDateTime(), event.getCalNumber(), false, settings); diff --git a/core/src/main/resources/commands/settings.json b/core/src/main/resources/commands/settings.json new file mode 100644 index 00000000..395fed48 --- /dev/null +++ b/core/src/main/resources/commands/settings.json @@ -0,0 +1,87 @@ +{ + "name": "settings", + "description": "A set of commands for changing various bot settings", + "options": [ + { + "name": "view", + "type": 1, + "description": "Displays the current settings for the bot in this guild", + "required": false + }, + { + "name": "role", + "type": 1, + "description": "Sets the role required to use protected commands", + "required": false, + "options": [ + { + "name": "role", + "type": 8, + "description": "The role required to use protected commands", + "required": true + } + ] + }, + { + "name": "announcement-style", + "type": 1, + "description": "Changes what style announcements will be posted as", + "required": false, + "options": [ + { + "name": "style", + "type": 3, + "description": "The announcement style to use", + "required": true, + "choices": [ + { + "name": "full", + "value": "FULL" + }, + { + "name": "simple", + "value": "SIMPLE" + }, + { + "name": "event only", + "value": "EVENT" + } + ] + } + ] + }, + { + "name": "language", + "type": 1, + "description": "Changes what language the bot will use in responses.", + "required": false, + "options": [ + { + "name": "lang", + "type": 3, + "description": "The language to use", + "required": true, + "choices": [ + { + "name": "English", + "value": "en" + } + ] + } + ] + }, + { + "name": "time-format", + "type": 1, + "description": "Toggles between 24-hour and 12-hour time formatting", + "required": false + }, + { + "name": "branding", + "type": 1, + "description": "Toggles between using discal branding or your guild's name/image where possible", + "required": false + } + ], + "default_permissions": true +} diff --git a/core/src/main/resources/i18n/command/discal/discal.properties b/core/src/main/resources/i18n/command/discal/discal.properties index 22df6fc8..3d7aa916 100644 --- a/core/src/main/resources/i18n/command/discal/discal.properties +++ b/core/src/main/resources/i18n/command/discal/discal.properties @@ -1,31 +1,6 @@ meta.description=Used for general functions related to DisCal meta.example=/discal (subcommand) (args...) -meta.description.settings=Displays the bot's settings for this guild -meta.description.role=Sets the role users need for some commands -meta.description.channel=Sets the channel the bot is allowed to respond in -meta.description.simpleAnnouncement=Makes announcements more friendly -meta.description.language=Sets the default language the bot will use in this server -meta.description.lang=Alias for `language` -meta.description.prefix=Sets the prefix for commands meta.description.invite=Displays the invite link for DisCal's support server meta.description.dashboard=Displays the link to the control panel on the website -meta.description.brand=Toggles server branding (hiding bot name/logo where possible) -meta.description.twelveHour=Toggles between a 12-hour or 24-hour time format -meta.description.timeFormat=Alias for `twelveHour` -role.success.reset=Role has been reset. Anyone can create/edit events/announcements. -role.success.set=Required role needed to use DisCal creation commands set to `{0}` -role.failure.notFound=Could not find that role. Maybe its misspelled? -role.failure.badArgs=Invalid arguments were supplied. See command info with `/help discal role` -channel.success.reset=Channel has been reset. DisCal can now be used in any channel with correct permissions. -channel.success.set=DisCal will now ***only*** respond in {0}. -channel.failure.notFound=Could not find that channel. Maybe its misspelled? -channel.failure.badArgs=Invalid arguments were supplied. See command info with `/help discal channel` -simpleAnnouncement.success=Simple announcement setting has been toggled to `{0}`. -timeFormat.success=Use 12-hour time format setting has been toggled to `{0}`. -prefix.success=DisCal will now respond to commands with the prefix `{0}` -prefix.failure.badArgs=Invalid arguments were supplied. See command info with `/help discal prefix` -language.success=Successfully changed default language! -language.failure.notSupported=Language not found. Currently supported languages are: {0} -language.failure.badArgs=Invalid arguments were supplied. See command info with `/help discal language` invite.success=Need help? Have questions? Join the official support server: {0} error.noSubcommand=Sorry, that subcommand doesn't exist. See command info with `/help discal` diff --git a/core/src/main/resources/i18n/command/settings/settings.properties b/core/src/main/resources/i18n/command/settings/settings.properties new file mode 100644 index 00000000..d34c6568 --- /dev/null +++ b/core/src/main/resources/i18n/command/settings/settings.properties @@ -0,0 +1,19 @@ +meta.description=Used for changing settings related to DisCal +meta.example=/settings (subcommand) (args...) +meta.description.view=Displays the bot's settings for this guild +meta.description.role=Sets the role users need for some commands +meta.description.simpleAnnouncement=Makes announcements more friendly +meta.description.language=Sets the default language the bot will use in this server +meta.description.brand=Toggles server branding (hiding bot name/logo where possible) +meta.description.twelveHour=Toggles between a 12-hour or 24-hour time format + +role.success.reset=Role has been reset. Anyone can create/edit events/announcements. +role.success.set=Required role needed to use DisCal creation commands set to `{0}` +role.failure.notFound=Could not find that role. Maybe its misspelled? +role.failure.badArgs=Invalid arguments were supplied. See command info with `/help discal role` +channel.success.reset=Channel has been reset. DisCal can now be used in any channel with correct permissions. +simpleAnnouncement.success=Simple announcement setting has been toggled to `{0}`. +timeFormat.success=Use 12-hour time format setting has been toggled to `{0}`. +language.success=Successfully changed default language! +language.failure.notSupported=Language not found. Currently supported languages are: {0} +language.failure.badArgs=Invalid arguments were supplied. See command info with `/help discal language`