Simplified timetable command; stats and help commands rebased

This commit is contained in:
ByteDream 2020-12-04 23:25:56 +01:00
parent 575058f541
commit 5d4e5e634c

View File

@ -13,6 +13,7 @@ import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
import net.dv8tion.jda.api.events.message.guild.GuildMessageReceivedEvent; import net.dv8tion.jda.api.events.message.guild.GuildMessageReceivedEvent;
import net.dv8tion.jda.api.hooks.ListenerAdapter; import net.dv8tion.jda.api.hooks.ListenerAdapter;
import org.bytedream.untis4j.Session; import org.bytedream.untis4j.Session;
import org.bytedream.untis4j.UntisUtils;
import org.bytedream.untis4j.responseObjects.Klassen; import org.bytedream.untis4j.responseObjects.Klassen;
import org.bytedream.untis4j.responseObjects.Teachers; import org.bytedream.untis4j.responseObjects.Teachers;
import org.bytedream.untis4j.responseObjects.TimeUnits; import org.bytedream.untis4j.responseObjects.TimeUnits;
@ -97,26 +98,23 @@ public class DiscordCommandListener extends ListenerAdapter {
if (args.length < 3) { if (args.length < 3) {
Session session = allUntisSessions.get(guildId); Session session = allUntisSessions.get(guildId);
LocalDate now = LocalDate.now(); LocalDate now = LocalDate.now();
Short classId = null; Short classId = data.getKlasseId();
LocalDate date = null; LocalDate date = now;
if (data.getServer() == null && data.getSchool() == null) { if (data.getServer() == null && data.getSchool() == null) {
channel.sendMessage("Please set your data with the `data` command first, before you use this command. Type `" + data.getPrefix() + "help data` to get information").queue(); channel.sendMessage("Please set your data with the `data` command first, before you use this command. Type `" + data.getPrefix() + "help data` to get information").queue();
return; return;
} }
if (args.length == 0) { if (args.length != 0) {
classId = data.getKlasseId();
date = now;
} else {
for (String arg : args) { for (String arg : args) {
if (date == null) { if (date.equals(now)) {
Integer number = null; Integer number = null;
try { try {
number = Integer.parseInt(arg); number = Integer.parseInt(arg);
} catch (NumberFormatException ignore) { } catch (NumberFormatException ignore) {
} }
if (number != null && number <= 31 && number >= 1) { if (number != null && number > 1 && number < 31) {
date = LocalDate.of(now.getYear(), now.getMonth(), number); date = LocalDate.of(now.getYear(), now.getMonth(), number);
continue; continue;
} else if (arg.contains(".")) { } else if (arg.contains(".")) {
@ -142,14 +140,15 @@ public class DiscordCommandListener extends ListenerAdapter {
} }
} }
} }
System.out.println("sss");
try { try {
classId = (short) session.getKlassen().findByName(arg).getId(); classId = (short) session.getKlassen().findByName(arg).getId();
} catch (IOException e) { } catch (IOException e) {
logger.warn(guildId + " ran into an exception while trying to receive classes for a timetable", e); logger.warn(guildId + " ran into an exception while trying to receive classes for a timetable", e);
channel.sendMessage("Couldn't search the class. Try again (later) or contact my author <@650417934073593886>, if the problem won't go away").queue(); channel.sendMessage("Couldn't search the class. Try again (later) or contact my author <@650417934073593886>, if the problem won't go away").queue();
return;
} catch (NullPointerException e) { } catch (NullPointerException e) {
channel.sendMessage("Couldn't find any class with the name '" + arg + "'").queue(); channel.sendMessage("Couldn't find any class with the name '" + arg + "'").queue();
return;
} }
} }
} }
@ -172,78 +171,67 @@ public class DiscordCommandListener extends ListenerAdapter {
put("date", finalDate.format(DateTimeFormatter.ofPattern("dd.MM.yyyy"))); put("date", finalDate.format(DateTimeFormatter.ofPattern("dd.MM.yyyy")));
}})); }}));
LinkedHashMap<LocalTime, ArrayList<Timetable.Lesson>> lessons = new LinkedHashMap<>();
boolean noMultiples = true;
LocalTime lastStartTime = LocalTime.MIN; LocalTime lastStartTime = LocalTime.MIN;
boolean multipleLessonAtOnce = false;
TreeMap<LocalTime, ArrayList<Timetable.Lesson>> lessons = new TreeMap<>();
try { try {
for (Timetable.Lesson lesson : Timetable.sortByStartTime(allUntisSessions.get(guildId).getTimetableFromKlasseId(date, date, classId))) { for (Timetable.Lesson lesson : Timetable.sortByStartTime(allUntisSessions.get(guildId).getTimetableFromKlasseId(date, date, classId))) {
lessons.putIfAbsent(lesson.getStartTime(), new ArrayList<>()); lessons.putIfAbsent(lesson.getStartTime(), new ArrayList<>());
lessons.get(lesson.getStartTime()).add(lesson); lessons.get(lesson.getStartTime()).add(lesson);
if (lastStartTime.equals(lesson.getStartTime())) { if (lastStartTime.equals(lesson.getStartTime())) noMultiples = false;
multipleLessonAtOnce = true;
}
lastStartTime = lesson.getStartTime(); lastStartTime = lesson.getStartTime();
} }
if (multipleLessonAtOnce) { for (int i = 0; i < lessons.size(); i++) {
for (ArrayList<Timetable.Lesson> listLessons: lessons.values()) { ArrayList<Timetable.Lesson> listLessons = (ArrayList<Timetable.Lesson>) lessons.values().toArray()[i];
for (Timetable.Lesson lesson: listLessons) { for (Timetable.Lesson lesson: (ArrayList<Timetable.Lesson>) lessons.values().toArray()[i]) {
embedBuilder.addField(Utils.advancedFormat(language.getString("timetable-lesson-title"), new HashMap<String, Object>() {{ String additional = "";
put("lesson-number", lesson.getTimeUnitObject().getName()); if (lesson.getCode() == UntisUtils.LessonCode.CANCELLED) {
put("start-time", lesson.getStartTime().format(DateTimeFormatter.ofPattern("HH:mm"))); additional = "~~";
put("end-time", lesson.getEndTime().format(DateTimeFormatter.ofPattern("HH:mm")));
}}), Utils.advancedFormat(language.getString("timetable-teachers"), new HashMap<String, Object>() {{
put("teachers", String.join(", ", lesson.getTeachers().getFullNames()));
}}) + "\n" + Utils.advancedFormat(language.getString("timetable-subjects"), new HashMap<String, Object>() {{
put("subjects", String.join(", ", lesson.getSubjects().getLongNames()));
}}) + "\n" + Utils.advancedFormat(language.getString("timetable-rooms"), new HashMap<String, Object>() {{
put("rooms", String.join(", ", lesson.getRooms().getLongNames()));
}}), listLessons.size() > 1);
} }
} embedBuilder.addField(additional + Utils.advancedFormat(language.getString("timetable-lesson-title"), new HashMap<String, Object>() {{
} else {
/*int halfSize = (int) Math.ceil((lessons.values().size() / 2));
for (int i = 0; i <= halfSize; i++) {
int j = i + 1;
Timetable.Lesson lesson = ((ArrayList<Timetable.Lesson>) lessons.values().toArray()[i]).get(0);
Timetable.Lesson[] leftRightLessons;
if (j + halfSize > lessons.values().size() - 1) {
leftRightLessons = new Timetable.Lesson[]{lesson};
} else {
leftRightLessons = new Timetable.Lesson[]{lesson, ((ArrayList<Timetable.Lesson>) lessons.values().toArray()[j + halfSize]).get(0)};
}
for (Timetable.Lesson lesson1: leftRightLessons) {
embedBuilder.addField(Utils.advancedFormat(language.getString("timetable-lesson-title"), new HashMap<String, Object>() {{
put("lesson-number", lesson1.getTimeUnitObject().getName());
put("start-time", lesson1.getStartTime().format(DateTimeFormatter.ofPattern("HH:mm")));
put("end-time", lesson1.getEndTime().format(DateTimeFormatter.ofPattern("HH:mm")));
}}), Utils.advancedFormat(language.getString("timetable-teachers"), new HashMap<String, Object>() {{
put("teachers", String.join(", ", lesson1.getTeachers().getFullNames()));
}}) + "\n" + Utils.advancedFormat(language.getString("timetable-subjects"), new HashMap<String, Object>() {{
put("subjects", String.join(", ", lesson1.getSubjects().getLongNames()));
}}) + "\n" + Utils.advancedFormat(language.getString("timetable-rooms"), new HashMap<String, Object>() {{
put("rooms", String.join(", ", lesson1.getRooms().getLongNames()));
}}), true);
}
embedBuilder.addBlankField(true);
}*/
for (ArrayList<Timetable.Lesson> listLesson: lessons.values()) {
Timetable.Lesson lesson = listLesson.get(0);
embedBuilder.addField(Utils.advancedFormat(language.getString("timetable-lesson-title"), new HashMap<String, Object>() {{
put("lesson-number", lesson.getTimeUnitObject().getName()); put("lesson-number", lesson.getTimeUnitObject().getName());
put("start-time", lesson.getStartTime().format(DateTimeFormatter.ofPattern("HH:mm"))); put("start-time", lesson.getStartTime().format(DateTimeFormatter.ofPattern("HH:mm")));
put("end-time", lesson.getEndTime().format(DateTimeFormatter.ofPattern("HH:mm"))); put("end-time", lesson.getEndTime().format(DateTimeFormatter.ofPattern("HH:mm")));
}}), Utils.advancedFormat(language.getString("timetable-teachers"), new HashMap<String, Object>() {{ }}) + additional, additional + Utils.advancedFormat(language.getString("timetable-teachers"), new HashMap<String, Object>() {{
put("teachers", String.join(", ", lesson.getTeachers().getFullNames())); put("teachers", String.join(", ", lesson.getTeachers().getFullNames()));
}}) + "\n" + Utils.advancedFormat(language.getString("timetable-subjects"), new HashMap<String, Object>() {{ }}) + "\n" + Utils.advancedFormat(language.getString("timetable-subjects"), new HashMap<String, Object>() {{
put("subjects", String.join(", ", lesson.getSubjects().getLongNames())); put("subjects", String.join(", ", lesson.getSubjects().getLongNames()));
}}) + "\n" + Utils.advancedFormat(language.getString("timetable-rooms"), new HashMap<String, Object>() {{ }}) + "\n" + Utils.advancedFormat(language.getString("timetable-rooms"), new HashMap<String, Object>() {{
put("rooms", String.join(", ", lesson.getRooms().getLongNames())); put("rooms", String.join(", ", lesson.getRooms().getLongNames()));
}}), true); }}) + additional, noMultiples || listLessons.size() > 1);
}
if (listLessons.size() == 2 && i + 1 != lessons.size()) {
embedBuilder.addBlankField(true);
} }
} }
/*int halfSize = (int) Math.ceil((lessons.values().size() / 2));
for (int i = 0; i <= halfSize; i++) {
int j = i + 1;
Timetable.Lesson lesson = ((ArrayList<Timetable.Lesson>) lessons.values().toArray()[i]).get(0);
Timetable.Lesson[] leftRightLessons;
if (j + halfSize > lessons.values().size() - 1) {
leftRightLessons = new Timetable.Lesson[]{lesson};
} else {
leftRightLessons = new Timetable.Lesson[]{lesson, ((ArrayList<Timetable.Lesson>) lessons.values().toArray()[j + halfSize]).get(0)};
}
for (Timetable.Lesson lesson1: leftRightLessons) {
embedBuilder.addField(Utils.advancedFormat(language.getString("timetable-lesson-title"), new HashMap<String, Object>() {{
put("lesson-number", lesson1.getTimeUnitObject().getName());
put("start-time", lesson1.getStartTime().format(DateTimeFormatter.ofPattern("HH:mm")));
put("end-time", lesson1.getEndTime().format(DateTimeFormatter.ofPattern("HH:mm")));
}}), Utils.advancedFormat(language.getString("timetable-teachers"), new HashMap<String, Object>() {{
put("teachers", String.join(", ", lesson1.getTeachers().getFullNames()));
}}) + "\n" + Utils.advancedFormat(language.getString("timetable-subjects"), new HashMap<String, Object>() {{
put("subjects", String.join(", ", lesson1.getSubjects().getLongNames()));
}}) + "\n" + Utils.advancedFormat(language.getString("timetable-rooms"), new HashMap<String, Object>() {{
put("rooms", String.join(", ", lesson1.getRooms().getLongNames()));
}}), true);
}
embedBuilder.addBlankField(true);
}*/
channel.sendMessage(embedBuilder.build()).queue(); channel.sendMessage(embedBuilder.build()).queue();
} catch (IOException e) { } catch (IOException e) {
logger.warn(guildId + " ran into an exception while trying to receive a timetable", e); logger.warn(guildId + " ran into an exception while trying to receive a timetable", e);
@ -258,11 +246,8 @@ public class DiscordCommandListener extends ListenerAdapter {
Data.Stats stats = statsDataConnector.get(guildId); Data.Stats stats = statsDataConnector.get(guildId);
EmbedBuilder embedBuilder = new EmbedBuilder(); EmbedBuilder embedBuilder = new EmbedBuilder();
if (guildName.trim().endsWith("s")) { if (guildName.trim().endsWith("s")) embedBuilder.setTitle(guild.getName() + " untis status");
embedBuilder.setTitle(guild.getName() + " untis status"); else embedBuilder.setTitle(guild.getName() + "'s untis status");
} else {
embedBuilder.setTitle(guild.getName() + "'s untis status");
}
ArrayList<String> mostMissedTeachers = new ArrayList<>(); ArrayList<String> mostMissedTeachers = new ArrayList<>();
short missedLessons = 0; short missedLessons = 0;
@ -283,17 +268,29 @@ public class DiscordCommandListener extends ListenerAdapter {
} }
String timetableChecking; String timetableChecking;
String dataSet;
if (data.isCheckActive()) { if (data.isCheckActive()) {
timetableChecking = "\uD83D\uDFE2 Active"; timetableChecking = "\uD83D\uDFE2 Active";
embedBuilder.setColor(Color.GREEN); embedBuilder.setColor(Color.GREEN);
} else { } else {
timetableChecking = "\uD83D\uDD34 Inactive"; timetableChecking = "\uD83D\uDD34 Inactive";
embedBuilder.setFooter("To start timetable checking, type `" + data.getPrefix() + "set-data <username> <password> <loginpage url>` - type `" + data.getPrefix() + "help` for more details");
embedBuilder.setColor(Color.RED); embedBuilder.setColor(Color.RED);
} }
if (data.getUsername() != null && data.getServer() != null && data.getSchool() != null) {
dataSet = "✅ Set";
if (!data.isCheckActive()) {
embedBuilder.setFooter("The timetable checker is deactivated. Type `" + data.getPrefix() + "start` - use `" + data.getPrefix() + "help start` for more details");
}
}
else {
dataSet = "❌ Not set";
embedBuilder.setFooter("To set your data, type `" + data.getPrefix() + "set-data <username> <password> <loginpage url>` - use `" + data.getPrefix() + "help data` for more details");
}
embedBuilder.addField("Timetable checking", timetableChecking, true); embedBuilder.addField("Timetable checking", timetableChecking, true);
embedBuilder.addField("Data status", dataSet, true);
//embedBuilder.addField("Checking interval", data.getSleepTime() / 60000 + " minutes", true); //embedBuilder.addField("Checking interval", data.getSleepTime() / 60000 + " minutes", true);
embedBuilder.addField("Total timetable requests", String.valueOf(stats.getTotalRequests()), true); //embedBuilder.addField("Total timetable requests", String.valueOf(stats.getTotalRequests()), true);
embedBuilder.addField("Total lessons checked", String.valueOf(stats.getTotalLessons()), true); embedBuilder.addField("Total lessons checked", String.valueOf(stats.getTotalLessons()), true);
embedBuilder.addField("Total weeks checked", String.valueOf((int) (Math.floor((float) stats.getTotalDays() / 7))), true); embedBuilder.addField("Total weeks checked", String.valueOf((int) (Math.floor((float) stats.getTotalDays() / 7))), true);
embedBuilder.addField("Total cancelled lessons", String.valueOf(stats.getTotalCancelledLessons()), true); embedBuilder.addField("Total cancelled lessons", String.valueOf(stats.getTotalCancelledLessons()), true);
@ -441,6 +438,7 @@ public class DiscordCommandListener extends ListenerAdapter {
if (data.isCheckActive()) { if (data.isCheckActive()) {
channel.sendMessage("Timetable listening already started").queue(); channel.sendMessage("Timetable listening already started").queue();
} else { } else {
guildDataConnector.update(guildId, null, null, null, null, null, null, null, null, null, true, null);
runTimetableChecker(guild); runTimetableChecker(guild);
logger.info(guildName + " started timetable listening"); logger.info(guildName + " started timetable listening");
channel.sendMessage("✅ Timetable listening has been started").queue(); channel.sendMessage("✅ Timetable listening has been started").queue();
@ -452,6 +450,7 @@ public class DiscordCommandListener extends ListenerAdapter {
case "stop": // `stop` command case "stop": // `stop` command
if (args.length == 0) { if (args.length == 0) {
if (data.isCheckActive()) { if (data.isCheckActive()) {
guildDataConnector.update(guildId, null, null, null, null, null, null, null, null, null, false, null);
Timer timer = allTimetableChecker.get(guildId); Timer timer = allTimetableChecker.get(guildId);
allTimetableChecker.remove(guildId); allTimetableChecker.remove(guildId);
timer.cancel(); timer.cancel();
@ -465,7 +464,9 @@ public class DiscordCommandListener extends ListenerAdapter {
channel.sendMessage("Wrong number of arguments were given (expected 0, got " + args.length + "), type `" + data.getPrefix() + "help stop` for help").queue(); channel.sendMessage("Wrong number of arguments were given (expected 0, got " + args.length + "), type `" + data.getPrefix() + "help stop` for help").queue();
} }
break; break;
case "help": // is handled in DiscordCommandListener.onMessageReceived() case "help":
case "info":
case "infos": // is handled in DiscordCommandListener.onMessageReceived()
return; return;
default: default:
channel.sendMessage("Unknown command").queue(); channel.sendMessage("Unknown command").queue();
@ -542,6 +543,8 @@ public class DiscordCommandListener extends ListenerAdapter {
} catch (ArrayIndexOutOfBoundsException e) { } catch (ArrayIndexOutOfBoundsException e) {
i++; i++;
daysToCheck++; daysToCheck++;
} catch (NullPointerException e) {
i++;
} }
for (; i <= daysToCheck; i++) { for (; i <= daysToCheck; i++) {
@ -756,111 +759,150 @@ public class DiscordCommandListener extends ListenerAdapter {
String message = event.getMessage().getContentDisplay().trim().toLowerCase(); String message = event.getMessage().getContentDisplay().trim().toLowerCase();
MessageChannel channel = event.getChannel(); MessageChannel channel = event.getChannel();
String prefix; String[] commands = new String[]{"help", "info"};
if (message.contains("help")) { // `help` command
if (event.isFromGuild()) { String prefix = null;
prefix = guildDataConnector.get(event.getGuild().getIdLong()).getPrefix(); String command = "";
if (!event.getMessage().getContentDisplay().startsWith(prefix + "help")) { String[] args = null;
System.out.println("sss");
return; for (String cmd: commands) {
if (message.contains(cmd)) {
if (event.isFromGuild()) {
prefix = guildDataConnector.get(event.getGuild().getIdLong()).getPrefix();
if (!event.getMessage().getContentDisplay().startsWith(prefix + cmd)) {
return;
}
} else if (message.equals(cmd) || message.startsWith(cmd + " ")) {
prefix = "";
} else {
continue;
} }
} else if (message.equals("help") || message.startsWith("help ")) { command = cmd;
prefix = ""; String[] splitMessage = message.substring(prefix.length()).split(" ");
} else { args = Arrays.copyOfRange(splitMessage, 1, splitMessage.length);
return; break;
} }
} else {
return;
} }
String[] splitMessage = message.substring(prefix.length()).split(" "); switch (command) {
String[] args = Arrays.copyOfRange(splitMessage, 1, splitMessage.length); case "help": // `help [command] command`
String help = "Use `" + prefix + "help <command>` to get help / information about a command.\n\n" + if (args.length < 2) {
"All available commands are:\n" + String help = "Use `" + prefix + "help <command>` to get help / information about a command.\n\n" +
"`channel` `clear` `data` `help` `language` `prefix` `stats` `start` `stop` `timetable`"; "All available commands are:\n" +
if (args.length > 1) { "`channel` • `clear` • `data` • `info` • `help` • `language` • `prefix` • `stats` • `start` • `stop` • `timetable`";
channel.sendMessage("Wrong number of arguments are given (expected 0 or 1, got " + splitMessage.length + "). " + help).queue(); if (args.length == 0) {
} else if (args.length == 0) { channel.sendMessage(help).queue();
channel.sendMessage(help).queue(); } else {
} else { String title;
String title; String description;
String description; String example;
String example; String default_ = null;
String default_ = null; switch (args[0]) {
switch (args[0]) { case "channel":
case "channel": title = "`channel` command";
title = "`channel` command"; description = "In the channel where this command is entered, the bot shows the timetable changes";
description = "In the channel where this command is entered, the bot shows the timetable changes"; example = "`channel`";
example = "`channel`"; break;
break; case "clear":
case "clear": title = "`clear` command";
title = "`clear` command"; description = "Clears the given untis data, given from the `data` command";
description = "Clears the given untis data, given from the `data` command"; example = "`clear`";
example = "`clear`"; break;
break; case "data":
case "data": title = "`data <username> <password> <login page url>` command";
title = "`data <username> <password> <login page url>` command"; description = "Sets the data with which the bot logs in to untis and checks for timetable changes. The data is stored encrypted on the server.\n" +
description = "Sets the data with which the bot logs in to untis and checks for timetable changes. The data is stored encrypted on the server.\n" + "`username` and `password` are the normal untis login data with which one also logs in to the untis website / app. To gain the login page url you have to go to webuntis.com, type in your school and choose it.\n" +
"`username` and `password` are the normal untis login data with which one also logs in to the untis website / app. To gain the login page url you have to go to webuntis.com, type in your school and choose it.\n" + "Then you will be redirected to the untis login page, The url of this page is the login page url, for example `https://example.webuntis.com/WebUntis/?school=myschool#/basic/main`.\n" +
"Then you will be redirected to the untis login page, The url of this page is the login page url, for example `https://example.webuntis.com/WebUntis/?school=myschool#/basic/main`.\n" + "`class name` is just the name of the class you want to check (eg. `12AB`). If `class name` is not specified, the bot tries to get the default class which is assigned to the given account.";
"`class name` is just the name of the class you want to check (eg. `12AB`). If `class name` is not specified, the bot tries to get the default class which is assigned to the given account."; example = "`data myname secure https://example.webuntis.com/WebUntis/?school=example#/basic/main 12AB`";
example = "`data myname secure https://example.webuntis.com/WebUntis/?school=example#/basic/main 12AB`"; default_ = "`en`";
default_ = "`en`"; break;
break; case "info":
case "help": title = "`info` command";
title = "`help <command>` command"; description = "Displays information about the bot";
description = "Displays help to a given command"; example = "`info`";
example = "`help data`"; break;
break; case "help":
case "language": title = "`help <command>` command";
title = "`language <language>` command"; description = "Displays help to a given command";
description = "Changes the language in which the timetable information are displayed. Currently only 'de' (german) and 'en' (english) are supported"; example = "`help data`";
example = "`language de`"; break;
default_ = "`en`"; case "language":
break; title = "`language <language>` command";
case "prefix": description = "Changes the language in which the timetable information are displayed. Currently only 'de' (german) and 'en' (english) are supported";
title = "`prefix <new prefix>` command"; example = "`language de`";
description = "Changes the prefix with which commands are called"; default_ = "`en`";
example = "`prefix $`"; break;
default_ = "`!untis `"; case "prefix":
break; title = "`prefix <new prefix>` command";
case "stats": description = "Changes the prefix with which commands are called";
title = "`stats` command"; example = "`prefix $`";
description = "Displays a message with some stats (total cancelled lessons, etc.)"; default_ = "`!untis `";
example = "`stats`"; break;
break; case "stats":
case "start": title = "`stats` command";
title = "`start` command"; description = "Displays a message with some stats (total cancelled lessons, etc.)";
description = "Starts the stopped timetable listener. Only works if data was set with the `data` command"; example = "`stats`";
example = "`start`"; break;
break; case "start":
case "stop": title = "`start` command";
title = "`stop` command"; description = "Starts the stopped timetable listener. Only works if data was set with the `data` command";
description = "Stops timetable listening. Only works if data was set with the `data` command"; example = "`start`";
example = "`stop`"; break;
break; case "stop":
case "timetable": title = "`stop` command";
title = "`timetable [date] [class name]` command"; description = "Stops timetable listening. Only works if data was set with the `data` command";
description = "Displays the timetable for a specific date. As `date` you can use 3 formats." + example = "`stop`";
"1: Only the day (`12`); 2. Day and month (`13.04`); 3. Day, month and year (`31.12.2020`)." + break;
"Only works if data was set with the `data` command. If no date is given, the timetable for the current date is displayed." + case "timetable":
"As `class name` you can use any class from your school. If class is not given, the class which was assigned in the `data` command is used"; title = "`timetable [date] [class name]` command";
example = "`timetable 11.11`"; description = "Displays the timetable for a specific date. As `date` you can use 3 formats." +
break; "1: Only the day (`12`); 2. Day and month (`13.04`); 3. Day, month and year (`31.12.2020`)." +
default: "Only works if data was set with the `data` command. If no date is given, the timetable for the current date is displayed." +
channel.sendMessage("Unknown command was given. " + help).queue(); "As `class name` you can use any class from your school. If class is not given, the class which was assigned in the `data` command is used";
return; example = "`timetable 11.11`";
} break;
EmbedBuilder embedBuilder = new EmbedBuilder(); default:
embedBuilder.setColor(Color.CYAN); channel.sendMessage("Unknown command was given. " + help).queue();
embedBuilder.setTitle(title); return;
embedBuilder.addField("Description", description, false); }
embedBuilder.addField("Example", example, false); EmbedBuilder embedBuilder = new EmbedBuilder();
if (default_ != null) { embedBuilder.setColor(Color.CYAN);
embedBuilder.addField("Default", default_, false); embedBuilder.setTitle(title);
} embedBuilder.addField("Description", description, false);
embedBuilder.setFooter("`<>` = required; `[]` = optional"); embedBuilder.addField("Example", example, false);
channel.sendMessage(embedBuilder.build()).queue(); if (default_ != null) {
embedBuilder.addField("Default", default_, false);
}
embedBuilder.setFooter("`<>` = required; `[]` = optional");
channel.sendMessage(embedBuilder.build()).queue();
}
} else {
channel.sendMessage("Wrong number of arguments were given (expected 0 or 1, got " + args.length + "), type `" + prefix + "help help` for help").queue();
}
break;
case "info":
if (args.length == 0) {
EmbedBuilder infoBuilder = new EmbedBuilder();
infoBuilder.setTitle("Untis information");
infoBuilder.setThumbnail("https://cdn.discordapp.com/avatars/768841979433451520/2742868bb029952ee00514a01f84b65b.webp?size=512");
infoBuilder.setDescription("<@768841979433451520> is a java programmed discord bot, which uses the [WebUntis](https://webuntis.com/) " +
"timetable software to receive the timetable for a specific date, " +
"automatically send messages when the timetable from a given account or class changes, " +
"displays total cancelled lessons etc., and more!");
infoBuilder.setColor(new Color(255, 165, 0));
infoBuilder.addField("\uD83D\uDCDDAuthor", "[<@650417934073593886>](https://discordapp.com/users/650417934073593886)", true);
infoBuilder.addField("✨Version", "[v1.1](https://github.com/ByteDream/untisbot-discord/releases/tag/v1.1)", true);
infoBuilder.addField("❓Help", "`" + prefix + "help`", true);
infoBuilder.addField("Source / GitHub", "[Source code!](https://github.com/ByteDream/untisbot-discord)", true);
//infoBuilder.addField("Total guilds (server)", String.valueOf(guildDataConnector.getAll().size()), true);
infoBuilder.addField("\uD83D\uDCC8Vote", "[Vote!](https://top.gg/bot/768841979433451520/vote)", true);
infoBuilder.addField("\uD83D\uDD10Data encryption algorithm", "[AES-256](https://en.wikipedia.org/wiki/Advanced_Encryption_Standard)", true);
channel.sendMessage(infoBuilder.build()).queue();
} else {
channel.sendMessage("Wrong number of arguments were given (expected 0, got " + args.length + "), type `" + prefix + "help info` for help").queue();
}
break;
} }
}); });
t.setName("Message handler"); t.setName("Message handler");