use of ml.duncte123.skybot.Variables in project SkyBot by duncte123.
the class GuildSettingsUtils method loadVcAutoRoles.
public static void loadVcAutoRoles(Variables variables) {
final DatabaseAdapter adapter = variables.getDatabaseAdapter();
final TLongObjectMap<TLongLongMap> vcAutoRoleCache = variables.getVcAutoRoleCache();
LOGGER.info("Loading vc auto roles.");
adapter.getVcAutoRoles((items) -> {
items.forEach((item) -> {
final TLongLongMap cache = Optional.ofNullable(vcAutoRoleCache.get(item.getGuildId())).orElseGet(() -> {
// This returns the old value which was null
vcAutoRoleCache.put(item.getGuildId(), new TLongLongHashMap());
return vcAutoRoleCache.get(item.getGuildId());
});
cache.put(item.getVoiceChannelId(), item.getRoleId());
});
LOGGER.info("Loaded " + items.size() + " vc auto roles.");
return null;
});
}
use of ml.duncte123.skybot.Variables in project SkyBot by DuncteBot.
the class CommandManager method runCustomCommand.
private void runCustomCommand(ICommand cmd, String invoke, List<String> args, GuildMessageReceivedEvent event) {
final CustomCommand cusomCommand = (CustomCommand) cmd;
if (cusomCommand.getGuildId() != event.getGuild().getIdLong()) {
return;
}
try {
MDC.put("command.custom.message", cusomCommand.getMessage());
final Parser parser = CommandUtils.getParser(new CommandContext(invoke, args, event, variables));
final String message = parser.parse(cusomCommand.getMessage());
final MessageConfig.Builder messageBuilder = MessageConfig.Builder.fromEvent(event);
final DataObject object = parser.get("embed");
boolean hasContent = false;
if (!message.isEmpty()) {
messageBuilder.setMessage("\u200B" + message);
hasContent = true;
}
if (object != null) {
final JDAImpl jda = (JDAImpl) event.getJDA();
final EmbedBuilder embed = new EmbedBuilder(jda.getEntityBuilder().createMessageEmbed(object));
messageBuilder.addEmbed(true, embed);
hasContent = true;
}
if (hasContent) {
sendMsg(messageBuilder.build());
}
parser.clear();
} catch (Exception e) {
sendMsg(MessageConfig.Builder.fromEvent(event).setMessage("Error with parsing custom command: " + e.getMessage()).build());
Sentry.captureException(e);
}
}
use of ml.duncte123.skybot.Variables in project SkyBot by DuncteBot.
the class CommandManager method runNormalCommand.
private void runNormalCommand(ICommand cmd, String invoke, List<String> args, GuildMessageReceivedEvent event) {
if (cmd.getCategory() == CommandCategory.NSFW && this.isSafeForWork(event)) {
sendMsg(MessageConfig.Builder.fromEvent(event).setMessage("Woops, this channel is not marked as NSFW.\n" + "Please mark this channel as NSFW to use this command").build());
return;
}
MDC.put("command.class", cmd.getClass().getName());
LOGGER.info("Dispatching command \"{}\" in guild \"{}\" with {}", cmd.getClass().getSimpleName(), event.getGuild(), args);
cmd.executeCommand(new CommandContext(invoke, args, event, variables));
}
use of ml.duncte123.skybot.Variables in project SkyBot by DuncteBot.
the class AudioUtils method getMusicManager.
public GuildMusicManager getMusicManager(long guildId) {
synchronized (this) {
GuildMusicManager mng = musicManagers.get(guildId);
if (mng == null) {
mng = new GuildMusicManager(guildId, variables);
musicManagers.put(guildId, mng);
}
return mng;
}
}
use of ml.duncte123.skybot.Variables in project SkyBot by DuncteBot.
the class GuildSettingsUtils method loadVcAutoRoles.
public static void loadVcAutoRoles(Variables variables) {
final DatabaseAdapter adapter = variables.getDatabaseAdapter();
final TLongObjectMap<TLongLongMap> vcAutoRoleCache = variables.getVcAutoRoleCache();
LOGGER.info("Loading vc auto roles.");
adapter.getVcAutoRoles((items) -> {
items.forEach((item) -> {
final TLongLongMap cache = Optional.ofNullable(vcAutoRoleCache.get(item.getGuildId())).orElseGet(() -> {
// This returns the old value which was null
vcAutoRoleCache.put(item.getGuildId(), new TLongLongHashMap());
return vcAutoRoleCache.get(item.getGuildId());
});
cache.put(item.getVoiceChannelId(), item.getRoleId());
});
LOGGER.info("Loaded " + items.size() + " vc auto roles.");
return null;
});
}
Aggregations