Search in sources :

Example 11 with ClientBuilder

use of sx.blah.discord.api.ClientBuilder in project Discord4J by Discord4J.

the class EmptyBot method main.

public static void main(String[] args) {
    ((Discord4J.Discord4JLogger) Discord4J.LOGGER).setLevel(Discord4J.Discord4JLogger.Level.DEBUG);
    // Log.setLog(new Logger() {
    // @Override
    // public String getName() {
    // return "sdfsdsdfsf";
    // }
    // 
    // @Override
    // public void warn(String s, Object... objects) {
    // Discord4J.LOGGER.warn(s, objects);
    // }
    // 
    // @Override
    // public void warn(Throwable throwable) {
    // Discord4J.LOGGER.warn("", throwable);
    // }
    // 
    // @Override
    // public void warn(String s, Throwable throwable) {
    // Discord4J.LOGGER.warn(s, throwable);
    // }
    // 
    // @Override
    // public void info(String s, Object... objects) {
    // Discord4J.LOGGER.info(s, objects);
    // }
    // 
    // @Override
    // public void info(Throwable throwable) {
    // Discord4J.LOGGER.info("", throwable);
    // }
    // 
    // @Override
    // public void info(String s, Throwable throwable) {
    // Discord4J.LOGGER.info(s, throwable);
    // }
    // 
    // @Override
    // public boolean isDebugEnabled() {
    // return true;
    // }
    // 
    // @Override
    // public void setDebugEnabled(boolean b) {
    // 
    // }
    // 
    // @Override
    // public void debug(String s, Object... objects) {
    // Discord4J.LOGGER.debug(s, objects);
    // }
    // 
    // @Override
    // public void debug(String s, long l) {
    // Discord4J.LOGGER.debug(s, l);
    // }
    // 
    // @Override
    // public void debug(Throwable throwable) {
    // Discord4J.LOGGER.debug("", throwable);
    // }
    // 
    // @Override
    // public void debug(String s, Throwable throwable) {
    // Discord4J.LOGGER.debug(s, throwable);
    // }
    // 
    // @Override
    // public Logger getLogger(String s) {
    // return this;
    // }
    // 
    // @Override
    // public void ignore(Throwable throwable) {
    // 
    // }
    // });
    IDiscordClient client = new ClientBuilder().withToken(args[0]).registerListener(new IListener<ReadyEvent>() {

        @Override
        public void handle(ReadyEvent event) {
            System.out.println("Ohai");
        }
    }).login();
}
Also used : ReadyEvent(sx.blah.discord.handle.impl.events.ReadyEvent) IListener(sx.blah.discord.api.events.IListener) IDiscordClient(sx.blah.discord.api.IDiscordClient) ClientBuilder(sx.blah.discord.api.ClientBuilder)

Example 12 with ClientBuilder

use of sx.blah.discord.api.ClientBuilder in project Discord4J by Discord4J.

the class Discord4J method main.

/**
 * Runs Discord4J using modules only.
 *
 * @param args The args should only include the bot token.
 */
public static void main(String[] args) {
    // This functionality is dependent on these options being true
    if (!Configuration.AUTOMATICALLY_ENABLE_MODULES || !Configuration.LOAD_EXTERNAL_MODULES)
        throw new RuntimeException("Invalid configuration! Must have auto-enabling of modules + loading of external modules enabled.");
    if (args.length == 0)
        throw new RuntimeException("Invalid configuration! No arguments passed in.");
    try {
        ClientBuilder builder = new ClientBuilder();
        IDiscordClient client = builder.withToken(args[0]).login();
        client.getDispatcher().registerListener((IListener<ReadyEvent>) (ReadyEvent e) -> {
            LOGGER.info(LogMarkers.MAIN, "Logged in as {}", e.getClient().getOurUser().getName());
        });
    // The modules should handle the rest
    } catch (DiscordException e) {
        LOGGER.error(LogMarkers.MAIN, "There was an error initializing the client", e);
    }
}
Also used : ReadyEvent(sx.blah.discord.handle.impl.events.ReadyEvent) DiscordException(sx.blah.discord.util.DiscordException) IDiscordClient(sx.blah.discord.api.IDiscordClient) ClientBuilder(sx.blah.discord.api.ClientBuilder)

Example 13 with ClientBuilder

use of sx.blah.discord.api.ClientBuilder in project Ublisk by Derkades.

the class DiscordBot method onEnable.

@Override
public void onEnable() {
    if (!DataFile.MYSQL.getConfig().getBoolean("discord.enabled")) {
        super.log(this, LogLevel.WARNING, "Discord bot is not enabled in the config!");
        return;
    }
    if (Var.DEBUG) {
        super.log(this, LogLevel.WARNING, "Debug mode is enabled. Bot startup has been cancelled");
        return;
    }
    String token = DataFile.MYSQL.getConfig().getString("discord.token");
    try {
        client = new ClientBuilder().withToken(token).login();
    } catch (DiscordException e) {
        super.log(this, LogLevel.SEVERE, "An error occured while trying to connect with Discord. Shutting down..");
        e.printStackTrace();
        this.terminate();
    }
    super.log(this, LogLevel.INFO, "Discord module has been initialized successfully!");
    enabled = true;
}
Also used : DiscordException(sx.blah.discord.util.DiscordException) ClientBuilder(sx.blah.discord.api.ClientBuilder)

Example 14 with ClientBuilder

use of sx.blah.discord.api.ClientBuilder in project Shadbot by Shadorc.

the class Shadbot method main.

public static void main(String[] args) {
    Locale.setDefault(new Locale("en", "US"));
    // Initialization
    if (!DataManager.init() || !CommandManager.init()) {
        System.exit(1);
    }
    Runtime.getRuntime().addShutdownHook(new Thread() {

        @Override
        public void run() {
            DataManager.stop();
        }
    });
    client = new ClientBuilder().withToken(APIKeys.get(APIKey.DISCORD_TOKEN)).withRecommendedShardCount().withPingTimeout(10).setMaxReconnectAttempts(10).setMaxMessageCacheCount(100).setPresence(StatusType.IDLE).build();
    LogUtils.infof("Connecting to %s...", StringUtils.pluralOf(client.getShardCount(), "shard"));
    client.getDispatcher().registerListeners(Shadbot.getEventThreadPool(), new ReadyListener(), new ShardListener());
    client.login();
}
Also used : Locale(java.util.Locale) ReadyListener(me.shadorc.shadbot.listener.ReadyListener) ShardListener(me.shadorc.shadbot.listener.ShardListener) ClientBuilder(sx.blah.discord.api.ClientBuilder)

Aggregations

ClientBuilder (sx.blah.discord.api.ClientBuilder)14 DiscordException (sx.blah.discord.util.DiscordException)8 IDiscordClient (sx.blah.discord.api.IDiscordClient)7 ReadyEvent (sx.blah.discord.handle.impl.events.ReadyEvent)5 IListener (sx.blah.discord.api.events.IListener)3 File (java.io.File)2 AccountCredentials (com.github.kennedyoliveira.pastebin4j.AccountCredentials)1 PasteBin (com.github.kennedyoliveira.pastebin4j.PasteBin)1 FileHandler (com.github.vaerys.handlers.FileHandler)1 RequestHandler (com.github.vaerys.handlers.RequestHandler)1 StringHandler (com.github.vaerys.handlers.StringHandler)1 EventAvatar (com.github.vaerys.objects.EventAvatar)1 PatreonAPI (com.github.vaerys.objects.PatreonAPI)1 TimedEvent (com.github.vaerys.objects.TimedEvent)1 PatreonOAuth (com.patreon.PatreonOAuth)1 Campaign (com.patreon.resources.Campaign)1 Pledge (com.patreon.resources.Pledge)1 IOException (java.io.IOException)1 SQLException (java.sql.SQLException)1 ZoneOffset (java.time.ZoneOffset)1