Browse Source

Added Command parsing to main Bot class.

Added command passing and access restriction to modules.
Renamed send commands to be friendlier.
master
Teknikode 7 years ago
parent
commit
4fcff398e1
  1. 13
      Combot/AccessType.cs
  2. 47
      Combot/Bot.cs
  3. 3
      Combot/Combot.csproj
  4. 37
      Combot/Configurations/ChannelConfig.cs
  5. 169
      Combot/Configurations/ServerConfig.cs
  6. 9
      Combot/Modules/Command.cs
  7. 13
      Combot/Modules/CommandMessage.cs
  8. 48
      Combot/Modules/Module.cs
  9. 95
      Combot/Modules/ModuleClasses/PingMe.cs
  10. 8
      IRCServices/IRC.cs
  11. 163
      IRCServices/IRCSend.cs
  12. 7
      IRCServices/Messaging/MessageTypes.cs
  13. 23
      IRCServices/Messaging/Messages.cs
  14. 44
      Interface/ViewModels/MainViewModel.cs
  15. 668
      readme.md

13
Combot/AccessType.cs

@ -0,0 +1,13 @@ @@ -0,0 +1,13 @@
namespace Combot
{
public enum AccessType
{
User,
Voice,
HalfOperator,
Operator,
SuperOperator,
Founder,
Owner
}
}

47
Combot/Bot.cs

@ -20,6 +20,7 @@ namespace Combot @@ -20,6 +20,7 @@ namespace Combot
public ServerConfig ServerConfig;
public IRC IRC;
public bool Connected = false;
public static Dictionary<PrivilegeMode, AccessType> AccessTypeMapping = new Dictionary<PrivilegeMode, AccessType>() { { PrivilegeMode.v, AccessType.Voice }, { PrivilegeMode.h, AccessType.HalfOperator }, { PrivilegeMode.o, AccessType.Operator }, { PrivilegeMode.a, AccessType.SuperOperator }, { PrivilegeMode.q, AccessType.Founder } };
private List<Module> _Modules;
@ -115,7 +116,7 @@ namespace Combot @@ -115,7 +116,7 @@ namespace Combot
{
foreach (ChannelConfig channel in ServerConfig.Channels)
{
IRC.IRCSendJoin(channel.Name, channel.Key);
IRC.SendJoin(channel.Name, channel.Key);
}
}
}
@ -126,14 +127,31 @@ namespace Combot @@ -126,14 +127,31 @@ namespace Combot
// The message was a command
if (e.Message.StartsWith(ServerConfig.CommandPrefix))
{
string[] msgArgs = e.Message.Split(new char[] {' '}, 2, StringSplitOptions.RemoveEmptyEntries);
string command = msgArgs[0].Remove(0, ServerConfig.CommandPrefix.Length);
List<string> argsOnly = msgArgs.ToList();
argsOnly.RemoveAt(0);
if (_Modules.Exists(module => module.Commands.Exists(cmd => cmd.Triggers.Contains(command)) && module.Loaded))
if (!ServerConfig.ChannelBlacklist.Contains(e.Channel)
&& !ServerConfig.NickBlacklist.Contains(e.Sender.Nickname)
)
{
ParseCommandMessage(e.TimeStamp, e.Message, e.Sender, e.Channel, LocationType.Channel);
}
}
}
private void ParseCommandMessage(DateTime timestamp, string message, Nick sender, string location, LocationType locationType)
{
// Extract command and arguments
string[] msgArgs = message.Split(new[] { ' ' }, 2, StringSplitOptions.RemoveEmptyEntries);
string command = msgArgs[0].Remove(0, ServerConfig.CommandPrefix.Length);
List<string> argsOnly = msgArgs.ToList();
argsOnly.RemoveAt(0);
Module module = _Modules.Find(mod => mod.Commands.Exists(c => c.Triggers.Contains(command)) && mod.Loaded);
if (module != null)
{
Command cmd = module.Commands.Find(c => c.Triggers.Contains(command));
if (cmd != null)
{
CommandMessage newCommand = new CommandMessage();
newCommand.Nick.Copy(e.Sender);
newCommand.Nick.Copy(sender);
IRC.Channels.ForEach(channel => channel.Nicks.ForEach(nick =>
{
if (nick.Nickname == newCommand.Nick.Nickname)
@ -141,10 +159,19 @@ namespace Combot @@ -141,10 +159,19 @@ namespace Combot
newCommand.Nick.AddPrivileges(nick.Privileges);
}
}));
newCommand.TimeStamp = e.TimeStamp;
newCommand.ModuleName =_Modules.Find(module => module.Commands.Exists(cmd => cmd.Triggers.Contains(command)) && module.Loaded).Name;
newCommand.TimeStamp = timestamp;
newCommand.Location = location;
newCommand.LocationType = locationType;
newCommand.Command = command;
newCommand.Arguments.AddRange(argsOnly);
if (argsOnly.Count > 0)
{
string[] argSplit = argsOnly.First()
.Split(new[] {' '}, cmd.Arguments.Count + 1, StringSplitOptions.RemoveEmptyEntries);
for (int i = 0; i < cmd.Arguments.Count; i++)
{
newCommand.Arguments.Add(argSplit[i]);
}
}
if (CommandReceivedEvent != null)
{

3
Combot/Combot.csproj

@ -11,6 +11,7 @@ @@ -11,6 +11,7 @@
<AssemblyName>Combot</AssemblyName>
<TargetFrameworkVersion>v4.5.1</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<IsWebBootstrapper>false</IsWebBootstrapper>
<PublishUrl>publish\</PublishUrl>
<Install>true</Install>
<InstallFrom>Disk</InstallFrom>
@ -23,7 +24,6 @@ @@ -23,7 +24,6 @@
<MapFileExtensions>true</MapFileExtensions>
<ApplicationRevision>0</ApplicationRevision>
<ApplicationVersion>1.0.0.%2a</ApplicationVersion>
<IsWebBootstrapper>false</IsWebBootstrapper>
<UseApplicationTrust>false</UseApplicationTrust>
<BootstrapperEnabled>true</BootstrapperEnabled>
</PropertyGroup>
@ -58,6 +58,7 @@ @@ -58,6 +58,7 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="AccessType.cs" />
<Compile Include="Bot.cs" />
<Compile Include="Modules\Command.cs" />
<Compile Include="Configurations\ChannelConfig.cs" />

37
Combot/Configurations/ChannelConfig.cs

@ -8,44 +8,13 @@ namespace Combot.Configurations @@ -8,44 +8,13 @@ namespace Combot.Configurations
{
public class ChannelConfig
{
public string Name { get; set; }
public string Key { get; set; }
public ChannelConfig()
{
Name = string.Empty;
Key = string.Empty;
}
private string _Name;
public string Name
{
get
{
return _Name;
}
set
{
if (_Name != value)
{
_Name = value;
}
}
}
private string _Key;
public string Key
{
get
{
return _Key;
}
set
{
if (_Key != value)
{
_Key = value;
}
}
}
}
}

169
Combot/Configurations/ServerConfig.cs

@ -11,6 +11,18 @@ namespace Combot.Configurations @@ -11,6 +11,18 @@ namespace Combot.Configurations
public class ServerConfig
{
public event Action ModifyEvent;
public string Name { get; set; }
public bool AutoConnect { get; set; }
public string CommandPrefix { get; set; }
public string Nickname { get; set; }
public string Realname { get; set; }
public string Username { get; set; }
public List<string> Owners { get; set; }
public List<string> ChannelBlacklist { get; set; }
public List<string> NickBlacklist { get; set; }
public List<HostConfig> Hosts { get; set; }
public List<ChannelConfig> Channels { get; set; }
public List<Module> Modules { get; set; }
public ServerConfig()
{
@ -19,8 +31,12 @@ namespace Combot.Configurations @@ -19,8 +31,12 @@ namespace Combot.Configurations
public void SetDefaults()
{
Name = string.Empty;
AutoConnect = false;
CommandPrefix = string.Empty;
Owners = new List<string>();
ChannelBlacklist = new List<string>();
NickBlacklist = new List<string>();
Channels = new List<ChannelConfig>();
Modules = new List<Module>();
Hosts = new List<HostConfig>();
@ -36,158 +52,5 @@ namespace Combot.Configurations @@ -36,158 +52,5 @@ namespace Combot.Configurations
ModifyEvent();
}
}
private string _Name;
public string Name
{
get
{
return _Name;
}
set
{
if (_Name != value)
{
_Name = value;
}
}
}
private string _Nickname;
public string Nickname
{
get
{
return _Nickname;
}
set
{
if (_Nickname != value)
{
_Nickname = value;
}
}
}
private string _Username;
public string Username
{
get
{
return _Username;
}
set
{
if (_Username != value)
{
_Username = value;
}
}
}
private string _Realname;
public string Realname
{
get
{
return _Realname;
}
set
{
if (_Realname != value)
{
_Realname = value;
}
}
}
private string _CommandPrefix;
public string CommandPrefix
{
get
{
return _CommandPrefix;
}
set
{
if (_CommandPrefix != value)
{
_CommandPrefix = value;
}
}
}
private bool _AutoConnect;
public bool AutoConnect
{
get
{
return _AutoConnect;
}
set
{
if (_AutoConnect != value)
{
_AutoConnect = value;
}
}
}
private List<HostConfig> _Hosts;
public List<HostConfig> Hosts
{
get
{
return _Hosts;
}
set
{
if (_Hosts != value)
{
_Hosts = value;
}
}
}
private List<ChannelConfig> _Channels;
public List<ChannelConfig> Channels
{
get
{
return _Channels;
}
set
{
if (_Channels != value)
{
_Channels = value;
}
}
}
private List<Module> _Modules;
public List<Module> Modules
{
get
{
return _Modules;
}
set
{
if (_Modules != value)
{
_Modules = value;
}
}
}
}
}

9
Combot/Modules/Command.cs

@ -6,10 +6,11 @@ namespace Combot.Modules @@ -6,10 +6,11 @@ namespace Combot.Modules
{
public string Name { get; set; }
public string Description { get; set; }
public List<string> Triggers { get; set; }
public List<string> ChannelBlacklist { get; set; }
public List<string> NickBlacklist { get; set; }
public List<string> Triggers { get; set; }
public List<CommandArgument> Arguments { get; set; }
public List<AccessType> AllowedAccess { get; set; }
public bool ShowHelp { get; set; }
public bool SpamCheck { get; set; }
@ -31,6 +32,7 @@ namespace Combot.Modules @@ -31,6 +32,7 @@ namespace Combot.Modules
ChannelBlacklist = new List<string>();
NickBlacklist = new List<string>();
Arguments = new List<CommandArgument>();
AllowedAccess = new List<AccessType>();
ShowHelp = true;
SpamCheck = true;
}
@ -61,6 +63,11 @@ namespace Combot.Modules @@ -61,6 +63,11 @@ namespace Combot.Modules
newArg.Copy(arg);
Arguments.Add(newArg);
}
AllowedAccess = new List<AccessType>();
foreach (AccessType accessType in command.AllowedAccess)
{
AllowedAccess.Add(accessType);
}
ShowHelp = command.ShowHelp;
SpamCheck = command.SpamCheck;
}

13
Combot/Modules/CommandMessage.cs

@ -6,19 +6,28 @@ namespace Combot.Modules @@ -6,19 +6,28 @@ namespace Combot.Modules
{
public class CommandMessage
{
public string Location { get; set; }
public LocationType LocationType { get; set; }
public Nick Nick { get; set; }
public DateTime TimeStamp { get; set; }
public string ModuleName { get; set; }
public string Command { get; set; }
public List<string> Arguments { get; set; }
public CommandMessage()
{
Location = string.Empty;
LocationType = LocationType.Channel;
Nick = new Nick();
TimeStamp = DateTime.Now;
ModuleName = string.Empty;
Command = string.Empty;
Arguments = new List<string>();
}
}
public enum LocationType
{
Channel,
Query,
Notice
}
}

48
Combot/Modules/Module.cs

@ -4,6 +4,7 @@ using System.Linq; @@ -4,6 +4,7 @@ using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Reflection;
using Combot.IRCServices;
namespace Combot.Modules
{
@ -12,6 +13,8 @@ namespace Combot.Modules @@ -12,6 +13,8 @@ namespace Combot.Modules
public string Name { get; set; }
public string ClassName { get; set; }
public bool Enabled { get; set; }
public List<string> ChannelBlacklist { get; set; }
public List<string> NickBlacklist { get; set; }
public List<Command> Commands { get; set; }
public List<Option> Options { get; set; }
@ -28,15 +31,48 @@ namespace Combot.Modules @@ -28,15 +31,48 @@ namespace Combot.Modules
SetDefaults();
}
public void HandleCommandEvent(CommandMessage command)
{
// Check to make sure the command exists, the nick or channel isn't on a blacklist, and the module is loaded.
if (Loaded
&& !ChannelBlacklist.Contains(command.Location)
&& !NickBlacklist.Contains(command.Nick.Nickname)
&& Commands.Exists(c => c.Triggers.Contains(command.Command)
&& !c.ChannelBlacklist.Contains(command.Location)
&& !c.NickBlacklist.Contains(command.Nick.Nickname)
)
)
{
// Figure out access of the nick
Command cmd = Commands.Find(c => c.Triggers.Contains(command.Command));
List<AccessType> nickAccessTypes = new List<AccessType>() { AccessType.User };
foreach (PrivilegeMode privilege in command.Nick.Privileges)
{
nickAccessTypes.Add(Bot.AccessTypeMapping[privilege]);
}
if (Bot.ServerConfig.Owners.Contains(command.Nick.Nickname) && command.Nick.Identified)
{
nickAccessTypes.Add(AccessType.Owner);
}
// If they have the correct access for the command, send it
if (cmd.AllowedAccess.Exists(access => nickAccessTypes.Contains(access)))
{
ParseCommand(command);
}
}
}
virtual public void Initialize() { }
virtual public void HandleCommandEvent(CommandMessage command) { }
virtual public void ParseCommand(CommandMessage command) { }
public void SetDefaults()
{
Name = string.Empty;
ClassName = string.Empty;
Enabled = false;
ChannelBlacklist = new List<string>();
NickBlacklist = new List<string>();
Loaded = false;
Commands = new List<Command>();
Options = new List<Option>();
@ -47,6 +83,16 @@ namespace Combot.Modules @@ -47,6 +83,16 @@ namespace Combot.Modules
Name = module.Name;
ClassName = module.ClassName;
Enabled = module.Enabled;
ChannelBlacklist = new List<string>();
foreach (string channel in module.ChannelBlacklist)
{
ChannelBlacklist.Add(channel);
}
NickBlacklist = new List<string>();
foreach (string nick in module.NickBlacklist)
{
NickBlacklist.Add(nick);
}
Commands = new List<Command>();
foreach (Command command in module.Commands)
{

95
Combot/Modules/ModuleClasses/PingMe.cs

@ -1,5 +1,7 @@ @@ -1,5 +1,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using Combot.IRCServices;
using Combot.IRCServices.Messaging;
@ -7,23 +9,104 @@ namespace Combot.Modules.ModuleClasses @@ -7,23 +9,104 @@ namespace Combot.Modules.ModuleClasses
{
public class PingMe : Module
{
private List<Dictionary<Nick, DateTime>> pingList;
private List<PingItem> pingList;
private ReaderWriterLockSlim listLock;
public override void Initialize()
{
pingList = new List<Dictionary<Nick, DateTime>>();
Bot.IRC.Message.CTCPMessageRecievedEvent += HandlePingResponse;
listLock = new ReaderWriterLockSlim();
pingList = new List<PingItem>();
Bot.IRC.Message.CTCPNoticeRecievedEvent += HandlePingResponse;
Bot.CommandReceivedEvent += HandleCommandEvent;
}
public override void HandleCommandEvent(CommandMessage command)
public override void ParseCommand(CommandMessage command)
{
if (Commands.Find(cmd => cmd.Name == "Ping Me").Triggers.Contains(command.Command))
{
int epoch = (int)(DateTime.UtcNow - new DateTime(1970, 1, 1)).TotalSeconds;
PingItem tmpItem = new PingItem();
tmpItem.Nick = command.Nick.Nickname;
tmpItem.Location = command.Location;
tmpItem.LocationType = command.LocationType;
tmpItem.Timestamp = DateTime.Now;
listLock.EnterWriteLock();
if (pingList.Exists(item => item.Nick == command.Nick.Nickname))
{
pingList.RemoveAll(item => item.Nick == command.Nick.Nickname);
}
pingList.Add(tmpItem);
listLock.ExitWriteLock();
Bot.IRC.SendCTCP(command.Nick.Nickname, "PING", epoch.ToString());
}
}
private void HandlePingResponse(object sender, CTCPMessage e)
{
if (e.Command == "PING")
{
listLock.EnterReadLock();
PingItem pingItem = pingList.Find(item => item.Nick == e.Sender.Nickname);
listLock.ExitReadLock();
if (pingItem != null)
{
DateTime curTime = DateTime.Now;
DateTime prevTime = pingItem.Timestamp;
TimeSpan difTime = curTime.Subtract(prevTime);
string timeString = string.Empty;
if (difTime.Days > 0)
{
timeString += difTime.Days.ToString() + " Days, ";
}
if (difTime.Hours > 0)
{
timeString += difTime.Hours.ToString() + " Hours, ";
}
if (difTime.Minutes > 0)
{
timeString += difTime.Minutes.ToString() + " Minutes, ";
}
if (difTime.Seconds > 0)
{
timeString += difTime.Seconds.ToString() + " Seconds, ";
}
if (difTime.Milliseconds > 0)
{
timeString += difTime.Milliseconds.ToString() + " Milliseconds";
}
switch (pingItem.LocationType)
{
case LocationType.Channel:
Bot.IRC.SendPrivateMessage(pingItem.Location, string.Format("{0}, your ping is {1}", pingItem.Nick, timeString));
break;
case LocationType.Notice:
Bot.IRC.SendNotice(pingItem.Nick, string.Format("Your ping is {0}", timeString));
break;
case LocationType.Query:
Bot.IRC.SendPrivateMessage(pingItem.Nick, string.Format("Your ping is {0}", timeString));
break;
}
listLock.EnterWriteLock();
pingList.RemoveAll(item => item.Nick == pingItem.Nick);
listLock.ExitWriteLock();
}
}
}
private class PingItem
{
public string Nick { get; set; }
public string Location { get; set; }
public LocationType LocationType { get; set; }
public DateTime Timestamp { get; set; }
public PingItem()
{
Nick = string.Empty;
Location = string.Empty;
LocationType = LocationType.Channel;
Timestamp = DateTime.Now;
}
}
}
}

8
IRCServices/IRC.cs

@ -110,8 +110,8 @@ namespace Combot.IRCServices @@ -110,8 +110,8 @@ namespace Combot.IRCServices
public void Login(string serverName, Nick nick)
{
Nickname = nick.Nickname;
IRCSendNick(nick.Nickname);
IRCSendUser(nick.Username, nick.Host, serverName, nick.Realname);
SendNick(nick.Nickname);
SendUser(nick.Username, nick.Host, serverName, nick.Realname);
}
private void ReadTCPMessages()
@ -173,7 +173,7 @@ namespace Combot.IRCServices @@ -173,7 +173,7 @@ namespace Combot.IRCServices
/// <param name="e"></param>
private void HandlePing(object sender, PingInfo e)
{
IRCSendPong(e.Message);
SendPong(e.Message);
}
private void HandleReply(object sender, IReply e)
@ -399,7 +399,7 @@ namespace Combot.IRCServices @@ -399,7 +399,7 @@ namespace Combot.IRCServices
}
newChannel.Nicks.Add(e.Nick);
Channels.Add(newChannel);
IRCSendWho(newChannel.Name);
SendWho(newChannel.Name);
}
ChannelRWLock.ExitWriteLock();
}

163
IRCServices/IRCSend.cs

@ -14,12 +14,12 @@ namespace Combot.IRCServices @@ -14,12 +14,12 @@ namespace Combot.IRCServices
/// </summary>
/// <param name="nick"></param>
/// <param name="message"></param>
public void IRCSendPrivMessage(string recipient, string message)
public void SendPrivateMessage(string recipient, string message)
{
SendTCPMessage(string.Format("PRIVMSG {0} :{1}", recipient, message));
}
public void IRCSendPrivMessage(List<string> recipients, string message)
public void SendPrivateMessage(List<string> recipients, string message)
{
string recipient_list = string.Empty;
foreach (string recipient in recipients)
@ -35,12 +35,12 @@ namespace Combot.IRCServices @@ -35,12 +35,12 @@ namespace Combot.IRCServices
/// </summary>
/// <param name="nick"></param>
/// <param name="message"></param>
public void IRCSendNotice(string recipient, string message)
public void SendNotice(string recipient, string message)
{
SendTCPMessage(string.Format("NOTICE {0} :{1}", recipient, message));
}
public void IRCSendNotice(List<string> recipients, string message)
public void SendNotice(List<string> recipients, string message)
{
string recipient_list = string.Empty;
foreach (string recipient in recipients)
@ -51,11 +51,40 @@ namespace Combot.IRCServices @@ -51,11 +51,40 @@ namespace Combot.IRCServices
SendTCPMessage(string.Format("NOTICE {0} :{1}", recipient_list.TrimEnd(','), message));
}
/// <summary>
/// Sends a CTCP command and optional message to a nick or channel
/// </summary>
/// <param name="recipient"></param>
/// <param name="command"></param>
/// <param name="message"></param>
public void SendCTCP(string recipient, string command, string message = "")
{
if (message != string.Empty)
{
message = " " + message;
}
SendTCPMessage(string.Format("PRIVMSG {0} :\u0001{1}{2}\u0001", recipient, command, message));
}
public void SendCTCP(List<string> recipients, string command, string message)
{
string recipient_list = string.Empty;
foreach (string recipient in recipients)
{
recipient_list += recipient + ",";
}
if (message != string.Empty)
{
message = " " + message;
}
SendTCPMessage(string.Format("PRIVMSG {0} :\u0001{1}{2}\u0001", recipient_list.TrimEnd(','), command, message));
}
/// <summary>
/// Sends the connection password
/// </summary>
/// <param name="password"></param>
public void IRCSendPassword(string password)
public void SendPassword(string password)
{
SendTCPMessage(string.Format("PASSWORD {0}", password));
}
@ -64,7 +93,7 @@ namespace Combot.IRCServices @@ -64,7 +93,7 @@ namespace Combot.IRCServices
/// Sends a Nick command to set the nickname
/// </summary>
/// <param name="nick"></param>
public void IRCSendNick(string nick)
public void SendNick(string nick)
{
SendTCPMessage(string.Format("NICK {0}", nick));
}
@ -73,7 +102,7 @@ namespace Combot.IRCServices @@ -73,7 +102,7 @@ namespace Combot.IRCServices
/// Sends the User command to set a user
/// </summary>
/// <param name="user"></param>
public void IRCSendUser(string username, string hostname, string servername, string realname)
public void SendUser(string username, string hostname, string servername, string realname)
{
SendTCPMessage(string.Format("USER {0} {1} {2} :{3}", username, hostname, servername, realname));
}
@ -83,7 +112,7 @@ namespace Combot.IRCServices @@ -83,7 +112,7 @@ namespace Combot.IRCServices
/// </summary>
/// <param name="username"></param>
/// <param name="password"></param>
public void IRCSendOper(string username, string password)
public void SendOper(string username, string password)
{
SendTCPMessage(string.Format("OPER {0} {1}", username, password));
}
@ -92,12 +121,12 @@ namespace Combot.IRCServices @@ -92,12 +121,12 @@ namespace Combot.IRCServices
/// Sends a Quit command to end the client session
/// </summary>
/// <param name="message"></param>
public void IRCSendQuit()
public void SendQuit()
{
SendTCPMessage("QUIT");
}
public void IRCSendQuit(string message)
public void SendQuit(string message)
{
SendTCPMessage(string.Format("QUIT :{0}", message));
}
@ -106,14 +135,14 @@ namespace Combot.IRCServices @@ -106,14 +135,14 @@ namespace Combot.IRCServices
/// Sends a Join command to join a channel
/// </summary>
/// <param name="channel"></param>
public void IRCSendJoin(string channel, string key = "")
public void SendJoin(string channel, string key = "")
{
string message = string.Empty;
message = (key != string.Empty) ? string.Format("{0}; {1}", channel, key) : channel;
SendTCPMessage(string.Format("JOIN {0}", message));
}
public void IRCSendJoin(List<string> channels, List<string> keys)
public void SendJoin(List<string> channels, List<string> keys)
{
string message = string.Empty;
string channel_string = string.Empty;
@ -141,12 +170,12 @@ namespace Combot.IRCServices @@ -141,12 +170,12 @@ namespace Combot.IRCServices
/// Sends a Part command to leave a channel
/// </summary>
/// <param name="channel"></param>
public void IRCSendPart(string channel)
public void SendPart(string channel)
{
SendTCPMessage(string.Format("PART {0}", channel));
}
public void IRCSendPart(List<string> channels)
public void SendPart(List<string> channels)
{
string channel_list = string.Empty;
foreach (string channel in channels)
@ -163,30 +192,30 @@ namespace Combot.IRCServices @@ -163,30 +192,30 @@ namespace Combot.IRCServices
/// </summary>
/// <param name="channel"></param>
/// <param name="mode"></param>
public void IRCSendMode(string channel, ChannelModeInfo modeInfo)
public void SendMode(string channel, ChannelModeInfo modeInfo)
{
string mode_set = modeInfo.Set ? "+" : "-";
SendTCPMessage(string.Format("MODE {0} {1} {2}", channel, mode_set + modeInfo.Mode.ToString(), modeInfo.Parameter));
}
public void IRCSendMode(string channel, List<ChannelModeInfo> modeInfos)
public void SendMode(string channel, List<ChannelModeInfo> modeInfos)
{
foreach (ChannelModeInfo modeInfo in modeInfos)
{
IRCSendMode(channel, modeInfo);
SendMode(channel, modeInfo);
}
}
public void IRCSendMode(string nick, UserModeInfo modeInfo)
public void SendMode(string nick, UserModeInfo modeInfo)
{
string mode_set = modeInfo.Set ? "+" : "-";
SendTCPMessage(string.Format("MODE {0} {1}", nick, mode_set + modeInfo.Mode.ToString()));
}
public void IRCSendMode(string nick, List<UserModeInfo> modeInfos)
public void SendMode(string nick, List<UserModeInfo> modeInfos)
{
foreach (UserModeInfo modeInfo in modeInfos)
{
IRCSendMode(nick, modeInfo);
SendMode(nick, modeInfo);
}
}
@ -194,12 +223,12 @@ namespace Combot.IRCServices @@ -194,12 +223,12 @@ namespace Combot.IRCServices
/// Sends a Topic command to change the channels topic or view the current one
/// </summary>
/// <param name="channel"></param>
public void IRCSendTopic(string channel)
public void SendTopic(string channel)
{
SendTCPMessage(string.Format("TOPIC {0}", channel));
}
public void IRCSendTopic(string channel, string topic)
public void SendTopic(string channel, string topic)
{
SendTCPMessage(string.Format("TOPIC {0} :{1}", channel, topic));
}
@ -207,17 +236,17 @@ namespace Combot.IRCServices @@ -207,17 +236,17 @@ namespace Combot.IRCServices
/// <summary>
/// Sends a Names command to get a list of visible users
/// </summary>
public void IRCSendNames()
public void SendNames()
{
SendTCPMessage("NAMES");
}
public void IRCSendNames(string channel)
public void SendNames(string channel)
{
SendTCPMessage(string.Format("NAMES {0}", channel));
}
public void IRCSendNames(List<string> channels)
public void SendNames(List<string> channels)
{
string channel_list = string.Empty;
foreach (string channel in channels)
@ -230,17 +259,17 @@ namespace Combot.IRCServices @@ -230,17 +259,17 @@ namespace Combot.IRCServices
/// <summary>
/// Sends a List command to get the topic of channels
/// </summary>
public void IRCSendList()
public void SendList()
{
SendTCPMessage("LIST");
}
public void IRCSendList(string channel)
public void SendList(string channel)
{
SendTCPMessage(string.Format("LIST {0}", channel));
}
public void IRCSendList(List<string> channels)
public void SendList(List<string> channels)
{
string channel_list = string.Empty;
foreach (string channel in channels)
@ -255,7 +284,7 @@ namespace Combot.IRCServices @@ -255,7 +284,7 @@ namespace Combot.IRCServices
/// </summary>
/// <param name="channel"></param>
/// <param name="nick"></param>
public void IRCSendInvite(string channel, string nick)
public void SendInvite(string channel, string nick)
{
SendTCPMessage(string.Format("INVITE {0} {1}", nick, channel));
}
@ -265,12 +294,12 @@ namespace Combot.IRCServices @@ -265,12 +294,12 @@ namespace Combot.IRCServices
/// </summary>
/// <param name="channel"></param>
/// <param name="nick"></param>
public void IRCSendKick(string channel, string nick)
public void SendKick(string channel, string nick)
{
SendTCPMessage(string.Format("KICK {0} {1}", channel, nick));
}
public void IRCSendKick(string channel, string nick, string reason)
public void SendKick(string channel, string nick, string reason)
{
SendTCPMessage(string.Format("KICK {0} {1} :{2}", channel, nick, reason));
}
@ -279,7 +308,7 @@ namespace Combot.IRCServices @@ -279,7 +308,7 @@ namespace Combot.IRCServices
/// Sends a Version command to the server to get a Version reply
/// </summary>
/// <param name="server"></param>
public void IRCSendVersion(string server)
public void SendVersion(string server)
{
SendTCPMessage(string.Format("VERSION {0}", server));
}
@ -288,12 +317,12 @@ namespace Combot.IRCServices @@ -288,12 +317,12 @@ namespace Combot.IRCServices
/// Sends a Stats command to view Server information and statistics
/// </summary>
/// <param name="stat"></param>
public void IRCSendStats(ServerStat stat)
public void SendStats(ServerStat stat)
{
SendTCPMessage(string.Format("STATS {0}", stat.ToString()));
}
public void IRCSendStats(ServerStat stat, string parameter)
public void SendStats(ServerStat stat, string parameter)
{
SendTCPMessage(string.Format("STATS {0} {1}", stat.ToString(), parameter));
}
@ -302,12 +331,12 @@ namespace Combot.IRCServices @@ -302,12 +331,12 @@ namespace Combot.IRCServices
/// Sends a Links command to list all servers matching a mask
/// </summary>
/// <param name="mask"></param>
public void IRCSendLinks(string mask)
public void SendLinks(string mask)
{
SendTCPMessage(string.Format("LINKS {0}", mask));
}
public void IRCSendLinks(string server, string mask)
public void SendLinks(string server, string mask)
{
SendTCPMessage(string.Format("LINKS {0} {1}", mask, server));
}
@ -315,12 +344,12 @@ namespace Combot.IRCServices @@ -315,12 +344,12 @@ namespace Combot.IRCServices
/// <summary>
/// Sends a Time command to query the local server time
/// </summary>
public void IRCSendTime()
public void SendTime()
{
SendTCPMessage("TIME");
}
public void IRCSendTime(string server)
public void SendTime(string server)
{
SendTCPMessage(string.Format("TIME {0}", server));
}
@ -329,12 +358,12 @@ namespace Combot.IRCServices @@ -329,12 +358,12 @@ namespace Combot.IRCServices
/// Senda a Connect command to have the server try to connect to another server
/// </summary>
/// <param name="server"></param>
public void IRCSendConnect(string server)
public void SendConnect(string server)
{
SendTCPMessage(string.Format("CONNECT {0}", server));
}
public void IRCSendConnect(string server, string originator, int port)
public void SendConnect(string server, string originator, int port)
{
SendTCPMessage(string.Format("CONNECT {0} {1} {2}", originator, port, server));
}
@ -343,7 +372,7 @@ namespace Combot.IRCServices @@ -343,7 +372,7 @@ namespace Combot.IRCServices
/// Sends a Trace command to find the route to the target (nick or server)
/// </summary>
/// <param name="target"></param>
public void IRCSendTrace(string target)
public void SendTrace(string target)
{
SendTCPMessage(string.Format("TRACE {0}", target));
}
@ -351,12 +380,12 @@ namespace Combot.IRCServices @@ -351,12 +380,12 @@ namespace Combot.IRCServices
/// <summary>
/// Sends an Admin command to get the name of the server Administrator
/// </summary>
public void IRCSendAdmin()
public void SendAdmin()
{
SendTCPMessage("ADMIN");
}
public void IRCSendAdmin(string host)
public void SendAdmin(string host)
{
SendTCPMessage(string.Format("ADMIN {0}", host));
}
@ -365,7 +394,7 @@ namespace Combot.IRCServices @@ -365,7 +394,7 @@ namespace Combot.IRCServices
/// Sends an Info command for a specific server or nick
/// </summary>
/// <param name="host"></param>
public void IRCSendInfo(string host)
public void SendInfo(string host)
{
SendTCPMessage(string.Format("INFO {0}", host));
}
@ -373,12 +402,12 @@ namespace Combot.IRCServices @@ -373,12 +402,12 @@ namespace Combot.IRCServices
/// <summary>
/// Sends a Who command to list all public users or matching a mask
/// </summary>
public void IRCSendWho()
public void SendWho()
{
SendTCPMessage("WHO");
}
public void IRCSendWho(string host, bool ops = false)
public void SendWho(string host, bool ops = false)
{
string msg = string.Empty;
if (ops)
@ -396,12 +425,12 @@ namespace Combot.IRCServices @@ -396,12 +425,12 @@ namespace Combot.IRCServices
/// Sends a Whois command to get info about a user
/// </summary>
/// <param name="nick"></param>
public void IRCSendWhois(string nick)
public void SendWhois(string nick)
{
SendTCPMessage(string.Format("WHOIS {0}", nick));
}
public void IRCSendWhois(string nick, string server)
public void SendWhois(string nick, string server)
{
SendTCPMessage(string.Format("WHOIS {0} {1}", server, nick));
}
@ -410,17 +439,17 @@ namespace Combot.IRCServices @@ -410,17 +439,17 @@ namespace Combot.IRCServices
/// Sends a Whowas command to get the nick history of a user
/// </summary>
/// <param name="nick"></param>
public void IRCSendWhowas(string nick)
public void SendWhowas(string nick)
{
SendTCPMessage(string.Format("WHOIS {0}", nick));
}
public void IRCSendWhowas(string nick, int entries)
public void SendWhowas(string nick, int entries)
{
SendTCPMessage(string.Format("WHOIS {0} {1}", nick, entries));
}
public void IRCSendWhowas(string nick, int entries, string server)
public void SendWhowas(string nick, int entries, string server)
{
SendTCPMessage(string.Format("WHOIS {0} {1} {2}", nick, entries, server));
}
@ -430,7 +459,7 @@ namespace Combot.IRCServices @@ -430,7 +459,7 @@ namespace Combot.IRCServices
/// </summary>
/// <param name="nick"></param>
/// <param name="comment"></param>
public void IRCSendKill(string nick, string comment)
public void SendKill(string nick, string comment)
{
SendTCPMessage(string.Format("KILL {0} {1}", nick, comment));
}
@ -439,7 +468,7 @@ namespace Combot.IRCServices @@ -439,7 +468,7 @@ namespace Combot.IRCServices
/// Sends a Ping command to the recipient
/// </summary>
/// <param name="recipient"></param>
public void IRCSendPing(string recipient)
public void SendPing(string recipient)
{
SendTCPMessage(string.Format("PING {0}", recipient));
}
@ -449,17 +478,17 @@ namespace Combot.IRCServices @@ -449,17 +478,17 @@ namespace Combot.IRCServices
/// </summary>
/// <param name="sender"></param>
/// <param name="recipient"></param>
public void IRCSendPong()
public void SendPong()
{
SendTCPMessage("PONG");
}
public void IRCSendPong(string message)
public void SendPong(string message)
{
SendTCPMessage(string.Format("PONG {0}", message));
}
public void IRCSendPong(string sender, string recipient)
public void SendPong(string sender, string recipient)
{
SendTCPMessage(string.Format("PONG {0} {1}", sender, recipient));
}
@ -468,7 +497,7 @@ namespace Combot.IRCServices @@ -468,7 +497,7 @@ namespace Combot.IRCServices
/// <summary>
/// Sends an Away command to unset away status
/// </summary>
public void IRCSendAway()
public void SendAway()
{
SendTCPMessage("AWAY");
}
@ -477,7 +506,7 @@ namespace Combot.IRCServices @@ -477,7 +506,7 @@ namespace Combot.IRCServices
/// Sends an Away comand to set away status with auto-reply message
/// </summary>
/// <param name="message"></param>
public void IRCSendAway(string message)
public void SendAway(string message)
{
SendTCPMessage(string.Format("AWAY {0}", message));
}
@ -485,7 +514,7 @@ namespace Combot.IRCServices @@ -485,7 +514,7 @@ namespace Combot.IRCServices
/// <summary>
/// Sends a Rehash command to the server to reload it's configuration file
/// </summary>
public void IRCSendRehash()
public void SendRehash()
{
SendTCPMessage("REHASH");
}
@ -493,7 +522,7 @@ namespace Combot.IRCServices @@ -493,7 +522,7 @@ namespace Combot.IRCServices
/// <summary>
/// Sends a Restart command to the server to restart
/// </summary>
public void IRCSendRestart()
public void SendRestart()
{
SendTCPMessage("RESTART");
}
@ -502,17 +531,17 @@ namespace Combot.IRCServices @@ -502,17 +531,17 @@ namespace Combot.IRCServices
/// Sends a Summon command to summon a nick to the server
/// </summary>
/// <param name="nick"></param>
public void IRCSendSummon()
public void SendSummon()
{
SendTCPMessage("SUMMON");
}
public void IRCSendSummon(string nick)
public void SendSummon(string nick)
{
SendTCPMessage(string.Format("SUMMON {0}", nick));
}
public void IRCSendSummon(string nick, string host)
public void SendSummon(string nick, string host)
{
SendTCPMessage(string.Format("SUMMON {0} {1}", nick, host));
}
@ -521,7 +550,7 @@ namespace Combot.IRCServices @@ -521,7 +550,7 @@ namespace Combot.IRCServices
/// Sends a Users command to get a list of Users from a server
/// </summary>
/// <param name="server"></param>
public void IRCSendUsers(string server)
public void SendUsers(string server)
{
SendTCPMessage(string.Format("USERS {0}", server));
}
@ -530,7 +559,7 @@ namespace Combot.IRCServices @@ -530,7 +559,7 @@ namespace Combot.IRCServices
/// Sends a Wallops command which sends a message to all connected ops
/// </summary>
/// <param name="message"></param>
public void IRCSendWallops(string message)
public void SendWallops(string message)
{
SendTCPMessage(string.Format("WALLOPS :{0}", message));
}
@ -539,7 +568,7 @@ namespace Combot.IRCServices @@ -539,7 +568,7 @@ namespace Combot.IRCServices
/// Sends an Userhost command to up to 5 nicknames to return information about each nick
/// </summary>
/// <param name="nicks"></param>
public void IRCSendUserhost(List<string> nicks)
public void SendUserhost(List<string> nicks)
{
string message = string.Empty;
foreach (string nick in nicks)
@ -553,7 +582,7 @@ namespace Combot.IRCServices @@ -553,7 +582,7 @@ namespace Combot.IRCServices
/// Sends an IsOn command to get a return if the nicks specified are online
/// </summary>
/// <param name="nicks"></param>
public void IRCSendIson(List<string> nicks)
public void SendIson(List<string> nicks)
{
string message = string.Empty;
foreach (string nick in nicks)

7
IRCServices/Messaging/MessageTypes.cs

@ -6,6 +6,11 @@ namespace Combot.IRCServices.Messaging @@ -6,6 +6,11 @@ namespace Combot.IRCServices.Messaging
abstract public class IMessage : EventArgs
{
public DateTime TimeStamp { get; set; }
public IMessage()
{
TimeStamp = DateTime.Now;
}
}
abstract public class IReply : IMessage
@ -61,7 +66,7 @@ namespace Combot.IRCServices.Messaging @@ -61,7 +66,7 @@ namespace Combot.IRCServices.Messaging
public class CTCPMessage : IMessage
{
public Nick Target { get; set; }
public Nick Sender { get; set; }
public string Command { get; set; }
public string Arguments { get; set; }
}

23
IRCServices/Messaging/Messages.cs

@ -17,7 +17,8 @@ namespace Combot.IRCServices.Messaging @@ -17,7 +17,8 @@ namespace Combot.IRCServices.Messaging
public event EventHandler<ServerNotice> ServerNoticeReceivedEvent;
public event EventHandler<ChannelNotice> ChannelNoticeReceivedEvent;
public event EventHandler<PrivateNotice> PrivateNoticeReceivedEvent;
public event EventHandler<CTCPMessage> CTCPMessageRecievedEvent;
public event EventHandler<CTCPMessage> CTCPMessageRecievedEvent;
public event EventHandler<CTCPMessage> CTCPNoticeRecievedEvent;
public event EventHandler<TopicChangeInfo> TopicChangeEvent;
public event EventHandler<ChannelModeChangeInfo> ChannelModeChangeEvent;
public event EventHandler<UserModeChangeInfo> UserModeChangeEvent;
@ -102,7 +103,7 @@ namespace Combot.IRCServices.Messaging @@ -102,7 +103,7 @@ namespace Combot.IRCServices.Messaging
{
Match ctcpMatch = CTCPRegex.Match(args);
CTCPMessage ctcpMessage = new CTCPMessage();
ctcpMessage.Target = new Nick()
ctcpMessage.Sender = new Nick()
{
Nickname = senderNick,
Realname = senderRealname,
@ -155,6 +156,24 @@ namespace Combot.IRCServices.Messaging @@ -155,6 +156,24 @@ namespace Combot.IRCServices.Messaging
break;
// The message was a notice to a channel or nick
case "NOTICE":
if (CTCPRegex.IsMatch(args))
{
Match ctcpMatch = CTCPRegex.Match(args);
CTCPMessage ctcpMessage = new CTCPMessage();
ctcpMessage.Sender = new Nick()
{
Nickname = senderNick,
Realname = senderRealname,
Host = senderHost
};
ctcpMessage.Command = ctcpMatch.Groups["Command"].Value;
ctcpMessage.Arguments = ctcpMatch.Groups["Args"].Value;
if (CTCPNoticeRecievedEvent != null)
{
CTCPNoticeRecievedEvent(this, ctcpMessage);
}
}
if (recipient.StartsWith("&") || recipient.StartsWith("#"))
{
ChannelNotice msg = new ChannelNotice();

44
Interface/ViewModels/MainViewModel.cs

@ -33,15 +33,28 @@ namespace Interface.ViewModels @@ -33,15 +33,28 @@ namespace Interface.ViewModels
public MainViewModel()
{
ApplicationTitle = "Combot";
Config.LoadServers();
/*
//Config.LoadServers();
ServerConfig serverConfig = new ServerConfig();
serverConfig.AutoConnect = true;
serverConfig.Channels = new List<ChannelConfig> { new ChannelConfig() { Name = "#testing", Key = string.Empty } };
serverConfig.Channels = new List<ChannelConfig>
{
new ChannelConfig()
{
Name = "#testing",
Key = string.Empty
},
new ChannelConfig()
{
Name = "#/g/technology",
Key = string.Empty
}
};
serverConfig.Name = "Rizon";
serverConfig.Nickname = "Combot_V3";
serverConfig.Realname = "Combot_Realname";
serverConfig.Username = "Combot_Username";
serverConfig.CommandPrefix = ".";
serverConfig.Hosts = new List<HostConfig> { new HostConfig() { Host = "irc.rizon.net", Port = 6667 } };
serverConfig.Modules = new List<Module>
{
@ -50,12 +63,33 @@ namespace Interface.ViewModels @@ -50,12 +63,33 @@ namespace Interface.ViewModels
Name = "Ping Me",
ClassName = "PingMe",
Enabled = true,
Commands = new List<Command> { new Command { Name = "Ping Me", Triggers = new List<string>() {"pingme"} } }
Commands = new List<Command>
{
new Command
{
Name = "Ping Me",
Description = "Checks the time it takes for a PING to be returned from a nick.",
AllowedAccess = new List<AccessType>()
{
AccessType.User,
AccessType.Voice,
AccessType.HalfOperator,
AccessType.Operator,
AccessType.SuperOperator,
AccessType.Founder,
AccessType.Owner
},
Triggers = new List<string>()
{
"pingme"
}
}
}
}
};
Config.Servers.Add(serverConfig);