本文整理汇总了Java中sx.blah.discord.handle.obj.IChannel类的典型用法代码示例。如果您正苦于以下问题:Java IChannel类的具体用法?Java IChannel怎么用?Java IChannel使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
IChannel类属于sx.blah.discord.handle.obj包,在下文中一共展示了IChannel类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: sendConnectionErrorMessage
import sx.blah.discord.handle.obj.IChannel; //导入依赖的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: showHelpIfPresent
import sx.blah.discord.handle.obj.IChannel; //导入依赖的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;
}
示例3: executeMessage
import sx.blah.discord.handle.obj.IChannel; //导入依赖的package包/类
private void executeMessage(String clientId, String channelId, String content, EmbedObject embedObject) {
clientRegistry.getClients().entrySet().stream()
.filter(entry -> matchesClient(clientId, entry))
.forEach(entry -> {
IChannel channel = entry.getValue().getChannelByID(snowflake(channelId));
if (channel != null) {
if (content != null && content.length() > Message.MAX_MESSAGE_LENGTH) {
answerToChannel(channel, content, false).get();
if (embedObject != null) {
sendMessage(channel, null, embedObject);
}
} else {
sendMessage(channel, content, embedObject);
}
} else {
log.warn("Did not found a channel with id {} in bot {}", channelId, clientId);
}
});
}
示例4: process
import sx.blah.discord.handle.obj.IChannel; //导入依赖的package包/类
private int process(List<GameServer> servers, Function<GameServer, Result<?>> action, IChannel channel) {
RequestBuffer.RequestFuture<IMessage> status = null;
int processed = 0;
StringBuilder builder = new StringBuilder();
for (GameServer target : servers) {
Result<?> result = action.apply(target);
if (result.isSuccessful()) {
processed++;
}
String toAppend = resultLine(target, result);
if (status == null || builder.length() + toAppend.length() > Message.MAX_MESSAGE_LENGTH) {
status = answerToChannel(channel, toAppend);
builder.setLength(0);
builder.append(toAppend);
} else {
IMessage newStatus = status.get();
builder.append(toAppend);
status = RequestBuffer.request(() -> (IMessage) newStatus.edit(builder.toString()));
}
}
return processed;
}
示例5: action
import sx.blah.discord.handle.obj.IChannel; //导入依赖的package包/类
public static void action(final Predicate<Channel> filter, final Consumer<IChannel> a) {
EEWBot.instance.getChannels().entrySet()
.forEach(entry -> {
final IGuild guild = EEWBot.instance.getClient().getGuildByID(entry.getKey());
if (guild!=null)
entry.getValue().stream().filter(filter)
.forEach(channel -> {
final IChannel dc = guild.getChannelByID(channel.id);
if (dc!=null)
try {
a.accept(dc);
} catch (final MissingPermissionsException ex) {
Log.logger.warn("権限がありません: "+guild.getName()+" #"+dc.getName());
}
});
});
}
示例6: checkAndGetBet
import sx.blah.discord.handle.obj.IChannel; //导入依赖的package包/类
public static Integer checkAndGetBet(IChannel channel, IUser user, String betStr, int maxValue) throws IllegalCmdArgumentException {
Integer bet = CastUtils.asPositiveInt(betStr);
if(bet == null) {
throw new IllegalCmdArgumentException(String.format("`%s` is not a valid amount for coins.", betStr));
}
if(Database.getDBUser(channel.getGuild(), user).getCoins() < bet) {
BotUtils.sendMessage(TextUtils.notEnoughCoins(user), channel);
return null;
}
if(bet > maxValue) {
BotUtils.sendMessage(String.format(Emoji.BANK + " Sorry, you can't bet more than **%s**.",
FormatUtils.formatCoins(maxValue)), channel);
return null;
}
return bet;
}
示例7: isLimited
import sx.blah.discord.handle.obj.IChannel; //导入依赖的package包/类
public boolean isLimited(IChannel channel, IUser user) {
guildsLimitedMap.putIfAbsent(channel.getGuild().getLongID(), new LimitedGuild());
LimitedGuild limitedGuild = guildsLimitedMap.get(channel.getGuild().getLongID());
limitedGuild.addUserIfAbsent(user);
LimitedUser limitedUser = limitedGuild.getUser(user);
limitedUser.increment();
// The user has not exceeded the limit yet, he is not limited
if(limitedUser.getCount() <= max) {
limitedGuild.scheduledDeletion(scheduledExecutor, user, cooldown);
return false;
}
// The user has exceeded the limit, he's warned and limited
if(limitedUser.getCount() == max + 1) {
limitedGuild.scheduledDeletion(scheduledExecutor, user, cooldown);
this.warn(channel, user);
return true;
}
// The user has already exceeded the limit, he will be unlimited when the deletion task will be done
return true;
}
示例8: subscribeAnnouncer
import sx.blah.discord.handle.obj.IChannel; //导入依赖的package包/类
private String subscribeAnnouncer(IUser author, String announcer, IChannel channel) {
if (!announcer.isEmpty()) {
Publisher publisher = findOrCreatePublisher(announcer);
List<ChannelSubscription> matching = publisher.getChannelSubscriptions().stream()
.filter(s -> s.getChannel().getId().equals(channel.getID())).collect(Collectors.toList());
if (matching.isEmpty()) {
ChannelSubscription subscription = new ChannelSubscription();
subscription.setChannel(cacheService.getOrCreateChannel(channel));
subscription.setEnabled(true);
subscription.setMode(Subscription.Mode.ALWAYS);
publisher.getChannelSubscriptions().add(subscription);
publisherRepository.save(publisher);
log.debug("Subscribing channel {} ({}) to announcer {}", channel.getName(), channel.getID(), announcer);
if (channel.isPrivate()) {
return ":satellite: I'll PM you about **" + announcer + "**";
} else {
return String.format("Subscription of %s to **%s** successful", channel.mention(), announcer);
}
} else {
return "The channel is already receiving announcements about **" + announcer + "**";
}
} else {
log.debug("Attempted to subscribe announcer: {}", author);
}
return null;
}
示例9: onAttack
import sx.blah.discord.handle.obj.IChannel; //导入依赖的package包/类
public void onAttack(IChannel channel, Player attacker, MoveSet moveSet, Player defender){
synchronized(this.attacks){
if(this.attacks.containsKey(attacker)){
this.sendMessage(attacker.mention()+" you've already sent your attack!");
return;
}
this.attacks.put(attacker, new IAttack(attacker, moveSet, defender));
if(!channel.getID().equals(this.channel.getID())){
this.sendMessage(attacker.mention()+" sent in their attack from another channel!");
} else {
this.sendMessage(attacker.mention()+" submitted their attack");
}
Move move = moveSet.getMove();
attacker.lastMove = moveSet;
attacker.lastTarget = move.has(Move.Flags.UNTARGETABLE) ? null : defender;
if(!move.has(Move.Flags.UNTARGETABLE))
defender.lastAttacker = attacker; //free-for-all may make it weird, but it's intentional
if(this.attacks.size() == this.participants.size()){
this.timer.cancel();
this.onTurn();
}
}
}
示例10: onJoinBattle
import sx.blah.discord.handle.obj.IChannel; //导入依赖的package包/类
public static void onJoinBattle(IChannel channel, IUser user, IUser host){
PreBattle pre = preBattles.get(host);
if(pre == null){
Pokebot.sendMessage(channel, user.mention()+" there is no battle pending for that person!");
return;
}
if(!pre.channel.getID().equals(channel.getID())){
Pokebot.sendMessage(channel, " you must do this in the same channel the battle is being hosted in!");
return;
}
List<Player> list = preBattles.get(host).participants;
Player player = PlayerHandler.getPlayer(user);
if(!list.contains(player)){
list.add(player);
inPreBattle.add(user);
}
Pokebot.sendMessage(channel, user.mention()+" joined the battle hosted by "+host.mention());
}
示例11: send
import sx.blah.discord.handle.obj.IChannel; //导入依赖的package包/类
/**
* Buffers and sends a message in a channel
*
* @param content Message content
* @param channel The channel to send in
*/
public static void send(String content, IChannel channel) {
RequestBuffer.request(() -> {
try {
String cnt = "\u200b" + content;
if (cnt.length() > 2000) {
cnt = cnt.substring(0, 1999);
}
new MessageBuilder(Launcher.getInstance().getClient()).withChannel(channel)
.appendContent(cnt).build();
} catch (DiscordException | MissingPermissionsException e) {
String desc = "";
if (channel.isPrivate()) {
desc += "DM To " +
((IPrivateChannel) channel).getRecipient().getName()
+ '#' + ((IPrivateChannel) channel).getRecipient().getDiscriminator()
+ " (ID: " + ((IPrivateChannel) channel).getRecipient().getID();
} else {
desc += channel + " (Guild: " + channel.getGuild().getName() + ')';
}
Launcher.getInstance().getLogger().error(
MessageFormatter.format("Could not send message! Channel: {}", desc).getMessage(), e);
}
});
}
示例12: sendException
import sx.blah.discord.handle.obj.IChannel; //导入依赖的package包/类
/**
* Sends an exception into a channel
*
* @param msg Message to prepend
* @param thrown The exception
* @param channel The channel to send to
*/
public static void sendException(String msg, Throwable thrown, IChannel channel) {
StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw);
thrown.printStackTrace(pw);
pw.close();
String x = sw.toString();
if (channel == null) {
try {
channel = Launcher.getInstance().getClient()
.getOrCreatePMChannel(Launcher.getInstance().getClient().getUserByID(ABot.ROOT_ID));
} catch (DiscordException | RateLimitException e) {
e.printStackTrace();
return;
}
}
msg = msg + " " + x;
send(msg, channel);
Launcher.getInstance().getLogger().error(msg);
try {
sw.close();
} catch (IOException ignored) {
}
}
示例13: runBefore
import sx.blah.discord.handle.obj.IChannel; //导入依赖的package包/类
@Override
public BeforeResult runBefore(IChannel channel, Player attacker, Player defender){
if(this.getAccuracy() < 0 || willHit(this, attacker, defender, true)){
switch(defender.getModifiedAbility()){
case BIG_PECKS:{
if(this.stat == Stats.DEFENSE && this.change < 0 && attacker != defender){ //TODO does not negate guard swap
Pokebot.sendMessage(channel, defender.mention()+"'s ability prevents lowering it's defense");
return BeforeResult.STOP;
}
break;
}
case CLEAR_BODY:{
if(this.change < 0 && attacker != defender){
Pokebot.sendMessage(channel, defender.mention()+"'s ability prevents lowering it's stats!");
}
break;
}
default:
break;
}
StatHandler.changeStat(channel, defender, this.stat, this.change);
} else {
missMessage(channel, attacker);
}
return BeforeResult.STOP;
}
示例14: getWrongArgumentsMessage
import sx.blah.discord.handle.obj.IChannel; //导入依赖的package包/类
public static MetadataMessageBuilder getWrongArgumentsMessage(IChannel channel, Command cmd, String cmdUsed,
CommandData commandData) {
if (cmd.hidden)
return null;
MetadataMessageBuilder builder = Bot.getNewBuilder(channel);
builder.withContent("Incorrect number of arguments. Use `help " + cmdUsed + "` for details.\n");
builder.appendContent("Acceptable parameter types:");
Map<String, String> tmp = new LinkedHashMap<>();
cmd.getCommandHelp(tmp, commandData);
for (String s : tmp.keySet()) {
builder.appendContent("\n`" + cmdUsed + " " + s + "`");
}
withAutoDeleteMessage(builder, Math.max(60, Bot.AUTO_DELETE_TIME));
return builder;
}
示例15: dispatch
import sx.blah.discord.handle.obj.IChannel; //导入依赖的package包/类
@Override
public void dispatch(String[] args, IUser sender, IChannel channel) {
if (args.length > 0) {
String nick = "";
for (String s : args) {
nick += s + ' ';
}
nick = nick.trim();
String finalNick = nick;
RequestBuffer.request(() -> {
try {
channel.getGuild().setUserNickname(Launcher.getInstance().getClient().getOurUser(), finalNick);
} catch (MissingPermissionsException | DiscordException e) {
Messages.sendException("Could not edit my own nickname :'(", e, channel);
}
});
} else Messages.send("You need to provide a nickname!", channel);
}