internal static SocketDMChannel Create(DiscordSocketClient discord, ClientState state, Model model) { var entity = new SocketDMChannel(discord, model.Id, discord.GetOrCreateTemporaryUser(state, model.Recipients.Value[0])); entity.Update(state, model); return(entity); }
internal static SocketDMChannel Create(DiscordSocketClient discord, ClientState state, ulong channelId, API.User recipient) { var entity = new SocketDMChannel(discord, channelId, discord.GetOrCreateTemporaryUser(state, recipient)); entity.Update(state, recipient); return(entity); }
/// <exception cref="InvalidOperationException">Unexpected channel type is created.</exception> internal static ISocketPrivateChannel CreatePrivate(DiscordSocketClient discord, ClientState state, Model model) { return(model.Type switch { ChannelType.DM => SocketDMChannel.Create(discord, state, model), ChannelType.Group => SocketGroupChannel.Create(discord, state, model), _ => throw new InvalidOperationException($"Unexpected channel type: {model.Type}"), });
/// <exception cref="NotSupportedException">Unexpected <see cref="ISocketMessageChannel"/> type.</exception> public static SocketMessage RemoveMessage(ISocketMessageChannel channel, DiscordSocketClient discord, ulong id) { return(channel switch { SocketDMChannel dmChannel => dmChannel.RemoveMessage(id), SocketGroupChannel groupChannel => groupChannel.RemoveMessage(id), SocketTextChannel textChannel => textChannel.RemoveMessage(id), _ => throw new NotSupportedException($"Unexpected {nameof(ISocketMessageChannel)} type."), });
internal static ISocketPrivateChannel CreatePrivate(DiscordSocketClient discord, ClientState state, Model model) { switch (model.Type) { case ChannelType.DM: return(SocketDMChannel.Create(discord, state, model)); case ChannelType.Group: return(SocketGroupChannel.Create(discord, state, model)); default: throw new InvalidOperationException($"Unexpected channel type: {model.Type}"); } }
/// <inheritdoc /> public IAsyncEnumerable <IReadOnlyCollection <IMessage> > GetMessagesAsync(IMessage fromMessage, Direction dir, int limit = 100, RequestOptions options = null) => SocketDMChannel.GetMessagesAsync(fromMessage, dir, limit, options) .Select(x => x .Select(MessageAbstractionExtensions.Abstract) .ToArray());
/// <inheritdoc /> public async Task <IMessage> GetMessageAsync(ulong id, RequestOptions options = null) => (await SocketDMChannel.GetMessageAsync(id, options)) ?.Abstract();
/// <inheritdoc /> public IReadOnlyCollection <ISocketMessage> GetCachedMessages(IMessage fromMessage, Direction dir, int limit = 100) => SocketDMChannel.GetCachedMessages(fromMessage, dir, limit) .Select(SocketMessageAbstractionExtensions.Abstract) .ToArray();
/// <summary> /// Converts an existing <see cref="SocketDMChannel"/> to an abstracted <see cref="ISocketDMChannel"/> value. /// </summary> /// <param name="socketDMChannel">The existing <see cref="SocketDMChannel"/> to be abstracted.</param> /// <exception cref="ArgumentNullException">Throws for <paramref name="socketDMChannel"/>.</exception> /// <returns>An <see cref="ISocketDMChannel"/> that abstracts <paramref name="socketDMChannel"/>.</returns> public static ISocketDMChannel Abstract(this SocketDMChannel socketDMChannel) => new SocketDMChannelAbstraction(socketDMChannel);
/// <inheritdoc /> public Task TriggerTypingAsync(RequestOptions options = null) => SocketDMChannel.TriggerTypingAsync(options);
/// <inheritdoc /> public async Task <IRestUserMessage> SendFileAsync(Stream stream, string filename, string text, bool isTTS = false, Embed embed = null, RequestOptions options = null, bool isSpoiler = false, AllowedMentions allowedMentions = null, MessageReference messageReference = null) => RestUserMessageAbstractionExtensions.Abstract( await SocketDMChannel.SendFileAsync(stream, filename, text, isTTS, embed, options, isSpoiler, allowedMentions, messageReference));
/// <inheritdoc /> public Task DeleteMessageAsync(ulong messageId, RequestOptions options = null) => SocketDMChannel.DeleteMessageAsync(messageId, options);
/// <inheritdoc /> public Task CloseAsync(RequestOptions options = null) => SocketDMChannel.CloseAsync(options);
/// <inheritdoc /> public async Task <IRestUserMessage> SendFileAsync(string filePath, string text, bool isTTS = false, Embed embed = null, RequestOptions options = null, bool isSpoiler = false, AllowedMentions allowedMentions = null) => RestUserMessageAbstractionExtensions.Abstract( await SocketDMChannel.SendFileAsync(filePath, text, isTTS, embed, options, isSpoiler, allowedMentions));
/// <inheritdoc /> public async Task <IReadOnlyCollection <IRestMessage> > GetPinnedMessagesAsync(RequestOptions options = null) => (await SocketDMChannel.GetPinnedMessagesAsync(options)) .Select(RestMessageAbstractionExtensions.Abstract) .ToArray();
/// <inheritdoc /> public Task DeleteMessageAsync(IMessage message, RequestOptions options = null) => SocketDMChannel.DeleteMessageAsync(message, options);
/// <inheritdoc /> public async Task <IUserMessage> ModifyMessageAsync(ulong messageId, Action <MessageProperties> func, RequestOptions options = null) => (await SocketDMChannel.ModifyMessageAsync(messageId, func, options)) ?.Abstract();
/// <inheritdoc /> public IDisposable EnterTypingState(RequestOptions options = null) => SocketDMChannel.EnterTypingState(options);
/// <inheritdoc /> public async Task <IRestUserMessage> SendMessageAsync(string text = null, bool isTTS = false, Embed embed = null, RequestOptions options = null, AllowedMentions allowedMentions = null, MessageReference messageReference = null) => RestUserMessageAbstractionExtensions.Abstract( await SocketDMChannel.SendMessageAsync(text, isTTS, embed, options, allowedMentions, messageReference));
/// <inheritdoc /> public ISocketMessage GetCachedMessage(ulong id) => SocketDMChannel.GetCachedMessage(id) ?.Abstract();
/// <inheritdoc cref="SocketDMChannel.ToString" /> public override string ToString() => SocketDMChannel.ToString();
/// <inheritdoc /> public IReadOnlyCollection <ISocketMessage> GetCachedMessages(int limit = 100) => SocketDMChannel.GetCachedMessages(limit) .Select(SocketMessageAbstractionExtensions.Abstract) .ToArray();
/// <summary> /// Constructs a new <see cref="SocketDMChannelAbstraction"/> around an existing <see cref="WebSocket.SocketDMChannel"/>. /// </summary> /// <param name="socketDMChannel">The value to use for <see cref="WebSocket.SocketDMChannel"/>.</param> /// <exception cref="ArgumentNullException">Throws for <paramref name="socketDMChannel"/>.</exception> public SocketDMChannelAbstraction(SocketDMChannel socketDMChannel) : base(socketDMChannel) { }
/// <inheritdoc /> public async Task <IRestUserMessage> SendFileAsync(Stream stream, string filename, string text, bool isTTS = false, Embed embed = null, RequestOptions options = null) => RestUserMessageAbstractionExtensions.Abstract( await SocketDMChannel.SendFileAsync(stream, filename, text, isTTS, embed, options));