private Task NewTopic(ServerMessagedEventArgs e) { Server.GetChannel(e.Message.Origin). Topic = e.Message.Args; return(Task.CompletedTask); }
private Task NamesReply(ServerMessagedEventArgs e) { string channelName = e.Message.SplitArgs[1]; // * SplitArgs [2] is always your nickname // in this case, Eve is the only one in the channel if (e.Message.SplitArgs.Count < 4) { return(Task.CompletedTask); } foreach (string s in e.Message.SplitArgs[3].Split(' ')) { Channel currentChannel = Server.Channels.SingleOrDefault(channel => channel.Name.Equals(channelName)); if (currentChannel == null || currentChannel.Inhabitants.Contains(s)) { continue; } Server?.Channels.Single(channel => channel.Name.Equals(channelName)). Inhabitants.Add(s); } return(Task.CompletedTask); }
private Task Part(ServerMessagedEventArgs e) { Server.GetChannel(e.Message.Origin)?. Inhabitants.RemoveAll(x => x.Equals(e.Message.Nickname)); return(Task.CompletedTask); }
private Task ChannelTopic(ServerMessagedEventArgs e) { Server.GetChannel(e.Message.SplitArgs[0]). Topic = e.Message.Args.Substring(e.Message.Args.IndexOf(' ') + 2); return(Task.CompletedTask); }
private async Task Eval(ServerMessagedEventArgs e) { Status = PluginStatus.Processing; CommandEventArgs message = new CommandEventArgs(Commands.PRIVMSG, e.Message.Origin, string.Empty); if (e.Message.SplitArgs.Count < 3) { message.Contents = "Not enough parameters."; } Status = PluginStatus.Running; if (string.IsNullOrEmpty(message.Contents)) { Status = PluginStatus.Running; string evalArgs = e.Message.SplitArgs.Count > 3 ? e.Message.SplitArgs[2] + e.Message.SplitArgs[3] : e.Message.SplitArgs[2]; try { message.Contents = calculator.Evaluate(evalArgs) .ToString(CultureInfo.CurrentCulture); } catch (Exception ex) { message.Contents = ex.Message; } } await DoCallback(this, new ActionEventArgs(PluginActionType.SendMessage, message)); Status = PluginStatus.Stopped; }
private Task Join(ServerMessagedEventArgs e) { Server.GetChannel(e.Message.Origin)?. Inhabitants.Add(e.Message.Nickname); return(Task.CompletedTask); }
private async Task Set(ServerMessagedEventArgs e) { if (e.Message.SplitArgs.Count < 2 || !e.Message.SplitArgs[1].Equals("set")) { return; } Status = PluginStatus.Processing; CommandEventArgs message = new CommandEventArgs(Commands.PRIVMSG, e.Message.Origin, string.Empty); if (e.Message.SplitArgs.Count < 5) { message.Contents = "Insufficient parameters. Type 'eve help lookup' to view correct usage."; await DoCallback(this, new ActionEventArgs(PluginActionType.SendMessage, message)); return; } if (e.Caller.GetUser(e.Message.Nickname) ?.Access > 0) { message.Contents = "Insufficient permissions."; } //e.Root.GetUser() Status = PluginStatus.Stopped; }
private async Task Channels(ServerMessagedEventArgs e) { Status = PluginStatus.Running; await DoCallback(this, new ActionEventArgs(PluginActionType.SendMessage, new CommandEventArgs(Commands.PRIVMSG, e.Message.Origin, string.Join(", ", e.Caller.Server.Channels.Where(channel => channel.Name.StartsWith("#")) .Select(channel => channel.Name))))); Status = PluginStatus.Stopped; }
private async Task Users(ServerMessagedEventArgs e) { Status = PluginStatus.Running; await DoCallback(this, new ActionEventArgs(PluginActionType.SendMessage, new CommandEventArgs(Commands.PRIVMSG, e.Message.Origin, string.Join(", ", e.Caller.GetAllUsers())))); Status = PluginStatus.Stopped; }
private async Task OnChannelMessaged(object source, ServerMessagedEventArgs e) { if (ChannelMessaged == null) { return; } await ChannelMessaged.Invoke(source, e); }
private async Task Info(ServerMessagedEventArgs e) { if ((e.Message.SplitArgs.Count < 2) || !e.Message.SplitArgs[1].Equals("info")) { return; } await _Bot.Server.Connection.SendDataAsync(this, new IrcCommandEventArgs(Commands.PRIVMSG, $"{e.Message.Origin} {BotInfo}")); }
private async Task Quit(ServerMessagedEventArgs e) { if (e.Message.SplitArgs.Count < 2 || !e.Message.SplitArgs[1].Equals("quit")) { return; } await DoCallback(this, new ActionEventArgs(PluginActionType.SendMessage, new CommandEventArgs(Commands.PRIVMSG, e.Message.Origin, "Shutting down."))); await DoCallback(this, new ActionEventArgs(PluginActionType.SignalTerminate)); }
private static async Task Default(ServerMessagedEventArgs e) { if (e.Caller.IgnoreList.Contains(e.Message.Realname)) { return; } if (!e.Message.SplitArgs[0].Replace(",", string.Empty) .Equals(e.Caller.ClientConfiguration.Nickname.ToLower())) { return; } if (e.Message.SplitArgs.Count < 2) // typed only 'eve' { await e.Caller.Server.Connection.SendDataAsync(Commands.PRIVMSG, $"{e.Message.Origin} Type 'eve help' to view my command list."); return; } // built-in 'help' command if (e.Message.SplitArgs[1].ToLower() .Equals("help")) { if (e.Message.SplitArgs.Count.Equals(2)) // in this case, 'help' is the only text in the string. { List <string> entries = e.Caller.LoadedCommands.Keys.ToList(); string commandsReadable = string.Join(", ", entries.Where(entry => entry != null)); await e.Caller.Server.Connection.SendDataAsync(Commands.PRIVMSG, entries.Count == 0 ?$"{e.Message.Origin} No commands currently active." : $"{e.Message.Origin} Active commands: {commandsReadable}"); return; } KeyValuePair <string, string> queriedCommand = e.Caller.GetCommand(e.Message.SplitArgs[2]); string valueToSend = queriedCommand.Equals(null) ? "Command not found." : $"{queriedCommand.Key}: {queriedCommand.Value}"; await e.Caller.Server.Connection.SendDataAsync(Commands.PRIVMSG, $"{e.Message.Origin} {valueToSend}"); return; } if (e.Caller.CommandExists(e.Message.SplitArgs[1].ToLower())) { return; } await e.Caller.Server.Connection.SendDataAsync(Commands.PRIVMSG, $"{e.Message.Origin} Invalid command. Type 'eve help' to view my command list."); }
private async Task Quit(ServerMessagedEventArgs args) { if ((args.Message.SplitArgs.Count < 2) || !args.Message.SplitArgs[1].Equals("quit")) { return; } await DoCallback(this, new PluginActionEventArgs(PluginActionType.SendMessage, new IrcCommandEventArgs(Commands.QUIT, "Shutting down."), Name)); await DoCallback(this, new PluginActionEventArgs(PluginActionType.SignalTerminate, null, Name)); }
public async Task InvokeAsync(object source, TEventArgs args) { if (args is ServerMessagedEventArgs) { ServerMessagedEventArgs _args = args as ServerMessagedEventArgs; if (methods.ContainsKey(_args.Message.Command)) { await methods[_args.Message.Command].InvokeAsync(source, args); } } }
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; }
private Task SortMessage(object source, ServerMessagedEventArgs e) { if (GetChannel(e.Message.Origin) == null) { GetChannel(Connection.Address). Messages.Add(e.Message); } else { GetChannel(e.Message.Origin). Messages.Add(e.Message); } return(Task.CompletedTask); }
private async Task Part(ServerMessagedEventArgs e) { Status = PluginStatus.Processing; CommandEventArgs message = new CommandEventArgs(Commands.PRIVMSG, e.Message.Origin, string.Empty); if (e.Caller.GetUser(e.Message.Realname) ?.Access > 1) { message.Contents = "Insufficient permissions."; } else if (e.Message.SplitArgs.Count < 3) { message.Contents = "Insufficient parameters. Type 'eve help part' to view command's help index."; } else if (e.Message.SplitArgs.Count < 2 || !e.Message.SplitArgs[2].StartsWith("#")) { message.Contents = "Channel parameter must be a proper name (starts with '#')."; } else if (e.Message.SplitArgs.Count < 2 || e.Caller.Server.GetChannel(e.Message.SplitArgs[2]) == null) { message.Contents = "I'm not in that channel."; } Status = PluginStatus.Running; if (!string.IsNullOrEmpty(message.Contents)) { await DoCallback(this, new ActionEventArgs(PluginActionType.SendMessage, message)); return; } string channel = e.Message.SplitArgs[2].ToLower(); e.Caller.Server.RemoveChannel(channel); message.Contents = $"Successfully parted channel: {channel}"; await DoCallback(this, new ActionEventArgs(PluginActionType.SendMessage, message)); await DoCallback(this, new ActionEventArgs(PluginActionType.SendMessage, new CommandEventArgs(Commands.PART, string.Empty, $"{channel} Channel part invoked by: {e.Message.Nickname}"))); Status = PluginStatus.Stopped; }
private Task LogChannelMessage(object source, ServerMessagedEventArgs e) { if (e.Message.Command.Equals(Commands.PRIVMSG)) { OnLog(this, new LogEventArgs(LogEventLevel.Information, $"<{e.Message.Origin} {e.Message.Nickname}> {e.Message.Args}")); } else if (e.Message.Command.Equals(Commands.ERROR)) { OnLog(this, new LogEventArgs(LogEventLevel.Error, e.Message.RawMessage)); } else { OnLog(this, new LogEventArgs(LogEventLevel.Information, e.Message.RawMessage)); } return(Task.CompletedTask); }
private async Task Listen(object source, ServerMessagedEventArgs e) { if (string.IsNullOrEmpty(e.Message.Command)) { return; } if (e.Message.Command.Equals(Commands.PRIVMSG)) { if (e.Message.Origin.StartsWith("#") && !Server.Channels.Any(channel => channel.Name.Equals(e.Message.Origin))) { Server.Channels.Add(new Channel(e.Message.Origin)); } if (GetUser(e.Message.Realname)?. GetTimeout() ?? false) { return; } } else if (e.Message.Command.Equals(Commands.ERROR)) { Server.Executing = false; return; } if (e.Message.Nickname.Equals(ClientConfiguration.Nickname) || ClientConfiguration.IgnoreList.Contains(e.Message.Realname)) { return; } if (e.Message.SplitArgs.Count >= 2 && e.Message.SplitArgs[0].Equals(ClientConfiguration.Nickname.ToLower())) { e.Message.InputCommand = e.Message.SplitArgs[1].ToLower(); } try { await wrapper.Host.InvokeAsync(this, e); } catch (Exception ex) { await OnFailure(this, new BasicEventArgs(ex.ToString())); } }
private static async Task MotdReplyEnd(ServerMessagedEventArgs e) { if (e.Caller.Server.Identified) { return; } await e.Caller.Server.Connection.SendDataAsync(Commands.PRIVMSG, $"NICKSERV IDENTIFY {e.Caller.ClientConfiguration.Password}"); await e.Caller.Server.Connection.SendDataAsync(Commands.MODE, $"{e.Caller.ClientConfiguration.Nickname} +B"); foreach (Channel channel in e.Caller.Server.Channels.Where(channel => !channel.Connected && !channel.IsPrivate)) { await e.Caller.Server.Connection.SendDataAsync(Commands.JOIN, channel.Name); channel.Connected = true; } e.Caller.Server.Identified = true; }
private async Task MotdReplyEnd(ServerMessagedEventArgs args) { if (MotdReplyEndSequenceEnacted) { return; } await DoCallback(this, new PluginActionEventArgs(PluginActionType.SendMessage, new IrcCommandEventArgs(Commands.PRIVMSG, $"NICKSERV IDENTIFY {Configuration[nameof(Core)]["Password"].StringValue}"), Name)); await DoCallback(this, new PluginActionEventArgs(PluginActionType.SendMessage, new IrcCommandEventArgs(Commands.MODE, $"{Configuration[nameof(Core)]["Nickname"].StringValue} +B"), Name)); //args.Caller.Server.Channels.Add(new Channel("#testgrounds")); MotdReplyEndSequenceEnacted = true; }
private async Task Join(ServerMessagedEventArgs e) { Status = PluginStatus.Processing; string message = string.Empty; if (e.Caller.GetUser(e.Message.Realname) ?.Access > 1) { message = "Insufficient permissions."; } else if (e.Message.SplitArgs.Count < 3) { message = "Insufficient parameters. Type 'eve help join' to view command's help index."; } else if (e.Message.SplitArgs.Count < 2 || !e.Message.SplitArgs[2].StartsWith("#")) { message = "Channel name must start with '#'."; } else if (e.Caller.Server.GetChannel(e.Message.SplitArgs[2].ToLower()) != null) { message = "I'm already in that channel."; } Status = PluginStatus.Running; if (string.IsNullOrEmpty(message)) { await DoCallback(this, new ActionEventArgs(PluginActionType.SendMessage, new CommandEventArgs(Commands.JOIN, string.Empty, e.Message.SplitArgs[2]))); e.Caller.Server.Channels.Add(new Channel(e.Message.SplitArgs[2].ToLower())); message = $"Successfully joined channel: {e.Message.SplitArgs[2]}."; } await DoCallback(this, new ActionEventArgs(PluginActionType.SendMessage, new CommandEventArgs(Commands.PRIVMSG, e.Message.Origin, message))); Status = PluginStatus.Stopped; }
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; }
private async Task YouTubeLinkResponse(ServerMessagedEventArgs e) { Status = PluginStatus.Running; const int maxDescriptionLength = 100; string getResponse = await $"https://www.googleapis.com/youtube/v3/videos?part=snippet&id={youtubeRegex.Match(e.Message.Args).Groups["ID"]}&key={e.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 ActionEventArgs(PluginActionType.SendMessage, new CommandEventArgs(Commands.PRIVMSG, e.Message.Origin, $"{title} (by {channel}) — {description}"))); Status = PluginStatus.Stopped; }
private static bool InputEquals(ServerMessagedEventArgs args, string comparison) => args.Message.SplitArgs[0].Equals(comparison, StringComparison.OrdinalIgnoreCase);
private async Task Default(ServerMessagedEventArgs e) { if (Configuration[nameof(Core)]["IgnoreList"].StringValueArray.Contains(e.Message.RealName)) { return; } if (!e.Message.SplitArgs[0].Replace(",", string.Empty) .Equals(Configuration[nameof(Core)]["Nickname"].StringValue.ToLower())) { return; } if (e.Message.SplitArgs.Count < 2) { // typed only 'eve' await DoCallback(this, new PluginActionEventArgs(PluginActionType.SendMessage, new IrcCommandEventArgs($"{Commands.PRIVMSG} {e.Message.Origin}", "Type 'eve help' to view my command list."), Name)); return; } // built-in 'help' command if (e.Message.SplitArgs[1].Equals("help", StringComparison.OrdinalIgnoreCase)) { if (e.Message.SplitArgs.Count.Equals(2)) { // in this case, 'help' is the only text in the string. List <CompositionDescription> entries = e.Caller.PluginCommands.Values.ToList(); string commandsReadable = string.Join(", ", entries.Where(entry => entry != null).Select(entry => entry.Command)); await DoCallback(this, new PluginActionEventArgs(PluginActionType.SendMessage, new IrcCommandEventArgs(Commands.PRIVMSG, entries.Count == 0 ? $"{e.Message.Origin} No commands currently active." : $"{e.Message.Origin} Active commands: {commandsReadable}"), Name)); return; } CompositionDescription queriedCommand = e.Caller.GetDescription(e.Message.SplitArgs[2]); string valueToSend = queriedCommand.Equals(null) ? "Command not found." : $"{queriedCommand.Command}: {queriedCommand.Description}"; await DoCallback(this, new PluginActionEventArgs(PluginActionType.SendMessage, new IrcCommandEventArgs($"{Commands.PRIVMSG} {e.Message.Origin}", valueToSend), Name)); return; } if (e.Caller.CommandExists(e.Message.SplitArgs[1].ToLower())) { return; } await DoCallback(this, new PluginActionEventArgs(PluginActionType.SendMessage, new IrcCommandEventArgs($"{Commands.PRIVMSG} {e.Message.Origin}", "Invalid command. Type 'eve help' to view my command list."), Name)); }
private async Task Define(ServerMessagedEventArgs e) { Status = PluginStatus.Processing; CommandEventArgs message = new CommandEventArgs(Commands.PRIVMSG, e.Message.Origin, string.Empty); if (e.Message.SplitArgs.Count < 3) { message.Contents = "Insufficient parameters. Type 'eve help define' to view correct usage."; await DoCallback(this, new ActionEventArgs(PluginActionType.SendMessage, message)); return; } Status = PluginStatus.Running; string partOfSpeech = e.Message.SplitArgs.Count > 3 ? $"&part_of_speech={e.Message.SplitArgs[3]}" : string.Empty; JObject entry = JObject.Parse(await $"http://api.pearson.com/v2/dictionaries/laad3/entries?headword={e.Message.SplitArgs[2]}{partOfSpeech}&limit=1".HttpGet()); if ((int)entry.SelectToken("count") < 1) { message.Contents = "Query returned no results."; await DoCallback(this, new ActionEventArgs(PluginActionType.SendMessage, message)); return; } Dictionary <string, string> _out = new Dictionary <string, string> { { "word", (string)entry["results"][0]["headword"] }, { "pos", (string)entry["results"][0]["part_of_speech"] } }; // 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"]})"; } message.Contents = returnMessage; await DoCallback(this, new ActionEventArgs(PluginActionType.SendMessage, message)); Status = PluginStatus.Stopped; }
private async Task Nick(ServerMessagedEventArgs e) { await OnQuery(this, new BasicEventArgs($"UPDATE users SET nickname='{e.Message.Origin}' WHERE realname='{e.Message.Realname}'")); }
public static bool InputEquals(this ServerMessagedEventArgs e, string compareTo) => e.Message.InputCommand.Equals(compareTo);