示例#1
0
        public async Task CreatePasta(EventContext e)
        {
            if (e.Arguments.Count < 2)
            {
                e.ErrorEmbed(e.Locale.GetString("createpasta_error_no_content"))
                .ToEmbed().QueueToChannel(e.Channel);
                return;
            }

            ArgObject arg = e.Arguments.FirstOrDefault();

            arg = arg.TakeString();
            string id = arg.Argument;

            arg = arg.Next();
            string text = arg.TakeUntilEnd().Argument;

            if (Regex.IsMatch(text, "(http[s]://)?((discord.gg)|(discordapp.com/invite))/([A-Za-z0-9]+)", RegexOptions.IgnoreCase))
            {
                throw new PastaInviteException();
            }

            using (var context = new MikiContext())
            {
                await GlobalPasta.AddAsync(context, id, text, (long)e.Author.Id);

                await context.SaveChangesAsync();
            }

            e.SuccessEmbed(e.Locale.GetString("miki_module_pasta_create_success", id))
            .QueueToChannel(e.Channel);
        }