use of stream.flarebot.flarebot.objects.GuildWrapper in project FlareBot by FlareBot.
the class FutureAction method execute.
public void execute() {
GuildWrapper gw = FlareBotManager.instance().getGuild(String.valueOf(guildId));
if (gw == null || gw.getGuild() == null)
return;
switch(action) {
case TEMP_MUTE:
if (gw.getGuild().getTextChannelById(channelId) != null) {
ModlogHandler.getInstance().handleAction(gw, gw.getGuild().getTextChannelById(channelId), null, GuildUtils.getUser(String.valueOf(target), String.valueOf(guildId), true), ModAction.UNMUTE, "Temporary mute expired, was muted for " + FormatUtils.formatJodaTime(delay));
} else
gw.getModeration().unmuteUser(gw, gw.getGuild().getMemberById(target));
break;
case TEMP_BAN:
if (gw.getGuild().getTextChannelById(channelId) != null) {
ModlogHandler.getInstance().handleAction(gw, gw.getGuild().getTextChannelById(channelId), null, GuildUtils.getUser(String.valueOf(target), String.valueOf(guildId), true), ModAction.UNBAN, "Temporary ban expired, was banned for " + FormatUtils.formatJodaTime(delay));
} else
gw.getGuild().getController().unban(String.valueOf(target)).queue();
break;
case REMINDER:
if (Getters.getChannelById(channelId) != null)
Getters.getChannelById(channelId).sendMessage(Getters.getUserById(responsible).getAsMention() + " You asked me to remind you " + FormatUtils.formatJodaTime(delay).toLowerCase() + " ago about: `" + content.replaceAll("`", "'") + "`").queue();
break;
case DM_REMINDER:
MessageUtils.sendPM(Getters.getChannelById(channelId), Getters.getUserById(responsible), Getters.getUserById(responsible).getAsMention() + " You asked me to remind you " + FormatUtils.formatJodaTime(delay).toLowerCase() + " ago about: `" + content.replaceAll("`", "'") + "`");
break;
default:
break;
}
delete();
}
use of stream.flarebot.flarebot.objects.GuildWrapper in project FlareBot by FlareBot.
the class MigrationHandler method migrateSinglePermissionForGuild.
public int migrateSinglePermissionForGuild(String oldPermission, String newPermission, Guild guild) {
int i = 0;
GuildWrapper wrapper = null;
try {
wrapper = FlareBotManager.instance().getGuildNoCache(guild.getId());
Pattern oldPerm = // Make sure it is exact permission
Pattern.compile("\\b" + oldPermission.replaceAll("\\.", "\\.") + "\\b");
for (Group g : wrapper.getPermissions().getGroups()) {
for (final Iterator<String> it = g.getPermissions().iterator(); it.hasNext(); ) {
String perm = it.next();
if (oldPerm.matcher(perm).find()) {
it.remove();
g.getPermissions().add(perm.replace(oldPermission, newPermission));
i++;
}
}
}
} catch (Exception e) {
FlareBot.LOGGER.error("Migration failed", e);
}
FlareBotManager.instance().saveGuild(guild.getId(), wrapper, System.currentTimeMillis());
return i;
}
use of stream.flarebot.flarebot.objects.GuildWrapper in project FlareBot by FlareBot.
the class ModlogEvents method onEvent.
@Override
public void onEvent(Event event) {
if (!(event instanceof GenericGuildEvent) && !(event instanceof GenericRoleEvent) && !(event instanceof GenericTextChannelEvent) && !(event instanceof GenericVoiceChannelEvent) && !(event instanceof GenericMessageEvent))
return;
Guild g = null;
if (event instanceof GenericGuildEvent && ((GenericGuildEvent) event).getGuild() != null)
g = ((GenericGuildEvent) event).getGuild();
else if (event instanceof GenericRoleEvent && ((GenericRoleEvent) event).getGuild() != null)
g = ((GenericRoleEvent) event).getGuild();
else if (event instanceof GenericTextChannelEvent && ((GenericTextChannelEvent) event).getGuild() != null)
g = ((GenericTextChannelEvent) event).getGuild();
else if (event instanceof GenericVoiceChannelEvent && ((GenericVoiceChannelEvent) event).getGuild() != null)
g = ((GenericVoiceChannelEvent) event).getGuild();
else if (event instanceof GenericMessageEvent && ((GenericMessageEvent) event).getGuild() != null)
g = ((GenericMessageEvent) event).getGuild();
if (g == null)
return;
GuildWrapper guildWrapper = FlareBotManager.instance().getGuild(g.getId());
if (guildWrapper == null)
return;
// GUILD
if (event instanceof GuildBanEvent)
onGuildBan((GuildBanEvent) event, guildWrapper);
else if (event instanceof GuildMemberJoinEvent)
onGuildMemberJoin((GuildMemberJoinEvent) event, guildWrapper);
else if (event instanceof GuildMemberLeaveEvent)
onGuildMemberLeave((GuildMemberLeaveEvent) event, guildWrapper);
else if (event instanceof GuildVoiceJoinEvent)
onGuildVoiceJoin((GuildVoiceJoinEvent) event, guildWrapper);
else if (event instanceof GuildVoiceLeaveEvent)
onGuildVoiceLeave((GuildVoiceLeaveEvent) event, guildWrapper);
else // ROLES
if (event instanceof RoleCreateEvent)
onRoleCreate((RoleCreateEvent) event, guildWrapper);
else if (event instanceof RoleDeleteEvent)
onRoleDelete((RoleDeleteEvent) event, guildWrapper);
else if (event instanceof GenericRoleUpdateEvent)
onGenericRoleUpdate((GenericRoleUpdateEvent) event, guildWrapper);
else if (event instanceof GuildMemberRoleAddEvent)
onGuildMemberRoleAdd((GuildMemberRoleAddEvent) event, guildWrapper);
else if (event instanceof GuildMemberRoleRemoveEvent)
onGuildMemberRoleRemove((GuildMemberRoleRemoveEvent) event, guildWrapper);
else // CHANNEL
if (event instanceof TextChannelCreateEvent)
onTextChannelCreate((TextChannelCreateEvent) event, guildWrapper);
else if (event instanceof VoiceChannelCreateEvent)
onVoiceChannelCreate((VoiceChannelCreateEvent) event, guildWrapper);
else if (event instanceof TextChannelDeleteEvent)
onTextChannelDelete((TextChannelDeleteEvent) event, guildWrapper);
else if (event instanceof VoiceChannelDeleteEvent)
onVoiceChannelDelete((VoiceChannelDeleteEvent) event, guildWrapper);
else /*else if (event instanceof GuildMessageReceivedEvent)
onGuildMessageReceived((GuildMessageReceivedEvent) event, guildWrapper);*/
if (event instanceof MessageUpdateEvent)
onMessageUpdate((MessageUpdateEvent) event, guildWrapper);
else if (event instanceof MessageDeleteEvent)
onMessageDelete((MessageDeleteEvent) event, guildWrapper);
else // GUILD
if (event instanceof GuildUpdateExplicitContentLevelEvent)
onGuildUpdateExplicitContentLevel((GuildUpdateExplicitContentLevelEvent) event, guildWrapper);
else if (event instanceof GuildMemberNickChangeEvent)
onGuildMemberNickChange((GuildMemberNickChangeEvent) event, guildWrapper);
else if (event instanceof GenericGuildUpdateEvent)
onGenericGuildUpdate((GenericGuildUpdateEvent) event, guildWrapper);
else if (event instanceof GuildVoiceMoveEvent)
onGuildVoiceMove((GuildVoiceMoveEvent) event, guildWrapper);
}
use of stream.flarebot.flarebot.objects.GuildWrapper in project FlareBot by FlareBot.
the class SkipCommand method onCommand.
@Override
public void onCommand(User sender, GuildWrapper guild, TextChannel channel, Message message, String[] args, Member member) {
boolean songMessage = message.getAuthor().getIdLong() == Getters.getSelfUser().getIdLong();
PlayerManager musicManager = FlareBot.instance().getMusicManager();
if (!channel.getGuild().getAudioManager().isConnected() || musicManager.getPlayer(channel.getGuild().getId()).getPlayingTrack() == null) {
channel.sendMessage("I am not playing anything!").queue();
return;
}
if (member.getVoiceState().inVoiceChannel() && !channel.getGuild().getSelfMember().getVoiceState().getChannel().getId().equals(member.getVoiceState().getChannel().getId()) && !getPermissions(channel).hasPermission(member, Permission.SKIP_FORCE)) {
channel.sendMessage("You must be in the channel in order to skip songs!").queue();
return;
}
Track currentTrack = musicManager.getPlayer(guild.getGuildId()).getPlayingTrack();
if (args.length == 0 && currentTrack.getMeta().get("requester").equals(sender.getId())) {
channel.sendMessage("Skipped your own song!").queue();
musicManager.getPlayer(guild.getGuildId()).skip();
if (songMessage)
SongCommand.updateSongMessage(sender, message, channel);
return;
}
if (args.length != 1) {
if (!channel.getGuild().getMember(sender).getVoiceState().inVoiceChannel() || channel.getGuild().getMember(sender).getVoiceState().getChannel().getIdLong() != channel.getGuild().getSelfMember().getVoiceState().getChannel().getIdLong()) {
MessageUtils.sendErrorMessage("You cannot skip if you aren't listening to it!", channel);
return;
}
if (VoteUtil.contains(skipUUID, guild.getGuild()))
MessageUtils.sendWarningMessage("There is already a vote to skip current song! Vote with `{%}skip yes | no`", channel, sender);
else {
VoteGroup group = new VoteGroup("Skip current song", skipUUID);
List<User> users = new ArrayList<>();
for (Member inChannelMember : channel.getGuild().getSelfMember().getVoiceState().getChannel().getMembers()) {
if (channel.getGuild().getSelfMember().getUser().getIdLong() != inChannelMember.getUser().getIdLong()) {
users.add(inChannelMember.getUser());
}
}
group.limitUsers(users);
VoteUtil.sendVoteMessage(skipUUID, (vote) -> {
if (vote.equals(VoteGroup.Vote.NONE) || vote.equals(VoteGroup.Vote.NO)) {
MessageUtils.sendMessage("Results are in: Keep!", channel);
} else {
MessageUtils.sendMessage("Skipping!", channel);
if (songMessage)
SongCommand.updateSongMessage(sender, message, channel);
musicManager.getPlayer(guild.getGuildId()).skip();
}
}, group, TimeUnit.MINUTES.toMillis(1), channel, sender, ButtonGroupConstants.VOTE_SKIP, new ButtonGroup.Button("\u23ED", (owner, user, message1) -> {
if (getPermissions(channel).hasPermission(channel.getGuild().getMember(user), Permission.SKIP_FORCE)) {
musicManager.getPlayer(channel.getGuild().getId()).skip();
if (songMessage) {
SongCommand.updateSongMessage(user, message1, channel);
}
musicManager.getPlayer(guild.getGuildId()).skip();
VoteUtil.remove(skipUUID, guild.getGuild());
} else {
channel.sendMessage("You are missing the permission `" + Permission.SKIP_FORCE + "` which is required for use of this button!").queue();
}
}));
}
} else {
if (args[0].equalsIgnoreCase("force")) {
if (getPermissions(channel).hasPermission(member, Permission.SKIP_FORCE)) {
if (songMessage)
SongCommand.updateSongMessage(sender, message, channel);
VoteUtil.remove(skipUUID, guild.getGuild());
musicManager.getPlayer(guild.getGuildId()).skip();
} else {
channel.sendMessage("You are missing the permission `" + Permission.SKIP_FORCE + "` which is required for use of this command!").queue();
}
return;
} else if (args[0].equalsIgnoreCase("cancel")) {
if (getPermissions(channel).hasPermission(member, Permission.SKIP_CANCEL)) {
VoteUtil.remove(skipUUID, channel.getGuild());
} else
channel.sendMessage("You are missing the permission `" + Permission.SKIP_CANCEL + "` which is required for use of this command!").queue();
return;
}
if (!channel.getGuild().getMember(sender).getVoiceState().inVoiceChannel() || channel.getGuild().getMember(sender).getVoiceState().getChannel().getIdLong() != channel.getGuild().getSelfMember().getVoiceState().getChannel().getIdLong()) {
MessageUtils.sendWarningMessage("You cannot vote to skip if you aren't listening to it!", channel);
return;
}
VoteGroup.Vote vote = VoteGroup.Vote.parseVote(args[0]);
if (vote != null) {
if (!VoteUtil.contains(skipUUID, guild.getGuild()))
MessageUtils.sendWarningMessage("Their is no vote currently running!", channel, sender);
else
VoteUtil.getVoteGroup(skipUUID, guild.getGuild()).addVote(vote, sender);
} else
MessageUtils.sendUsage(this, channel, sender, args);
}
}
use of stream.flarebot.flarebot.objects.GuildWrapper in project FlareBot by FlareBot.
the class SongCommand method onCommand.
@Override
public void onCommand(User sender, GuildWrapper guild, TextChannel channel, Message message, String[] args, Member member) {
PlayerManager manager = FlareBot.instance().getMusicManager();
if (manager.getPlayer(channel.getGuild().getId()).getPlayingTrack() != null) {
Track track = manager.getPlayer(channel.getGuild().getId()).getPlayingTrack();
EmbedBuilder eb = MessageUtils.getEmbed(sender).addField("Current Song", getLink(track), false).setThumbnail("https://img.youtube.com/vi/" + track.getTrack().getIdentifier() + "/hqdefault.jpg");
if (track.getTrack().getInfo().isStream)
eb.addField("Amount Played", "Issa livestream ;)", false);
else
eb.addField("Amount Played", GeneralUtils.getProgressBar(track), true).addField("Time", String.format("%s / %s", FormatUtils.formatDuration(track.getTrack().getPosition()), FormatUtils.formatDuration(track.getTrack().getDuration())), false);
ButtonGroup buttonGroup = new ButtonGroup(sender.getIdLong(), ButtonGroupConstants.SONG);
buttonGroup.addButton(new ButtonGroup.Button("\u23EF", (owner, user, message1) -> {
if (manager.hasPlayer(guild.getGuildId())) {
if (manager.getPlayer(guild.getGuild().getId()).getPaused()) {
if (getPermissions(channel).hasPermission(guild.getGuild().getMember(user), Permission.RESUME_COMMAND)) {
manager.getPlayer(guild.getGuild().getId()).play();
}
} else {
if (getPermissions(channel).hasPermission(guild.getGuild().getMember(user), Permission.PAUSE_COMMAND)) {
manager.getPlayer(guild.getGuild().getId()).setPaused(true);
}
}
}
}));
buttonGroup.addButton(new ButtonGroup.Button("\u23F9", (owner, user, message1) -> {
if (manager.hasPlayer(guild.getGuildId()) && getPermissions(channel).hasPermission(guild.getGuild().getMember(user), Permission.STOP_COMMAND)) {
manager.getPlayer(guild.getGuildId()).stop();
}
}));
buttonGroup.addButton(new ButtonGroup.Button("\u23ED", (owner, user, message1) -> {
if (getPermissions(channel).hasPermission(guild.getGuild().getMember(user), Permission.SKIP_COMMAND)) {
Command cmd = FlareBot.getCommandManager().getCommand("skip", user);
if (cmd != null)
cmd.onCommand(user, guild, channel, message1, new String[0], guild.getGuild().getMember(user));
}
}));
buttonGroup.addButton(new ButtonGroup.Button("\uD83D\uDD01", (ownerID, user, message1) -> {
updateSongMessage(user, message1, message1.getTextChannel());
}));
ButtonUtil.sendButtonedMessage(channel, eb.build(), buttonGroup);
} else {
channel.sendMessage(MessageUtils.getEmbed(sender).addField("Current song", "**No song playing right now!**", false).build()).queue();
}
}
Aggregations