use of sx.blah.discord.api.events.EventSubscriber in project BoltBot by DiscordBolt.
the class VoiceManager method reactionEvent.
/* Listeners */
@EventSubscriber
public void reactionEvent(ReactionAddEvent e) {
if (e.getUser().equals(MusicModule.getClient().getOurUser()))
return;
DJ dj = getDJ(e.getGuild());
IMessage message = e.getMessage();
AudioTrack track = null;
if (message.equals(dj.getNowPlayingMessage()))
track = dj.getPlaying();
else if (dj.getTrackMessages().containsKey(message))
track = dj.getTrackMessages().get(message);
if (track == null)
return;
switch(e.getReaction().getUnicodeEmoji().getAliases().get(0)) {
case "black_right_pointing_double_triangle_with_vertical_bar":
if (track.getIdentifier().equals(dj.getPlaying().getIdentifier())) {
try {
skip(e.getGuild(), e.getUser(), false, 1);
ChannelUtil.sendMessage(e.getChannel(), e.getUser().getDisplayName(e.getGuild()) + " has voted to skip this track.");
} catch (CommandException ex) {
ChannelUtil.sendMessage(e.getChannel(), ex.getMessage());
}
} else {
ChannelUtil.sendMessage(e.getChannel(), e.getUser().getName() + ", You can only skip currently playing songs");
return;
}
break;
case "star":
try {
getDJ(e.getGuild()).starSong(track, e.getUser());
ChannelUtil.sendMessage(e.getChannel(), e.getUser().getDisplayName(e.getGuild()) + ", successfully added the song to your selected playlist.");
} catch (CommandException ex) {
ChannelUtil.sendMessage(e.getChannel(), ex.getMessage());
}
break;
}
}
use of sx.blah.discord.api.events.EventSubscriber in project KaellyBot by Kaysoro.
the class GuildCreateListener method onReady.
@EventSubscriber
public void onReady(GuildCreateEvent event) {
try {
if (!Guild.getGuilds().containsKey(event.getGuild().getStringID())) {
Guild guild = new Guild(event.getGuild().getStringID(), event.getGuild().getName(), Translator.detectLanguage(event.getGuild().getDefaultChannel()));
guild.addToDatabase();
Language lg = guild.getLanguage();
LOG.info("La guilde " + guild.getId() + " - " + guild.getName() + " a ajouté " + Constants.name);
String customMessage = Translator.getLabel(lg, "welcome.message");
customMessage = customMessage.replaceAll("\\{name\\}", Constants.name).replaceAll("\\{game\\}", Constants.game).replaceAll("\\{prefix\\}", Constants.prefixCommand).replaceAll("\\{help\\}", HelpCommand.NAME).replaceAll("\\{server\\}", new ServerCommand().getName()).replaceAll("\\{lang\\}", new LanguageCommand().getName()).replaceAll("\\{twitter\\}", new TwitterCommand().getName()).replaceAll("\\{almanax\\}", new AlmanaxCommand().getName()).replaceAll("\\{rss\\}", new RSSCommand().getName()).replaceAll("\\{owner\\}", event.getGuild().getOwner().mention()).replaceAll("\\{guild\\}", event.getGuild().getName());
if (event.getGuild().getDefaultChannel() != null && event.getGuild().getDefaultChannel().getModifiedPermissions(ClientConfig.DISCORD().getOurUser()).contains(Permissions.SEND_MESSAGES))
Message.sendText(event.getGuild().getDefaultChannel(), customMessage);
else
try {
Message.sendText(event.getGuild().getOwner().getOrCreatePMChannel(), customMessage);
} catch (DiscordException e) {
LOG.warn("onReady", "Impossible de contacter l'administrateur de la guilde [" + guild.getName() + "].");
}
Message.sendText(ClientConfig.DISCORD().getChannelByID(Constants.chanReportID), "[NEW] **" + guild.getName() + "** (" + guild.getLanguage().getAbrev() + "), +" + event.getGuild().getUsers().size() + " utilisateurs");
}
} catch (Exception e) {
Reporter.report(e, event.getGuild());
LOG.error("onReady", e);
}
}
use of sx.blah.discord.api.events.EventSubscriber in project de-DiscordBot by DACH-Discord.
the class DiscordBot method onMessageEdited.
/**
* Wird bei jeder geänderten Nachricht aufgerufen, bearbeitete Nachrichten die jünger als 20 Sekunden sind
* werden auch als Befehl interpretiert
*
* @param event Das Event der geänderten Nachricht
*/
@EventSubscriber
public void onMessageEdited(final MessageUpdateEvent event) {
final IMessage message = event.getNewMessage();
if (message.getEditedTimestamp().isPresent()) {
final LocalDateTime messageTimestamp = message.getTimestamp();
final LocalDateTime editTimestamp = message.getEditedTimestamp().get();
final long seconds = messageTimestamp.until(editTimestamp, ChronoUnit.SECONDS);
if (seconds < 20) {
handleMessage(message);
}
}
}
use of sx.blah.discord.api.events.EventSubscriber in project de-DiscordBot by DACH-Discord.
the class UserLog method onStartup.
@EventSubscriber
public void onStartup(ReadyEvent event) {
// UserLog Kanal auslesen
final String userLogFileContent = Util.readFile(USERLOG_PATH);
if (userLogFileContent == null) {
throw new RuntimeException("[ERROR] Could not read userLog File!");
}
jsonUserLog = new JSONObject(userLogFileContent);
this.isEnabled = jsonUserLog.getBoolean("on");
final long channelID = jsonUserLog.getLong("channel");
this.userLogChannel = bot.client.getChannelByID(channelID);
if (this.userLogChannel == null) {
System.err.println("[ERR] Invalid UserLog Channel!");
}
}
use of sx.blah.discord.api.events.EventSubscriber in project solinia3-core by mixxit.
the class DiscordListener method onMessageReceivedEvent.
@EventSubscriber
public void onMessageReceivedEvent(MessageReceivedEvent event) {
// This method is NOT called because it doesn't have the @EventSubscriber annotation
System.out.println(event.getAuthor().getName() + "@" + event.getChannel().getName() + ":" + event.getMessage().getContent());
if (event.getChannel().getStringID().equals(StateManager.getInstance().getChannelManager().getDefaultDiscordChannel())) {
// Handle command messaging here
if (event.getMessage().getContent().startsWith("?")) {
StateManager.getInstance().getChannelManager().handleDiscordCommand(DiscordChannel.DEFAULT, event);
} else {
StateManager.getInstance().getChannelManager().sendToGlobalChannel(event.getAuthor().getName() + "@" + event.getChannel().getName(), event.getMessage().getContent());
}
}
IRole role = null;
for (IRole currentRole : event.getGuild().getRoles()) {
if (!currentRole.getName().equals("Admin"))
continue;
role = currentRole;
}
if (event.getAuthor().getRolesForGuild(event.getGuild()).contains(role)) {
if (event.getMessage().getContent().startsWith("?")) {
String[] words = event.getMessage().getContent().split(" ");
String command = "";
for (int i = 0; i < words.length; i++) {
if (i == 0) {
command += words[i].replace("?", "") + " ";
} else {
command += words[i] + " ";
}
}
if (event.getChannel().getStringID().equals(StateManager.getInstance().getChannelManager().getDefaultDiscordChannel())) {
Bukkit.getServer().dispatchCommand(StateManager.getInstance().getDiscordDefaultChannelCommandSender(), command.trim());
} else {
Bukkit.getServer().dispatchCommand(StateManager.getInstance().getDiscordAdminChannelCommandSender(), command.trim());
}
} else {
StateManager.getInstance().getChannelManager().sendToOps("[OPONLY]" + event.getAuthor().getName() + "@" + event.getChannel().getName(), event.getMessage().getContent());
}
}
}
Aggregations