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()); }
public async Task <string[]> SetClasses(BotUser bUser, EduLinkClient client) { bUser.Classes = new Dictionary <string, string>(); var timetable = await client.TimetableAsync(); foreach (var week in timetable) { foreach (var day in week.Days) { foreach (var lesson in day.Lessons) { bUser.Classes[lesson.TeachingGroup.Name] = lesson.TeachingGroup.Subject ?? "unknown"; } } } return(bUser.Classes.Keys.ToArray()); }
public static void logHandler(EduLinkClient cl, EduLinkDLL.LogMessage m) { if (m.Severity == EduLinkDLL.LogSeverity.Debug && (m.Source == "Response" || m.Source == "Request")) { /*var path = Path.Combine(Program.BASE_PATH, "data", "logs", "edulink", cl.CurrentUser?.Username ?? cl.UserName ?? "nouser"); * if(!Directory.Exists(path)) * Directory.CreateDirectory(path); * path = Path.Combine(path, $"{DateTime.Now:yyyy-MM-dd}.txt"); * var id = Guid.NewGuid(); * var chr = m.Source == "Request" ? '>' : '<'; * var pad = new string(chr, 3); * string header = pad + id.ToString() + pad; * string full = header + "\r\n" + m.Message + "\r\n" + new string(chr, header.Length) + "\r\n"; * if (m.Source == "Response") * full += "\r\n"; * File.AppendAllText(path, full); * Program.LogMsg($"Logged as {id}", Discord.LogSeverity.Verbose, "EL:" + m.Source);*/ return; } var conv = new Discord.LogMessage((Discord.LogSeverity)m.Severity, $"EL:{(cl?.CurrentUser?.UserName ?? "")}:" + (m.Source ?? ""), m.Message, m.Exception); Program.LogMsg(conv); }