Search in sources :

Example 1 with InitializationException

use of de.nikos410.discordbot.exception.InitializationException in project de-DiscordBot by DACH-Discord.

the class ModStuff method init.

@Override
public void init() {
    final String rolesFileContent = IOUtil.readFile(MODSTUFF_PATH);
    if (rolesFileContent == null) {
        LOG.error("Could not read modstuff file.");
        throw new InitializationException("Could not read modstuff file.", ModStuff.class);
    }
    this.modstuffJSON = new JSONObject(rolesFileContent);
    LOG.info("Loaded modstuff file for {} guilds.", modstuffJSON.keySet().size());
}
Also used : JSONObject(org.json.JSONObject) InitializationException(de.nikos410.discordbot.exception.InitializationException)

Example 2 with InitializationException

use of de.nikos410.discordbot.exception.InitializationException in project de-DiscordBot by DACH-Discord.

the class DiscordBot method start.

private void start() {
    // Get token from config
    if (!configJSON.has("token")) {
        throw new InitializationException("No token configured.", DiscordBot.class);
    }
    final String token = configJSON.getString("token");
    // Authorize using token
    try {
        this.client = Authorization.createClient(token, true);
    } catch (DiscordException e) {
        throw new InitializationException("Could not log in client.", e, DiscordBot.class);
    }
    LOG.info("Bot authorized.");
    // Register Eventlistener
    try {
        this.client.getDispatcher().registerListener(this);
    } catch (NullPointerException e) {
        throw new InitializationException("Could not get EventDispatcher.", e, DiscordBot.class);
    }
    // Initialize Modules
    discoverModules();
    loadModules();
}
Also used : DiscordException(sx.blah.discord.util.DiscordException) InitializationException(de.nikos410.discordbot.exception.InitializationException)

Example 3 with InitializationException

use of de.nikos410.discordbot.exception.InitializationException in project de-DiscordBot by DACH-Discord.

the class GameStats method init.

@Override
public void init() {
    final String jsonContent = IOUtil.readFile(GAMESTATS_PATH);
    if (jsonContent == null) {
        throw new InitializationException("Could not read module data.", GameStats.class);
    }
    this.gameStatsJSON = new JSONObject(jsonContent);
    LOG.info("Loaded GameStats file for {} guilds.", gameStatsJSON.keySet().size());
}
Also used : JSONObject(org.json.JSONObject) InitializationException(de.nikos410.discordbot.exception.InitializationException)

Example 4 with InitializationException

use of de.nikos410.discordbot.exception.InitializationException in project de-DiscordBot by DACH-Discord.

the class LastFm method init.

@Override
public void init() {
    this.botPrefix = bot.configJSON.getString("prefix");
    final String jsonContent = IOUtil.readFile(LASTFM_PATH);
    if (jsonContent == null) {
        throw new InitializationException("Could not read module data.", LastFm.class);
    }
    this.lastFmJSON = new JSONObject(jsonContent);
    LOG.info("Loaded Last.fm config file.");
    if (!lastFmJSON.has("apiKey")) {
        throw new InitializationException("No Last.fm Api-Key configured.", LastFm.class);
    }
    this.apiKey = lastFmJSON.getString("apiKey");
    Caller.getInstance().setUserAgent("de-DiscordBot/1.0");
    // disable caching to always get recent charts
    Caller.getInstance().setCache(null);
    offsets3x3 = new int[] { 3, 567, 108, 243 };
    offsets4x4 = new int[] { 4, 425, 78, 113 };
    offsets5x5 = new int[] { 5, 340, 58, 49 };
}
Also used : JSONObject(org.json.JSONObject) InitializationException(de.nikos410.discordbot.exception.InitializationException)

Aggregations

InitializationException (de.nikos410.discordbot.exception.InitializationException)4 JSONObject (org.json.JSONObject)3 DiscordException (sx.blah.discord.util.DiscordException)1