/// <summary> /// Gets the snowflake identifier values of the users in the voice channel specified by /// <paramref name="voiceChannelId"/> (the snowflake identifier of the voice channel). /// </summary> /// <param name="guildId">the guild identifier snowflake where the channel is in</param> /// <param name="voiceChannelId">the snowflake identifier of the voice channel</param> /// <returns> /// a task that represents the asynchronous operation /// <para>the snowflake identifier values of the users in the voice channel</para> /// </returns> public Task <IEnumerable <ulong> > GetChannelUsersAsync(ulong guildId, ulong voiceChannelId) { var guild = _baseSocketClient.GetGuild(guildId) ?? throw new ArgumentException("Invalid or inaccessible guild: " + guildId, nameof(guildId)); var channel = guild.GetVoiceChannel(voiceChannelId) ?? throw new ArgumentException("Invalid or inaccessible voice channel: " + voiceChannelId, nameof(voiceChannelId)); return(Task.FromResult(channel.Users.Select(s => s.Id))); }
public async Task ServerInfo(ICommand command) { SocketGuild guild; if (command["ServerNameOrId"].AsId.HasValue) { guild = _client.GetGuild(command["ServerNameOrId"].AsId.Value); } else { guild = _client.Guilds.FirstOrDefault(x => x.Name == command["ServerNameOrId"]) as SocketGuild; } if (guild == null) { await command.ReplyError("No guild with this name or ID."); return; } var owner = (IGuildUser)guild.Owner ?? await _client.Rest.GetGuildUserAsync(guild.Id, guild.OwnerId); var embed = new EmbedBuilder() .WithTitle(guild.Name) .WithThumbnailUrl(guild.IconUrl) .AddField(x => x.WithIsInline(true).WithName("ID").WithValue(guild.Id)) .AddField(x => x.WithIsInline(true).WithName("Owner").WithValue($"{owner.Username}#{owner.Discriminator}")) .AddField(x => x.WithIsInline(true).WithName("Owner ID").WithValue(guild.OwnerId)) .AddField(x => x.WithIsInline(true).WithName("Members").WithValue(guild.MemberCount)) .AddField(x => x.WithIsInline(true).WithName("Created").WithValue(guild.CreatedAt.ToString(@"yyyy\/MM\/dd H:mm:ss UTC"))); await command.Reply(embed.Build()); }
public static SocketGuild GetPrimaryGuild(this BaseSocketClient client) => client.GetGuild(405806471578648588); //yes hardcoded, the functions that use this guild are not meant for volte selfhosters anyways
private void OnUpdate(object state) { TaskHelper.FireForget(async() => { lock (_updatingLock) { if (_updating) { return; // Skip if the previous update is still running } _updating = true; } try { foreach (var settings in await _settings.Read <ScheduleSettings>()) { if (settings.Calendars.OfType <UpcomingScheduleCalendar>().Count() <= 0) { continue; } var targetToday = DateTime.UtcNow.Add(settings.TimezoneOffset).Date; if (targetToday <= settings.LastUpcomingCalendarsUpdate.Date) { continue; // Already updated today (in target timezone) } var guild = _client.GetGuild(settings.ServerId) as IGuild; if (guild == null) { continue; } var logger = _logger.WithScope(guild); foreach (var calendar in settings.Calendars.OfType <UpcomingScheduleCalendar>()) { try { var channel = await guild.GetTextChannelAsync(calendar.ChannelId); var message = channel != null ? (await channel.GetMessageAsync(calendar.MessageId)) as IUserMessage : null; if (message == null) { await _settings.Modify(guild.Id, (ScheduleSettings s) => s.Calendars.RemoveAll(x => x.MessageId == calendar.MessageId)); logger.LogInformation("Removed deleted calendar {CalendarMessageId}", calendar.MessageId); continue; } var(text, embed) = Modules.ScheduleModule.BuildCalendarMessage(calendar, settings); await message.ModifyAsync(x => { x.Content = text; x.Embed = embed; }); logger.LogInformation("Updated calendar {CalendarMessageId}", calendar.MessageId); } catch (Exception ex) { logger.LogError(ex, "Failed to update calendar {CalendarMessageId}", calendar.MessageId); } } await _settings.Modify(guild.Id, (ScheduleSettings s) => s.LastUpcomingCalendarsUpdate = targetToday); } } catch (Exception ex) { _logger.LogError(ex, "Failed to update calendars"); } finally { _updating = false; } }); }
private async Task UpdateFeed(DaumCafeFeed feed, ulong serverId, CancellationToken ct) { var guild = _client.GetGuild(serverId); if (guild == null) { return; } var channel = guild.GetTextChannel(feed.TargetChannel); if (channel == null) { return; } var logger = _logger.WithScope(channel); // Choose a session DaumCafeSession session; if (feed.CredentialId != Guid.Empty) { if (!_sessionCache.TryGetValue(feed.CredentialId, out var dateSession) || DateTime.Now - dateSession.Item1 > SessionLifetime) { var credential = await Modules.CafeModule.GetCredential(_credentialsService, feed.CredentialUser, feed.CredentialId, ct); try { session = await DaumCafeSession.Create(credential.Login, credential.Password, ct); _sessionCache[feed.CredentialId] = Tuple.Create(DateTime.Now, session); } catch (Exception ex) when(ex is CountryBlockException || ex is LoginFailedException) { session = DaumCafeSession.Anonymous; _sessionCache[feed.CredentialId] = Tuple.Create(DateTime.Now, session); } } else { session = dateSession.Item2; } } else { session = DaumCafeSession.Anonymous; } // Get last post ID int lastPostId; try { lastPostId = await session.GetLastPostId(feed.CafeId, feed.BoardId, ct); } catch (WebException ex) when(ex.Response is HttpWebResponse r && r.StatusCode == HttpStatusCode.Forbidden) { logger.LogInformation("Cafe feed {CafeId}/{BoardId} update forbidden", feed.CafeId, feed.BoardId); return; } // If new feed -> just store the last post ID and return if (feed.LastPostId < 0) { await _settings.Modify <MediaSettings>(serverId, s => { var current = s.DaumCafeFeeds.FirstOrDefault(x => x.Id == feed.Id); if (current != null && current.LastPostId < 0) { current.LastPostId = lastPostId; } }); return; } var currentPostId = feed.LastPostId; if (lastPostId <= feed.LastPostId) { return; } logger.LogInformation("Updating feed {CafeId}/{BoardId} found {PostCount} new posts ({FirstPostId} to {LastPostId})", feed.CafeId, feed.BoardId, lastPostId - currentPostId, currentPostId + 1, lastPostId, guild.Name, guild.Id); while (lastPostId > currentPostId) { var preview = await CreatePreview(session, feed.CafeId, feed.BoardId, currentPostId + 1, ct); if (!guild.CurrentUser.GetPermissions(channel).SendMessages) { logger.LogInformation("Can't update Cafe feed because of permissions"); currentPostId = lastPostId; break; } await channel.SendMessageAsync(preview.Item1.Sanitise(), false, preview.Item2); currentPostId++; } await _settings.Modify <MediaSettings>(serverId, settings => { var current = settings.DaumCafeFeeds.FirstOrDefault(x => x.Id == feed.Id); if (current != null && current.LastPostId < currentPostId) { current.LastPostId = currentPostId; } }); }
public static SocketGuild GetPrimaryGuild(this BaseSocketClient client) => client.GetGuild(405806471578648588);
public virtual ISocketGuildWrapper?GetGuild(ulong id) { return(new SocketGuildWrapper(_baseSocketClient.GetGuild(id))); }