本文整理汇总了Java中sx.blah.discord.api.ClientBuilder类的典型用法代码示例。如果您正苦于以下问题:Java ClientBuilder类的具体用法?Java ClientBuilder怎么用?Java ClientBuilder使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ClientBuilder类属于sx.blah.discord.api包,在下文中一共展示了ClientBuilder类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: run
import sx.blah.discord.api.ClientBuilder; //导入依赖的package包/类
@Override
public void run(String... arg0) throws Exception
{
IDiscordClient client;
ClientBuilder clientBuilder = new ClientBuilder();
clientBuilder.withToken(token);
try
{
client = clientBuilder.login();
EventDispatcher dispatcher = client.getDispatcher();
dispatcher.registerListener(new LeaderboardDiscordActions(client, prefix, leaderboardDao, leaderboardColumnDao));
}
catch (DiscordException e)
{
e.printStackTrace();
System.exit(0);
}
}
示例2: main
import sx.blah.discord.api.ClientBuilder; //导入依赖的package包/类
public static void main(String[] args) {
dateFormatter.setTimeZone(TimeZone.getTimeZone("GMT"));
CoinsHandler coinsHandler = new CoinsHandler();
BitcoinsHandler btcHandler = new BitcoinsHandler();
Botcoins botcoins = new Botcoins(coinsHandler, btcHandler);
client = new ClientBuilder()
.withToken(Utils.readResource("/discord.token"))
.registerListener(botcoins)
.registerListener(coinsHandler)
.registerListener(btcHandler)
.setMaxMessageCacheCount(0) // Default is 256
.setMaxReconnectAttempts(Integer.MAX_VALUE)
.login();
botcoins.onInit();
}
示例3: initialize
import sx.blah.discord.api.ClientBuilder; //导入依赖的package包/类
public void initialize() throws IOException {
this.config.init();
this.channels.init();
this.permissions.init();
if (getConfig().isDebug())
((Discord4JLogger) Log.logger).setLevel(Discord4JLogger.Level.DEBUG);
if (StringUtils.isEmpty(getConfig().getToken())) {
Log.logger.info("Please set a token");
return;
}
this.client = new ClientBuilder()
.withToken(getConfig().getToken())
.registerListeners(this, new DiscordEventListener(), new EEWEventListener())
.login();
}
示例4: main
import sx.blah.discord.api.ClientBuilder; //导入依赖的package包/类
public static void main (String... args) throws RateLimitException {
LOG.info("Wrapping standard output and error streams with tracer!");
System.setOut(new PrintStreamTraced(System.out));
System.setErr(new PrintStreamTraced(System.err));
LOG.info("Shutting Discord4J's Yap");
LoggingHandler.setLoggerLevel((ch.qos.logback.classic.Logger) Discord4J.LOGGER, Level.OFF);
LOG.info("Starting bot with token " + Utilities.partiallyReplace(config.authToken, 4));
try {
instance = new ClientBuilder().withToken(config.authToken).login();
instance.getDispatcher().registerListener(state);
instance.getDispatcher().registerListener(commands);
instance.getDispatcher().registerListener(auditor);
}
catch (final DiscordException e) {
LOG.trace("Error during startup", e);
instance.logout();
System.exit(0);
}
}
示例5: run
import sx.blah.discord.api.ClientBuilder; //导入依赖的package包/类
private void run(String token) {
try {
permissions = gson.fromJson(new FileReader(PERMISSIONS), Permissions.class);
if (permissions == null) {
permissions = new Permissions();
}
client = new ClientBuilder().withToken(token).login();
dispatcher = new CommandDispatcher(client);
} catch (DiscordException e) {
logger.error("Could not log into Discord!", e);
System.exit(2);
} catch (FileNotFoundException ignore) {
}
}
示例6: login
import sx.blah.discord.api.ClientBuilder; //导入依赖的package包/类
/**
* Creates Discord client and logins to the service
* @throws DiscordException
*/
public void login() throws DiscordException {
if(connected) {
return;
}
plugin.getLogger().info(plugin.lang("discord-logging-in"));
FileConfiguration config = plugin.getConfig();
try {
// Create ClientBuilder, which returns the client to interact with the Discord uAPI
ClientBuilder builder = (new ClientBuilder()).withToken(
config.getString("discord-bot-token")
);
client = builder.login();
client.getDispatcher().registerListener(listener);
connected = true;
} catch (DiscordException e) {
connected = false;
throw e;
}
}
示例7: main
import sx.blah.discord.api.ClientBuilder; //导入依赖的package包/类
public static void main(String... args) throws Exception{
System.out.println("Pokebot version "+VERSION);
if(config.TOKEN.isEmpty()){
System.out.println("Error: No token found in pokebot.conf file");
System.exit(0);
}
if(config.WEBENABLED){
System.out.println("Web interface enabled on port "+config.PORT);
WebInterface.initWebInterface(config.REDIRECT_URL, config.PORT);
}
client = new ClientBuilder().withToken(config.TOKEN).login();
System.out.println("Logging in");
client.getDispatcher().registerListener(new BotReadyHandler(Thread.currentThread()));
timer.scheduleAtFixedRate(PlayerHandler::saveAll, SAVE_DELAY, SAVE_DELAY, TimeUnit.MINUTES);
timer.scheduleAtFixedRate(Pokebot::sendAllMessages, MESSAGE_DELAY, MESSAGE_DELAY,
TimeUnit.MILLISECONDS);
timer.scheduleAtFixedRate(() -> Pokebot.client.changeStatus(Status.game(Pokebot.getRandomGame()))
, GAME_DELAY, GAME_DELAY, TimeUnit.MINUTES);
//Now that the main thread is done doing it's business and the bot is busy logging in...
Move.registerMoves();
}
示例8: startBot
import sx.blah.discord.api.ClientBuilder; //导入依赖的package包/类
public void startBot(){
Karren.log.info("Watchdog is now starting the bot...");
//Build our discord client
IDiscordClient client = null;
try {
client = new ClientBuilder().withToken(Karren.conf.getDiscordToken()).withRecommendedShardCount().build();
} catch (DiscordException e) {
e.printStackTrace();
}
//Setup the objects we need.
Karren.bot = new KarrenBot(client);
//Pass execution to main bot class.
Karren.bot.initDiscord();
}
示例9: start
import sx.blah.discord.api.ClientBuilder; //导入依赖的package包/类
public final void start() {
LOGGER.traceEntry();
final IDiscordClient client;
try {
client = new ClientBuilder()
.withToken(ConfigurationManager.Configurations.BotToken.value())
.setDaemon(false)
.login();
} catch (DiscordException e) {
LOGGER.fatal("Fail to login to discord.", e);
throw new BotLoginFailedException(e);
}
this.discordClient = client;
this.discordClient.getShards().forEach(s -> s.changeStatus(Status.game("IntelliJ IDEA")));
this.invite = new BotInviteBuilder(discordClient)
.withClientID(ConfigurationManager.Configurations.ClientID.value().toString())
.withPermissions(EnumSet.of(Permissions.ADMINISTRATOR))
.build();
System.out.println(MessageFormat.format("Bot Created, invitation link: {0}", invite));
addEventManager();
LOGGER.traceExit();
}
示例10: createDiscordClient
import sx.blah.discord.api.ClientBuilder; //导入依赖的package包/类
/**
* Handles the creation of a Bot Client
*
* @return A new Bot Client
*/
public IDiscordClient createDiscordClient() {
client = new ClientBuilder()
.withToken(botToken)
.build();
return client;
}
示例11: createClient
import sx.blah.discord.api.ClientBuilder; //导入依赖的package包/类
/**
* Creates the DisCal bot client.
*
* @param token The Bot Token.
* @return The client if successful, otherwise <code>null</code>.
*/
private static IDiscordClient createClient(String token) {
ClientBuilder clientBuilder = new ClientBuilder(); // Creates the ClientBuilder instance
clientBuilder.withToken(token).withRecommendedShardCount(); // Adds the login info to the builder
try {
return clientBuilder.login();
} catch (DiscordException e) {
e.printStackTrace();
}
return null;
}
示例12: createClient
import sx.blah.discord.api.ClientBuilder; //导入依赖的package包/类
public static IDiscordClient createClient(String token, boolean login) { // Returns a new instance of the Discord client
ClientBuilder clientBuilder = new ClientBuilder(); // Creates the ClientBuilder instance
clientBuilder.withToken(token); // Adds the login info to the builder
try {
if (login) {
return clientBuilder.login(); // Creates the client instance and logs the client in
} else {
return clientBuilder.build(); // Creates the client instance but it doesn't log the client in yet, you would have to call client.login() yourself
}
} catch (DiscordException e) { // This is thrown if there was a problem building the client
e.printStackTrace();
return null;
}
}
示例13: getBuiltDiscordClient
import sx.blah.discord.api.ClientBuilder; //导入依赖的package包/类
/**
* Creates a Bot Instance
* @param token the Auth Token
* @return the BotInstance
*/
static IDiscordClient getBuiltDiscordClient(String token){
// The ClientBuilder object is where you will attach your params for configuring the instance of your bot.
// Such as withToken, setDaemon etc
return new ClientBuilder()
.withRecommendedShardCount()
.withToken(token)
.build();
}
示例14: main
import sx.blah.discord.api.ClientBuilder; //导入依赖的package包/类
public static void main(String[] args) {
try {
AccessController.checkPermission(new FilePermission(".", "read"));
} catch (AccessControlException e) {
throw new RuntimeException("Invalid policy settings!", e);
}
instance = new ClientBuilder().withToken(args[0]).login();
instance.getDispatcher().registerListener(new MCBot());
instance.getDispatcher().registerListener(CommandListener.INSTANCE);
// Handle "stop" and any future commands
Thread consoleThread = new Thread(() -> {
Scanner scan = new Scanner(System.in);
while (true) {
while (scan.hasNextLine()) {
if (scan.nextLine().equals("stop")) {
scan.close();
System.exit(0);
}
}
Threads.sleep(100);
}
});
// Make sure shutdown things are run, regardless of where shutdown came from
// The above System.exit(0) will trigger this hook
Runtime.getRuntime().addShutdownHook(new Thread(() -> {
CommandRegistrar.INSTANCE.onShutdown();
}));
consoleThread.start();
if(args.length > 1)
new MCBotIRC(args[1]);
}
示例15: main
import sx.blah.discord.api.ClientBuilder; //导入依赖的package包/类
public static void main(String[] args) {
Locale.setDefault(new Locale("en", "US"));
try {
Properties properties = new Properties();
properties.load(Shadbot.class.getClassLoader().getResourceAsStream("project.properties"));
version = properties.getProperty("version");
} catch (IOException err) {
LogUtils.errorf(err, "An error occurred while getting version.");
}
// Initialization
if(!DataManager.init() || !CommandManager.init()) {
System.exit(1);
}
Runtime.getRuntime().addShutdownHook(new Thread() {
@Override
public void run() {
GuildMusicManager.stop();
ShardManager.stop();
DataManager.stop();
}
});
client = new ClientBuilder()
.withToken(APIKeys.get(APIKey.DISCORD_TOKEN))
.withRecommendedShardCount()
.setMaxMessageCacheCount(0)
.setMaxReconnectAttempts(10)
.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();
}