public string GetStatisticRule(long chatId) { using (var db = new SqliteContext()) { var fnd = db.Rules.Where(o => o.CharId == chatId); var ret = @"All statistic rules:" + Environment.NewLine; foreach (var rule in fnd) { ret += $"Word: {rule.StatisticWord}" + Environment.NewLine; } return(ret); } }
public void AddInfo(int ruleId, string user) { using (var db = new SqliteContext()) { var info = db.Infos.SingleOrDefault(o => o.RuleId == ruleId && o.UserId == user); if (info == null) { info = new StatisticInfo(ruleId, user); db.Infos.Add(info); db.SaveChanges(); } info.Count++; db.Infos.Update(info); db.SaveChanges(); } }
public string GetTopString(long?ruleId, string word, int topNum = 1) { var ret = string.Empty; if (ruleId == null) { ret = $"Can't find rule: \"{word}\"."; } else { using (var db = new SqliteContext()) { var infoList = db.Infos.Where(o => o.RuleId == ruleId); var i = 1; foreach (var info in infoList.OrderByDescending(o => o.Count).Take(topNum)) { ret += $"Top{i}: {info.UserId}, count: {info.Count}" + Environment.NewLine; i++; } } } return(ret); }