本文整理汇总了Java中sx.blah.discord.api.IDiscordClient类的典型用法代码示例。如果您正苦于以下问题:Java IDiscordClient类的具体用法?Java IDiscordClient怎么用?Java IDiscordClient使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
IDiscordClient类属于sx.blah.discord.api包,在下文中一共展示了IDiscordClient类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: sendConnectionErrorMessage
import sx.blah.discord.api.IDiscordClient; //导入依赖的package包/类
public static void sendConnectionErrorMessage(IDiscordClient client, IChannel channel, String command, @Nullable String message, @NotNull HttpStatusException httpe) throws RateLimitException, DiscordException, MissingPermissionsException {
@NotNull String problem = message != null ? message + "\n" : "";
if (httpe.getStatusCode() == HttpStatus.SC_SERVICE_UNAVAILABLE) {
problem += "Service unavailable, please try again latter.";
} else if (httpe.getStatusCode() == HttpStatus.SC_FORBIDDEN) {
problem += "Acess dennied.";
} else if (httpe.getStatusCode() == HttpStatus.SC_NOT_FOUND) {
problem += "Not Found";
} else {
problem += httpe.getStatusCode() + SPACE + httpe.getMessage();
}
new MessageBuilder(client)
.appendContent("Error during HTTP Connection ", MessageBuilder.Styles.BOLD)
.appendContent("\n")
.appendContent(EventManager.MAIN_COMMAND_NAME, MessageBuilder.Styles.BOLD)
.appendContent(SPACE)
.appendContent(command, MessageBuilder.Styles.BOLD)
.appendContent("\n")
.appendContent(problem, MessageBuilder.Styles.BOLD)
.withChannel(channel)
.send();
}
示例2: run
import sx.blah.discord.api.IDiscordClient; //导入依赖的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);
}
}
示例3: enable
import sx.blah.discord.api.IDiscordClient; //导入依赖的package包/类
@Override
public boolean enable(IDiscordClient client) {
discordClient = client;
discordClient.getDispatcher().registerListener(PoolCommand.getInstance());
discordClient.getDispatcher().registerListener(new InviteCommand());
discordClient.getDispatcher().registerListener(new XKCDCommand());
discordClient.getDispatcher().registerListener(new PingCommand());
discordClient.getDispatcher().registerListener(new UptimeCommand());
discordClient.getDispatcher().registerListener(new EigthBallCommand());
discordClient.getDispatcher().registerListener(new RandomNumberCommand());
discordClient.getDispatcher().registerListener(new ImdbSearchCommand());
registerListener(MessageReceivedEventReceiver.getInstace());
return true;
}
示例4: showHelpIfPresent
import sx.blah.discord.api.IDiscordClient; //导入依赖的package包/类
public boolean showHelpIfPresent(IDiscordClient client, IChannel channnel, @NotNull CommandLine cmd) throws RateLimitException, DiscordException, MissingPermissionsException {
if (cmd.hasOption("h") || cmd.hasOption("help") || cmd.hasOption("showHelp")) {
@NotNull StringWriter writter = new StringWriter(200);
@NotNull PrintWriter pw = new PrintWriter(writter);
new HelpFormatter()
.printHelp(pw, 200,
EventManager.MAIN_COMMAND_NAME + " " + this.mainCommand,
this.commandInfo,
this.options,
3,
5,
null,
true);
new MessageBuilder(client)
.withChannel(channnel)
.withQuote(writter.toString())
.send();
return true;
}
return false;
}
示例5: logout
import sx.blah.discord.api.IDiscordClient; //导入依赖的package包/类
private IDiscordClient logout(Bot bot) throws DiscordException {
log.debug("Request to logout: {}", bot);
if (!clientRegistry.getClients().containsKey(bot)) {
throw new IllegalStateException("Bot is not logged in");
}
IDiscordClient client = clientRegistry.getClients().get(bot);
if (client != null) {
if (client.isLoggedIn()) {
client.logout();
} else {
log.warn("Bot {} is not logged in", bot.getName());
}
clientRegistry.getClients().remove(bot);
commandRegistry.remove(client);
}
return client;
}
示例6: Battle
import sx.blah.discord.api.IDiscordClient; //导入依赖的package包/类
public Battle(IDiscordClient client, Battler one, Battler two) {
this.client = client;
battlers[0] = one;
battlers[1] = two;
one.opponent = two;
two.opponent = one;
for (int i = 0; i < battlers.length; i++) {
final int index = i;
RequestBuffer.request(() -> {
try {
IPrivateChannel priv = battlers[index].owner.getOrCreatePMChannel();
privateChannels[index] = priv;
} catch (DiscordException e) {
e.printStackTrace();
}
}).get();
}
}
示例7: startBot
import sx.blah.discord.api.IDiscordClient; //导入依赖的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();
}
示例8: sendIncorrectUsageMessage
import sx.blah.discord.api.IDiscordClient; //导入依赖的package包/类
public static void sendIncorrectUsageMessage(IDiscordClient client, IChannel channel, String command, String reason) throws RateLimitException, DiscordException, MissingPermissionsException {
new MessageBuilder(client)
.appendContent("Incorrect usage of command: ", MessageBuilder.Styles.BOLD)
.appendContent(command, MessageBuilder.Styles.BOLD)
.appendContent("\n")
.appendContent(reason, MessageBuilder.Styles.BOLD)
.withChannel(channel)
.send();
}
示例9: start
import sx.blah.discord.api.IDiscordClient; //导入依赖的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: startClient
import sx.blah.discord.api.IDiscordClient; //导入依赖的package包/类
/**
* Starts Bot Client
* @param rexCord main instance of RexCord
*/
private static void startClient(RexCord rexCord) {
// Creates a new Client
IDiscordClient client = rexCord.createDiscordClient();
// Registers a new listener
client.getDispatcher().registerListener(new CommandHandler(rexCord));
// Logs in
client.login();
}
示例11: createDiscordClient
import sx.blah.discord.api.IDiscordClient; //导入依赖的package包/类
/**
* Handles the creation of a Bot Client
*
* @return A new Bot Client
*/
public IDiscordClient createDiscordClient() {
client = new ClientBuilder()
.withToken(botToken)
.build();
return client;
}
示例12: createClient
import sx.blah.discord.api.IDiscordClient; //导入依赖的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;
}
示例13: execute
import sx.blah.discord.api.IDiscordClient; //导入依赖的package包/类
@Override
public void execute(JobExecutionContext context) throws JobExecutionException {
JobDataMap jobDataMap = context.getMergedJobDataMap();
String botId = jobDataMap.getString("bot");
String channelId = jobDataMap.getString("channel");
String content = jobDataMap.getString("content");
if (botId != null && channelId != null && content != null) {
Optional<IDiscordClient> client = clientRegistry.getClients().entrySet().stream()
.filter(entry -> botId.equals(entry.getKey().getId())
|| botId.equals(entry.getKey().getName())
|| (entry.getValue().isReady() && botId.equals(entry.getValue().getOurUser().getStringID())))
.map(Map.Entry::getValue)
.findAny();
if (client.isPresent()) {
IChannel channel = client.get().getChannelByID(snowflake(channelId));
if (channel != null) {
sendMessage(channel, content);
} else {
throw new JobExecutionException("Channel " + channelId + " is not known by the bot");
}
} else {
throw new JobExecutionException("No bot exists with identifier: " + botId);
}
} else {
throw new JobExecutionException("Job requires bot, channel and content parameters");
}
}
示例14: execute
import sx.blah.discord.api.IDiscordClient; //导入依赖的package包/类
@Override
public void execute(JobExecutionContext context) throws JobExecutionException {
if (clientRegistry.getClients().isEmpty()) {
log.warn("No bots to track data for");
}
for (Map.Entry<Bot, IDiscordClient> entry : clientRegistry.getClients().entrySet()) {
IDiscordClient client = entry.getValue();
if (client.isReady()) {
String botTag = "bot:" + entry.getKey().getName();
for (IShard shard : client.getShards()) {
String shardTag = "shard:" + shard.getInfo()[0];
long millis = shard.getResponseTime();
metricRegistry.timer("discord.ws.response[" + botTag + "," + shardTag + "]")
.update(millis, TimeUnit.MILLISECONDS);
}
for (IGuild guild : client.getGuilds()) {
String guildTag = "guild:" + guild.getStringID();
long online = guild.getUsers().stream()
.filter(user -> user.getPresence().getStatus() == StatusType.ONLINE)
.count();
long connected = guild.getUsers().stream()
.filter(user -> user.getPresence().getStatus() != StatusType.OFFLINE)
.count();
long joined = guild.getUsers().size();
String onlineMetric = "discord.ws.users[" + botTag + "," + guildTag + "," + "status:online]";
String connectedMetric = "discord.ws.users[" + botTag + "," + guildTag + "," + "status:connected]";
String joinedMetric = "discord.ws.users[" + botTag + "," + guildTag + "," + "status:joined]";
metricRegistry.histogram(onlineMetric).update(online);
metricRegistry.histogram(connectedMetric).update(connected);
metricRegistry.histogram(joinedMetric).update(joined);
}
LoggerContext loggerContext = (LoggerContext) LoggerFactory.getILoggerFactory();
loggerContext.getLogger("org.eclipse.jetty.websocket").setLevel(Level.WARN);
loggerContext.getLogger(Discord4J.class).setLevel(Level.DEBUG);
} else {
log.warn("Bot {} is not ready!", entry.getKey().getName());
}
}
}
示例15: botToBotDTO
import sx.blah.discord.api.IDiscordClient; //导入依赖的package包/类
@Override
public BotDTO botToBotDTO(Bot bot) {
BotDTO dto = delegate.botToBotDTO(bot);
IDiscordClient client = clientRegistry.getClients().get(bot);
if (client != null) {
dto.setCreated(true);
dto.setReady(client.isReady());
dto.setLoggedIn(client.isLoggedIn());
}
return dto;
}