Browse Source

Added whois module.

Fixed messaging where it was adding the nickname as host and realname.
tags/3.1.0
Teknikode 4 years ago
parent
commit
049b1422b9

+ 7
- 0
Combot.sln View File

@@ -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

+ 2
- 2
IRCServices/Messaging/Messages.cs View File

@@ -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;

+ 63
- 0
Modules/Whois/Module.Default.json View File

@@ -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": []
}

+ 33
- 0
Modules/Whois/Properties/AssemblyInfo.cs View File

@@ -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:

+ 78
- 0
Modules/Whois/Whois.cs View File

@@ -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<string> nicksList = new List<string>();
List<string> hostList = new List<string>();
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<string> nickList, ref List<string> hostList, string nick, string host)
{
List<Dictionary<string, object>> 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<Dictionary<string, object>> 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 });
}
}
}

+ 82
- 0
Modules/Whois/Whois.csproj View File

@@ -0,0 +1,82 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{A6EDD673-A10D-48BC-81D9-506D08AEC083}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>Whois</RootNamespace>
<AssemblyName>Whois</AssemblyName>
<TargetFrameworkVersion>v4.5.1</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<TargetFrameworkProfile />
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>..\..\Bin\Debug\Modules\Whois\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>..\..\Bin\Release\Modules\Whois\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Whois.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\Combot\Combot.csproj">
<Project>{23e4c371-16e4-4fac-8b11-44288399bb55}</Project>
<Name>Combot</Name>
</ProjectReference>
<ProjectReference Include="..\..\IRCServices\IRCServices.csproj">
<Project>{65fcbf1c-8c9e-4688-becc-185d9030899f}</Project>
<Name>IRCServices</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<None Include="Module.Default.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="packages.config" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<PropertyGroup>
<PostBuildEvent>md "$(SolutionDir)$(ConfigurationName)\Modules\$(TargetName)"
copy /Y "$(TargetPath)" "$(SolutionDir)$(ConfigurationName)\Modules\$(TargetName)"
copy /Y "$(TargetDir)Module.Default.json" "$(SolutionDir)$(ConfigurationName)\Modules\$(TargetName)"</PostBuildEvent>
</PropertyGroup>
<Import Project="..\..\packages\GitVersionTask.2.0.1\Build\GitVersionTask.targets" Condition="Exists('..\..\packages\GitVersionTask.2.0.1\Build\GitVersionTask.targets')" />
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
<PropertyGroup>
<ErrorText>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}.</ErrorText>
</PropertyGroup>
<Error Condition="!Exists('..\..\packages\GitVersionTask.2.0.1\Build\GitVersionTask.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\..\packages\GitVersionTask.2.0.1\Build\GitVersionTask.targets'))" />
</Target>
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>

+ 4
- 0
Modules/Whois/packages.config View File

@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="GitVersionTask" version="2.0.1" targetFramework="net451" developmentDependency="true" />
</packages>

Loading…
Cancel
Save