Add json for settings command

This commit is contained in:
NovaFox161
2021-08-09 14:10:38 -05:00
parent 120c0c4a8f
commit 9a70ac37cc
4 changed files with 106 additions and 86 deletions

View File

@@ -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<EmbedCreateSpec> getEventEmbed(Event event, int calNum, GuildSettings settings) {
final Mono<Guild> guild = DisCalClient.getClient().getGuildById(settings.getGuildID());
Mono<EventData> data = DatabaseManager.INSTANCE.getEventData(settings.getGuildID(), event.getId())
@@ -120,63 +116,6 @@ public class EventMessageFormatter {
}));
}
public static Mono<EmbedCreateSpec> getCondensedEventEmbed(Event event, int calNum, GuildSettings settings) {
Mono<Guild> guild = DisCalClient.getClient().getGuildById(settings.getGuildID());
Mono<EventData> data = DatabaseManager.INSTANCE.getEventData(settings.getGuildID(), event.getId())
.defaultIfEmpty(new EventData())
.cache();
Mono<String> date = getHumanReadableDate(event.getStart(), calNum, false, settings);
Mono<String> time = getHumanReadableTime(event.getStart(), 1, false, settings);
Mono<Boolean> 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<EmbedCreateSpec> getPreEventEmbed(PreEvent event, GuildSettings settings) {
Mono<Guild> guild = DisCalClient.getClient().getGuildById(settings.getGuildID());
Mono<String> sDate = getHumanReadableDate(event.getStartDateTime(), event.getCalNumber(), false, settings);

View File

@@ -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
}

View File

@@ -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`

View File

@@ -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`