本文整理汇总了Java中sx.blah.discord.handle.obj.IMessage类的典型用法代码示例。如果您正苦于以下问题:Java IMessage类的具体用法?Java IMessage怎么用?Java IMessage使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
IMessage类属于sx.blah.discord.handle.obj包,在下文中一共展示了IMessage类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: privateMessageReceived
import sx.blah.discord.handle.obj.IMessage; //导入依赖的package包/类
private void privateMessageReceived(IMessage message) throws MissingArgumentException, IllegalCmdArgumentException {
StatsManager.increment(VariousEnum.PRIVATE_MESSAGES_RECEIVED);
if(message.getContent().startsWith(Config.DEFAULT_PREFIX + "help")) {
CommandManager.getCommand("help").execute(new Context(Config.DEFAULT_PREFIX, message));
return;
}
// If Shadbot didn't already send a message
if(!message.getChannel().getMessageHistory().stream().anyMatch(msg -> msg.getAuthor().equals(message.getClient().getOurUser()))) {
BotUtils.sendMessage(String.format("Hello !"
+ "%nCommands only work in a server but you can see help using `%shelp`."
+ "%nIf you have a question, a suggestion or if you just want to talk, don't hesitate to "
+ "join my support server : %s", Config.DEFAULT_PREFIX, Config.SUPPORT_SERVER), message.getChannel());
}
}
示例2: handleDiscord4JException
import sx.blah.discord.handle.obj.IMessage; //导入依赖的package包/类
public static void handleDiscord4JException(@NotNull Logger logger, @NotNull Exception e, @NotNull ICommand commandHandler, @NotNull IMessage message) {
try {
logger.error("{} failed to handle command, a {} was captured",
() -> commandHandler.getClass().getSimpleName(),
() -> e.getClass().getSimpleName());
logger.error(e);
if (e instanceof MissingPermissionsException) {
messageDeletionService().schedule(getMessageBuilder(message)
.appendContent(message.getAuthor().mention())
.appendContent(" I dont have the necessary permissions to execute that action,")
.appendContent(" please give me the following permissions and try again")
.appendContent(System.lineSeparator())
.appendContent(((MissingPermissionsException) e).getMissingPermissions().toString())
.send());
}
} catch (@NotNull RateLimitException | DiscordException | MissingPermissionsException e1) {
logger.error(e1);
}
}
示例3: intercept
import sx.blah.discord.handle.obj.IMessage; //导入依赖的package包/类
@Override
public boolean intercept(IMessage message) {
if(this.isCancelCmd(message)) {
return true;
}
if(!message.getAuthor().equals(this.getAuthor())) {
return false;
}
String content = message.getContent().toLowerCase().trim();
// Check only if content is an unique word/letter
if(!content.matches("[a-z]+")) {
return false;
}
if(content.length() == 1 && !rateLimiter.isLimited(this.getChannel(), message.getAuthor())) {
this.checkLetter(content);
} else if(content.length() == word.length() && !rateLimiter.isLimited(this.getChannel(), message.getAuthor())) {
this.checkWord(content);
}
return false;
}
示例4: init
import sx.blah.discord.handle.obj.IMessage; //导入依赖的package包/类
/**
* Initiates the creator for the guild involved.
* @param e The event received upon init.
* @return A new Announcement.
*/
public Announcement init(MessageReceivedEvent e, GuildSettings settings) {
if (!hasAnnouncement(e.getGuild().getLongID())) {
Announcement a = new Announcement(e.getGuild().getLongID());
a.setAnnouncementChannelId(e.getChannel().getStringID());
if (PermissionChecker.botHasMessageManagePerms(e)) {
IMessage msg = Message.sendMessage(AnnouncementMessageFormatter.getFormatAnnouncementEmbed(a, settings), MessageManager.getMessage("Creator.Announcement.Create.Init", settings), e);
a.setCreatorMessage(msg);
} else {
Message.sendMessage(MessageManager.getMessage("Creator.Notif.MANAGE_MESSAGES", settings), e);
}
announcements.add(a);
return a;
}
return getAnnouncement(e.getGuild().getLongID());
}
示例5: moduleCancel
import sx.blah.discord.handle.obj.IMessage; //导入依赖的package包/类
private void moduleCancel(MessageReceivedEvent event, GuildSettings settings) {
long guildId = event.getGuild().getLongID();
IMessage msg = null;
if (EventCreator.getCreator().hasCreatorMessage(guildId))
msg = EventCreator.getCreator().getCreatorMessage(guildId);
if (EventCreator.getCreator().terminate(event)) {
if (msg != null) {
Message.deleteMessage(event);
Message.deleteMessage(msg);
Message.sendMessage(MessageManager.getMessage("Creator.Event.Cancel.Success", settings), event);
} else {
Message.sendMessage(MessageManager.getMessage("Creator.Event.Cancel.Success", settings), event);
}
} else {
Message.sendMessage(MessageManager.getMessage("Creator.Event.NotInit", settings), event);
}
}
示例6: moduleRestart
import sx.blah.discord.handle.obj.IMessage; //导入依赖的package包/类
private void moduleRestart(String[] args, MessageReceivedEvent event, CalendarData calendarData, GuildSettings settings) {
long guildId = event.getGuild().getLongID();
IMessage msg = null;
boolean editing = false;
if (EventCreator.getCreator().hasPreEvent(guildId)) {
editing = EventCreator.getCreator().getPreEvent(guildId).isEditing();
}
if (EventCreator.getCreator().hasCreatorMessage(guildId))
msg = EventCreator.getCreator().getCreatorMessage(guildId);
if (EventCreator.getCreator().terminate(event)) {
if (msg != null) {
Message.deleteMessage(msg);
Message.deleteMessage(event);
}
if (!editing) {
moduleCreate(args, event, calendarData, settings);
} else {
moduleEdit(args, event, calendarData, settings);
}
} else {
Message.sendMessage(MessageManager.getMessage("Creator.Event.NotInit", settings), event);
}
}
示例7: init
import sx.blah.discord.handle.obj.IMessage; //导入依赖的package包/类
/**
* Initiates the CalendarCreator for the guild involved in the event.
*
* @param e The event received upon creation start.
* @param calendarName The name of the calendar to create.
* @return The PreCalendar object created.
*/
public PreCalendar init(MessageReceivedEvent e, String calendarName, GuildSettings settings, boolean handleCreatorMessage) {
long guildId = e.getMessage().getGuild().getLongID();
if (!hasPreCalendar(guildId)) {
PreCalendar calendar = new PreCalendar(guildId, calendarName);
if (handleCreatorMessage) {
if (PermissionChecker.botHasMessageManagePerms(e)) {
IMessage msg = Message.sendMessage(CalendarMessageFormatter.getPreCalendarEmbed(calendar, settings), MessageManager.getMessage("Creator.Calendar.Create.Init", settings), e);
calendar.setCreatorMessage(msg);
} else {
Message.sendMessage(MessageManager.getMessage("Creator.Notif.MANAGE_MESSAGES", settings), e);
}
}
calendars.add(calendar);
return calendar;
}
return getPreCalendar(e.getMessage().getGuild().getLongID());
}
示例8: intercept
import sx.blah.discord.handle.obj.IMessage; //导入依赖的package包/类
@Override
public boolean intercept(IMessage message) {
if(!message.getAuthor().equals(message.getClient().getApplicationOwner())) {
return false;
}
String content = message.getContent().toLowerCase();
if("yes".equalsIgnoreCase(content) || "y".equalsIgnoreCase(content)) {
Shadbot.getScheduler().submit(() -> System.exit(0));
return true;
} else if("no".equalsIgnoreCase(content) || "n".equalsIgnoreCase(content)) {
MessageManager.removeListener(message.getChannel(), this);
BotUtils.sendMessage(Emoji.INFO + " Shutdown cancelled.", message.getChannel());
return true;
}
return false;
}
示例9: process
import sx.blah.discord.handle.obj.IMessage; //导入依赖的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;
}
示例10: logout
import sx.blah.discord.handle.obj.IMessage; //导入依赖的package包/类
private Command logout() {
return CommandBuilder.of("logout")
.describedAs("Disconnect from Discord")
.in("Administrative")
.nonParsed()
.secured()
.onExecute(context -> {
IMessage message = context.getMessage();
String[] args = context.getArgs();
if (args != null) {
String id = ourBotId(message.getClient());
String[] array = args[0].split(" ");
// shutdown if the args match this bot but not this instance
if (array.length >= 2 && array[0].equals(id) && !array[1].equals(INSTANCE_KEY)) {
deleteMessage(message);
doLogout(context);
} else {
log.debug("Ignoring: Expected args {} and anything but {}", id, INSTANCE_KEY);
}
} else {
deleteMessage(message);
answer(message, ":wave:");
doLogout(context);
}
}).build();
}
示例11: newMessageDeletionTask
import sx.blah.discord.handle.obj.IMessage; //导入依赖的package包/类
@NotNull
private TimerTask newMessageDeletionTask(@NotNull IMessage message) {
return new TimerTask() {
@Override
public void run() {
try {
message.delete();
} catch (@NotNull MissingPermissionsException | RateLimitException | DiscordException e) {
MessageUtils.handleDiscord4JException(logger, e);
}
}
};
}
示例12: registerPool
import sx.blah.discord.handle.obj.IMessage; //导入依赖的package包/类
public final void registerPool(@NotNull IMessage message, @NotNull Pool pool) {
logger.trace("Registering new pool {}, called by {} for {} seconds.",
pool::id,
() -> message.getAuthor().getName(),
() -> TimeUnit.MILLISECONDS.convert(pool.time(), TimeUnit.SECONDS));
new Timer("Pool timer" + pool.id(), true)
.schedule(new PoolFinalizerTask(pool), TimeUnit.MILLISECONDS.convert(pool.time(), TimeUnit.SECONDS));
}
示例13: createMessage
import sx.blah.discord.handle.obj.IMessage; //导入依赖的package包/类
public static IMessage createMessage(String content, boolean isPrivate) {
return new Message(null, 1, content, null,
isPrivate
? new PrivateChannel(null, null, 1)
: new Channel(null, null, 1, null, null, 0, null, null),
null, null, false, null, null, null, false, null, null, null);
}
示例14: sendMessage
import sx.blah.discord.handle.obj.IMessage; //导入依赖的package包/类
/**
* Sends a message via Discord as DisCal.
*
* @param message The message to send, with formatting.
* @param event The Event received (to send to the same channel and guild).
*/
public static IMessage sendMessage(String message, MessageReceivedEvent event) {
return RequestBuffer.request(() -> {
try {
return new MessageBuilder(Main.client).appendContent(message).withChannel(event.getMessage().getChannel()).build();
} catch (DiscordException | MissingPermissionsException e) {
//Failed to send message.
return null;
}
}).get();
}
示例15: sendDirectMessage
import sx.blah.discord.handle.obj.IMessage; //导入依赖的package包/类
public static IMessage sendDirectMessage(String message, IUser user) {
return RequestBuffer.request(() -> {
try {
IPrivateChannel pc = user.getOrCreatePMChannel();
return new MessageBuilder(Main.client).withChannel(pc).appendContent(message).build();
} catch (DiscordException | MissingPermissionsException e) {
//Failed to send message.
return null;
}
}).get();
}