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());
}
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();
}
}
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.");
}
});
}
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("") + ">");
}
}
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;
}
Aggregations