Ejemplo n.º 1
0
        public async Task ViewUser(DiscordHwkUser user)
        {
            EmbedBuilder builder = new EmbedBuilder()
            {
                Title = user.Name
            };
            string classes = string.Join("\r\n", user.Classes);

            builder.AddField("Classes", classes.Length > 0 ? classes : $"None, `{BOT_PREFIX}edulink class {user.Name} [class]`");
            builder.AddField("Days", string.Join(", ", user.NotifyOnDays));
            builder.AddField("Self-Hwk", user.NotifyForSelfHomework.ToString());
            await ReplyAsync("", false, builder.Build());
        }
Ejemplo n.º 2
0
        public async Task AdminAddNotify(SocketGuildUser user, string username)
        {
            var existing = await GetUser(Context, user.Id.ToString());

            if (existing == null)
            {
                var DiscordHwkUser = new DiscordHwkUser(user, username, "");
                Users.Add(DiscordHwkUser);
                await ReplyAsync($"User added, use the `{BOT_PREFIX}edulink class {user.Username} [class]` to add a class to the user.");
            }
            else
            {
                await ReplyAsync("User already exists:", false, existing.ToEmbed());
            }
        }
Ejemplo n.º 3
0
        public async Task DoPreferences()
        {
            TimeSpan       timeout = TimeSpan.FromSeconds(30);
            DiscordHwkUser user    = Users.FirstOrDefault(x => x.User.Id == Context.User.Id);

            if (user == null)
            {
                await ReplyAsync("You have no account, please do `/edulink setup` first.");

                return;
            }
            await ReplyAsync("Please reply with the days you want to be mentioned on, relative to when the homework is due." +
                             "\r\nFor example, to be mentioned 7 days, 3 days, the day before, and on the day, of the due date:" +
                             $"\r\nreply with: `0 1 3 7` (no special coding, just space-seperated)\r\nYour current value is: `{string.Join(" ", user.NotifyOnDays)}`");

            var replyOnDays = await NextMessageAsync(timeout : timeout);

            if (replyOnDays != null && !string.IsNullOrWhiteSpace(replyOnDays.Content))
            {
                string[]   items = replyOnDays.Content.Split(' ');
                List <int> days  = new List <int>();
                foreach (var i in items)
                {
                    if (int.TryParse(i, out int in_))
                    {
                        days.Add(in_);
                    }
                }
                user.NotifyOnDays = days;
                await ReplyAsync("Now set to: " + string.Join(" ", days));
            }

            await ReplyAsync("Please reply with whether you want to be notified for homeworks set by non-teachers, but for your class" +
                             $"\r\nThis is either `true` or `false`, your current value is: `{user.NotifyForSelfHomework}`");

            var notifySelf = await NextMessageAsync(timeout : timeout);

            if (notifySelf != null && !string.IsNullOrWhiteSpace(notifySelf.Content))
            {
                if (bool.TryParse(notifySelf.Content, out bool result))
                {
                    user.NotifyForSelfHomework = result;
                }
                await ReplyAsync("Now set to: " + result.ToString());
            }
            await ReplyAsync("Settings updated! (or remain as they were)");
        }
Ejemplo n.º 4
0
        public async Task AddNewUser(string username)
        {
            if (Users.FirstOrDefault(x => x.User.Id == Context.User.Id) != null)
            {
                await ReplyAsync("Error: your account has already been added.\r\nPlease contact Bob123#4008 to change your password");

                return;
            }
            await ReplyAsync(":warning: ***WARNING*** :warning: \r\n" +
                             "Your username and password **will be stored in plain text**\r\n" +
                             "This is **compeltely** unsecure.\r\n\r\n" +
                             "***Only reply with your password if you do not use it elsewhere***");
            await ReplyAsync("Reply with only your password within 30 seconds, or wait for timeout.\r\n*You can ignore the message saying this is 'only' for commands*");

            var pwd = await NextMessageAsync(timeout : TimeSpan.FromSeconds(30));

            if (pwd == null || string.IsNullOrWhiteSpace(pwd.Content))
            {
                await ReplyAsync("Addition cancelled, timed out.");
            }
            else
            {
                var password = pwd.Content;
                var edulink  = new EduLinkRPC.Edulink(username, password);
                edulink.SendingRequest += EdulinkSentRequest;
                JToken thing = null;
                try
                {
                    thing = edulink.Login();
                }
                catch (Exception ex)
                {
                    await ReplyAsync(ex.Message);

                    Program.LogMsg($"Failed login/edulink attempt for {username} by {Context.User.Username}@{Context.User.Id}, response: {ex}", LogSeverity.Warning, "EduLink");
                    return;
                }
                var user     = thing["user"];
                var forename = user.Value <string>("forename");
                await ReplyAsync("Thank you for logging in, " + forename);

                var DiscordHwkUser = new DiscordHwkUser(Program.TheGrandCodingGuild.GetUser(Context.User.Id), username, password);
                Users.Add(DiscordHwkUser);
                await ReplyAsync("Please contact an Adminstrator with a list of your classes for you to be assigned.\r\nTo edit your preferences (on when you are messaged), please see `/edulink settings`");
            }
        }
Ejemplo n.º 5
0
        public async Task getAchievement(DiscordHwkUser user)
        {
            var ach = user.Client.GetAchievements();

            ach.OrderByDescending(x => x.Date);
            EmbedBuilder builder = new EmbedBuilder();
            int          count   = 0;

            while (count < 25 && ach.Count > count)
            {
                var achievement = ach[count];
                count++;

                builder.AddField(x =>
                {
                    x.Name  = $"{achievement.Id}: {achievement.Date}";
                    x.Value = $"{achievement.Points} - {achievement.Comments}";
                });
            }
            await ReplyAsync("", false, builder.Build());
        }
Ejemplo n.º 6
0
        public async Task SetInClass(DiscordHwkUser user, [Remainder] string class_)
        {
            class_ = class_.Replace("Maths", "Mathematics");
            class_ = class_.Replace("RE", "R.E.");
            Class cls = null;

            if (Classes.TryGetValue(class_, out cls))
            {
            }
            else
            {
                Discord.Rest.RestRole role = await Program.TheGrandCodingGuild.CreateRoleAsync(class_);

                SocketRole sRole = role.GetSocketRole(500, Program.TheGrandCodingGuild);
                cls = new Class(sRole);
                Classes.Add(cls.Name, cls);
            }
            if (user.Classes.Contains(cls.Name))
            {
                cls.Users.Remove(user);
                user.Classes.Remove(cls.Name);
                await user.User.RemoveRoleAsync(cls.Role);

                if (user.Classes.Count == 0)
                {
                    await user.User.RemoveRoleAsync(Separator);
                }
                await ReplyAsync($"Removed {user.Name} from {cls.Name}");
            }
            else
            {
                cls.Users.Add(user);
                user.Classes.Add(cls.Name);
                await user.User.AddRoleAsync(cls.Role);

                await user.User.AddRoleAsync(Separator);
                await ReplyAsync($"Added {user.Name} to {cls.Name}");
            }
        }
Ejemplo n.º 7
0
        public async Task CurrentHomework()
        {
            DiscordHwkUser user = await GetUser(Context, Context.User.Id.ToString());

            EmbedBuilder builder = new EmbedBuilder()
            {
                Title = user.Name + " - Current Homework"
            };

            foreach (var hwk in user.Homework.OrderByDescending(x => x.DueDate.DayOfYear).Select(x => x as ClassHomework))
            {
                if (!hwk.Completed)
                {
                    string name = Clamp($"{hwk.Id}: {hwk.Activity}", 128);
                    string desc = Clamp($"Added {hwk.AvailableText}, due {hwk.DueText}\r\nSubject {hwk.Subject}\r\nSet {hwk.SetBy}", 1000);
                    builder.AddField(name, desc);
                }
            }
            if (builder.Fields.Count == 0)
            {
                builder.AddField("No homework", "You do not have any current homework");
            }
            await ReplyAsync("", false, builder.Build());
        }