Example #1
0
        private async Task Eval(ServerMessagedEventArgs e)
        {
            Status = PluginStatus.Processing;

            IrcCommandEventArgs command =
                new IrcCommandEventArgs($"{Commands.PRIVMSG} {e.Message.Origin}", string.Empty);

            if (e.Message.SplitArgs.Count < 3)
            {
                command.Arguments = "Not enough parameters.";
            }

            Status = PluginStatus.Running;

            if (string.IsNullOrEmpty(command.Arguments))
            {
                Status = PluginStatus.Running;
                string evalArgs = e.Message.SplitArgs.Count > 3
                    ? e.Message.SplitArgs[2] + e.Message.SplitArgs[3]
                    : e.Message.SplitArgs[2];

                try
                {
                    command.Arguments = _Calculator.Evaluate(evalArgs).ToString(CultureInfo.CurrentCulture);
                }
                catch (Exception ex)
                {
                    command.Arguments = ex.Message;
                }
            }

            await DoCallback(this, new PluginActionEventArgs(PluginActionType.SendMessage, command, Name));

            Status = PluginStatus.Stopped;
        }
Example #2
0
        private async Task OnCommandReceived(object source, IrcCommandEventArgs args)
        {
            if (CommandReceived == null)
            {
                return;
            }

            await CommandReceived.Invoke(source, args);
        }
Example #3
0
        private async Task Lookup(ServerMessagedEventArgs args)
        {
            Status = PluginStatus.Processing;

            if ((args.Message.SplitArgs.Count < 2) || !args.Message.SplitArgs[1].Equals("lookup"))
            {
                return;
            }

            IrcCommandEventArgs command =
                new IrcCommandEventArgs($"{Commands.PRIVMSG} {args.Message.Origin}", string.Empty);

            if (args.Message.SplitArgs.Count < 3)
            {
                command.Arguments = "Insufficient parameters. Type 'eve help lookup' to view correct usage.";
                await DoCallback(this, new PluginActionEventArgs(PluginActionType.SendMessage, command, Name));

                return;
            }

            Status = PluginStatus.Running;

            string query    = string.Join(" ", args.Message.SplitArgs.Skip(1));
            string response =
                await
                $"https://en.wikipedia.org/w/api.php?format=json&action=query&prop=extracts&exintro=&explaintext=&titles={query}"
                .HttpGet();

            JToken pages = JObject.Parse(response)["query"]["pages"].Values().First();

            if (string.IsNullOrEmpty((string)pages["extract"]))
            {
                command.Arguments = "Query failed to return results. Perhaps try a different term?";
                await DoCallback(this, new PluginActionEventArgs(PluginActionType.SendMessage, command, Name));

                return;
            }

            string fullReplyStr =
                $"\x02{(string)pages["title"]}\x0F — {Regex.Replace((string)pages["extract"], @"\n\n?|\n", " ")}";

            command.Command = args.Message.Nickname;

            foreach (string splitMessage in fullReplyStr.LengthSplit(400))
            {
                command.Arguments = splitMessage;
                await DoCallback(this, new PluginActionEventArgs(PluginActionType.SendMessage, command, Name));
            }

            Status = PluginStatus.Stopped;
        }
Example #4
0
        private async Task Set(ServerMessagedEventArgs args)
        {
            if ((args.Message.SplitArgs.Count < 2) || !args.Message.SplitArgs[1].Equals("set"))
            {
                return;
            }

            Status = PluginStatus.Processing;

            IrcCommandEventArgs command =
                new IrcCommandEventArgs($"{Commands.PRIVMSG} {args.Message.Origin}", string.Empty);

            if (args.Message.SplitArgs.Count < 5)
            {
                command.Arguments = "Insufficient parameters. Type 'eve help lookup' to view correct usage.";
                await DoCallback(this, new PluginActionEventArgs(PluginActionType.SendMessage, command, Name));

                return;
            }

            Status = PluginStatus.Stopped;
        }
Example #5
0
 public async Task SendDataAsync(object source, IrcCommandEventArgs args)
 {
     await WriteAsync(args.ToString());
 }
Example #6
0
        //private async Task Join(ServerMessagedEventArgs args) {
        //    Status = PluginStatus.Processing;

        //    string message = string.Empty;

        //    if (args.Message.SplitArgs.Count < 3) {
        //        message = "Insufficient parameters. Type 'eve help join' to view command's help index.";
        //    } else if (args.Message.SplitArgs.Count < 2 || !args.Message.SplitArgs[2].StartsWith("#")) {
        //        message = "Channel name must start with '#'.";
        //    } else if (args.Caller.Server.GetChannel(args.Message.SplitArgs[2].ToLower()) != null) {
        //        message = "I'm already in that channel.";
        //    }

        //    Status = PluginStatus.Running;

        //    if (string.IsNullOrEmpty(message)) {
        //        await DoCallback(this, new PluginActionEventArgs(PluginActionType.SendMessage, new IrcCommandEventArgs(Commands.JOIN, args.Message.SplitArgs[2]), Name));

        //        args.Caller.Server.Channels.Add(new Channel(args.Message.SplitArgs[2].ToLower()));

        //        message = $"Successfully joined channel: {args.Message.SplitArgs[2]}.";
        //    }

        //    await DoCallback(this, new PluginActionEventArgs(PluginActionType.SendMessage, new IrcCommandEventArgs($"{Commands.PRIVMSG} {args.Message.Origin}", message), Name));

        //    Status = PluginStatus.Stopped;
        //}

        //private async Task Part(ServerMessagedEventArgs args) {
        //    Status = PluginStatus.Processing;

        //    IrcCommandEventArgs command = new IrcCommandEventArgs($"{Commands.PRIVMSG} {args.Message.Origin}", string.Empty);

        //    if (args.Message.SplitArgs.Count < 3) {
        //        command.Arguments = "Insufficient parameters. Type 'eve help part' to view command's help index.";
        //    } else if (args.Message.SplitArgs.Count < 2 || !args.Message.SplitArgs[2].StartsWith("#")) {
        //        command.Arguments = "Channel parameter must be a proper name (starts with '#').";
        //    } else if (args.Message.SplitArgs.Count < 2 || args.Caller.Server.GetChannel(args.Message.SplitArgs[2]) == null) {
        //        command.Arguments = "I'm not in that channel.";
        //    }

        //    Status = PluginStatus.Running;

        //    if (!string.IsNullOrEmpty(command.Arguments)) {
        //        await DoCallback(this, new PluginActionEventArgs(PluginActionType.SendMessage, command, Name));
        //        return;
        //    }

        //    string channel = args.Message.SplitArgs[2].ToLower();

        //    args.Caller.Server.RemoveChannel(channel);

        //    command.Arguments = $"Successfully parted channel: {channel}";

        //    await DoCallback(this, new PluginActionEventArgs(PluginActionType.SendMessage, command, Name));
        //    await DoCallback(this, new PluginActionEventArgs(PluginActionType.SendMessage, new IrcCommandEventArgs(Commands.PART, $"{channel} Channel part invoked by: {args.Message.Nickname}"), Name));

        //    Status = PluginStatus.Stopped;
        //}

        //private async Task Channels(ServerMessagedEventArgs args) {
        //    Status = PluginStatus.Running;
        //    await DoCallback(this, new PluginActionEventArgs(PluginActionType.SendMessage, new IrcCommandEventArgs($"{Commands.PRIVMSG} {args.Message.Origin}", string.Join(", ", args.Caller.Server.Channels.Where(channel => channel.Name.StartsWith("#")).Select(channel => channel.Name))), Name));

        //    Status = PluginStatus.Stopped;
        //}

        //private async Task YouTubeLinkResponse(ServerMessagedEventArgs args) {
        //    Status = PluginStatus.Running;

        //    const int maxDescriptionLength = 100;

        //    string getResponse = await $"https://www.googleapis.com/youtube/v3/videos?part=snippet&id={_youtubeRegex.Match(args.Message.Args).Groups["ID"]}&key={args.Caller.GetApiKey("YouTube")}".HttpGet();

        //    JToken video = JObject.Parse(getResponse)["items"][0]["snippet"];
        //    string channel = (string)video["channelTitle"];
        //    string title = (string)video["title"];
        //    string description = video["description"].ToString().Split('\n')[0];
        //    string[] descArray = description.Split(' ');

        //    if (description.Length > maxDescriptionLength) {
        //        description = string.Empty;

        //        for (int i = 0; description.Length < maxDescriptionLength; i++) {
        //            description += $" {descArray[i]}";
        //        }

        //        if (!description.EndsWith(" ")) {
        //            description.Remove(description.LastIndexOf(' '));
        //        }

        //        description += "....";
        //    }

        //    await DoCallback(this, new PluginActionEventArgs(PluginActionType.SendMessage, new IrcCommandEventArgs($"{Commands.PRIVMSG} {args.Message.Origin}", $"{title} (by {channel}) — {description}"), Name));

        //    Status = PluginStatus.Stopped;
        //}

        private async Task Define(ServerMessagedEventArgs args)
        {
            Status = PluginStatus.Processing;

            IrcCommandEventArgs command =
                new IrcCommandEventArgs($"{Commands.PRIVMSG} {args.Message.Origin}", string.Empty);

            if (args.Message.SplitArgs.Count < 3)
            {
                command.Arguments = "Insufficient parameters. Type 'eve help define' to view correct usage.";
                await DoCallback(this, new PluginActionEventArgs(PluginActionType.SendMessage, command, Name));

                return;
            }

            Status = PluginStatus.Running;

            string partOfSpeech = args.Message.SplitArgs.Count > 3
                ? $"&part_of_speech={args.Message.SplitArgs[3]}"
                : string.Empty;

            JObject entry =
                JObject.Parse(
                    await
                    $"http://api.pearson.com/v2/dictionaries/laad3/entries?headword={args.Message.SplitArgs[2]}{partOfSpeech}&limit=1"
                    .HttpGet());

            if ((int)entry.SelectToken("count") < 1)
            {
                command.Arguments = "Query returned no results.";
                await DoCallback(this, new PluginActionEventArgs(PluginActionType.SendMessage, command, Name));

                return;
            }

            Dictionary <string, string> _out = new Dictionary <string, string>
            {
                { "word", (string)entry["results"][0]["headword"] },
                { "pos", (string)entry["results"][0]["part_of_speech"] }
            };

            // todo optimise if block
            // this 'if' block seems messy and unoptimised.
            // I'll likely change it in the future.
            if (entry["results"][0]["senses"][0]["subsenses"] != null)
            {
                _out.Add("definition", (string)entry["results"][0]["senses"][0]["subsenses"][0]["definition"]);

                if (entry["results"][0]["senses"][0]["subsenses"][0]["examples"] != null)
                {
                    _out.Add("example",
                             (string)entry["results"][0]["senses"][0]["subsenses"][0]["examples"][0]["text"]);
                }
            }
            else
            {
                _out.Add("definition", (string)entry["results"][0]["senses"][0]["definition"]);

                if (entry["results"][0]["senses"][0]["examples"] != null)
                {
                    _out.Add("example", (string)entry["results"][0]["senses"][0]["examples"][0]["text"]);
                }
            }

            string returnMessage = $"{_out["word"]} [{_out["pos"]}] — {_out["definition"]}";

            if (_out.ContainsKey("example"))
            {
                returnMessage += $" (ex. {_out["example"]})";
            }

            command.Arguments = returnMessage;
            await DoCallback(this, new PluginActionEventArgs(PluginActionType.SendMessage, command, Name));

            Status = PluginStatus.Stopped;
        }