Exemplo n.º 1
0
    public void Tell(ITriggerMsg e)
    {
        // tell <nick> <message>
        var message =
            e.GetArg(out string destinationNick)
            .ToJoined(JoinedOptions.TrimExterior);

        if (ParseArgs.Success(destinationNick, message))
        {
            var inbox = inboxes.GetOrNew(destinationNick);

            if (inbox.Add(e.Nick, message))
            {
                e.Reply("Sending message to {0} when they're active. [{1}/{2}]",
                        destinationNick, inbox.MessagesCount, inbox.Capacity);

                inboxes.Save(inbox);
            }
            else
            {
                e.Reply("Sorry, {0}'s inbox is full!", destinationNick);
            }
        }
        // Short circuit tell to tell-read if not enough arguments.
        else
        {
            Read(e);
        }
    }
Exemplo n.º 2
0
    void Say(ITriggerMsg e)
    {
        var    rest    = e.GetArg(out string channel);
        string message = null;

        // say [channel] <message>
        // Send message to specified channel.
        if (channel.StartsWith("#", StringComparison.Ordinal))
        {
            message = rest.ToJoined();
        }
        // say <message>
        // Send message to current channel.
        if (!message.HasValue())
        {
            channel = e.Channel;
            message = e.MessageWithoutTrigger();
        }

        if (ParseArgs.Success(channel, message) && Say(channel, message))
        {
            string origin = string.Empty;
            if (e.Channel != null)
            {
                origin = '/' + e.Channel;
            }

            log.Message("Say: {0}{1} -> {2}", e.Nick, origin, channel);
        }
    }
Exemplo n.º 3
0
    public void Timer(ITriggerMsg e)
    {
        var timers = ircTimers.GetTimers(e.Nick);
        var rest   = e.GetArg(out string command, toLower: true);

        // timer
        if (!command.HasValue())
        {
            EmitDescriptions(timers.Descriptions(), e);
            return;
        }

        // timer <delta> [index]
        // Delta is +N or -N
        char deltaSign = command[0];

        if (deltaSign == '+' || deltaSign == '-')
        {
            TimerChange(
                ParseIdx(rest.GetArg(), 0),
                ParseTs(command),
                e, timers
                );
        }

        // timer stop [index]
        else if (command == "stop")
        {
            TimerStop(
                ParseIdx(rest.GetArg(), -1),
                e, timers
                );
        }

        // timer change <index> <delta>
        else if (command == "change")
        {
            var args = rest.GetArgs(2);
            if (ParseArgs.Success(args))
            {
                TimerChange(
                    ParseIdx(args[0], -1),
                    ParseTs(args[1]),
                    e, timers
                    );
            }
        }

        // timer <duration> [message]
        else
        {
            TimerStart(
                ParseTs(command),
                rest.ToJoined(JoinedOptions.TrimExterior),
                e, timers
                );
        }
    }
Exemplo n.º 4
0
    void DefVar(ITriggerMsg e)
    {
        var expression = e.GetArg(out string symbol).ToJoined();

        if (ParseArgs.Success(symbol, expression))
        {
            var expr = VerifiedExpression.Parse(expression, CalcEnv);
            if (CheckPreconditions(e, expr, symbol))
            {
                double result = ShuntingYard.Calculate(expr);
                if (CalcEnv.Variable(symbol, out double previous))
                {
                    e.Reply("{0} = {1} (Previous value: {2})", symbol, result, previous);
                }
                else
                {
                    e.Reply("{0} = {1}", symbol, result);
                }

                CalcEnv.AssignVariable(symbol, result);
            }
        }
    }