public override void OnReady() { var content = ReadSave(); var dict = Program.Deserialise <Dictionary <ulong, userInfo> >(content); Clients = new Dictionary <ulong, EduLinkClient>(); foreach (var x in dict) { var client = new EduLinkClient(); client.Log = logHandler; try { client.LoginAsync(x.Value.username, x.Value.password, x.Value.establishment).Wait(); Clients[x.Key] = client; } catch (Exception ex) when(ex is EduLinkException || ex is AggregateException ag && ag.InnerExceptions.Any(x => x is EduLinkException)) { Program.LogMsg($"EduLink-{x.Value.username}", ex); #if !DEBUG try { var usr = Program.Client.GetUser(x.Key); usr.SendMessageAsync($"Your EduLink login information has failed; you may use `{Program.Prefix}edulink setup {x.Value.username} [password]` to update it:\r\n" + $">>> {ex.Message}"); } catch { } #endif } } }
public async Task <RuntimeResult> Setup(string username, [Sensitive][Remainder] string password) { var hadPrior = Service.Clients.Remove(Context.User.Id); var client = new EduLinkClient(); client.Log = EduLinkService.logHandler; try { var successLogin = await client.LoginAsync(username, password, 60); if (!successLogin) { return(new BotResult("Failed to login for an unknown reason")); } } catch (EduLinkException ex) { return(new BotResult($"Failed to login: {ex.Message}")); } Service.Clients[Context.User.Id] = client; Service.OnSave(); await ReplyAsync($"Account information {(hadPrior ? "updated" : "registered")} to {client.CurrentUser.Forename}\r\n" + $"Please delete your message."); return(new BotResult()); }