From 049b1422b9ac57340eeb27fab30f1b67270b56e1 Mon Sep 17 00:00:00 2001 From: Uncled1023 Date: Sat, 2 May 2015 17:14:55 -0700 Subject: [PATCH] Added whois module. Fixed messaging where it was adding the nickname as host and realname. --- Combot.sln | 7 +++ IRCServices/Messaging/Messages.cs | 4 +- Modules/Whois/Module.Default.json | 63 ++++++++++++++++++++++++ Modules/Whois/Properties/AssemblyInfo.cs | 33 +++++++++++++ Modules/Whois/Whois.cs | 78 ++++++++++++++++++++++++++++++ Modules/Whois/Whois.csproj | 82 ++++++++++++++++++++++++++++++++ Modules/Whois/packages.config | 4 ++ 7 files changed, 269 insertions(+), 2 deletions(-) create mode 100644 Modules/Whois/Module.Default.json create mode 100644 Modules/Whois/Properties/AssemblyInfo.cs create mode 100644 Modules/Whois/Whois.cs create mode 100644 Modules/Whois/Whois.csproj create mode 100644 Modules/Whois/packages.config diff --git a/Combot.sln b/Combot.sln index 25b8d0b..f508907 100644 --- a/Combot.sln +++ b/Combot.sln @@ -73,6 +73,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Github", "Modules\Github\Gi EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Timer", "Modules\Timer\Timer.csproj", "{84166880-FC04-4F50-90CD-8486B797948A}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Whois", "Modules\Whois\Whois.csproj", "{A6EDD673-A10D-48BC-81D9-506D08AEC083}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -195,6 +197,10 @@ Global {84166880-FC04-4F50-90CD-8486B797948A}.Debug|Any CPU.Build.0 = Debug|Any CPU {84166880-FC04-4F50-90CD-8486B797948A}.Release|Any CPU.ActiveCfg = Release|Any CPU {84166880-FC04-4F50-90CD-8486B797948A}.Release|Any CPU.Build.0 = Release|Any CPU + {A6EDD673-A10D-48BC-81D9-506D08AEC083}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {A6EDD673-A10D-48BC-81D9-506D08AEC083}.Debug|Any CPU.Build.0 = Debug|Any CPU + {A6EDD673-A10D-48BC-81D9-506D08AEC083}.Release|Any CPU.ActiveCfg = Release|Any CPU + {A6EDD673-A10D-48BC-81D9-506D08AEC083}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -225,5 +231,6 @@ Global {6CB41404-02E8-4CA3-834C-CE8C30999450} = {D157677E-4D33-4156-B55E-E21C4B5A3024} {7D7B5FCB-C9CC-4CB1-B5EF-827BD3398E39} = {D157677E-4D33-4156-B55E-E21C4B5A3024} {84166880-FC04-4F50-90CD-8486B797948A} = {D157677E-4D33-4156-B55E-E21C4B5A3024} + {A6EDD673-A10D-48BC-81D9-506D08AEC083} = {D157677E-4D33-4156-B55E-E21C4B5A3024} EndGlobalSection EndGlobal diff --git a/IRCServices/Messaging/Messages.cs b/IRCServices/Messaging/Messages.cs index 6e4fb23..effaf95 100644 --- a/IRCServices/Messaging/Messages.cs +++ b/IRCServices/Messaging/Messages.cs @@ -65,8 +65,8 @@ namespace Combot.IRCServices.Messaging string args = match.Groups["Args"].Value; Match senderMatch = senderRegex.Match(sender); string senderNick = sender; - string senderRealname = sender; - string senderHost = sender; + string senderRealname = null; + string senderHost = null; if (senderMatch.Success) { senderNick = senderMatch.Groups["Nick"].Value; diff --git a/Modules/Whois/Module.Default.json b/Modules/Whois/Module.Default.json new file mode 100644 index 0000000..526434e --- /dev/null +++ b/Modules/Whois/Module.Default.json @@ -0,0 +1,63 @@ +{ + "Name": "Whois", + "ClassName": "Whois", + "Enabled": true, + "ChannelBlacklist": [ ], + "NickBlacklist": [ ], + "Commands": [ + { + "Name": "Whois", + "Description": "Displays the nicknames and hosts that a nick or host have used.", + "Enabled": true, + "ChannelBlacklist": [ ], + "NickBlacklist": [ ], + "Triggers": [ + "whois" + ], + "Arguments": [ + { + "Name": "Nickname", + "Description": "The nickname or host you want to view the information on.", + "AllowedValues": [ ], + "MessageTypes": [ + 0, + 1, + 2 + ], + "Required": true + }, + { + "Name": "Option", + "Description": "Specify the type of information you want.", + "AllowedValues": [ + "Nicks", + "Hosts" + ], + "MessageTypes": [ + 0, + 1, + 2 + ], + "Required": false + } + ], + "AllowedMessageTypes": [ + 0, + 1, + 2 + ], + "AllowedAccess": [ + 0, + 1, + 2, + 3, + 4, + 5, + 6 + ], + "ShowHelp": true, + "SpamCheck": true + } + ], + "Options": [] +} \ No newline at end of file diff --git a/Modules/Whois/Properties/AssemblyInfo.cs b/Modules/Whois/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..ae6f781 --- /dev/null +++ b/Modules/Whois/Properties/AssemblyInfo.cs @@ -0,0 +1,33 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("Whois Module")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("Teknik")] +[assembly: AssemblyProduct("Combot")] +[assembly: AssemblyCopyright("Copyright © 2015")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("5c350b8e-5820-4034-9d67-49d2ddbfcc6f")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Build and Revision Numbers +// by using the '*' as shown below: diff --git a/Modules/Whois/Whois.cs b/Modules/Whois/Whois.cs new file mode 100644 index 0000000..300abc9 --- /dev/null +++ b/Modules/Whois/Whois.cs @@ -0,0 +1,78 @@ +using System.Collections.Generic; +using System.Linq; + +namespace Combot.Modules.Plugins +{ + public class Whois : Module + { + public override void Initialize() + { + Bot.CommandReceivedEvent += HandleCommandEvent; + } + + public override void ParseCommand(CommandMessage command) + { + Command foundCommand = Commands.Find(c => c.Triggers.Contains(command.Command)); + switch (foundCommand.Name) + { + case "Whois": + string option = (command.Arguments.ContainsKey("Option")) ? command.Arguments["Option"] : string.Empty; + string mask = (command.Arguments.ContainsKey("Nickname")) ? command.Arguments["Nickname"] : command.Nick.Nickname; + List nicksList = new List(); + List hostList = new List(); + findMatches(ref nicksList, ref hostList, mask, mask); + if (nicksList.Any() || hostList.Any()) + { + // display results + if (nicksList.Any() && (string.IsNullOrEmpty(option) || option.ToLower() == "nicks")) + { + string nicksFound = string.Format("\u0002{0}\u0002 has been seen as: \u0002{1}\u0002", mask, string.Join(", ", nicksList)); + SendResponse(command.MessageType, command.Location, command.Nick.Nickname, nicksFound); + } + if (hostList.Any() && (string.IsNullOrEmpty(option) || option.ToLower() == "hosts")) + { + string hostsFound = string.Format("\u0002{0}\u0002 has used the following hosts: \u0002{1}\u0002", mask, string.Join(", ", hostList)); + SendResponse(command.MessageType, command.Location, command.Nick.Nickname, hostsFound); + } + } + else + { + SendResponse(command.MessageType, command.Location, command.Nick.Nickname, string.Format("I have no information about \u0002{0}\u0002", mask)); + } + break; + } + } + + private void findMatches(ref List nickList, ref List hostList, string nick, string host) + { + List> results = findAssociationList(nick, host); + for (int i = 0; i < results.Count; i++) + { + string foundNick = results[i]["nickname"].ToString(); + string foundHost = results[i]["host"].ToString(); + if (nickList != null && !nickList.Contains(foundNick)) + { + nickList.Add(foundNick); + findMatches(ref nickList, ref hostList, foundNick, foundNick); + } + if (hostList != null && !hostList.Contains(foundHost)) + { + hostList.Add(foundHost); + findMatches(ref nickList, ref hostList, foundHost, foundHost); + } + } + } + + private List> findAssociationList(string nick, string host) + { + string search = "SELECT `nickinfo`.`host`, `nicks`.`nickname` FROM `nickinfo` " + + "INNER JOIN `nicks` " + + "ON `nickinfo`.`nick_id` = `nicks`.`id` " + + "INNER JOIN `servers` " + + "ON `nicks`.`server_id` = `servers`.`id` " + + "WHERE `servers`.`name` = {0} AND (`nicks`.`nickname` = {1} OR `nickinfo`.`host` = {2})" + + "GROUP BY `nickinfo`.`host`, `nicks`.`nickname`"; + return Bot.Database.Query(search, new object[] { Bot.ServerConfig.Name, nick, host }); + } + } +} diff --git a/Modules/Whois/Whois.csproj b/Modules/Whois/Whois.csproj new file mode 100644 index 0000000..caa8f0a --- /dev/null +++ b/Modules/Whois/Whois.csproj @@ -0,0 +1,82 @@ + + + + + Debug + AnyCPU + {A6EDD673-A10D-48BC-81D9-506D08AEC083} + Library + Properties + Whois + Whois + v4.5.1 + 512 + + + + true + full + false + ..\..\Bin\Debug\Modules\Whois\ + DEBUG;TRACE + prompt + 4 + + + pdbonly + true + ..\..\Bin\Release\Modules\Whois\ + TRACE + prompt + 4 + + + + + + + + + + + + + + + + + {23e4c371-16e4-4fac-8b11-44288399bb55} + Combot + + + {65fcbf1c-8c9e-4688-becc-185d9030899f} + IRCServices + + + + + Always + + + + + + md "$(SolutionDir)$(ConfigurationName)\Modules\$(TargetName)" +copy /Y "$(TargetPath)" "$(SolutionDir)$(ConfigurationName)\Modules\$(TargetName)" +copy /Y "$(TargetDir)Module.Default.json" "$(SolutionDir)$(ConfigurationName)\Modules\$(TargetName)" + + + + + This project references NuGet package(s) that are missing on this computer. Enable NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. + + + + + \ No newline at end of file diff --git a/Modules/Whois/packages.config b/Modules/Whois/packages.config new file mode 100644 index 0000000..6472181 --- /dev/null +++ b/Modules/Whois/packages.config @@ -0,0 +1,4 @@ + + + + \ No newline at end of file