Beispiel #1
0
        // Constructor (all fields are required to be valid).
        public Bulletin(DiscordMessage message, BulletinData data, ulong original_id)
        {
            this.message     = message;
            this.data        = data;
            this.original_id = original_id;
            do_notify_owner  = true;

            updater = new Timer(interval_refresh)
            {
                AutoReset = true
            };
            updater.Elapsed += (o, e) => { _ = Update(); };
            updater.Start();
        }
Beispiel #2
0
        public static string ToString(BulletinData data)
        {
            string post       = "";
            bool   is_expired = (data.expiry <= DateTimeOffset.Now);

            // @mention + group title
            if (data.mention != null && !is_expired)
            {
                post += data.mention.Mention() + " ";
            }
            string title_str = data.title.Bold();

            if (is_expired)
            {
                title_str = title_str.Strike();
            }
            post += title_str + "\n";

            // group
            post += "group lead: " + data.owner.Mention + "\n";
            post += data.group.ToString() + "\n";

            // expiry time
            TimeSpan expiry_round  = data.expiry - DateTimeOffset.Now;
            double   seconds_round = Util.RoundToFive(expiry_round.TotalSeconds);

            expiry_round = TimeSpan.FromSeconds(seconds_round);

            string delist_str =
                "this group will be delisted in ~" +
                expiry_round.ToString(@"mm\:ss");

            if (is_expired)
            {
                delist_str = "this group has been delisted";
            }
            post += delist_str.Italics();

            return(post);
        }
Beispiel #3
0
        static async Task <BulletinData?> ParseMessage(DiscordMessage message)
        {
            // Strip @mentions
            string command = message.Content;

            command = Regex.Replace(command, @"<@[!&]?\d+>", "");
            command = command.Trim();
            log.Debug("Trimmed message:", 1, message.Id);
            log.Debug(command, 2, message.Id);

            // Separate command into component parts
            Regex  regex           = new Regex(@"^(?:-(\S+))?\s*(?:!(\S+))?\s*(?:(.+))?$");
            Match  match           = regex.Match(command);
            string command_option  = match.Groups[1].Value.ToLower();
            string command_mention = match.Groups[2].Value;
            string command_data    = match.Groups[3].Value;

            log.Debug("option:  " + command_option, 1, message.Id);
            log.Debug("mention: " + command_mention, 1, message.Id);
            log.Debug("data:    " + command_data, 1, message.Id);

            // Handle help command
            if (IsHelp(command_option))
            {
                DiscordChannel?channel = await Util.GetPrivateChannel(message);

                if (channel == null)
                {
                    log.Error("Cannot send help text to user:"******"User: "******"Cannot notify user:"******"User: "******"Tried to post bulletin from non-server channel.", 0, message.Id);
                return(null);
            }
            if (!Program.settings.ContainsKey(guild.Id))
            {
                log.Warning("Tried to post bulletin to un-configured server.", 0, message.Id);
                return(null);
            }
            Settings settings = Program.settings[guild.Id];

            return(BulletinData.Parse(
                       command_option,
                       command_mention,
                       command_data,
                       message,
                       settings
                       ));
        }