Пример #1
0
        public async Task ModifyeRichMessageAsync(ulong id, [FromBody, Required] Models.RichMessage message)
        {
            var config = _config.Get();

            _ = Task.Run(async() =>
            {
                foreach (var rmc in config.RMConfig)
                {
                    var guild = _client.GetGuild(rmc.GuildId);
                    if (guild == null)
                    {
                        continue;
                    }

                    var channel = guild.GetTextChannel(rmc.ChannelId);
                    if (channel == null)
                    {
                        continue;
                    }

                    var msg = await channel.GetMessageAsync(id);
                    if (msg == null)
                    {
                        continue;
                    }

                    await((IUserMessage)msg).ModifyAsync(x => x.Embed = message.ToEmbed());
                    break;
                }
            });

            await "Message modified!".ToResponse(200).ExecuteResultAsync(ControllerContext);
        }
Пример #2
0
        public async Task PostRichMessageAsync([FromBody, Required] Models.RichMessage message, [FromQuery] bool?mention)
        {
            var config = _config.Get();

            if (!mention.HasValue)
            {
                mention = false;
            }

            var msgList = new List <ulong>();
            var rmcs    = config.RMConfig.Where(x => x.Type == message.MessageType);

            foreach (var rmc in rmcs)
            {
                if (rmc.Type == Models.RichMessageType.UserNotify)
                {
                    var user = _client.GetUser(rmc.ChannelId);
                    if (user == null)
                    {
                        continue;
                    }

                    var pwCh = await user.GetOrCreateDMChannelAsync();

                    var pwm = await pwCh.SendMessageAsync("", embed : message.ToEmbed());

                    msgList.Add(pwm.Id);
                    continue;
                }

                var guild = _client.GetGuild(rmc.GuildId);
                if (guild == null)
                {
                    continue;
                }

                var channel = guild.GetTextChannel(rmc.ChannelId);
                if (channel == null)
                {
                    continue;
                }

                string mentionContent = "";
                if (mention.Value)
                {
                    var role = guild.GetRole(rmc.RoleId);
                    if (role != null)
                    {
                        mentionContent = role.Mention;
                    }
                }

                var msg = await channel.SendMessageAsync(mentionContent, embed : message.ToEmbed());

                if (msg != null)
                {
                    msgList.Add(msg.Id);
                }
            }

            if (msgList.Count == 0)
            {
                await "Message not send!".ToResponse(400).ExecuteResultAsync(ControllerContext);
                return;
            }

            if (msgList.Count > 1)
            {
                await "Message sended!".ToResponseRich(msgList).ExecuteResultAsync(ControllerContext);
                return;
            }

            await "Message sended!".ToResponseRich(msgList.First()).ExecuteResultAsync(ControllerContext);
        }