Search in sources :

Example 1 with Trace

use of datadog.trace.api.Trace in project Vinny by kikkia.

the class AliasesCommand method executeCommand.

@Override
@Trace(operationName = "executeCommand", resourceName = "Aliases")
protected void executeCommand(CommandEvent commandEvent) {
    // TODO: Will need updating for channel and user aliases
    InternalGuild guild = guildDAO.getGuildById(commandEvent.getGuild().getId());
    if (guild.getAliasList().isEmpty()) {
        commandEvent.reply("There are no aliases available to you here");
        return;
    }
    ArrayList<String> aliases = new ArrayList<>();
    for (Map.Entry<String, Alias> entry : guild.getAliasList().entrySet()) {
        aliases.add(entry.getKey() + " -> " + entry.getValue().getCommand());
    }
    builder.setText("Aliases you can use here: ");
    builder.setItems(aliases.toArray(new String[] {}));
    builder.build().paginate(commandEvent.getChannel(), 1);
}
Also used : Alias(com.bot.models.Alias) InternalGuild(com.bot.models.InternalGuild) ArrayList(java.util.ArrayList) Map(java.util.Map) Trace(datadog.trace.api.Trace)

Example 2 with Trace

use of datadog.trace.api.Trace in project Vinny by kikkia.

the class RemoveGuildAliasCommand method executeCommand.

@Override
@Trace(operationName = "executeCommand", resourceName = "RemoveGuildAlias")
protected void executeCommand(CommandEvent commandEvent) {
    InternalGuild guild = guildDAO.getGuildById(commandEvent.getGuild().getId());
    Alias alias = guild.getAliasList().get(commandEvent.getArgs());
    if (alias == null) {
        commandEvent.replyWarning("Could not find that alias, make sure its typed correctly.");
        return;
    }
    try {
        aliasDAO.removeGuildAlias(alias, commandEvent.getGuild().getId());
        guild.getAliasList().remove(commandEvent.getArgs());
        guildDAO.updateGuildInCache(guild);
        commandEvent.reactSuccess();
    } catch (SQLException e) {
        logger.severe("Failed to remove alias", e);
        commandEvent.replyError("Failed to remove alias from db");
    }
}
Also used : SQLException(java.sql.SQLException) Alias(com.bot.models.Alias) InternalGuild(com.bot.models.InternalGuild) Trace(datadog.trace.api.Trace)

Example 3 with Trace

use of datadog.trace.api.Trace in project Vinny by kikkia.

the class ServerInfoCommand method executeCommand.

@Override
@Trace(operationName = "executeCommand", resourceName = "ServerInfo")
protected void executeCommand(CommandEvent commandEvent) {
    Guild g = commandEvent.getGuild();
    int botCount = g.getMembers().stream().filter(m -> m.getUser().isBot()).collect(Collectors.toList()).size();
    int staticEmojiCount = g.getEmotes().stream().filter(m -> !m.isAnimated()).collect(Collectors.toList()).size();
    int animatedEmojiCount = g.getEmotes().stream().filter(Emote::isAnimated).collect(Collectors.toList()).size();
    int membersCount = g.getMembers().stream().filter(m -> !m.getUser().isBot()).collect(Collectors.toList()).size();
    int onlineCount = g.getMembers().stream().filter(m -> m.getOnlineStatus().getKey().equals("online")).collect(Collectors.toList()).size();
    String customEmojis = "**Static**: " + staticEmojiCount + "\n**Animated:** " + animatedEmojiCount;
    String channels = "Voice Channels: " + g.getVoiceChannels().size() + "\nText Channels: " + g.getTextChannels().size() + "\n**Total:** " + g.getChannels().size();
    String members = "Members: " + membersCount + "\nBots: " + botCount + "\n**Total:** " + g.getMembers().size() + "\nOnline: " + onlineCount;
    EmbedBuilder embedBuilder = new EmbedBuilder();
    embedBuilder.setTitle(g.getName());
    embedBuilder.setDescription("**Owner:** " + g.getOwner().getAsMention());
    embedBuilder.setImage(g.getIconUrl());
    embedBuilder.addField("Members", members, false);
    embedBuilder.addField("Channels", channels, false);
    embedBuilder.addField("Roles", g.getRoles().size() + "", false);
    embedBuilder.addField("Custom Emojis", customEmojis, false);
    embedBuilder.addField("Region", g.getRegionRaw(), false);
    embedBuilder.addField("Shard", commandEvent.getJDA().getShardInfo().getShardString(), false);
    embedBuilder.setFooter(FormattingUtils.formatOffsetDateTimeToDay(g.getTimeCreated()), null);
    commandEvent.reply(embedBuilder.build());
}
Also used : EmbedBuilder(net.dv8tion.jda.api.EmbedBuilder) Emote(net.dv8tion.jda.api.entities.Emote) Guild(net.dv8tion.jda.api.entities.Guild) Trace(datadog.trace.api.Trace)

Example 4 with Trace

use of datadog.trace.api.Trace in project Vinny by kikkia.

the class SetVoiceRoleCommand method executeCommand.

@Override
@Trace(operationName = "executeCommand", resourceName = "SetVoiceRole")
protected void executeCommand(CommandEvent commandEvent) {
    InternalGuild guild = null;
    Guild commandGuild = commandEvent.getGuild();
    try {
        guild = guildDAO.getGuildById(commandGuild.getId());
    } catch (Exception e) {
        logger.log(Level.SEVERE, "Problem getting guild settings " + e.getMessage());
        commandEvent.reply(commandEvent.getClient().getError() + " There was a problem getting the settings for your guild. Please contact the developer on the support server. " + Bot.SUPPORT_INVITE_LINK);
        metricsManager.markCommandFailed(this, commandEvent.getAuthor(), commandEvent.getGuild());
        return;
    }
    if (guild == null) {
        logger.log(Level.WARNING, "Guild not found in db, attempting to add: " + commandGuild.getId());
        commandEvent.reply(commandEvent.getClient().getWarning() + " This guild was not found in my database. I am going to try to add it. Please standby.");
        if (!guildDAO.addGuild(commandGuild)) {
            logger.log(Level.SEVERE, "Failed to add the guild to the db");
            commandEvent.reply(commandEvent.getClient().getError() + " Error adding the guild to the db. Please contact the developer on the support server. " + Bot.SUPPORT_INVITE_LINK);
            metricsManager.markCommandFailed(this, commandEvent.getAuthor(), commandEvent.getGuild());
            return;
        }
        commandEvent.reply(commandEvent.getClient().getSuccess() + " Added the guild to the database. Retrying");
        executeCommand(commandEvent);
        return;
    }
    // If nothing then set to all
    if (commandEvent.getArgs().isEmpty()) {
        if (!guildDAO.updateMinVoiceRole(guild.getId(), commandEvent.getGuild().getPublicRole().getId())) {
            logger.log(Level.SEVERE, "Failed to update voice role for guild " + guild.getId());
            commandEvent.reply("Something went wrong. Please contact the developers on the support server. " + Bot.SUPPORT_INVITE_LINK);
            metricsManager.markCommandFailed(this, commandEvent.getAuthor(), commandEvent.getGuild());
        }
        commandEvent.getMessage().addReaction(commandEvent.getClient().getSuccess()).queue();
        return;
    }
    List<Role> mentionedRoles = commandEvent.getMessage().getMentionedRoles();
    if (mentionedRoles == null || mentionedRoles.isEmpty()) {
        commandEvent.reply(commandEvent.getClient().getWarning() + " You must specify a role.");
        return;
    }
    // Just use the first mentioned roles
    if (!guildDAO.updateMinVoiceRole(guild.getId(), mentionedRoles.get(0).getId())) {
        commandEvent.reply(commandEvent.getClient().getError() + " Something went wrong! Please contact the devs on the support server. " + Bot.SUPPORT_INVITE_LINK);
        metricsManager.markCommandFailed(this, commandEvent.getAuthor(), commandEvent.getGuild());
    }
    commandEvent.getMessage().addReaction(commandEvent.getClient().getSuccess()).queue();
}
Also used : Role(net.dv8tion.jda.api.entities.Role) InternalGuild(com.bot.models.InternalGuild) Guild(net.dv8tion.jda.api.entities.Guild) InternalGuild(com.bot.models.InternalGuild) Trace(datadog.trace.api.Trace)

Example 5 with Trace

use of datadog.trace.api.Trace in project Vinny by kikkia.

the class AddPrefixCommand method executeCommand.

@Override
@Trace(operationName = "executeCommand", resourceName = "AddPrefix")
protected void executeCommand(CommandEvent commandEvent) {
    InternalGuild guild = guildDAO.getGuildById(commandEvent.getGuild().getId());
    if (commandEvent.getArgs().isEmpty()) {
        commandEvent.reply(commandEvent.getClient().getWarning() + " You must specify at least one custom prefix to add.");
        return;
    }
    ArrayList<String> prefixes = guild.getPrefixList();
    prefixes.addAll(Arrays.asList(commandEvent.getArgs().split(" ")));
    String newPrefixes = GuildUtils.convertListToPrefixesString(prefixes);
    if (newPrefixes.length() > 254) {
        commandEvent.reply(commandEvent.getClient().getWarning() + " Failed to add custom prefixes. The length of all" + " prefixes on the server cannot be more than 250 characters. You can remove custom prefixes with the `removeprefix` command.");
        return;
    }
    if (guildDAO.updateGuildPrefixes(commandEvent.getGuild().getId(), prefixes)) {
        commandEvent.getMessage().addReaction(commandEvent.getClient().getSuccess()).queue();
    } else {
        commandEvent.reply(commandEvent.getClient().getError() + " Failed to update prefixes for server. Please contact a developer on the support server if this issue persists.");
        metricsManager.markCommandFailed(this, commandEvent.getAuthor(), commandEvent.getGuild());
    }
}
Also used : InternalGuild(com.bot.models.InternalGuild) Trace(datadog.trace.api.Trace)

Aggregations

Trace (datadog.trace.api.Trace)72 VoiceSendHandler (com.bot.voice.VoiceSendHandler)11 InternalGuild (com.bot.models.InternalGuild)10 EmbedBuilder (net.dv8tion.jda.api.EmbedBuilder)7 Guild (net.dv8tion.jda.api.entities.Guild)7 Role (net.dv8tion.jda.api.entities.Role)6 Playlist (com.bot.models.Playlist)4 SQLException (java.sql.SQLException)4 ArrayList (java.util.ArrayList)4 BaseResponseBean (org.commcare.formplayer.beans.menus.BaseResponseBean)4 CommCareSessionException (org.commcare.util.screen.CommCareSessionException)4 QueuedAudioTrack (com.bot.voice.QueuedAudioTrack)3 IOException (java.io.IOException)3 NotificationMessage (org.commcare.formplayer.beans.NotificationMessage)3 EntityScreen (org.commcare.util.screen.EntityScreen)3 MenuScreen (org.commcare.util.screen.MenuScreen)3 QueryScreen (org.commcare.util.screen.QueryScreen)3 Screen (org.commcare.util.screen.Screen)3 InvalidStructureException (org.javarosa.xml.util.InvalidStructureException)3 UnfullfilledRequirementsException (org.javarosa.xml.util.UnfullfilledRequirementsException)3