public void Update() { commands.CreateCommand("Update") .Do(async(e) => { RankCommands rankCommands = new RankCommands(BotUser, commands); string returnstring = ""; ServerRepo serverRepo = new ServerRepo(new ServerContext()); UserRepo userRepo = new UserRepo(new UserContext()); RoleManagementTrigger rmt = new RoleManagementTrigger(BotUser, commands); /* * if (userRepo.IsAtlasAdmin(e.User.Id)) * { * foreach (Discord.Server server in BotUser.Servers) * { * if (serverRepo.IsServerVerified(server.Id)) * { * foreach (Discord.User user in server.Users) * { * * try * { * await Task.Run(() => rmt.RemoveRoles(server, user)); * await Task.Run(() => rankCommands.GetRankRoles(server, user)); * } * catch * { * * } * * } * } * } * returnstring = "System update complete."; * } * * else*/if (new ServerRepo(new ServerContext()).IsAdmin(e.User.Id, e.Server.Id)) { if ((serverRepo.GetLastupdateDateServer(e.Server.Id) < DateTime.Today) && serverRepo.IsServerVerified(e.Server.Id)) { foreach (Discord.User user in e.Server.Users) { try { await Task.Run(() => rmt.RemoveRoles(e.Server, user)); await Task.Run(() => rankCommands.GetRankRoles(e.Server, user)); } catch { Console.WriteLine("Failed to give roles, account not registered."); } } serverRepo.SetUpdateDateServer(e.Server.Id, DateTime.Today); returnstring = "Server update successfull."; } else { returnstring = "Please wait for one day to update your server again."; } } else { if (userRepo.GetLastRefreshDate(e.User.Id) > DateTime.Today && serverRepo.IsServerVerified(e.Server.Id)) { try { await Task.Run(() => rmt.RemoveRoles(e.Server, e.User)); await Task.Run(() => rankCommands.GetRankRoles(e.Server, e.User)); } catch { } userRepo.SetLastRefreshDate(e.User.Id, DateTime.Now); } } await e.Channel.SendMessage(returnstring); }); }
public Bot() { BotUser = new DiscordClient(x => { x.LogLevel = LogSeverity.Info; }); BotUser.Log.Message += (s, e) => Console.WriteLine($"[{e.Severity}] {e.Source}: {e.Message}"); BotUser.UsingCommands(x => { x.PrefixChar = '-'; x.AllowMentionPrefix = true; }); commands = BotUser.GetService <CommandService>(); RoleManagementCommands rmc = new RoleManagementCommands(BotUser, commands); AccountManagementCommands amc = new AccountManagementCommands(BotUser, commands); RoleManagementTrigger roleManagementTrigger = new RoleManagementTrigger(BotUser, commands); RegionCommands regionCommands = new RegionCommands(BotUser, commands); RoleCommand roleCommand = new RoleCommand(BotUser, commands); ManagementTools managementTools = new ManagementTools(BotUser, commands); ServerInfoCommands serverInfoCommands = new ServerInfoCommands(BotUser, commands); MasteryCommands masteryCommands = new MasteryCommands(BotUser, commands); ServerManagement serverManagement = new ServerManagement(BotUser, commands); RankCommands rankCommands = new RankCommands(BotUser, commands); SummonerInfo summonerInfo = new SummonerInfo(commands); BotManagement botManagement = new BotManagement(commands, BotUser); Interaction inter = new Interaction(BotUser, commands); CreateRoles createRoles = new CreateRoles(commands); Matchmaking_Settings matchmakingSettings = new Matchmaking_Settings(commands); CoachCommands coachCommands = new CoachCommands(commands); Stopwatch stopwatch = new Stopwatch(); stopwatch.Start(); MatchmakingTrigger trigger = new MatchmakingTrigger(BotUser, commands); MatchmakingCommands matchmakingCommands = new MatchmakingCommands(commands, BotUser, trigger); new HelpCommand(BotUser, commands); Task.Run(() => trigger.TimedClear(stopwatch)); matchmakingCommands.CreateCommands(); matchmakingSettings.ChannelSettings(); coachCommands.CreateCommands(); createRoles.CreateRank(); summonerInfo.SelfInfo(); summonerInfo.OtherInfo(); serverManagement.ServerAdded(); serverManagement.VerifyServer(); serverInfoCommands.InviteLink(); amc.ClaimAccount(); amc.Claim(); rankCommands.GetRank(); new Universal_Role(BotUser, commands).UniversalRole(); regionCommands.GetRegion(); roleCommand.GetRole(); rmc.Update(); rmc.GetRoles(); managementTools.ChangeType(); managementTools.ChangeCommandAllowed(); managementTools.OverrideSystem(); serverInfoCommands.ServerInfo(); serverInfoCommands.Description(); serverManagement.CheckForNewServer(); managementTools.Admin(); roleCommand.GetRoleParameter(); Legal(); roleManagementTrigger.JoiningRoleGive(); masteryCommands.GetMasteryPoints(); managementTools.AdminMastery(); Test(); BotUser.ExecuteAndWait(async() => { await BotUser.Connect(global::Keys.Keys.discordKey, TokenType.Bot); }); }