public async Task ReminderLog(CommandContext ctx, string date, string time, string about) { DateTime parsedEventDate; DateTime parsedEventTime; DateTime.TryParse(time, out parsedEventTime); DateTime.TryParse(date, out parsedEventDate); PersonalReminder reminder = new PersonalReminder { SetForDate = parsedEventDate.Date.Add(parsedEventTime.TimeOfDay), LogById = ctx.Message.Author.Id, LogByUsername = ctx.Message.Author.Username + "#" + ctx.Message.Author.Discriminator, About = about, UserMention = ctx.Message.Author.Mention, ChannelId = ctx.Channel.Id }; try { JackTheStudent.Program.reminderList.Add(reminder); using (var db = new JackTheStudentContext()) { db.PersonalReminder.Add(reminder); await db.SaveChangesAsync(); } } catch (Exception ex) { Console.Error.WriteLine("[Jack] " + ex.ToString()); await ctx.RespondAsync("Log failed"); return; } await ctx.RespondAsync($"Reminder about \"{about}\" set for {date} {time}"); }
public async Task RestoreClasses(List <Class> backupList, CommandContext ctx) { await ctx.RespondAsync("Failed, aborting and restoring from backup."); using (var db = new JackTheStudentContext()) { await db.Database.ExecuteSqlRawAsync("truncate table class"); foreach (Class backupClass in backupList) { db.Class.Add(backupClass); } await db.SaveChangesAsync(); } await ctx.RespondAsync("Groups restored from backup."); return; }
private async Task Remind() { if (reminderList.Count == 0) { return; } for (int i = 1; i <= reminderList.Count(); i++) { if (DateTime.Now >= reminderList[i - 1].SetForDate) { await reminderList[i - 1].Ping(_discord); try { using (var db = new JackTheStudentContext()) { db.PersonalReminder.Remove(reminderList[i - 1]); await db.SaveChangesAsync(); } reminderList.Remove(reminderList[i - 1]); } catch (Exception ex) { Console.Error.WriteLine("[Jack] " + ex.ToString()); } } } }
private async Task AutoRemind() { if (examList.Count == 0) { return; } TimeSpan interval = new TimeSpan(7, 00, 00, 00); TimeSpan timeLeft = new TimeSpan(); TimeSpan checkTime = new TimeSpan(15, 20, 00); bool isTime = DateTime.Now.TimeOfDay >= checkTime; bool isLessThanAWeek = false; if (!isTime) { return; } for (int i = 1; i <= examList.Count(); i++) { timeLeft = examList[i - 1].Date.Date - DateTime.Now.Date; isLessThanAWeek = timeLeft <= interval; if (isLessThanAWeek) { await examList[i - 1].Ping(_discord); examList[i - 1].wasReminded = true; using (var db = new JackTheStudentContext()) { try { var exam = db.Exam.Where(e => e.Id == examList[i - 1].Id).FirstOrDefault(); exam.wasReminded = true; await db.SaveChangesAsync(); } catch (Exception ex) { Console.Error.WriteLine("[Jack] " + ex.ToString()); } } } } }
public async Task ProjectLog(CommandContext ctx, [Description("\nTakes either 1 (true) or 0 (false)\n")] string isGroup = "", [Description("\nTakes group IDs, type !group to retrieve all groups.\n")] string groupId = "", [Description("\nTakes class' short names, type !class to retrive all classes.\n")] string classType = "", [Description("\nTakes dates in dd/mm/yyyy format, accepts different separators.\n")] string eventDate = "", [Description("\nTakes time in hh:mm format.\n")] string eventTime = "", [Description("\nTakes additional information, multiple words must be wrapped with \"\".\n")] string additionalInfo = "") { DateTime parsedEventDate = new DateTime(); DateTime parsedEventTime = new DateTime(); if (isGroup == "") { await ctx.RespondAsync("Learn to read you dumbass. The command looks like: !project <isGroup> <group> <class> <projectDate> <projectTime> Try again!"); return; } else if (isGroup != "0" && isGroup != "1") { await ctx.RespondAsync("How stupid are you, really? isGroup argument takes either 1 (true) or 0 (false)!"); return; } else if (groupId == "") { await ctx.RespondAsync("Learn to read you dumbass. The command looks like: !project <isGroup> <group> <class> <projectDate> <projectTime> Try again!"); return; } else if (!JackTheStudent.Program.groupList.Contains(groupId)) { await ctx.RespondAsync("There's no such group dumbass. Try again!"); return; } else if (classType == "") { await ctx.RespondAsync("Learn to read you dumbass. The command looks like: !project <isGroup> <group> <class> <projectDate> <projectTime> Try again!"); return; } else if (!JackTheStudent.Program.classList.Any(c => c.ShortName == classType)) { await ctx.RespondAsync("There's no such class, you high bruh?"); return; } else if (eventDate == "") { await ctx.RespondAsync("There's date missing, fix it!"); return; } else if (!DateTime.TryParse(eventDate, out parsedEventDate)) { await ctx.RespondAsync("That's not a valid date you retard, learn to type!"); return; } else if (eventTime == "") { await ctx.RespondAsync("There's time missing, fix it!"); return; } else if (!DateTime.TryParse(eventTime, out parsedEventTime)) { await ctx.RespondAsync("That's not a valid time you retard, learn to type!"); return; } else if (isGroup == "0") { try { using (var db = new JackTheStudentContext()){ var project = new Project { Class = classType, Date = parsedEventDate.Date.Add(parsedEventTime.TimeOfDay), GroupId = groupId, isGroup = Convert.ToBoolean(Convert.ToInt16(isGroup)), LogById = ctx.Message.Author.Id.ToString(), LogByUsername = ctx.Message.Author.Username + "#" + ctx.Message.Author.Discriminator, AdditionalInfo = additionalInfo }; db.Project.Add(project); await db.SaveChangesAsync(); } } catch (Exception ex) { Console.Error.WriteLine("[Jack] " + ex.ToString()); await ctx.RespondAsync("Log failed"); return; } await ctx.RespondAsync("Project logged successfully"); return; } else { await ctx.RespondAsync("How many members does the project have?"); var intr = ctx.Client.GetInteractivity(); // Grab the interactivity module var response = await intr.WaitForMessageAsync( c => c.Author.Id == ctx.Message.Author.Id, // Make sure the response is from the same person who sent the command TimeSpan.FromSeconds(5) // Wait 60 seconds for a response instead of the default 30 we set earlier! ); short membersCount = 1; while (!Int16.TryParse(response.Result.Content, out membersCount) && membersCount <= 2) { await ctx.RespondAsync("Ever heard of intigers? Try again."); response = await intr.WaitForMessageAsync( c => c.Author.Id == ctx.Message.Author.Id, // Make sure the response is from the same person who sent the command TimeSpan.FromSeconds(5) // Wait 60 seconds for a response instead of the default 30 we set earlier! ); } try { using (var db = new JackTheStudentContext()){ var project = new Project { Class = classType, Date = parsedEventDate.Date.Add(parsedEventTime.TimeOfDay), GroupId = groupId, isGroup = Convert.ToBoolean(Convert.ToInt16(isGroup)), LogById = ctx.Message.Author.Id.ToString(), LogByUsername = ctx.Message.Author.Username + "#" + ctx.Message.Author.Discriminator, AdditionalInfo = additionalInfo, GroupProjectMembers = new List <GroupProjectMember>() }; for (int i = 1; i <= membersCount; i++) { await ctx.RespondAsync("What's the name of the " + i + " participant?"); var participant = await intr.WaitForMessageAsync( c => c.Author.Id == ctx.Message.Author.Id, // Make sure the response is from the same person who sent the command TimeSpan.FromSeconds(5) // Wait 60 seconds for a response instead of the default 30 we set earlier! ); var groupProjectMember = new GroupProjectMember { Member = participant.Result.Content }; project.GroupProjectMembers.Add(groupProjectMember); } JackTheStudent.Program.projectList.Add(project); db.Project.Add(project); await db.SaveChangesAsync(); } } catch (Exception ex) { Console.Error.WriteLine("[Jack] " + ex.ToString()); await ctx.RespondAsync("Log failed"); return; } await ctx.RespondAsync("Project logged successfully"); return; } }
public async Task HomeworkLog(CommandContext ctx, [Description("\nTakes group IDs, type !group to retrieve all groups.\n")] string groupId = "", [Description("\nTakes class' short names, type !class to retrive all classes.\n")] string classType = "", [Description("\nTakes dates in dd/mm/yyyy format, accepts different separators.\n")] string eventDate = "", [Description("\nTakes time in hh:mm format.\n")] string eventTime = "", [Description("\nTakes additional information, multiple words must be wrapped with \"\".\n")] string additionalInfo = "", [Description("\nTakes material links, multiple links must be wrapped with \"\".\n")] string materials = "") { DateTime parsedEventDate = new DateTime(); DateTime parsedEventTime = new DateTime(); if (groupId == "") { await ctx.RespondAsync("Learn to read you dumbass. The command looks like: !homework <group> <class> <deadlineDate> <deadlineTime> Try again!"); return; } else if (!JackTheStudent.Program.groupList.Contains(groupId)) { await ctx.RespondAsync("There's no such group dumbass. Try again!"); return; } else if (classType == "") { await ctx.RespondAsync("Learn to read you dumbass. The command looks like: !homework <group> <class> <deadlineDate> <deadlineTime> Try again!"); return; } else if (!JackTheStudent.Program.classList.Any(c => c.ShortName == classType)) { await ctx.RespondAsync("There's no such class, you high bruh?"); return; } else if (eventDate == "") { await ctx.RespondAsync("There's date missing, fix it!"); return; } else if (!DateTime.TryParse(eventDate, out parsedEventDate)) { await ctx.RespondAsync("That's not a valid date you retard, learn to type!"); return; } else if (eventTime == "") { await ctx.RespondAsync("There's time missing, fix it!"); return; } else if (!DateTime.TryParse(eventTime, out parsedEventTime)) { await ctx.RespondAsync("That's not a valid time you retard, learn to type!"); return; } else { try { using (var db = new JackTheStudentContext()){ var homeWork = new Homework { Class = classType, Date = parsedEventDate.Date.Add(parsedEventTime.TimeOfDay), GroupId = groupId, LogById = ctx.Message.Author.Id.ToString(), LogByUsername = ctx.Message.Author.Username + "#" + ctx.Message.Author.Discriminator, AdditionalInfo = additionalInfo, Materials = materials }; JackTheStudent.Program.homeworkList.Add(homeWork); db.Homework.Add(homeWork); await db.SaveChangesAsync(); } } catch (Exception ex) { Console.Error.WriteLine("[Jack] " + ex.ToString()); await ctx.RespondAsync("Log failed"); return; } await ctx.RespondAsync("Homework logged successfully"); return; } }
public async Task TeamsLinkLog(CommandContext ctx, [Description("\nTakes class' short names, type !class to retrive all classes.\n")] string uniClass = "", [Description("\nTakes class' short names, type !class to retrive all classes.\n")] string classType = "", [Description("\nTakes dates in dd/mm/yyyy format, accepts different separators.\n")] string eventDayOfWeek = "", [Description("\nTakes time in hh:mm format.\n")] string eventTime = "", [Description("\nTakes group IDs, type !group to retrieve all groups.\n")] string groupId = ".", [Description("\nTakes time in hh:mm format.\n")] string link = "", [Description("\nTakes additional information, multiple words must be wrapped with \"\".\n")] string additionalInfo = "") { DayOfWeek parsedEventDayOfWeek = new DayOfWeek(); DateTime parsedEventTime = new DateTime(); if (uniClass == "") { await ctx.RespondAsync("Learn to read you dumbass. The command looks like: !teamsLink <group> <class> <teamsLinkDate> <teamsLinkTime> Try again!"); return; } else if (!JackTheStudent.Program.classList.Any(c => c.ShortName == uniClass)) { await ctx.RespondAsync("There's no such class, you high bruh?"); return; } else if (classType == "") { await ctx.RespondAsync("Class type is missing!"); return; } else if (!JackTheStudent.Program.classTypeList.Any(c => c.ShortName == classType)) { await ctx.RespondAsync("There's no such class type -_- . Try again!"); return; } else if (eventDayOfWeek == "") { await ctx.RespondAsync("There's date missing, fix it!"); return; } else if (!DayOfWeek.TryParse(eventDayOfWeek, out parsedEventDayOfWeek)) { await ctx.RespondAsync("That's not a valid date you retard, learn to type!"); return; } else if (eventTime == "") { await ctx.RespondAsync("There's time missing, fix it!"); return; } else if (!DateTime.TryParse(eventTime, out parsedEventTime)) { await ctx.RespondAsync("That's not a valid time you retard, learn to type!"); return; } else if (link == "") { await ctx.RespondAsync("Learn to read you dumbass. The command looks like: !teamsLink <group> <class> <teamsLinkDate> <teamsLinkTime> Try again!"); return; } else if (!link.Contains("teams.microsoft.com/l/meetup-join/19%3ameeting")) { await ctx.RespondAsync("That's not a valid teams meetup link!"); return; } else if (!JackTheStudent.Program.groupList.Contains(groupId) && groupId != ".") { await ctx.RespondAsync("There's no such group dumbass. Try again!"); return; } else { try { using (var db = new JackTheStudentContext()){ var teamsLink = new TeamsLink { Class = uniClass, ClassType = classType, Date = $"{parsedEventDayOfWeek} {eventTime}", GroupId = groupId, Link = link, LogById = ctx.Message.Author.Id.ToString(), LogByUsername = ctx.Message.Author.Username + "#" + ctx.Message.Author.Discriminator, AdditionalInfo = additionalInfo }; JackTheStudent.Program.teamsLinkList.Add(teamsLink); db.TeamsLink.Add(teamsLink); await db.SaveChangesAsync(); } } catch (Exception ex) { Console.Error.WriteLine("[Jack] " + ex.ToString()); await ctx.RespondAsync("Log failed"); return; } await ctx.RespondAsync("Teams link logged successfully"); return; } }
public async Task SemesterClass(CommandContext ctx) { List <Class> backupClasses = new List <Class>(); await ctx.RespondAsync("Are you absolutely sure you want to do it?"); var intr = ctx.Client.GetInteractivity(); var sureResponse = await intr.WaitForMessageAsync( c => c.Author.Id == ctx.Message.Author.Id, TimeSpan.FromSeconds(5) ); if (sureResponse.Result.Content.ToLower() != "yes" || sureResponse.Result == null) { await ctx.RespondAsync("Aborting, all good"); return; } using (var context = new JackTheStudentContext()) { backupClasses = context.Class.ToList(); var truncateText = "truncate table class"; try { await context.Database.ExecuteSqlRawAsync(truncateText); } catch (Exception ex) { Console.Error.WriteLine("[Jack] " + ex.ToString()); await ctx.RespondAsync("Truncate failed"); return; } await context.SaveChangesAsync(); await ctx.RespondAsync("Truncate successful"); } using (var db = new JackTheStudentContext()){ await ctx.RespondAsync("Let's populate the table with new data, how many classes are there for the new semester?"); var amountOfClassesResponse = await intr.WaitForMessageAsync( c => c.Author.Id == ctx.Message.Author.Id, TimeSpan.FromSeconds(10) ); if (amountOfClassesResponse.Result == null) { await RestoreClasses(backupClasses, ctx); return; } short classesCount = 0; while (!Int16.TryParse(amountOfClassesResponse.Result.Content, out classesCount) || classesCount < 2) { await ctx.RespondAsync("That's not a valid number, try again."); amountOfClassesResponse = await intr.WaitForMessageAsync( c => c.Author.Id == ctx.Message.Author.Id, TimeSpan.FromSeconds(10) ); if (amountOfClassesResponse.TimedOut) { await RestoreClasses(backupClasses, ctx); return; } } if (amountOfClassesResponse.Result == null) { await RestoreClasses(backupClasses, ctx); return; } for (int i = 1; i <= classesCount; i++) { await ctx.RespondAsync($"What's the name and shortname of the {i} class? Answer with NAME SHORTNAME"); var newClassNames = await intr.WaitForMessageAsync( c => c.Author.Id == ctx.Message.Author.Id, TimeSpan.FromSeconds(30) ); if (newClassNames.TimedOut) { await RestoreClasses(backupClasses, ctx); return; } string[] classArray = newClassNames.Result.Content.Split(new Char[] { ' ' }); while (classArray.Count() != 2) { await ctx.RespondAsync("Try again -.-"); newClassNames = await intr.WaitForMessageAsync( c => c.Author.Id == ctx.Message.Author.Id, TimeSpan.FromSeconds(30) ); classArray = newClassNames.Result.Content.Split(new Char[] { ' ' }); if (newClassNames.TimedOut) { await RestoreClasses(backupClasses, ctx); return; } } var newClass = new Class { Name = classArray[0], ShortName = classArray[1] }; db.Class.Add(newClass); await ctx.RespondAsync($"Added class: {newClass.Name} with short name: {newClass.ShortName}"); Task.Delay(1000).Wait(); } try { await db.SaveChangesAsync(); } catch (Exception ex) { Console.Error.WriteLine("[Jack] " + ex.ToString()); await RestoreClasses(backupClasses, ctx); return; } await db.SaveChangesAsync(); await ctx.RespondAsync("Class table repopulated successfully"); } return; }
public async Task SemeterGroup(CommandContext ctx) { List <Group> backupGroups = new List <Group>(); await ctx.RespondAsync("Are you absolutely sure you wanna do it?"); var intr = ctx.Client.GetInteractivity(); var sureResponse = await intr.WaitForMessageAsync( c => c.Author.Id == ctx.Message.Author.Id, TimeSpan.FromSeconds(5) ); if (sureResponse.Result.Content.ToLower() != "yes" || sureResponse.Result == null) { await ctx.RespondAsync("Aborting, all good"); return; } using (var context = new JackTheStudentContext()) { backupGroups = context.Group.ToList(); var truncateText = "truncate table `group`"; try { await context.Database.ExecuteSqlRawAsync(truncateText); } catch (Exception ex) { Console.Error.WriteLine("[Jack] " + ex.ToString()); await ctx.RespondAsync("Truncate failed"); return; } await context.SaveChangesAsync(); await ctx.RespondAsync("Truncate successful"); } using (var db = new JackTheStudentContext()){ await ctx.RespondAsync("Let's populate the table with new data, how many groups are there for the new semester?"); var amountOfGroupsResponse = await intr.WaitForMessageAsync( c => c.Author.Id == ctx.Message.Author.Id, TimeSpan.FromSeconds(10) ); if (amountOfGroupsResponse.Result == null) { await RestoreGroups(backupGroups, ctx); return; } short groupsCount = 0; while (!Int16.TryParse(amountOfGroupsResponse.Result.Content, out groupsCount) || groupsCount < 1) { await ctx.RespondAsync("That's not a valid number, try again."); amountOfGroupsResponse = await intr.WaitForMessageAsync( c => c.Author.Id == ctx.Message.Author.Id, TimeSpan.FromSeconds(10) ); if (amountOfGroupsResponse.TimedOut) { await RestoreGroups(backupGroups, ctx); return; } } for (int i = 1; i <= groupsCount; i++) { await ctx.RespondAsync($"What's the ID of the {i} group? Answer with ID"); var groupId = await intr.WaitForMessageAsync( c => c.Author.Id == ctx.Message.Author.Id, TimeSpan.FromSeconds(30) ); if (groupId.Result == null) { await RestoreGroups(backupGroups, ctx); return; } var newGroup = new Group { GroupId = groupId.Result.Content }; db.Group.Add(newGroup); await ctx.RespondAsync($"Added group with ID: {newGroup.GroupId}."); Task.Delay(1000).Wait(); } try { await db.SaveChangesAsync(); } catch (Exception ex) { Console.Error.WriteLine("[Jack] " + ex.ToString()); await RestoreGroups(backupGroups, ctx); return; } await ctx.RespondAsync("Group table repopulated successfully"); } return; }
public async Task ExamLog(CommandContext ctx, [Description("\nTakes class' short names, type !class to retrive all classes.\n")] string classType = "", [Description("\nTakes dates in dd/mm/yyyy format, accepts different separators.\n")] string examDate = "", [Description("\nTakes time in hh:mm format.\n")] string examTime = "", [Description("\nTakes additional information, multiple words must be wrapped with \"\".\n")] string additionalInfo = "", [Description("\nTakes material links, multiple links must be wrapped with \"\".\n")] string materials = "") { DateTime parsedEventDate = new DateTime(); DateTime parsedEventTime = new DateTime(); if (classType == "") { await ctx.RespondAsync("Learn to read you dumbass. The command looks like: !exam <class> <examDate> <examTime> Try again!"); return; } else if (!JackTheStudent.Program.classList.Any(c => c.ShortName == classType)) { await ctx.RespondAsync("There's no such class, you high bruh?"); return; } else if (examDate == "") { await ctx.RespondAsync("There's date missing, fix it!"); return; } else if (!DateTime.TryParse(examDate, out parsedEventDate)) { await ctx.RespondAsync("That's not a valid date you retard, learn to type!"); return; } else if (examTime == "") { await ctx.RespondAsync("There's time missing, fix it!"); return; } else if (!DateTime.TryParse(examTime, out parsedEventTime)) { await ctx.RespondAsync("That's not a valid time you retard, learn to type!"); return; } else { try { using (var db = new JackTheStudentContext()){ var exam = new Exam { ClassShortName = classType, Class = JackTheStudent.Program.classList.Where(e => e.ShortName == classType).Select(e => e.Name).FirstOrDefault(), Date = parsedEventDate.Date.Add(parsedEventTime.TimeOfDay), LogById = ctx.Message.Author.Id.ToString(), LogByUsername = ctx.Message.Author.Username + "#" + ctx.Message.Author.Discriminator, AdditionalInfo = additionalInfo, Materials = materials }; JackTheStudent.Program.examList.Add(exam); db.Exam.Add(exam); await db.SaveChangesAsync(); } } catch (Exception ex) { Console.Error.WriteLine("[Jack] " + ex.ToString()); await ctx.RespondAsync("Exam log failed"); return; } await ctx.RespondAsync("Logged successfully"); return; } }