コード例 #1
0
ファイル: Context.cs プロジェクト: Tiefseetauchner/PluralKit
    public async Task <Message> Reply(string text = null, Embed embed = null, AllowedMentions?mentions = null)
    {
        var botPerms = await BotPermissions;

        if (!botPerms.HasFlag(PermissionSet.SendMessages))
        {
            // Will be "swallowed" during the error handler anyway, this message is never shown.
            throw new PKError("PluralKit does not have permission to send messages in this channel.");
        }

        if (embed != null && !botPerms.HasFlag(PermissionSet.EmbedLinks))
        {
            throw new PKError("PluralKit does not have permission to send embeds in this channel. Please ensure I have the **Embed Links** permission enabled.");
        }

        var msg = await Rest.CreateMessage(Channel.Id, new MessageRequest
        {
            Content = text,
            Embeds  = embed != null ? new[] { embed } : null,
            // Default to an empty allowed mentions object instead of null (which means no mentions allowed)
            AllowedMentions = mentions ?? new AllowedMentions()
        });

        if (embed != null)
        {
            // Sensitive information that might want to be deleted by :x: reaction is typically in an embed format (member cards, for example)
            // This may need to be changed at some point but works well enough for now
            await _commandMessageService.RegisterMessage(msg.Id, msg.ChannelId, Author.Id);
        }

        return(msg);
    }
コード例 #2
0
ファイル: IUserExtensions.cs プロジェクト: emre1702/BonusBot
        public static async Task <IUserMessage> SendErrorMessage(this IUser user, string?message   = null, bool isTTS = false, Embed?embed = null, RequestOptions?options = null, AllowedMentions?allowedMentions = null,
                                                                 MessageReference?messageReference = null, MessageComponent?components = null, ISticker[]?stickers = null, Embed[]?embeds = null)
        {
            var dmChannel = await user.CreateDMChannelAsync();

            if (dmChannel is IErrorChannel errorChannel)
            {
                return(await errorChannel.SendErrorMessageAsync(message ?? "?"));
            }
            else
            {
                return(await dmChannel.SendMessageAsync(message, isTTS, embed, options, allowedMentions, messageReference, components, stickers, embeds));
            }
        }
コード例 #3
0
        /// <summary>
        /// Responds to the interaction message and returns the original message
        /// </summary>
        /// <param name="cmd"></param>
        /// <param name="text"></param>
        /// <param name="embeds"></param>
        /// <param name="isTTS"></param>
        /// <param name="ephemeral"></param>
        /// <param name="allowedMentions"></param>
        /// <param name="components"></param>
        /// <param name="embed"></param>
        /// <param name="options"></param>
        /// <returns>The original interaction message</returns>
        public static async Task <RestInteractionMessage> Respond(this SocketSlashCommand cmd, string?text = null, Embed[]?embeds = null, bool isTTS = false, bool ephemeral = false, AllowedMentions?allowedMentions = null, MessageComponent?components = null, Embed?embed = null, RequestOptions?options = null)
        {
            await cmd.RespondAsync(text, embeds, isTTS, ephemeral, allowedMentions, components, embed, options);

            return(await cmd.GetOriginalResponseAsync());
        }
コード例 #4
0
        public async Task <IUserMessage> ReplyToUserAsync(string?message = null, bool isTTS = false, Embed?embed = null, RequestOptions?options = null, AllowedMentions?allowedMentions = null,
                                                          MessageReference?messageReference = null, MessageComponent?components = null, ISticker[]?stickers = null, Embed[]?embeds = null)
        {
            var channel = await Context.User.CreateDMChannelAsync();

            return(await channel.SendMessageAsync(message, isTTS, embed, options, allowedMentions, messageReference, components, stickers, embeds));
        }
コード例 #5
0
 public Task <IUserMessage> ReplyErrorToUserAsync(string?message = null, bool isTTS = false, Embed?embed = null, RequestOptions?options = null, AllowedMentions?allowedMentions = null,
                                                  MessageReference?messageReference = null, MessageComponent?components = null, ISticker[]?stickers = null, Embed[]?embeds = null)
 => Context.User.SendErrorMessage(message, isTTS, embed, options, allowedMentions, messageReference, components, stickers, embeds);
コード例 #6
0
 public Task <IUserMessage> SendFileAsync(Stream stream, string filename, string?text = null, bool isTTS                  = false, Embed?embed = null, RequestOptions?options = null, bool isSpoiler = false, AllowedMentions?allowedMentions = null,
                                          MessageReference?messageReference           = null, MessageComponent?components = null, ISticker[]?stickers = null, Embed[]?embeds  = null)
 {
     throw new NotImplementedException();
 }
コード例 #7
0
 public Task <IUserMessage> SendFilesAsync(IEnumerable <FileAttachment> attachments, string?text = null, bool isTTS = false, Embed?embed                      = null,
                                           RequestOptions?options = null, AllowedMentions?allowedMentions           = null, MessageReference?messageReference = null, MessageComponent?components = null,
                                           ISticker[]?stickers    = null, Embed[]?embeds = null, MessageFlags flags = MessageFlags.None)
 {
     throw new NotImplementedException();
 }
コード例 #8
0
 public Task <IUserMessage> SendMessageAsync(string?text = null, bool isTTS = false, Embed?embed = null, RequestOptions?options = null,
                                             AllowedMentions?allowedMentions = null, MessageReference?messageReference = null,
                                             MessageComponent?components     = null, ISticker[]?stickers = null, Embed[]?embeds = null, MessageFlags flags = MessageFlags.None)
 => Task.FromResult(_user.AddWebMessage(text, this));
コード例 #9
0
        protected async Task <IUserMessage?> ReplyToDirectMessageAsync(string?message = null, bool isTextToSpeech = false, Embed?embed = null, RequestOptions?options = null, AllowedMentions?allowedMentions = null, MessageReference?messageReference = null)
        {
            var messageContext = Context.Message;

            if (messageContext.Channel is SocketDMChannel)
            {
                return(await ReplyAsync(message, isTextToSpeech, embed, options ?? _requestOptions, allowedMentions, messageReference));
            }

            var dmChannel = await messageContext.Author.GetOrCreateDMChannelAsync(options ?? _requestOptions);

            return(await dmChannel.SendMessageAsync(message, isTextToSpeech, embed, options ?? _requestOptions, allowedMentions, messageReference));
        }
コード例 #10
0
        protected override async Task <IUserMessage?> ReplyAsync(string?message = null, bool isTextToSpeech = false, Embed?embed = null, RequestOptions?options = null, AllowedMentions?allowedMentions = null, MessageReference?messageReference = null)
        {
            var channelContext = Context.Channel;

            if (Context.Message.Channel is SocketDMChannel)
            {
                return(await channelContext.SendMessageAsync(message, isTextToSpeech, embed, options ?? _requestOptions, allowedMentions, messageReference));
            }

            var guildContext = Context.Guild;

            if (guildContext.GetUser(Context.Client.CurrentUser.Id).GetPermissions(guildContext.GetChannel(channelContext.Id)).SendMessages)
            {
                return(await channelContext.SendMessageAsync(message, isTextToSpeech, embed, options ?? _requestOptions, allowedMentions, messageReference));
            }

            return(null);
        }