public static Task <MessageJsonModel> FetchWebhookMessageAsync(this IRestApiClient client, Snowflake webhookId, string token, Snowflake messageId, Snowflake?threadId = null, IRestRequestOptions options = null, CancellationToken cancellationToken = default) { var queryParameters = threadId != null ? new KeyValuePair <string, object>[] { new("thread_id", threadId.Value) }
internal CachedUserMessage(DiscordClient client, MessageModel model, ICachedMessageChannel channel, CachedUser author) : base(client, model, channel, author) { IsTextToSpeech = model.Tts.GetValueOrDefault(); Nonce = model.Nonce.GetValueOrDefault(); WebhookId = model.WebhookId.GetValueOrDefault(); Update(model); }
public Message(Snowflake id, Snowflake channelId, Snowflake guildId, User author, GuildMember member, string content, DateTime timestamp, DateTime?editedTimestamp, bool tts, bool mentionEveryone, User[] mentions, Role[] mentionRoles, ChannelMention[] mentionChannels, Attachment[] attachments, Embed[] embeds, Reaction[] reactions, bool pinned, Snowflake?webhookId, MessageType type, MessageActivity?activity, MessageApplication?application, MessageReference?messageReference, MessageFlags?flags) { Id = id; ChannelId = channelId; GuildId = guildId; Author = author; Member = member; Content = content; Timestamp = timestamp; EditedTimestamp = editedTimestamp; TTS = tts; MentionEveryone = mentionEveryone; Mentions = mentions; MentionRoles = mentionRoles; MentionChannels = mentionChannels; Attachments = attachments; Embeds = embeds; Reactions = reactions; Pinned = pinned; WebhookId = webhookId; Type = type; Activity = activity; Application = application; MessageReference = messageReference; Flags = flags; }
/// <summary> /// Modifies a message sent by this webhook. /// </summary> /// <param name="client"> The webhook client. </param> /// <param name="messageId"> The ID of the message to modify. </param> /// <param name="action"> The action specifying what properties to modify. </param> /// <param name="threadId"> The ID of the thread (within the webhook's channel) in which this request should be performed. </param> /// <param name="options"> The optional request options. </param> /// <param name="cancellationToken"> The cancellation token to observe. </param> /// <returns> /// A <see cref="Task{TResult}"/> representing the asynchronous request /// that wraps the updated <see cref="IUserMessage"/>. /// </returns> public static Task <IUserMessage> ModifyMessageAsync(this IWebhookClient client, Snowflake messageId, Action <ModifyWebhookMessageActionProperties> action, Snowflake?threadId = null, IRestRequestOptions options = null, CancellationToken cancellationToken = default) { return(client.RestClient.ModifyWebhookMessageAsync(client.Id, client.Token, messageId, action, threadId, options, cancellationToken)); }
/// <summary> /// Gets a list of user guilds the current bot is in. /// </summary> /// <exception cref="DiscordHttpApiException"></exception> public async Task <DiscordUserGuild[]> GetCurrentUserGuilds(int?limit = null, Snowflake?baseGuildId = null, GuildGetStrategy getStrategy = GuildGetStrategy.After) { UrlParametersBuilder paramBuilder = new UrlParametersBuilder(); if (baseGuildId.HasValue) { paramBuilder.Add(getStrategy.ToString().ToLower(), baseGuildId.ToString()); } if (limit.HasValue) { paramBuilder.Add("limit", limit.Value.ToString()); } DiscordApiData data = await rest.Get($"users/@me/guilds{paramBuilder.ToQueryString()}", "users/@me/guilds").ConfigureAwait(false); DiscordUserGuild[] guilds = new DiscordUserGuild[data.Values.Count]; for (int i = 0; i < guilds.Length; i++) { guilds[i] = new DiscordUserGuild(data.Values[i]); } return(guilds); }
public InviteCreatedEventArgs( Snowflake?guildId, Snowflake channelId, string code, DateTimeOffset createdAt, IUser inviter, int maxAge, int maxUses, InviteTargetType?targetType, IUser targetUser, IApplication targetApplication, bool isTemporaryMembership, int uses) { GuildId = guildId; ChannelId = channelId; Code = code; CreatedAt = createdAt; Inviter = inviter; MaxAge = maxAge; MaxUses = maxUses; TargetType = targetType; TargetUser = targetUser; TargetApplication = targetApplication; IsTemporaryMembership = isTemporaryMembership; Uses = uses; }
/// <summary> /// Fetch a message sent by this webhook. /// </summary> /// <param name="client"> The webhook client. </param> /// <param name="messageId"> The ID of the message to fetch. </param> /// <param name="threadId"> The ID of the thread (within the webhook's channel) in which this request should be performed. </param> /// <param name="options"> The optional request options. </param> /// <param name="cancellationToken"> The cancellation token to observe. </param> /// <returns> /// A <see cref="Task"/> representing the asynchronous request. /// </returns> public static Task <IUserMessage> FetchMessageAsync(this IWebhookClient client, Snowflake messageId, Snowflake?threadId = null, IRestRequestOptions options = null, CancellationToken cancellationToken = default) { return(client.RestClient.FetchWebhookMessageAsync(client.Id, client.Token, messageId, threadId, options, cancellationToken)); }
internal RestUserMessage(RestDiscordClient client, MessageModel model) : base(client, model) { IsTextToSpeech = model.Tts.Value; Nonce = model.Nonce.GetValueOrDefault(); WebhookId = model.WebhookId.GetValueOrDefault(); Update(model); }
/// <summary> /// Sets the role to use as a default @everyone role. /// </summary> /// <param name="serverID">The server.</param> /// <param name="roleID">The role to use.</param> /// <returns>A modification result which may or may not have succeeded.</returns> public async Task <Result> SetDefaultUserRoleAsync ( Snowflake serverID, Snowflake?roleID ) { var getSettingsResult = await GetOrCreateServerRoleplaySettingsAsync(serverID); if (!getSettingsResult.IsSuccess) { return(Result.FromError(getSettingsResult)); } var settings = getSettingsResult.Entity; if (settings.DefaultUserRole == roleID) { return(new UserError("That's already the default user role.")); } settings.DefaultUserRole = roleID; await _database.SaveChangesAsync(); return(Result.FromSuccess()); }
/// <summary> /// Executes this webhook, i.e. sends a message from it. /// </summary> /// <param name="client"> The webhook client. </param> /// <param name="message"> The message to send. </param> /// <param name="threadId"> The ID of the thread (within the webhook's channel) in which this request should be performed. </param> /// <param name="wait"> Whether the API should return the sent message object. </param> /// <param name="options"> The optional request options. </param> /// <param name="cancellationToken"> The cancellation token to observe. </param> /// <returns> /// A <see cref="Task{TResult}"/> representing the asynchronous request /// that wraps the returned <see cref="IUserMessage"/> if <paramref name="wait"/> is <see langword="true"/>. /// </returns> public static Task <IUserMessage> ExecuteAsync(this IWebhookClient client, LocalWebhookMessage message, Snowflake?threadId = null, bool wait = false, IRestRequestOptions options = null, CancellationToken cancellationToken = default) { return(client.RestClient.ExecuteWebhookAsync(client.Id, client.Token, message, threadId, wait, options, cancellationToken)); }
async Task HandleVoiceServerUpdateEvent(DiscordApiData data) { Snowflake?guildId = data.GetSnowflake("guild_id"); if (guildId.HasValue) // Only guild voice channels are supported so far. { string token = data.GetString("token"); string endpoint = data.GetString("endpoint"); DiscordVoiceConnection connection; if (shard.Voice.TryGetVoiceConnection(guildId.Value, out connection)) { // Notify the connection of the server update await connection.OnVoiceServerUpdated(token, endpoint).ConfigureAwait(false); } else { throw new ShardCacheException($"Voice connection for guild {guildId.Value} was not in the cache!"); } } else { throw new NotImplementedException("Non-guild voice channels are not supported yet."); } }
/// <summary> /// Gets messages from a text channel. /// <para>Requires <see cref="DiscordPermission.ReadMessages"/>.</para> /// </summary> /// <exception cref="DiscordHttpApiException"></exception> public async Task <IReadOnlyList <DiscordMessage> > GetChannelMessages(Snowflake channelId, Snowflake?baseMessageId = null, int?limit = null, MessageGetStrategy getStrategy = MessageGetStrategy.Before) { UrlParametersBuilder builder = new UrlParametersBuilder(); if (baseMessageId.HasValue) { builder.Add(getStrategy.ToString().ToLower(), baseMessageId.Value.ToString()); } if (limit.HasValue) { builder.Add("limit", limit.Value.ToString()); } DiscordApiData data = await rest.Get($"channels/{channelId}/messages{builder.ToQueryString()}", $"channels/{channelId}/messages").ConfigureAwait(false); DiscordMessage[] messages = new DiscordMessage[data.Values.Count]; for (int i = 0; i < messages.Length; i++) { messages[i] = new DiscordMessage(this, data.Values[i]); } return(messages); }
public ExportRequest( Guild guild, Channel channel, string outputPath, ExportFormat format, Snowflake?after, Snowflake?before, PartitionLimit partitionLimit, bool shouldDownloadMedia, bool shouldReuseMedia, string dateFormat) { Guild = guild; Channel = channel; OutputPath = outputPath; Format = format; After = after; Before = before; PartitionLimit = partitionLimit; ShouldDownloadMedia = shouldDownloadMedia; ShouldReuseMedia = shouldReuseMedia; DateFormat = dateFormat; OutputBaseFilePath = GetOutputBaseFilePath( guild, channel, outputPath, format, after, before ); OutputBaseDirPath = Path.GetDirectoryName(OutputBaseFilePath) ?? OutputPath; OutputMediaDirPath = $"{OutputBaseFilePath}_Files{Path.DirectorySeparatorChar}"; }
private void CreateInteractionMethods ( Snowflake?guildID, IApplication application, out Func <IReadOnlyList <IApplicationCommandOption>, Task <Result <IReadOnlyList <IApplicationCommand> > > > updateMethod, CancellationToken ct) { if (guildID is null) { updateMethod = cs => _applicationAPI.BulkOverwriteGlobalApplicationCommandsAsync ( application.ID, cs.Select(c => (c.Name, c.Description, c.Options)).ToList(), ct ); return; } updateMethod = cs => _applicationAPI.BulkOverwriteGuildApplicationCommandsAsync ( application.ID, guildID.Value, cs.Select(c => (c.Name, c.Description, c.Options)).ToList(), ct ); }
/// <summary> /// Gets the best matching character for the given owner and name combination. If no owner is provided, then the /// global list is searched for a unique name. If no name is provided, then the user's current character is /// used. If neither are set, no character will ever be returned. /// </summary> /// <param name="guildID">The ID of the guild the user is on.</param> /// <param name="userID">The ID of the discord user.</param> /// <param name="name">The name of the character.</param> /// <param name="ct">The cancellation token in use.</param> /// <returns>A retrieval result which may or may not have succeeded.</returns> public async Task <Result <Character> > GetBestMatchingCharacterAsync ( Snowflake guildID, Snowflake?userID, string?name, CancellationToken ct = default ) { var getServer = await _servers.GetOrRegisterServerAsync(guildID, ct); if (!getServer.IsSuccess) { return(Result <Character> .FromError(getServer)); } var server = getServer.Entity; if (userID is null) { return(await _characters.GetBestMatchingCharacterAsync(server, null, name, ct)); } var getUser = await _users.GetOrRegisterUserAsync(userID.Value, ct); if (!getUser.IsSuccess) { return(Result <Character> .FromError(getUser)); } var user = getUser.Entity; return(await _characters.GetBestMatchingCharacterAsync(server, user, name, ct)); }
public TransientEmoji(Snowflake?id, string name) : base(new EmojiJsonModel { Id = id, Name = name }) { }
/* * Threads */ public static Task <IThreadChannel> CreatePublicThreadAsync(this ITextChannel channel, string name, Snowflake?messageId = null, TimeSpan?automaticArchiveDuration = null, IRestRequestOptions options = null, CancellationToken cancellationToken = default) { var client = channel.GetRestClient(); return(client.CreatePublicThreadAsync(channel.Id, name, messageId, automaticArchiveDuration, options, cancellationToken)); }
public RestRequestEnumerable <T> GetAuditLogsEnumerable <T>( int limit = 100, Snowflake?userId = null, Snowflake?startFromId = null, RestRequestOptions options = null) where T : RestAuditLog { throw new NotImplementedException(); }
public static IPagedEnumerable <IMember> EnumerateMembers(this IGuild guild, int limit, Snowflake?startFromId = null, IRestRequestOptions options = null) { var client = guild.GetRestClient(); return(client.EnumerateMembers(guild.Id, limit, startFromId, options)); }
internal DiscordGuildStoreChannel(DiscordHttpClient http, DiscordApiData data, Snowflake?guildId = null) : base(http, data, DiscordChannelType.GuildStore, guildId) { this.http = http; Nsfw = data.GetBoolean("nsfw") ?? false; ParentId = data.GetSnowflake("parent_id"); }
public RestMembersRequestEnumerator(RestDiscordClient client, Snowflake guildId, int limit, Snowflake?startFromId, RestRequestOptions options) : base(client, 1000, limit, options) { _guildId = guildId; _startFromId = startFromId; }
public RestGuildsRequestEnumerator(RestDiscordClient client, int limit, RetrievalDirection direction, Snowflake?startFromId, RestRequestOptions options) : base(client, 100, limit, options) { _direction = direction; _startFromId = startFromId; }
public Task <IReadOnlyList <T> > GetAuditLogsAsync <T>( int limit = 100, Snowflake?userId = null, Snowflake?startFromId = null, RestRequestOptions options = null) where T : RestAuditLog { throw new NotImplementedException(); }
/// <summary> /// Sets a snowflake value in this api data container. /// </summary> /// <exception cref="InvalidOperationException">Thrown if this data is not a container.</exception> public DiscordApiData SetSnowflake(string key, Snowflake?snowflake) { AssertContainer(); DiscordApiData apiValue = snowflake.HasValue ? new DiscordApiData(snowflake.Value) : new DiscordApiData(value: null); data[key] = apiValue; return(apiValue); }
public FetchMembersPagedEnumerator( IRestClient client, Snowflake guildId, int limit, Snowflake?startFromId, IRestRequestOptions options) : base(client, limit, options) { _guildId = guildId; _startFromId = startFromId; }
/// <exception cref="OperationCanceledException">Thrown if the gateway connection is closed while sending.</exception> internal async Task SendVoiceStateUpdatePayload(Snowflake guildId, Snowflake?channelId, bool isMute, bool isDeaf, CancellationToken cancellationToken) { await RepeatTrySendPayload(cancellationToken, "RequestGuildMembers", async() => { // Try to send the status update await socket.SendVoiceStateUpdatePayload(guildId, channelId, isMute, isDeaf).ConfigureAwait(false); }).ConfigureAwait(false); }
public RichActivityAsset( Snowflake?applicationId, Optional <string> id, Optional <string> text) { _applicationId = applicationId; Id = id.GetValueOrDefault(); Text = text.GetValueOrDefault(); }
public static IPagedEnumerable <IUser> EnumerateEventUsers(this IGuild guild, Snowflake eventId, int limit, RetrievalDirection direction = RetrievalDirection.After, Snowflake?startFromId = null, bool?withMember = null, IRestRequestOptions options = null) { var client = guild.GetRestClient(); return(client.EnumerateGuildEventUsers(guild.Id, eventId, limit, direction, startFromId, withMember, options)); }
public IntegrationDeletedEventArgs( Snowflake guildId, Snowflake integrationId, Snowflake?applicationId) { GuildId = guildId; IntegrationId = integrationId; ApplicationId = applicationId; }
/// <summary> /// Returns a guild for the specific ID /// </summary> /// <param name="guildId">ID of the guild</param> /// <returns>Guild with the specified ID</returns> public DiscordGuild GetGuild(Snowflake?guildId) { if (guildId.HasValue && guildId.Value.IsValid()) { return(Servers[guildId.Value]); } return(null); }