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); }
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); }
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); }
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); }
public async Task AddItemAsync(AutoReplyItem item) { await Context.AutoReply.AddAsync(item).ConfigureAwait(false); await Context.SaveChangesAsync().ConfigureAwait(false); }
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); }
private StringComparison GetStringComparison(AutoReplyItem item) { return(!item.CaseSensitive ? StringComparison.InvariantCultureIgnoreCase : StringComparison.InvariantCulture); }