Exemplo n.º 1
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.º 2
0
    void ExecuteSearch(ITriggerMsg e, Site site)
    {
        var searchTerms = e.MessageWithoutTrigger();

        if (!string.IsNullOrEmpty(searchTerms))
        {
            var results = site.Search(searchTerms);

            if (results.Success)
            {
                if (results.Count > 0)
                {
                    PrintResults(results, site, e.ReturnTo);
                }
                else
                {
                    e.Reply("Sorry, the query '{0}' didn't result in any hits.", searchTerms);
                }
            }
            else
            {
                e.Reply("Error executing search: " + results.Exception.Message);
            }
        }
    }
Exemplo n.º 3
0
    // --- Set Weather Location, 'W' trigger ---

    void SetWeatherLocation(ITriggerMsg e)
    {
        var location = e.MessageWithoutTrigger(trim: true);

        if (!string.IsNullOrEmpty(location))
        {
            defaultLocations.Set(e.Nick, location);
            defaultLocations.Serialize(storagePath);
            e.Reply("Your default location has been set to '{0}'.", location);
        }
        else
        {
            e.Reply("Your current default location is '{0}'.", defaultLocations.Get(e.Nick));
        }
    }
Exemplo n.º 4
0
    void HandleTrigger(ITriggerMsg e)
    {
        var exprStr = e.MessageWithoutTrigger();

        if (exprStr.HasValue())
        {
            var expr = VerifiedExpression.Parse(exprStr, CalcEnv);

            if (expr.Success)
            {
                double result = ShuntingYard.Calculate(expr);
                e.Reply(result.ToString());
            }
            else
            {
                OutputError(e, expr);
            }
        }
    }
Exemplo n.º 5
0
    // --- Helper functions for WeatherSearch ---

    string GetLocation(ITriggerMsg e)
    {
        // w <location>
        var location = e.MessageWithoutTrigger(trim: true);

        if (!string.IsNullOrEmpty(location))
        {
            // w @<nick>
            // Special form to query weather location associated with `nick`.
            if (location.Length > 1 && location[0] == '@')
            {
                var nick = location.Substring(1, location.Length - 1);
                location = defaultLocations.Get(nick);
            }
        }
        else
        {
            location = defaultLocations.Get(e.Nick);
        }

        return(location);
    }