Пример #1
0
        public async Task CreateFile([Remainder] String param)
        {
            String[] args = param.Split("~");

            var eb = new EmbedBuilder();

            eb.WithColor(Color.Orange);
            eb.WithAuthor("ScrumBot");
            eb.WithTitle("CreateFile");
            eb.WithDescription("Creates a file with the given textual information.");
            eb.WithFooter("Thank you!");

            if (args.Length < 2)
            {
                eb.AddField("Incorrect syntax!", ".CreateFile <filename>~<text>", true);
            }
            else
            {
                rw.CreateFileWithTitle(args[0], args[1]);
                eb.AddField("File '" + args[0] + "' created successfully!", args[1], true);
            }

            await Context.Channel.SendMessageAsync("", false, eb.Build());
        }
Пример #2
0
        public async Task CreateRem([Remainder] string param)
        {
            // Parse all input data
            string[] args = param.Split('~'); // Parses parameters using '~' delimiter
            if (args.Length >= 4)
            {
                string name        = args[0];                                // Reminder name (must be unique)
                string message     = args[1];                                // Reminder message text
                var    timeCreated = DateTime.Now;                           // Time it was created
                var    timeExpires = DateTime.Parse(args[2]);                // Time it will expire       ex. 08/18/2018 07:22:16 AM/PM
                var    createdBy   = Context.User.Mention;                   // User who created the reminder
                string targetUsers = args[3];                                // Users to be notified when reminder expires

                // Send response as pretty embed
                var eb = new EmbedBuilder();
                eb.WithColor(Color.Orange);
                eb.WithTitle("New Reminder:");
                eb.WithDescription(message);
                eb.AddField("Reminder Name:", name, true);
                eb.AddField("For time:", "(" + timeExpires + ")", true);
                eb.AddField("Will notify: ", targetUsers, false);
                eb.WithFooter("Reminder logged!");
                await Context.Channel.SendMessageAsync("", false, eb.Build());

                // Log reminder
                try
                {
                    // Add reminder name to ReminderList.txt
                    ReadAndWrite rw = new ReadAndWrite();
                    using (StreamWriter sw = File.AppendText(rw.getPath(@"Reminders\ReminderList")))
                    {
                        await sw.WriteLineAsync(name);

                        sw.Close();
                    }

                    // Create new reminder file
                    string fileName = @"Reminders\" + name;
                    rw.CreateFileWithTitle(fileName, name);
                    StreamWriter file = rw.openTextToWrite(fileName);
                    rw.addSection(file, "Name", name);
                    rw.addSection(file, "Message", message);
                    rw.addSection(file, "Time created", timeCreated.ToString());
                    rw.addSection(file, "Time Expires", timeExpires.ToString());
                    rw.addSection(file, "Created By", createdBy);
                    rw.addSection(file, "Target Users", targetUsers);
                    rw.closeText(file);
                }
                catch (Exception e)
                {
                    Console.WriteLine(e);
                }
            }
            else
            {
                // Too few args. Print an error
                await Context.Channel.SendMessageAsync("Oops! That's not enough input arguments for this command. Try:\n" +
                                                       ".Reminder <Reminder name>~<Reminder message>~<MM/DD/YYYY HH:MM:SS AM/PM>~<TargetUser1><MoreUsers>...");
            }

            while (true)
            {
                await Task.Delay(30000);
                await expireReminders();
            }
        }