示例#1
0
        private async Task GroupFinderCommand(MessageCreateEventArgs e, string[] commandParts)
        {
            const int messageLifetime = 60000;
            int       days            = 7;

            if (commandParts.Length > 2)
            {
                await SendError(e, $"That is too many parameters for a GF command.");

                return;
            }
            if (commandParts.Length == 2)
            {
                string dayString = commandParts[1];
                if (!int.TryParse(dayString, out days))
                {
                    await SendError(e, $"{dayString} is not a number.");

                    return;
                }
                if (days > 14)
                {
                    days = 14;
                }
            }
            List <string> ops = GroupFinder.NextDays(days);
            DateTime      dt  = DateTime.Now.Date;
            StringBuilder msg = new StringBuilder(512);

            msg.AppendLine(DiscordText.BigText("group  finder"));
            msg.AppendLine();
            msg.Append("Operations for the next ");
            msg.Append(days);
            msg.AppendLine(" days are");
            msg.AppendLine(DiscordText.CodeBlock);
            foreach (string opCode in ops)
            {
                msg.Append(dt.ToString("ddd"));
                msg.Append(' ');
                msg.Append(opCode.PadRight(4));
                msg.AppendLine(Operation.GetFullName(opCode));
                dt = dt.AddDays(1);
            }
            msg.AppendLine(DiscordText.CodeBlock);
            msg.Append(GetSelfDestructText(messageLifetime));
            DiscordMessage message = await e.Channel.SendMessageAsync(msg.ToString());

            _messageDeleter.AddMessage(message, messageLifetime);
            await SafeDeleteMessage(e);
        }
示例#2
0
        private async Task CreateCommand(MessageCreateEventArgs e, ParsedCommand cmd)
        {
            try
            {
                OperationParameters opParams = OperationParameters.ParseWithDefault(cmd.CommandParts);

                Operation newOperation = new Operation()
                {
                    Size = opParams.Size,
                    Mode = opParams.Mode,
                    Date = DateHelper.GetDateForNextOccuranceOfDay(opParams.Day) + opParams.Time,
                    Side = opParams.Side,
                };
                newOperation.OperationName = opParams.OperationCode == "GF" ? GroupFinder.OperationOn(newOperation.Date) : opParams.OperationCode;

                DiscordMessage newOpMessage = await e.Channel.SendMessageAsync("Creating event...");

                newOperation.MessageId = newOpMessage.Id;

                string text = _ops.Add(newOperation).GetOperationMessageText();
                await newOpMessage.ModifyAsync(text);
                await PinMessage(e, newOpMessage);

                await _repository.SaveAsync(_ops);

                SendAlerts(e, newOperation);
            }
            catch (OperationException ex)
            {
                await SendError(e, ex.Message);
            }
            catch (OpBotInvalidValueException opEx)
            {
                await SendError(e, $"I don't understand part of that create command.\n\n{opEx.Message}\n\nSo meat bag, try again and get it right this time or you will be terminated as an undesirable {DiscordText.StuckOutTongue}.");
            }
        }