static async Task Recieved(SocketMessage message) { bool nowrite = false; var cs = await AbbybotSql.GetAbbybotChannelIdAsync(); foreach (var(guildId, channelId) in cs) { if (message.Channel.Id != channelId) { nowrite = true; } } if (!nowrite) { WriteMessage(message); } ulong guidId = 0, chanelId = 0; ulong abbybotId = Discord.__client.CurrentUser.Id; if (message.Author is SocketGuildUser sgu) { guidId = sgu.Guild.Id; chanelId = message.Channel.Id; var pref = await GuildSql.GetGuild(guidId); if (pref.PrefAbbybot == 0) { await GuildSql.UpdatePrefAbbybot(guidId, abbybotId); pref = await GuildSql.GetGuild(guidId); } if (pref.PrefAbbybot != abbybotId) { Abbybot.print("I'm not the prefered abbybot for this message"); return; } } await PassiveUserSql.IncreaseStat(abbybotId, guidId, chanelId, message.Author.Id, "MessagesSent"); await CommandHandler.Handle(message); }
public override async Task OnWork(DateTime time) { var roleIds = await MostActiveSql.GetRoles(); var client = Apis.Discord.__client; var abbybotid = client.CurrentUser.Id; foreach (var role in roleIds) { List <(ulong user, ulong role)> ugrs = new List <(ulong user, ulong role)>(); var stats = await PassiveUserSql.GetGuildStat(abbybotid, role.guildId, "MessagesSent"); var guildi = client.GetGuild(role.guildId); foreach (var sss in stats.ToList()) { try { if (client.GetUser(sss.userId).IsBot) { stats.Remove(sss); } } catch { stats.Remove(sss); } } ulong count = 0; ulong score = 0; foreach (var user in stats) { count++; score += user.stat; } if (score == 0 || count == 0) { continue; } score = score / count; foreach (var user in stats.ToList()) { if (user.stat < (score * .15f)) { stats.Remove(user); } } stats = stats.OrderByDescending(x => x.stat).ToList(); foreach (var user in stats) { var gxzer = await LastTimeSql.GetLastTime(user.userId, role.guildId, "Message"); if (gxzer.Length > 2) { if ((DateTime.Now - DateTime.Parse(gxzer)).TotalDays < 10) { ugrs.Add((user.userId, role.roleId)); } } } //get the a list of everyone who has sent a message at all in the last month var guz = client.GetGuild(role.guildId).Users.ToList(); var rols = guildi.Roles.Where(x => x.Id == role.roleId).ToList(); if (rols.Count() > 0) { foreach (var gu in guz) { await Task.Delay(1000); if (ugrs.Select(x => x.user).Contains(gu.Id)) { await gu.AddRoleAsync(rols[0]); } else { await gu.RemoveRoleAsync(rols[0]); } } } } //assign most active roll to the users who fit the category }
public override async Task DoWork(AbbybotCommandArgs aca) { await PassiveUserSql.SetUsernameSql(aca.user.Id, aca.user.Username, aca.user.Nickname); }