Search in sources :

Example 1 with InsufficientPermissionException

use of net.dv8tion.jda.api.exceptions.InsufficientPermissionException in project MantaroBot by Mantaro.

the class Character method onStart.

@Override
public boolean onStart(GameLobby lobby) {
    final I18nContext languageContext = lobby.getLanguageContext();
    try {
        var data = JsonDataManager.fromJson(APIUtils.getFrom("/mantaroapi/bot/character"), AnimeGameData.class);
        characterNameL = new ArrayList<>();
        characterName = data.getName();
        var imageUrl = data.getImage();
        // Allow for replying with only the first name of the character.
        if (characterName.contains(" ")) {
            characterNameL.add(characterName.split(" ")[0]);
        }
        characterNameL.add(characterName);
        sendEmbedImage(lobby.getChannel(), imageUrl, eb -> eb.setAuthor(languageContext.get("commands.game.character_start"), null, lobby.getEvent().getAuthor().getEffectiveAvatarUrl()).setFooter(languageContext.get("commands.game.end_footer"), null)).queue(success -> lobby.setGameLoaded(true));
        return true;
    } catch (JsonProcessingException ex) {
        ex.printStackTrace();
        lobby.getChannel().sendMessageFormat(languageContext.get("commands.game.character_load_error"), EmoteReference.WARNING, characterName).queue();
        return false;
    } catch (InsufficientPermissionException ex) {
        lobby.getChannel().sendMessageFormat(languageContext.get("commands.game.error_missing_permissions"), EmoteReference.ERROR).queue();
        return false;
    } catch (Exception e) {
        lobby.getChannel().sendMessageFormat(languageContext.get("commands.game.error"), EmoteReference.ERROR).queue();
        log.warn("Exception while setting up a game", e);
        return false;
    }
}
Also used : InsufficientPermissionException(net.dv8tion.jda.api.exceptions.InsufficientPermissionException) GuildMessageReceivedEvent(net.dv8tion.jda.api.events.message.guild.GuildMessageReceivedEvent) ImageGame(net.kodehawa.mantarobot.commands.game.core.ImageGame) Logger(org.slf4j.Logger) GameLobby(net.kodehawa.mantarobot.commands.game.core.GameLobby) InteractiveOperations(net.kodehawa.mantarobot.core.listeners.operations.InteractiveOperations) LoggerFactory(org.slf4j.LoggerFactory) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) InteractiveOperation(net.kodehawa.mantarobot.core.listeners.operations.core.InteractiveOperation) ArrayList(java.util.ArrayList) APIUtils(net.kodehawa.mantarobot.utils.APIUtils) List(java.util.List) I18nContext(net.kodehawa.mantarobot.core.modules.commands.i18n.I18nContext) JsonDataManager(net.kodehawa.mantarobot.utils.data.JsonDataManager) EmoteReference(net.kodehawa.mantarobot.utils.commands.EmoteReference) AnimeGameData(net.kodehawa.mantarobot.commands.game.core.AnimeGameData) InsufficientPermissionException(net.dv8tion.jda.api.exceptions.InsufficientPermissionException) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) InsufficientPermissionException(net.dv8tion.jda.api.exceptions.InsufficientPermissionException) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) I18nContext(net.kodehawa.mantarobot.core.modules.commands.i18n.I18nContext)

Aggregations

JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 GuildMessageReceivedEvent (net.dv8tion.jda.api.events.message.guild.GuildMessageReceivedEvent)1 InsufficientPermissionException (net.dv8tion.jda.api.exceptions.InsufficientPermissionException)1 AnimeGameData (net.kodehawa.mantarobot.commands.game.core.AnimeGameData)1 GameLobby (net.kodehawa.mantarobot.commands.game.core.GameLobby)1 ImageGame (net.kodehawa.mantarobot.commands.game.core.ImageGame)1 InteractiveOperations (net.kodehawa.mantarobot.core.listeners.operations.InteractiveOperations)1 InteractiveOperation (net.kodehawa.mantarobot.core.listeners.operations.core.InteractiveOperation)1 I18nContext (net.kodehawa.mantarobot.core.modules.commands.i18n.I18nContext)1 APIUtils (net.kodehawa.mantarobot.utils.APIUtils)1 EmoteReference (net.kodehawa.mantarobot.utils.commands.EmoteReference)1 JsonDataManager (net.kodehawa.mantarobot.utils.data.JsonDataManager)1 Logger (org.slf4j.Logger)1 LoggerFactory (org.slf4j.LoggerFactory)1