Example #1
0
        /**<summary>Parses the message send in by discord and builds it into an <c>Reminder</c></summary>
         * <param name="msg">The message sent from discord</param>
         * <param name="prefix">The prefix that is to be considered for commands</param>
         * <param name="reminder">The reminder that was built</param>
         * <returns>
         * <para>1: Success</para>
         * <para>0: Command ignored (not meant for this class)</para>
         * <para>Negative: Errors</para>
         * <para>-1: Only prefix provided</para>
         * <para>-2: Invalid Prefix</para>
         * <para>-3: Invalid Time</para>
         * <para>-4: Missing when reminder should go off</para>
         * </returns>
         */
        private int ParseCommand(SocketMessage msg, string prefix, out Reminder reminder)
        {
            reminder = default(Reminder);

            //Checks if the message is meant for the bot
            if (msg.Content.StartsWith(prefix))
            {
                //Split up user message
                char[] delimiters = { ' ' };
                var    args       = msg.Content.Split(delimiters);

                if (args.Length < 2) //Only prefix provided
                {
                    return(-1);
                }

                int repeat = ParseRepeat(args[0], prefix);
                if (repeat < -1) //Invalid prefix
                {
                    return(-2);
                }

                int index = ParseWhen(args, msg.Timestamp, out DateTimeOffset when, out int interval);

                if (index <= 0)
                {
                    if (index == 0)     //Invalid Time
                    {
                        return(-3);
                    }
                    else                //Missing when arguement
                    {
                        return(-4);
                    }
                }

                string reminderMessage = ParseReminderMessage(msg.Content, args, index, delimiters);

                reminder = new ReminderBuilder()
                           .ChannelId(msg.Channel.Id)
                           .Interval(interval)
                           .Message(reminderMessage)
                           .Repeat(repeat)
                           .UserId(msg.Author.Id)
                           .HasMention(msg.MentionedUsers.Count > 0 || msg.MentionedRoles.Count > 0)
                           .When(when)
                           .Build();

                return(1);
            }

            return(0);
        }
Example #2
0
        }                     //For serializing and deserializing; Probably not safe

        public Reminder(ReminderBuilder r)
        {
            if (default(DateTimeOffset) == r.when)
            {
                throw new ArgumentNullException("An reminder has not been set or has been set to an invalid time");
            }
            if (r.message == null)
            {
                message = "";
            }

            reminderId = r.reminderId;
            when       = r.when;
            message    = r.message;
            userId     = r.userId;
            channelId  = r.channelId;
            interval   = r.interval;
            repeat     = r.repeat;
            hasMention = r.hasMention;
        }