Пример #1
0
        public async Task AddReplyAsync(SocketGuild guild, string mustContains, string reply, string compareType, bool disabled, bool caseSensitive, string channel)
        {
            if (BotState.AutoReplyItems.Any(o => o.MustContains == mustContains))
            {
                throw new ArgumentException($"Automatická odpověď **{mustContains}** již existuje.");
            }

            var item = new AutoReplyItem()
            {
                MustContains       = mustContains,
                IsDisabled         = disabled,
                ReplyMessage       = reply,
                CaseSensitive      = caseSensitive,
                GuildIDSnowflake   = guild.Id,
                ChannelIDSnowflake = channel == "*" ? (ulong?)null : Convert.ToUInt64(channel)
            };

            item.SetCompareType(compareType);

            await GrillBotRepository.AddAsync(item);

            await GrillBotRepository.CommitAsync();

            BotState.AutoReplyItems.Add(item);
        }
Пример #2
0
        public async Task AddReplyAsync(SocketGuild guild, string mustContains, string reply, string compareType, bool disabled, bool caseSensitive, string channel)
        {
            if (Data.Any(o => o.MustContains == mustContains))
            {
                throw new ArgumentException($"Automatická odpověď **{mustContains}** již existuje.");
            }

            var item = new AutoReplyItem()
            {
                MustContains       = mustContains,
                IsDisabled         = disabled,
                ReplyMessage       = reply,
                CaseSensitive      = caseSensitive,
                GuildIDSnowflake   = guild.Id,
                ChannelIDSnowflake = channel == "*" ? (ulong?)null : Convert.ToUInt64(channel)
            };

            item.SetCompareType(compareType);

            using var scope      = Provider.CreateScope();
            using var repository = scope.ServiceProvider.GetService <AutoReplyRepository>();
            await repository.AddItemAsync(item).ConfigureAwait(false);

            Data.Add(item);
        }
Пример #3
0
        private async Task <bool> TryReplyWithAbsolute(SocketUserMessage message, AutoReplyItem item)
        {
            if (!message.Content.Equals(item.MustContains, GetStringComparison(item)))
            {
                return(false);
            }

            if (item.CanReply())
            {
                item.CallsCount++;
                await message.Channel.SendMessageAsync(item.ReplyMessage.PreventMassTags()).ConfigureAwait(false);

                return(true);
            }

            return(false);
        }
Пример #4
0
        public async Task AddReplyAsync(string mustContains, string reply, string compareType, bool disabled = false, bool caseSensitive = false)
        {
            if (Data.Any(o => o.MustContains == mustContains))
            {
                throw new ArgumentException($"Automatická odpověď **{mustContains}** již existuje.");
            }

            var item = new AutoReplyItem()
            {
                MustContains  = mustContains,
                IsDisabled    = disabled,
                ReplyMessage  = reply,
                CaseSensitive = caseSensitive
            };

            item.SetCompareType(compareType);

            using (var repository = new GrillBotRepository(Config))
            {
                await repository.AutoReply.AddItemAsync(item).ConfigureAwait(false);
            }

            Data.Add(item);
        }
Пример #5
0
        public async Task AddItemAsync(AutoReplyItem item)
        {
            await Context.AutoReply.AddAsync(item).ConfigureAwait(false);

            await Context.SaveChangesAsync().ConfigureAwait(false);
        }
Пример #6
0
        private async Task <bool> TryReplyWithAbsolute(SocketGuild guild, SocketUserMessage message, AutoReplyItem item)
        {
            if (!message.Content.Equals(item.MustContains, GetStringComparison(item)))
            {
                return(false);
            }

            if (item.CanReply(guild, message.Channel))
            {
                item.CallsCount++;
                await message.Channel.SendMessageAsync(FormatMessage(item.ReplyMessage, message), allowedMentions : AllowedMentions);

                return(true);
            }

            return(false);
        }
Пример #7
0
 private StringComparison GetStringComparison(AutoReplyItem item)
 {
     return(!item.CaseSensitive ? StringComparison.InvariantCultureIgnoreCase : StringComparison.InvariantCulture);
 }