Search in sources :

Example 16 with IGuild

use of sx.blah.discord.handle.obj.IGuild in project Shadbot by Shadorc.

the class ServerInfoCmd method execute.

@Override
public void execute(Context context) throws MissingArgumentException {
    IGuild guild = context.getGuild();
    DBGuild dbGuild = Database.getDBGuild(guild);
    StringBuilder settingsStr = new StringBuilder();
    if (!dbGuild.getPrefix().equals(Config.DEFAULT_PREFIX)) {
        settingsStr.append(String.format("**Prefix:** %s", context.getPrefix()));
    }
    if (dbGuild.getDefaultVol() != Config.DEFAULT_VOLUME) {
        settingsStr.append(String.format("%n**Default volume:** %d%%", dbGuild.getDefaultVol()));
    }
    if (!dbGuild.getAllowedChannels().isEmpty()) {
        List<IChannel> channels = dbGuild.getAllowedChannels().stream().map(guild::getChannelByID).filter(Objects::nonNull).collect(Collectors.toList());
        settingsStr.append(String.format("%n**Allowed channels:**%n\t%s", FormatUtils.format(channels, IChannel::getName, "\n\t")));
    }
    if (!dbGuild.getBlacklistedCmd().isEmpty()) {
        settingsStr.append(String.format("%n**Blacklisted commands:**%n\t%s", FormatUtils.format(dbGuild.getBlacklistedCmd(), Object::toString, "\n\t")));
    }
    if (!dbGuild.getAutoRoles().isEmpty()) {
        List<IRole> roles = dbGuild.getAutoRoles().stream().map(guild::getRoleByID).filter(Objects::nonNull).collect(Collectors.toList());
        settingsStr.append(String.format("%n**Auto-roles:**%n\t%s", FormatUtils.format(roles, IRole::mention, "\n\t")));
    }
    String creationDate = String.format("%s%n(%s)", TimeUtils.toLocalDate(guild.getCreationDate()).format(dateFormatter), FormatUtils.formatLongDuration(guild.getCreationDate()));
    EmbedBuilder embed = EmbedUtils.getDefaultEmbed().setLenient(true).withAuthorName(String.format("Info about \"%s\"", guild.getName())).withThumbnail(guild.getIconURL()).appendField("Owner", guild.getOwner().getName(), true).appendField("Server ID", Long.toString(guild.getLongID()), true).appendField("Creation date", creationDate, true).appendField("Region", guild.getRegion().getName(), true).appendField("Channels", String.format("**Voice:** %d", guild.getVoiceChannels().size()) + String.format("%n**Text:** %d", guild.getChannels().size()), true).appendField("Members", Integer.toString(guild.getTotalMemberCount()), true).appendField("Settings", settingsStr.toString(), true);
    BotUtils.sendMessage(embed.build(), context.getChannel());
}
Also used : EmbedBuilder(sx.blah.discord.util.EmbedBuilder) DBGuild(me.shadorc.shadbot.data.db.DBGuild) IChannel(sx.blah.discord.handle.obj.IChannel) IRole(sx.blah.discord.handle.obj.IRole) EmbedObject(sx.blah.discord.api.internal.json.objects.EmbedObject) IGuild(sx.blah.discord.handle.obj.IGuild)

Example 17 with IGuild

use of sx.blah.discord.handle.obj.IGuild in project Shadbot by Shadorc.

the class LottoCmd method draw.

public static void draw() {
    LogUtils.infof("Lottery draw started...");
    int winningNum = ThreadLocalRandom.current().nextInt(MIN_NUM, MAX_NUM + 1);
    List<LottoPlayer> winners = LottoManager.getPlayers().stream().filter(player -> player.getNum() == winningNum && Shadbot.getClient().getGuildByID(player.getGuildID()) != null && Shadbot.getClient().getUserByID(player.getUserID()) != null).collect(Collectors.toList());
    for (LottoPlayer winner : winners) {
        IGuild guild = Shadbot.getClient().getGuildByID(winner.getGuildID());
        IUser user = Shadbot.getClient().getUserByID(winner.getUserID());
        int coins = (int) Math.ceil((double) LottoManager.getPool() / winners.size());
        Database.getDBUser(guild, user).addCoins(coins);
        BotUtils.sendMessage(String.format("Congratulations, you have the winning Lotto number! You earn %s.", FormatUtils.formatCoins(coins)), user.getOrCreatePMChannel());
    }
    LogUtils.infof("Lottery draw done (Winning number: %d | %d winner(s) | Prize pool: %d)", winningNum, winners.size(), LottoManager.getPool());
    LottoManager.setHistoric(winners.size(), LottoManager.getPool(), winningNum);
    LottoManager.resetUsers();
    if (!winners.isEmpty()) {
        LottoManager.resetPool();
    }
}
Also used : HelpBuilder(me.shadorc.shadbot.utils.embed.HelpBuilder) CommandCategory(me.shadorc.shadbot.core.command.CommandCategory) LottoManager(me.shadorc.shadbot.data.lotto.LottoManager) ZonedDateTime(java.time.ZonedDateTime) LogUtils(me.shadorc.shadbot.utils.LogUtils) DBUser(me.shadorc.shadbot.data.db.DBUser) LottoPlayer(me.shadorc.shadbot.data.lotto.LottoPlayer) BotUtils(me.shadorc.shadbot.utils.BotUtils) TimeUtils(me.shadorc.shadbot.utils.TimeUtils) MissingArgumentException(me.shadorc.shadbot.exception.MissingArgumentException) Command(me.shadorc.shadbot.core.command.annotation.Command) EmbedBuilder(sx.blah.discord.util.EmbedBuilder) IUser(sx.blah.discord.handle.obj.IUser) TextUtils(me.shadorc.shadbot.utils.TextUtils) ThreadLocalRandom(java.util.concurrent.ThreadLocalRandom) RateLimited(me.shadorc.shadbot.core.command.annotation.RateLimited) LottoHistoric(me.shadorc.shadbot.data.lotto.LottoHistoric) EmbedObject(sx.blah.discord.api.internal.json.objects.EmbedObject) FormatUtils(me.shadorc.shadbot.utils.FormatUtils) Collectors(java.util.stream.Collectors) Shadbot(me.shadorc.shadbot.Shadbot) IllegalCmdArgumentException(me.shadorc.shadbot.exception.IllegalCmdArgumentException) CastUtils(me.shadorc.shadbot.utils.CastUtils) IGuild(sx.blah.discord.handle.obj.IGuild) List(java.util.List) Context(me.shadorc.shadbot.core.command.Context) DayOfWeek(java.time.DayOfWeek) AbstractCommand(me.shadorc.shadbot.core.command.AbstractCommand) Database(me.shadorc.shadbot.data.db.Database) Emoji(me.shadorc.shadbot.utils.object.Emoji) EmbedUtils(me.shadorc.shadbot.utils.embed.EmbedUtils) LottoPlayer(me.shadorc.shadbot.data.lotto.LottoPlayer) IUser(sx.blah.discord.handle.obj.IUser) IGuild(sx.blah.discord.handle.obj.IGuild)

Example 18 with IGuild

use of sx.blah.discord.handle.obj.IGuild in project BoltBot by DiscordBolt.

the class VoiceManager method queue.

public void queue(IGuild guild, IUser requester, String songID) throws CommandPermissionException, CommandRuntimeException, CommandStateException {
    if (songID.toLowerCase().contains("twitch.tv") && !MusicModule.hasAdminPermissions(requester, guild))
        throw new CommandPermissionException("You must be a \"" + MusicModule.ADMIN_ROLE + "\" to add Twitch.tv live streams!");
    if (requester.getVoiceStateForGuild(guild).getChannel() == null)
        throw new CommandStateException("You must be connected to a voice channel to execute this command!");
    if (getDJ(guild).getVoiceChannel() != null && !requester.getVoiceStateForGuild(guild).getChannel().equals(getDJ(guild).getVoiceChannel()))
        throw new CommandStateException("You must be in my voice channel to control the music!");
    DJ dj = getDJ(guild);
    if ((dj.getPlaying() != null && songID.contains(dj.getPlaying().getIdentifier())) || dj.getQueue().stream().anyMatch(t -> songID.contains(t.getIdentifier()))) {
        throw new CommandStateException("That song is already in the queue!");
    }
    playerManager.loadItemOrdered(dj, songID, new AudioLoadResultHandler() {

        @Override
        public void trackLoaded(AudioTrack track) {
            dj.queue(requester, track);
        }

        @Override
        public void playlistLoaded(AudioPlaylist playlist) {
            for (AudioTrack track : playlist.getTracks()) {
                dj.queue(requester, track);
            }
        }

        @Override
        public void noMatches() {
            throw new CommandRuntimeException("Sorry, I was unable to find the song you specified.");
        }

        @Override
        public void loadFailed(FriendlyException exception) {
            if (exception.severity == FriendlyException.Severity.COMMON)
                throw new CommandRuntimeException(exception.getMessage());
            throw new CommandRuntimeException("Sorry, an error occurred while loading your song. Please try again later.");
        }
    });
}
Also used : ExceptionMessage(com.discordbolt.boltbot.utils.ExceptionMessage) com.discordbolt.api.command.exceptions(com.discordbolt.api.command.exceptions) HashMap(java.util.HashMap) AudioPlaylist(com.sedmelluq.discord.lavaplayer.track.AudioPlaylist) MissingPermissionsException(sx.blah.discord.util.MissingPermissionsException) ReactionRemoveEvent(sx.blah.discord.handle.impl.events.guild.channel.message.reaction.ReactionRemoveEvent) IVoiceChannel(sx.blah.discord.handle.obj.IVoiceChannel) IMessage(sx.blah.discord.handle.obj.IMessage) IUser(sx.blah.discord.handle.obj.IUser) FriendlyException(com.sedmelluq.discord.lavaplayer.tools.FriendlyException) DefaultAudioPlayerManager(com.sedmelluq.discord.lavaplayer.player.DefaultAudioPlayerManager) Semaphore(java.util.concurrent.Semaphore) ReactionAddEvent(sx.blah.discord.handle.impl.events.guild.channel.message.reaction.ReactionAddEvent) EventSubscriber(sx.blah.discord.api.events.EventSubscriber) Playlist(com.discordbolt.boltbot.modules.music.playlists.Playlist) AudioLoadResultHandler(com.sedmelluq.discord.lavaplayer.player.AudioLoadResultHandler) AudioConfiguration(com.sedmelluq.discord.lavaplayer.player.AudioConfiguration) AudioPlayerManager(com.sedmelluq.discord.lavaplayer.player.AudioPlayerManager) ChannelUtil(com.discordbolt.boltbot.utils.ChannelUtil) IGuild(sx.blah.discord.handle.obj.IGuild) List(java.util.List) MusicModule(com.discordbolt.boltbot.modules.music.MusicModule) AudioSourceManagers(com.sedmelluq.discord.lavaplayer.source.AudioSourceManagers) AudioTrack(com.sedmelluq.discord.lavaplayer.track.AudioTrack) StandardAudioDataFormats(com.sedmelluq.discord.lavaplayer.format.StandardAudioDataFormats) AudioLoadResultHandler(com.sedmelluq.discord.lavaplayer.player.AudioLoadResultHandler) AudioTrack(com.sedmelluq.discord.lavaplayer.track.AudioTrack) AudioPlaylist(com.sedmelluq.discord.lavaplayer.track.AudioPlaylist) FriendlyException(com.sedmelluq.discord.lavaplayer.tools.FriendlyException)

Example 19 with IGuild

use of sx.blah.discord.handle.obj.IGuild in project BoltBot by DiscordBolt.

the class StreamAnnouncer method sendAnnouncement.

private void sendAnnouncement(PresenceUpdateEvent e) {
    for (IGuild guild : client.getGuilds()) {
        long channelID = GuildData.getById(guild.getLongID()).get().getStreamAnnounceChannel();
        if (channelID == 0L)
            continue;
        if (!guild.getUsers().contains(e.getUser()))
            continue;
        ChannelUtil.sendMessage(guild.getChannelByID(channelID), e.getUser().mention() + " just started streaming " + e.getNewPresence().getPlayingText().orElse("") + "\nCome join in on the fun! <" + e.getNewPresence().getStreamingUrl().orElse("") + ">");
    }
}
Also used : IGuild(sx.blah.discord.handle.obj.IGuild)

Example 20 with IGuild

use of sx.blah.discord.handle.obj.IGuild in project KaellyBot by Kaysoro.

the class StatCommand method request.

@Override
public boolean request(IMessage message) {
    if (super.request(message)) {
        Matcher m = getMatcher(message);
        m.find();
        Language lg = Translator.getLanguageFrom(message.getChannel());
        int totalUser = 0;
        for (IGuild guild : ClientConfig.DISCORD().getGuilds()) totalUser += guild.getUsers().size();
        String answer = Translator.getLabel(lg, "stat.request").replace("{guilds.size}", String.valueOf(ClientConfig.DISCORD().getGuilds().size())).replace("{users.size}", String.valueOf(ClientConfig.DISCORD().getUsers().size())).replace("{users_max.size}", String.valueOf(totalUser));
        Message.sendText(message.getChannel(), answer);
    }
    return false;
}
Also used : Language(enums.Language) Matcher(java.util.regex.Matcher) IGuild(sx.blah.discord.handle.obj.IGuild)

Aggregations

IGuild (sx.blah.discord.handle.obj.IGuild)31 IUser (sx.blah.discord.handle.obj.IUser)13 EmbedBuilder (sx.blah.discord.util.EmbedBuilder)9 IChannel (sx.blah.discord.handle.obj.IChannel)7 ArrayList (java.util.ArrayList)5 IRole (sx.blah.discord.handle.obj.IRole)5 EventSubscriber (sx.blah.discord.api.events.EventSubscriber)4 IMessage (sx.blah.discord.handle.obj.IMessage)4 DiscordException (sx.blah.discord.util.DiscordException)4 WebGuild (com.cloudcraftgaming.discal.api.object.web.WebGuild)3 HashMap (java.util.HashMap)3 List (java.util.List)3 MissingPermissionsException (sx.blah.discord.util.MissingPermissionsException)3 EventColor (com.cloudcraftgaming.discal.api.enums.event.EventColor)2 EventData (com.cloudcraftgaming.discal.api.object.event.EventData)2 Calendar (com.google.api.services.calendar.Calendar)2 Language (enums.Language)2 FileWriter (java.io.FileWriter)2 IOException (java.io.IOException)2 SimpleDateFormat (java.text.SimpleDateFormat)2