use of sx.blah.discord.util.EmbedBuilder in project DisCal-Discord-Bot by NovaFox161.
the class Logger method debug.
public void debug(@Nullable IUser author, String message, @Nullable String info, Class clazz, boolean post) {
String timeStamp = new SimpleDateFormat("yyyy/MM/dd-HH:mm:ss").format(Calendar.getInstance().getTime());
if (Main.client != null) {
if (post) {
IUser bot = Main.getSelfUser();
EmbedBuilder em = new EmbedBuilder();
assert bot != null;
em.withAuthorIcon(bot.getAvatarURL());
if (author != null) {
em.withAuthorName(author.getName());
em.withThumbnail(author.getAvatarURL());
}
em.withColor(239, 15, 0);
em.withFooterText(clazz.getName());
em.appendField("Time", timeStamp, true);
if (info != null) {
em.appendField("Additional Info", info, true);
}
// Get DisCal guild and channel..
IGuild guild = Main.client.getGuildByID(266063520112574464L);
IChannel channel = guild.getChannelByID(302249332244217856L);
Message.sendMessage(em.build(), "```" + message + "```", channel);
}
}
// ALWAYS LOG TO FILE!
try {
FileWriter file = new FileWriter(debugFile, true);
file.write("DEBUG --- " + timeStamp + " ---" + MessageUtils.lineBreak);
if (author != null) {
file.write("user: " + author.getName() + "#" + author.getDiscriminator() + MessageUtils.lineBreak);
}
if (message != null) {
file.write("message: " + message + MessageUtils.lineBreak);
}
if (info != null) {
file.write("info: " + info + MessageUtils.lineBreak);
}
file.close();
} catch (IOException io) {
io.printStackTrace();
}
}
use of sx.blah.discord.util.EmbedBuilder in project de-DiscordBot by DACH-Discord.
the class DiscordBot method handleMessage.
/**
* Erhaltene/geänderte Nachricht verarbeiten
*/
private void handleMessage(final IMessage message) {
final String messageContent = message.getContent();
// Message doesn't start with the prefix
if (!messageContent.startsWith(this.prefix)) {
return;
}
final String messageCommand = (messageContent.contains(" ") ? // Message has Arguments
messageContent.substring(this.prefix.length(), messageContent.indexOf(' ')) : // Message doesn't have arguments
messageContent.substring(this.prefix.length())).toLowerCase();
if (messageCommand.equalsIgnoreCase("help")) {
this.command_help(message);
return;
}
if (commands.containsKey(messageCommand)) {
final Command command = commands.get(messageCommand);
final int userPermissionLevel = this.getUserPermissionLevel(message.getAuthor(), message.getGuild());
if (userPermissionLevel < command.permissionLevel) {
Util.sendMessage(message.getChannel(), "Dieser Befehl ist für deine Gruppe (" + CommandPermissions.getPermissionLevelName(userPermissionLevel) + ") nicht verfügbar.");
return;
}
if (message.getChannel().isPrivate() && !command.pmAllowed) {
Util.sendMessage(message.getChannel(), "Dieser Befehl ist nicht in Privatnachrichten verfügbar!");
return;
}
try {
final int parameterCount = command.parameterCount;
final boolean passContext = command.passContext;
ArrayList<String> params = parseParameters(messageContent, parameterCount, passContext);
switch(parameterCount) {
case 0:
{
command.method.invoke(command.object, message);
break;
}
case 1:
{
command.method.invoke(command.object, message, params.get(0));
break;
}
case 2:
{
command.method.invoke(command.object, message, params.get(0), params.get(1));
break;
}
case 3:
{
command.method.invoke(command.object, message, params.get(0), params.get(1), params.get(2));
break;
}
case 4:
{
command.method.invoke(command.object, message, params.get(0), params.get(1), params.get(2), params.get(3));
break;
}
case 5:
{
command.method.invoke(command.object, message, params.get(0), params.get(1), params.get(2), params.get(3), params.get(4));
break;
}
default:
{
Util.error(new RuntimeException("Invalid number of parameters!"), message.getChannel());
}
}
} catch (IllegalAccessException | InvocationTargetException e) {
final Throwable cause = e.getCause();
cause.printStackTrace(System.err);
System.err.println(cause.getMessage());
final EmbedBuilder embedBuilder = new EmbedBuilder();
embedBuilder.withColor(new Color(255, 42, 50));
embedBuilder.appendField("Fehler aufgetreten", cause.toString(), false);
embedBuilder.withFooterText("Mehr Infos in der Konsole");
Util.sendEmbed(message.getChannel(), embedBuilder.build());
}
}
}
use of sx.blah.discord.util.EmbedBuilder in project de-DiscordBot by DACH-Discord.
the class UserLog method userJoinNotify.
private void userJoinNotify(final IUser user) {
final LocalDateTime joinTimeStamp = user.getCreationDate();
int joinedDays = (int) joinTimeStamp.until(LocalDateTime.now(), ChronoUnit.DAYS);
// String für Embed
String embedString = "**Name:** " + user.getName() + '#' + user.getDiscriminator() + '\n' + "**ID:** " + user.getStringID() + '\n' + "**Discord beigetreten:** vor " + joinedDays + " Tagen";
if (joinedDays <= 1) {
embedString = embedString + '\n' + ":exclamation: Neuer Nutzer! :exclamation:";
}
// Embed
final EmbedBuilder embedBuilder = new EmbedBuilder();
embedBuilder.appendField(":white_check_mark: Nutzer ist dem Server beigetreten!", embedString, false);
embedBuilder.withThumbnail(user.getAvatarURL());
embedBuilder.withFooterText(LocalDateTime.now().format(DateTimeFormatter.ofPattern("dd.MM. | HH:mm")));
embedBuilder.withColor(new Color(119, 178, 85));
final EmbedObject embedObject = embedBuilder.build();
Util.sendEmbed(userLogChannel, embedObject);
}
use of sx.blah.discord.util.EmbedBuilder in project Shadbot by Shadorc.
the class MoneyStatsManager method getAverageEmbed.
public static EmbedBuilder getAverageEmbed() {
Map<String, AtomicLong> moneyGained = MONEY_STATS_MAP.getOrDefault(MoneyEnum.MONEY_GAINED, Collections.emptyMap());
Map<String, AtomicLong> moneyLost = MONEY_STATS_MAP.getOrDefault(MoneyEnum.MONEY_LOST, Collections.emptyMap());
EmbedBuilder embed = EmbedUtils.getDefaultEmbed().withAuthorName("Stats: average");
List<String> gamesName = new ArrayList<>();
gamesName.addAll(moneyGained.keySet());
gamesName.addAll(moneyLost.keySet());
gamesName = gamesName.stream().distinct().collect(Collectors.toList());
if (gamesName.isEmpty()) {
return embed.withDescription("No statistics yet.");
}
Map<String, AtomicInteger> commandsUsed = CommandStatsManager.get(CommandEnum.COMMAND_USED);
Map<String, Pair<Float, Long>> averageMap = new HashMap<>();
for (String gameName : gamesName) {
long gains = moneyGained.getOrDefault(gameName, new AtomicLong(0)).get();
long losses = moneyLost.getOrDefault(gameName, new AtomicLong(0)).get();
long usages = commandsUsed.get(gameName).get();
float average = ((float) gains - losses) / usages;
averageMap.put(gameName, new Pair<Float, Long>(average, usages));
}
Comparator<Entry<String, Pair<Float, Long>>> comparator = (v1, v2) -> v1.getValue().getSecond().compareTo(v2.getValue().getSecond());
Map<String, Pair<Float, Long>> sortedMap = Utils.sortByValue(averageMap, comparator.reversed());
return embed.appendField("Name", FormatUtils.format(sortedMap.keySet().stream(), Object::toString, "\n"), true).appendField("Average", FormatUtils.format(sortedMap.values().stream().map(Pair::getFirst), num -> FormatUtils.formatNum(num.intValue()), "\n"), true).appendField("Count", FormatUtils.format(sortedMap.values().stream().map(Pair::getSecond), num -> FormatUtils.formatNum(num), "\n"), true);
}
use of sx.blah.discord.util.EmbedBuilder in project Shadbot by Shadorc.
the class EmbedUtils method getStatsEmbed.
public static <K, V extends Number> EmbedBuilder getStatsEmbed(Map<K, V> statsMap, String name) {
EmbedBuilder embed = EmbedUtils.getDefaultEmbed().withAuthorName(String.format("Stats: %s", name.toLowerCase()));
if (statsMap == null) {
return embed.withDescription("No statistics yet.");
}
Comparator<? super Map.Entry<K, V>> comparator = (v1, v2) -> new BigDecimal(v1.getValue().toString()).compareTo(new BigDecimal(v2.getValue().toString()));
Map<K, V> sortedMap = Utils.sortByValue(statsMap, comparator.reversed());
return embed.appendField("Name", FormatUtils.format(sortedMap.keySet().stream(), key -> key.toString().toLowerCase(), "\n"), true).appendField("Value", FormatUtils.format(sortedMap.values().stream(), value -> FormatUtils.formatNum(Long.parseLong(value.toString())), "\n"), true);
}
Aggregations