Browse Source

Added Sed, Rules, About, Fun, and Configuration modules.

Made most module responses into a shared function call.
Fixed some bugs.
pull/1/head
Teknikode 7 years ago
parent
commit
7392aedaaa
  1. 32
      Combot.sln
  2. 29
      Combot/Bot.cs
  3. 33
      Combot/Configurations/Config.cs
  4. 56
      Combot/Configurations/ServerConfig.cs
  5. 6
      Combot/Modules/Command.cs
  6. 17
      Combot/Modules/Module.cs
  7. 28
      IRCServices/IRC.cs
  8. 4
      IRCServices/SendCommand.cs
  9. 4
      Interface/ViewModels/MainViewModel.cs
  10. 94
      Modules/About/About.cs
  11. 74
      Modules/About/About.csproj
  12. 124
      Modules/About/Module.config
  13. 36
      Modules/About/Properties/AssemblyInfo.cs
  14. 74
      Modules/Channel Rules/Channel Rules.csproj
  15. 150
      Modules/Channel Rules/Channel_Rules.cs
  16. 104
      Modules/Channel Rules/Module.config
  17. 36
      Modules/Channel Rules/Properties/AssemblyInfo.cs
  18. 641
      Modules/Configuration/Configuration.cs
  19. 5
      Modules/Configuration/Configuration.csproj
  20. 180
      Modules/Configuration/Module.config
  21. 4
      Modules/Configuration/packages.config
  22. 56
      Modules/Fun/Fun.cs
  23. 74
      Modules/Fun/Fun.csproj
  24. 247
      Modules/Fun/Module.config
  25. 36
      Modules/Fun/Properties/AssemblyInfo.cs
  26. 2
      Modules/Help/Help.cs
  27. 174
      Modules/Introductions/Introductions.cs
  28. 4
      Modules/Introductions/Module.config
  29. 26
      Modules/Messaging/Messaging.cs
  30. 147
      Modules/Moderation/Moderation.cs
  31. 42
      Modules/Moderation/Module.config
  32. 21
      Modules/Owner Control/Module.config
  33. 1
      Modules/Owner Control/Owner Control.csproj
  34. 173
      Modules/Owner Control/Owner_Control.cs
  35. 39
      Modules/Quotes/Quotes.cs
  36. 39
      Modules/Search/Search.cs
  37. 9
      Modules/Sed/Module.config
  38. 36
      Modules/Sed/Properties/AssemblyInfo.cs
  39. 96
      Modules/Sed/Sed.cs
  40. 74
      Modules/Sed/Sed.csproj
  41. 26
      Modules/Seen/Seen.cs
  42. 14
      Modules/Version/Version.cs
  43. 31
      Modules/Weather Information/Weather_Information.cs
  44. 43
      Modules/Wolfram Alpha/Wolfram_Alpha.cs
  45. 26
      Modules/YouTube/YouTube.cs

32
Combot.sln

@ -6,6 +6,7 @@ MinimumVisualStudioVersion = 10.0.40219.1 @@ -6,6 +6,7 @@ MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Interface", "Interface\Interface.csproj", "{AE4AFD7A-CAA4-46A0-9E00-2B3D53F8D0AB}"
ProjectSection(ProjectDependencies) = postProject
{2CE88104-14EB-436A-9E74-610212FF42F6} = {2CE88104-14EB-436A-9E74-610212FF42F6}
{6F4BBF10-0D1A-4092-8A06-C7587EBC3F03} = {6F4BBF10-0D1A-4092-8A06-C7587EBC3F03}
{D469C717-7625-40F1-966D-3C9DD00F5B9C} = {D469C717-7625-40F1-966D-3C9DD00F5B9C}
{EBAC601C-652C-466A-B4F0-94495F4C8E49} = {EBAC601C-652C-466A-B4F0-94495F4C8E49}
{289A0E25-F669-4E00-9DB9-0C5AE51E2BCC} = {289A0E25-F669-4E00-9DB9-0C5AE51E2BCC}
@ -14,6 +15,7 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Interface", "Interface\Inte @@ -14,6 +15,7 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Interface", "Interface\Inte
{72CCA645-3E1D-4355-9BDE-5C1884BCB6FC} = {72CCA645-3E1D-4355-9BDE-5C1884BCB6FC}
{1A544D51-1041-4A9A-B1ED-E738735DF52E} = {1A544D51-1041-4A9A-B1ED-E738735DF52E}
{2AD43A57-CDFF-4098-AC09-82159744C6E4} = {2AD43A57-CDFF-4098-AC09-82159744C6E4}
{0DAE9869-DE0E-442F-B8EF-B4F54EDE9559} = {0DAE9869-DE0E-442F-B8EF-B4F54EDE9559}
{42BB7F70-53A1-4FA4-80C2-9DB47A092FB0} = {42BB7F70-53A1-4FA4-80C2-9DB47A092FB0}
{18369F84-BD20-4946-B3D6-F2152148B2B4} = {18369F84-BD20-4946-B3D6-F2152148B2B4}
{60902085-CEF9-4C38-96F4-644F4574681F} = {60902085-CEF9-4C38-96F4-644F4574681F}
@ -23,6 +25,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Interface", "Interface\Inte @@ -23,6 +25,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Interface", "Interface\Inte
{2434E995-592F-4EE2-B321-033B7493F93E} = {2434E995-592F-4EE2-B321-033B7493F93E}
{516ECE98-0D6D-4713-AEDA-EDF47FFAA80B} = {516ECE98-0D6D-4713-AEDA-EDF47FFAA80B}
{EFAC8BA8-AF57-4D9C-9F00-1758FCC2F22E} = {EFAC8BA8-AF57-4D9C-9F00-1758FCC2F22E}
{FE9C7DB3-C4AA-4CF4-A6CF-CBE2244D3F2D} = {FE9C7DB3-C4AA-4CF4-A6CF-CBE2244D3F2D}
{569F61C2-3B06-4313-A299-E643C3786D3D} = {569F61C2-3B06-4313-A299-E643C3786D3D}
EndProjectSection
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Combot", "Combot\Combot.csproj", "{23E4C371-16E4-4FAC-8B11-44288399BB55}"
@ -73,6 +77,14 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Messaging", "Modules\Messag @@ -73,6 +77,14 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Messaging", "Modules\Messag
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Spam Control", "Modules\Spam Control\Spam Control.csproj", "{921B252D-D2D0-412F-BD6D-9559DCD20BB0}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Sed", "Modules\Sed\Sed.csproj", "{6F4BBF10-0D1A-4092-8A06-C7587EBC3F03}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Fun", "Modules\Fun\Fun.csproj", "{FE9C7DB3-C4AA-4CF4-A6CF-CBE2244D3F2D}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Channel Rules", "Modules\Channel Rules\Channel Rules.csproj", "{569F61C2-3B06-4313-A299-E643C3786D3D}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "About", "Modules\About\About.csproj", "{0DAE9869-DE0E-442F-B8EF-B4F54EDE9559}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@ -163,6 +175,22 @@ Global @@ -163,6 +175,22 @@ Global
{921B252D-D2D0-412F-BD6D-9559DCD20BB0}.Debug|Any CPU.Build.0 = Debug|Any CPU
{921B252D-D2D0-412F-BD6D-9559DCD20BB0}.Release|Any CPU.ActiveCfg = Release|Any CPU
{921B252D-D2D0-412F-BD6D-9559DCD20BB0}.Release|Any CPU.Build.0 = Release|Any CPU
{6F4BBF10-0D1A-4092-8A06-C7587EBC3F03}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{6F4BBF10-0D1A-4092-8A06-C7587EBC3F03}.Debug|Any CPU.Build.0 = Debug|Any CPU
{6F4BBF10-0D1A-4092-8A06-C7587EBC3F03}.Release|Any CPU.ActiveCfg = Release|Any CPU
{6F4BBF10-0D1A-4092-8A06-C7587EBC3F03}.Release|Any CPU.Build.0 = Release|Any CPU
{FE9C7DB3-C4AA-4CF4-A6CF-CBE2244D3F2D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{FE9C7DB3-C4AA-4CF4-A6CF-CBE2244D3F2D}.Debug|Any CPU.Build.0 = Debug|Any CPU
{FE9C7DB3-C4AA-4CF4-A6CF-CBE2244D3F2D}.Release|Any CPU.ActiveCfg = Release|Any CPU
{FE9C7DB3-C4AA-4CF4-A6CF-CBE2244D3F2D}.Release|Any CPU.Build.0 = Release|Any CPU
{569F61C2-3B06-4313-A299-E643C3786D3D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{569F61C2-3B06-4313-A299-E643C3786D3D}.Debug|Any CPU.Build.0 = Debug|Any CPU
{569F61C2-3B06-4313-A299-E643C3786D3D}.Release|Any CPU.ActiveCfg = Release|Any CPU
{569F61C2-3B06-4313-A299-E643C3786D3D}.Release|Any CPU.Build.0 = Release|Any CPU
{0DAE9869-DE0E-442F-B8EF-B4F54EDE9559}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{0DAE9869-DE0E-442F-B8EF-B4F54EDE9559}.Debug|Any CPU.Build.0 = Debug|Any CPU
{0DAE9869-DE0E-442F-B8EF-B4F54EDE9559}.Release|Any CPU.ActiveCfg = Release|Any CPU
{0DAE9869-DE0E-442F-B8EF-B4F54EDE9559}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
@ -186,5 +214,9 @@ Global @@ -186,5 +214,9 @@ Global
{909F6291-F0F5-4452-A4CA-BEF96916C01D} = {D157677E-4D33-4156-B55E-E21C4B5A3024}
{2434E995-592F-4EE2-B321-033B7493F93E} = {D157677E-4D33-4156-B55E-E21C4B5A3024}
{921B252D-D2D0-412F-BD6D-9559DCD20BB0} = {D157677E-4D33-4156-B55E-E21C4B5A3024}
{6F4BBF10-0D1A-4092-8A06-C7587EBC3F03} = {D157677E-4D33-4156-B55E-E21C4B5A3024}
{FE9C7DB3-C4AA-4CF4-A6CF-CBE2244D3F2D} = {D157677E-4D33-4156-B55E-E21C4B5A3024}
{569F61C2-3B06-4313-A299-E643C3786D3D} = {D157677E-4D33-4156-B55E-E21C4B5A3024}
{0DAE9869-DE0E-442F-B8EF-B4F54EDE9559} = {D157677E-4D33-4156-B55E-E21C4B5A3024}
EndGlobalSection
EndGlobal

29
Combot/Bot.cs

@ -23,6 +23,8 @@ namespace Combot @@ -23,6 +23,8 @@ namespace Combot
public List<Module> Modules;
public bool Connected = false;
public bool LoggedIn = false;
public DateTime ConnectionTime;
public DateTime LoadTime;
public Dictionary<PrivilegeMode, AccessType> PrivilegeModeMapping = new Dictionary<PrivilegeMode, AccessType>() { { PrivilegeMode.v, AccessType.Voice }, { PrivilegeMode.h, AccessType.HalfOperator }, { PrivilegeMode.o, AccessType.Operator }, { PrivilegeMode.a, AccessType.SuperOperator }, { PrivilegeMode.q, AccessType.Founder } };
public Dictionary<ChannelMode, AccessType> ChannelModeMapping = new Dictionary<ChannelMode, AccessType>() { { ChannelMode.v, AccessType.Voice }, { ChannelMode.h, AccessType.HalfOperator }, { ChannelMode.o, AccessType.Operator }, { ChannelMode.a, AccessType.SuperOperator }, { ChannelMode.q, AccessType.Founder } };
@ -38,6 +40,8 @@ namespace Combot @@ -38,6 +40,8 @@ namespace Combot
CurNickChoice = 0;
RetryCount = 0;
ServerConfig = serverConfig;
LoadTime = DateTime.Now;
ConnectionTime = DateTime.Now;
IRC = new IRC(serverConfig.MaxMessageLength, serverConfig.MessageSendDelay);
IRC.ConnectEvent += HandleConnectEvent;
@ -58,6 +62,7 @@ namespace Combot @@ -58,6 +62,7 @@ namespace Combot
/// </summary>
public void Connect()
{
ConnectionTime = DateTime.Now;
GhostSent = false;
CurNickChoice = 0;
RetryAllowed = ServerConfig.Reconnect;
@ -121,11 +126,11 @@ namespace Combot @@ -121,11 +126,11 @@ namespace Combot
/// </summary>
public void Disconnect()
{
RetryAllowed = false;
RetryCount = 0;
IRC.Disconnect();
Connected = false;
LoggedIn = false;
RetryCount = 0;
RetryAllowed = false;
}
private void Reconnect()
@ -543,16 +548,7 @@ namespace Combot @@ -543,16 +548,7 @@ namespace Combot
return argString;
})));
string invalidMessage = string.Format("Invalid value for \u0002{0}\u0002 in \u0002{1}{2}\u0002{3}. Valid options are \u0002{4}\u0002.", validArguments[i].Name, ServerConfig.CommandPrefix, command, argHelp, string.Join(", ", validArguments[i].AllowedValues));
switch (messageType)
{
case MessageType.Channel:
case MessageType.Query:
IRC.SendPrivateMessage(location, invalidMessage);
break;
case MessageType.Notice:
IRC.SendNotice(location, invalidMessage);
break;
}
module.SendResponse(messageType, location, sender.Nickname, invalidMessage);
break;
}
}
@ -591,14 +587,7 @@ namespace Combot @@ -591,14 +587,7 @@ namespace Combot
return argString;
})));
string missingArgument = string.Format("Missing a required argument for \u0002{0}{1}\u0002{2}. The required arguments are \u0002{3}\u0002.", ServerConfig.CommandPrefix, command, argHelp, string.Join(", ", validArguments.Where(arg => arg.Required).Select(arg => arg.Name)));
if (messageType == MessageType.Channel || messageType == MessageType.Query)
{
IRC.SendPrivateMessage(location, missingArgument);
}
else if (messageType == MessageType.Notice)
{
IRC.SendNotice(location, missingArgument);
}
module.SendResponse(messageType, location, sender.Nickname, missingArgument);
}
}

33
Combot/Configurations/Config.cs

@ -50,6 +50,7 @@ namespace Combot.Configurations @@ -50,6 +50,7 @@ namespace Combot.Configurations
if (!Servers.Exists(server => server.Name == config.Name))
{
config.ModifyEvent += SaveServers;
config.LoadEvent += LoadServers;
Servers.Add(config);
}
ConfigRWLock.ExitWriteLock();
@ -98,5 +99,37 @@ namespace Combot.Configurations @@ -98,5 +99,37 @@ namespace Combot.Configurations
}
ConfigFileRWLock.ExitReadLock();
}
public void UpdateServers()
{
ConfigFileRWLock.EnterReadLock();
string ConfigPath = Path.Combine(Directory.GetCurrentDirectory(), @"Combot.Servers.config");
if (File.Exists(ConfigPath))
{
string configContents;
using (StreamReader streamReader = new StreamReader(ConfigPath, Encoding.UTF8))
{
configContents = streamReader.ReadToEnd();
}
// Load the deserialized file into the config
ConfigRWLock.EnterWriteLock();
List<ServerConfig> newConfigs = JsonConvert.DeserializeObject<List<ServerConfig>>(configContents, JsonSettings);
for (int i = 0; i < newConfigs.Count; i++)
{
if (Servers.Count > i)
{
Servers[i].Copy(newConfigs[i]);
}
else
{
Servers.Add(newConfigs[i]);
}
}
ConfigRWLock.ExitWriteLock();
}
ConfigFileRWLock.ExitReadLock();
}
}
}

56
Combot/Configurations/ServerConfig.cs

@ -6,6 +6,7 @@ namespace Combot.Configurations @@ -6,6 +6,7 @@ namespace Combot.Configurations
public class ServerConfig
{
public event Action ModifyEvent;
public event Action LoadEvent;
public string Name { get; set; }
public List<string> Nicknames { get; set; }
public string Realname { get; set; }
@ -55,6 +56,53 @@ namespace Combot.Configurations @@ -55,6 +56,53 @@ namespace Combot.Configurations
Database = new DatabaseConfig();
}
public void Copy(ServerConfig config)
{
Name = config.Name;
Nicknames = new List<string>();
for (int i = 0; i < config.Nicknames.Count; i++)
{
Nicknames.Add(config.Nicknames[i]);
}
Realname = config.Realname;
Username = config.Username;
Password = config.Password;
Email = config.Email;
AutoConnect = config.AutoConnect;
AutoRegister = config.AutoRegister;
CommandPrefix = config.CommandPrefix;
JoinDelay = config.JoinDelay;
MaxMessageLength = config.MaxMessageLength;
MessageSendDelay = config.MessageSendDelay;
ModuleLocation = config.ModuleLocation;
Owners = new List<string>();
for (int i = 0; i < config.Owners.Count; i++)
{
Owners.Add(config.Owners[i]);
}
ChannelBlacklist = new List<string>();
for (int i = 0; i < config.ChannelBlacklist.Count; i++)
{
ChannelBlacklist.Add(config.ChannelBlacklist[i]);
}
NickBlacklist = new List<string>();
for (int i = 0; i < config.NickBlacklist.Count; i++)
{
NickBlacklist.Add(config.NickBlacklist[i]);
}
Channels = new List<ChannelConfig>();
for (int i = 0; i < config.Channels.Count; i++)
{
Channels.Add(config.Channels[i]);
}
Hosts = new List<HostConfig>();
for (int i = 0; i < config.Hosts.Count; i++)
{
Hosts.Add(config.Hosts[i]);
}
Database = config.Database;
}
public void Save()
{
if (ModifyEvent != null)
@ -62,5 +110,13 @@ namespace Combot.Configurations @@ -62,5 +110,13 @@ namespace Combot.Configurations
ModifyEvent();
}
}
public void Load()
{
if (LoadEvent != null)
{
LoadEvent();
}
}
}
}

6
Combot/Modules/Command.cs

@ -104,12 +104,6 @@ namespace Combot.Modules @@ -104,12 +104,6 @@ namespace Combot.Modules
validArguments.Add(newArgument);
}
}
else
{
CommandArgument newArgument = new CommandArgument();
newArgument.Copy(Arguments[i]);
validArguments.Add(newArgument);
}
}
}
else

17
Combot/Modules/Module.cs

@ -56,6 +56,7 @@ namespace Combot.Modules @@ -56,6 +56,7 @@ namespace Combot.Modules
{
// Check to make sure the command exists, the nick or channel isn't on a blacklist, and the module is loaded.
if (Loaded
&& Enabled
&& !ChannelBlacklist.Contains(command.Location)
&& !NickBlacklist.Contains(command.Nick.Nickname)
&& Commands.Exists(c => c.Triggers.Contains(command.Command)
@ -290,5 +291,21 @@ namespace Combot.Modules @@ -290,5 +291,21 @@ namespace Combot.Modules
}
return nickname;
}
public void SendResponse(MessageType messageType, string location, string nickname, string message)
{
switch (messageType)
{
case MessageType.Channel:
Bot.IRC.SendPrivateMessage(location, message);
break;
case MessageType.Query:
Bot.IRC.SendPrivateMessage(nickname, message);
break;
case MessageType.Notice:
Bot.IRC.SendNotice(nickname, message);
break;
}
}
}
}

28
IRCServices/IRC.cs

@ -99,15 +99,23 @@ namespace Combot.IRCServices @@ -99,15 +99,23 @@ namespace Combot.IRCServices
/// Disconencts from the active TCP connection.
/// </summary>
/// <returns></returns>
public bool Disconnect()
public void Disconnect()
{
bool result = false;
if (_TCP.Connected)
{
_TCP.Disconnect();
}
if (KeepAlive.IsAlive)
{
KeepAlive.Join();
}
if (TCPReader.IsAlive)
{
TCPReader.Join();
}
ChannelRWLock.EnterWriteLock();
Channels = new List<Channel>();
ChannelRWLock.ExitWriteLock();
@ -116,8 +124,6 @@ namespace Combot.IRCServices @@ -116,8 +124,6 @@ namespace Combot.IRCServices
{
DisconnectEvent();
}
return result;
}
/// <summary>
@ -271,11 +277,11 @@ namespace Combot.IRCServices @@ -271,11 +277,11 @@ namespace Combot.IRCServices
private void CheckConnection(IPAddress IP, int port)
{
int diconnectCount = 0;
bool stillConnected = true;
bool disconnectActivated = false;
while (_TCP.Connected)
{
Thread.Sleep(1000);
stillConnected = NetworkInterface.GetIsNetworkAvailable();
bool stillConnected = NetworkInterface.GetIsNetworkAvailable();
if (stillConnected)
{
@ -299,9 +305,13 @@ namespace Combot.IRCServices @@ -299,9 +305,13 @@ namespace Combot.IRCServices
diconnectCount = 0;
}
if (diconnectCount >= 5)
if (diconnectCount >= 5 && !disconnectActivated)
{
Disconnect();
disconnectActivated = true;
Task.Run(() =>
{
Disconnect();
});
}
}
}

4
IRCServices/SendCommand.cs

@ -20,7 +20,7 @@ namespace Combot.IRCServices @@ -20,7 +20,7 @@ namespace Combot.IRCServices
TimeSpan sinceLastMessage = (DateTime.Now - LastMessageSend);
if (sinceLastMessage.TotalMilliseconds < MessageSendDelay)
{
Thread.Sleep((int) sinceLastMessage.TotalMilliseconds);
Thread.Sleep((int)(MessageSendDelay - sinceLastMessage.TotalMilliseconds));
}
LastMessageSend = DateTime.Now;
if (message.Length > MaxMessageLength)
@ -68,7 +68,7 @@ namespace Combot.IRCServices @@ -68,7 +68,7 @@ namespace Combot.IRCServices
TimeSpan sinceLastMessage = (DateTime.Now - LastMessageSend);
if (sinceLastMessage.TotalMilliseconds < MessageSendDelay)
{
Thread.Sleep((int) sinceLastMessage.TotalMilliseconds);
Thread.Sleep((int) (MessageSendDelay - sinceLastMessage.TotalMilliseconds));
}
LastMessageSend = DateTime.Now;
if (message.Length > MaxMessageLength)

4
Interface/ViewModels/MainViewModel.cs

@ -251,8 +251,8 @@ namespace Interface.ViewModels @@ -251,8 +251,8 @@ namespace Interface.ViewModels
if (server == SelectedServer)
{
Connected = true;
AddToBuffer(server, null, "-- Connected --");
}
AddToBuffer(server, null, "-- Connected --");
}
private void DisconnectHandler(string server)
@ -260,8 +260,8 @@ namespace Interface.ViewModels @@ -260,8 +260,8 @@ namespace Interface.ViewModels
if (server == SelectedServer)
{
Connected = false;
AddToBuffer(server, null, "-- Disconnected --");
}
AddToBuffer(server, null, "-- Disconnected --");
}
private void ExecuteToggleConnection()

94
Modules/About/About.cs

@ -0,0 +1,94 @@ @@ -0,0 +1,94 @@
using System;
using System.Reflection;
namespace Combot.Modules.Plugins
{
public class About : 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 "About":
string ownerNum = " is";
if (Bot.ServerConfig.Owners.Count > 1)
{
ownerNum = "s are";
}
string aboutMessage = string.Format("Combot v{0} is created by Uncled1023. My current owner{1} {2}.", Assembly.GetExecutingAssembly().GetName().Version, ownerNum, string.Join(", ", Bot.ServerConfig.Owners));
SendResponse(command.MessageType, command.Location, command.Nick.Nickname, aboutMessage);
break;
case "Source":
SendResponse(command.MessageType, command.Location, command.Nick.Nickname, string.Format("You can find my source code here: {0}", GetOptionValue("Source Code")));
break;
case "Uptime":
DateTime now = DateTime.Now;
int days = now.Subtract(Bot.ConnectionTime).Days;
int hours = now.Subtract(Bot.ConnectionTime).Hours;
int minutes = now.Subtract(Bot.ConnectionTime).Minutes;
int seconds = now.Subtract(Bot.ConnectionTime).Seconds;
string uptime = string.Empty;
if (days > 0)
{
string plural = (days > 1) ? "s" : string.Empty;
uptime += string.Format("{0} day{1}, ", days, plural);
}
if (hours > 0)
{
string plural = (hours > 1) ? "s" : string.Empty;
uptime += string.Format("{0} hour{1}, ", hours, plural);
}
if (minutes > 0)
{
string plural = (minutes > 1) ? "s" : string.Empty;
uptime += string.Format("{0} minute{1}, ", minutes, plural);
}
if (seconds > 0)
{
string plural = (seconds > 1) ? "s" : string.Empty;
uptime += string.Format("{0} second{1}", seconds, plural);
}
SendResponse(command.MessageType, command.Location, command.Nick.Nickname, string.Format("I have been connected to this server for \u0002{0}\u0002.", uptime.Trim().TrimEnd(',')));
break;
case "Runtime":
DateTime runtimeNow = DateTime.Now;
int totalDays = runtimeNow.Subtract(Bot.LoadTime).Days;
int totalHours = runtimeNow.Subtract(Bot.LoadTime).Hours;
int totalMinutes = runtimeNow.Subtract(Bot.LoadTime).Minutes;
int totalSeconds = runtimeNow.Subtract(Bot.LoadTime).Seconds;
string runtime = string.Empty;
if (totalDays > 0)
{
string plural = (totalDays > 1) ? "s" : string.Empty;
runtime += string.Format("{0} day{1}, ", totalDays, plural);
}
if (totalHours > 0)
{
string plural = (totalHours > 1) ? "s" : string.Empty;
runtime += string.Format("{0} hour{1}, ", totalHours, plural);
}
if (totalMinutes > 0)
{
string plural = (totalMinutes > 1) ? "s" : string.Empty;
runtime += string.Format("{0} minute{1}, ", totalMinutes, plural);
}
if (totalSeconds > 0)
{
string plural = (totalSeconds > 1) ? "s" : string.Empty;
runtime += string.Format("{0} second{1}", totalSeconds, plural);
}
SendResponse(command.MessageType, command.Location, command.Nick.Nickname, string.Format("I have been running for \u0002{0}\u0002.", runtime.Trim().TrimEnd(',')));
break;
}
}
}
}

74
Modules/About/About.csproj

@ -0,0 +1,74 @@ @@ -0,0 +1,74 @@
<?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>{0DAE9869-DE0E-442F-B8EF-B4F54EDE9559}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>About</RootNamespace>
<AssemblyName>About</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\Modules\About\Debug\</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\Modules\About\Release\</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="About.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.config">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<PropertyGroup>
<PostBuildEvent>mkdir "$(SolutionDir)Bin\Interface\$(ConfigurationName)\Modules\$(TargetName)"
copy /Y "$(TargetPath)" "$(SolutionDir)Bin\Interface\$(ConfigurationName)\Modules\$(TargetName)"
copy /Y "$(TargetDir)Module.config" "$(SolutionDir)Bin\Interface\$(ConfigurationName)\Modules\$(TargetName)"</PostBuildEvent>
</PropertyGroup>
<!-- 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>

124
Modules/About/Module.config

@ -0,0 +1,124 @@ @@ -0,0 +1,124 @@
{
"Name": "About",
"ClassName": "About",
"Enabled": true,
"ChannelBlacklist": [],
"NickBlacklist": [],
"Commands": [
{
"Name": "About",
"Description": "Displays information about this bot.",
"Enabled": true,
"ChannelBlacklist": [],
"NickBlacklist": [],
"Triggers": [
"about"
],
"Arguments": [],
"AllowedMessageTypes": [
0,
1,
2
],
"AllowedAccess": [
0,
1,
2,
3,
4,
5,
6
],
"ShowHelp": true,
"SpamCheck": true
},
{
"Name": "Source",
"Description": "Displays the location for the source code of the bot.",
"Enabled": true,
"ChannelBlacklist": [],
"NickBlacklist": [],
"Triggers": [
"source"
],
"Arguments": [],
"AllowedMessageTypes": [
0,
1,
2
],
"AllowedAccess": [
0,
1,
2,
3,
4,
5,
6
],
"ShowHelp": true,
"SpamCheck": true
},
{
"Name": "Uptime",
"Description": "Displays the time the bot has been connected to the server since last disconnect.",
"Enabled": true,
"ChannelBlacklist": [],
"NickBlacklist": [],
"Triggers": [
"uptime"
],
"Arguments": [],
"AllowedMessageTypes": [
0,
1,
2
],
"AllowedAccess": [
0,
1,
2,
3,
4,
5,
6
],
"ShowHelp": true,
"SpamCheck": true
},
{
"Name": "Runtime",
"Description": "Displays the time the bot has been running.",
"Enabled": true,
"ChannelBlacklist": [],
"NickBlacklist": [],
"Triggers": [
"runtime"
],
"Arguments": [],
"AllowedMessageTypes": [
0,
1,
2
],
"AllowedAccess": [
0,
1,
2,
3,
4,
5,
6
],
"ShowHelp": true,
"SpamCheck": true
}
],
"Options": [
{
"Name": "Source Code",
"Description": "The location of the source code for the bot.",
"Value": "https://github.com/uncled1023/Combot"
}
]
}

36
Modules/About/Properties/AssemblyInfo.cs

@ -0,0 +1,36 @@ @@ -0,0 +1,36 @@
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("About 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:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]

74
Modules/Channel Rules/Channel Rules.csproj

@ -0,0 +1,74 @@ @@ -0,0 +1,74 @@
<?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>{569F61C2-3B06-4313-A299-E643C3786D3D}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>Channel_Rules</RootNamespace>
<AssemblyName>Channel Rules</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\Modules\Channel Rules\Debug\</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\Modules\Channel Rules\Release\</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="Channel_Rules.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.config">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<PropertyGroup>
<PostBuildEvent>mkdir "$(SolutionDir)Bin\Interface\$(ConfigurationName)\Modules\$(TargetName)"
copy /Y "$(TargetPath)" "$(SolutionDir)Bin\Interface\$(ConfigurationName)\Modules\$(TargetName)"
copy /Y "$(TargetDir)Module.config" "$(SolutionDir)Bin\Interface\$(ConfigurationName)\Modules\$(TargetName)"</PostBuildEvent>
</PropertyGroup>
<!-- 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>

150
Modules/Channel Rules/Channel_Rules.cs

@ -0,0 +1,150 @@ @@ -0,0 +1,150 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Combot.Databases;
namespace Combot.Modules.Plugins
{
public class Channel_Rules : 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 "Rules":
string channel = command.Arguments.ContainsKey("Channel") ? command.Arguments["Channel"] : command.Location;
if (command.Arguments.ContainsKey("Action"))
{
string action = command.Arguments["Action"].ToString();
switch (action.ToLower())
{
case "add":
AddRule(command);
break;
case "edit":
EditRule(command);
break;
case "del":
DeleteRule(command);
break;
}
}
else
{
List<Dictionary<string, object>> foundRules = GetRuleList(channel);
if (foundRules.Any())
{
int index = 1;
foundRules.ForEach(rule =>
{
SendResponse(command.MessageType, command.Location, command.Nick.Nickname, string.Format("Rule \u0002#{0}\u0002: {1}", index, rule["rule"]));
index++;
});
}
else
{
SendResponse(command.MessageType, command.Location, command.Nick.Nickname, string.Format("There are no rules for \u0002{0}\u0002", channel));
}
}
break;
}
}
private void AddRule(CommandMessage command)
{
string channel = command.Arguments.ContainsKey("Channel") ? command.Arguments["Channel"] : command.Location;
List<Dictionary<string, object>> results = GetRuleList(channel);
AddChannel(channel);
Database database = new Database(Bot.ServerConfig.Database);
string query = "INSERT INTO `channelrules` SET " +
"`server_id` = (SELECT `id` FROM `servers` WHERE `name` = {0}), " +
"`channel_id` = (SELECT `channels`.`id` FROM `channels` INNER JOIN `servers` ON `servers`.`id` = `channels`.`server_id` WHERE `servers`.`name` = {1} && `channels`.`name` = {2}), " +
"`rule` = {3}, " +
"`date_added` = {4}";
database.Execute(query, new object[] { Bot.ServerConfig.Name, Bot.ServerConfig.Name, channel, command.Arguments["Rule"], command.TimeStamp });
string ruleMessage = string.Format("Rule Added. \u0002{0}\u0002 now has \u0002{1}\u0002 rules.", channel, results.Count + 1);
SendResponse(command.MessageType, command.Location, command.Nick.Nickname, ruleMessage);
}
private void EditRule(CommandMessage command)
{
string channel = command.Arguments.ContainsKey("Channel") ? command.Arguments["Channel"] : command.Location;
List<Dictionary<string, object>> results = GetRuleList(channel);
int num = 0;
if (int.TryParse(command.Arguments["ID"], out num))
{
if (results.Count >= num)
{
int id = Convert.ToInt32(results[num - 1]["id"]);
Database database = new Database(Bot.ServerConfig.Database);
string query = "UPDATE `channelrules` SET " +
"`rule` = {0} " +
"WHERE `id` = {1}";
database.Execute(query, new object[] { command.Arguments["Rule"], id });
string ruleMessage = string.Format("Rule \u0002#{0}\u0002 for \u0002{1}\u0002 is now: {2}", num, channel, command.Arguments["Rule"]);
SendResponse(command.MessageType, command.Location, command.Nick.Nickname, ruleMessage);
}
else
{
string invalid = "Invalid Rule ID.";
SendResponse(command.MessageType, command.Location, command.Nick.Nickname, invalid);
}
}
else
{
string invalid = "Invalid Rule ID.";
SendResponse(command.MessageType, command.Location, command.Nick.Nickname, invalid);
}
}
private void DeleteRule(CommandMessage command)
{
string channel = command.Arguments.ContainsKey("Channel") ? command.Arguments["Channel"] : command.Location;
List<Dictionary<string, object>> results = GetRuleList(channel);
int num = 0;
if (int.TryParse(command.Arguments["ID"], out num))
{
if (results.Count >= num)
{
int id = Convert.ToInt32(results[num - 1]["id"]);
Database database = new Database(Bot.ServerConfig.Database);
string query = "DELETE FROM `channelrules` " +
"WHERE `id` = {0}";
database.Execute(query, new object[] { id });
string ruleMessage = string.Format("Rule \u0002#{0}\u0002 for \u0002{1}\u0002 has been deleted.", num, channel);
SendResponse(command.MessageType, command.Location, command.Nick.Nickname, ruleMessage);
}
else
{
string invalid = "Invalid Rule ID.";
SendResponse(command.MessageType, command.Location, command.Nick.Nickname, invalid);
}
}
else
{
string invalid = "Invalid Rule ID.";
SendResponse(command.MessageType, command.Location, command.Nick.Nickname, invalid);
}
}
private List<Dictionary<string, object>> GetRuleList(string channel)
{
Database database = new Database(Bot.ServerConfig.Database);
string search = "SELECT `channelrules`.`id`, `channelrules`.`rule` FROM `channelrules` " +
"INNER JOIN `channels` " +
"ON `channelrules`.`channel_id` = `channels`.`id` " +
"INNER JOIN `servers` " +
"ON `channelrules`.`server_id` = `servers`.`id` " +
"WHERE `servers`.`name` = {0} AND `channels`.`name` = {1} " +
"ORDER BY date_added ASC";
return database.Query(search, new object[] { Bot.ServerConfig.Name, channel });
}
}
}

104
Modules/Channel Rules/Module.config

@ -0,0 +1,104 @@ @@ -0,0 +1,104 @@
{
"Name": "Channel Rules",
"ClassName": "Channel_Rules",
"Enabled": true,
"ChannelBlacklist": [],
"NickBlacklist": [],
"Commands": [
{
"Name": "Rules",
"Description": "Displays the rules for a given channel.",
"Enabled": true,
"ChannelBlacklist": [],
"NickBlacklist": [],
"Triggers": [
"rules"
],
"Arguments": [
{
"Name": "Channel",
"Description": "The channel the rules are for.",
"AllowedValues": [],
"DependentArguments": [],
"MessageTypes": [
1,
2
],
"Required": true
},
{
"Name": "Action",
"Description": "What you want to do with the rules.",
"AllowedValues": [
"Add",
"Edit",
"Del"
],
"MessageTypes": [
0,
1,
2
],
"Required": false
},
{
"Name": "ID",
"Description": "The ID of the rule you want to edit or delete.",
"AllowedValues": [],
"DependentArguments": [
{
"Name": "Action",
"Values": [
"Edit",
"Del"
]
}
],
"MessageTypes": [
0,
1,
2
],
"Required": true
},
{
"Name": "Rule",
"Description": "The rule you want to add or set.",
"AllowedValues": [],
"DependentArguments": [
{
"Name": "Action",
"Values": [
"Add",
"Edit"
]
}
],
"MessageTypes": [
0,
1,
2
],
"Required": true
}
],
"AllowedMessageTypes": [
0,
1,
2
],
"AllowedAccess": [
0,
1,
2,
3,
4,
5,
6
],
"ShowHelp": true,
"SpamCheck": true
}
],
"Options": []
}

36
Modules/Channel Rules/Properties/AssemblyInfo.cs

@ -0,0 +1,36 @@ @@ -0,0 +1,36 @@
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("Channel_Rules 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:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]

641
Modules/Configuration/Configuration.cs

@ -1,15 +1,654 @@ @@ -1,15 +1,654 @@
namespace Combot.Modules.Plugins
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Reflection;
using System.Threading;
using Newtonsoft.Json;
namespace Combot.Modules.Plugins
{
public class Configuration : Module
{
private ReaderWriterLockSlim ConfigLock;
public override void Initialize()
{
ConfigLock = new ReaderWriterLockSlim();
Bot.CommandReceivedEvent += HandleCommandEvent;
}
public override void ParseCommand(CommandMessage command)
{
Command foundCommand = Commands.Find(c => c.Triggers.Contains(command.Command));
switch (foundCommand.Name)
{
case "Command Configuration":
string parameter = command.Arguments["Parameter"];
Module mod = Bot.Modules.Find(module => module.Commands.Exists(c => c.Triggers.Contains(command.Arguments["Command"]) || c.Name == command.Arguments["Command"]));
if (mod != null)
{
Command cmd = mod.Commands.Find(c => c.Triggers.Contains(command.Arguments["Command"]) || c.Name == command.Arguments["Command"]);
string action = command.Arguments["Action"];
switch (parameter)
{
case "name":
switch (action.ToLower())
{
case "edit":
ConfigLock.EnterWriteLock();
cmd.Name = command.Arguments["Value"];
mod.SaveConfig();
string editMessage = string.Format("Command Name is now: \u0002{0}\u0002", cmd.Name);
SendResponse(command.MessageType, command.Location, command.Nick.Nickname, editMessage);
ConfigLock.ExitWriteLock();
break;
case "view":
string viewMessage = string.Format("Command Name: \u0002{0}\u0002", cmd.Name);
SendResponse(command.MessageType, command.Location, command.Nick.Nickname, viewMessage);
break;
}
break;
case "description":
switch (action.ToLower())
{
case "edit":
ConfigLock.EnterWriteLock();
cmd.Description = command.Arguments["Value"];
mod.SaveConfig();
string editMessage = string.Format("\u0002{0}\u0002 Description is now: \u0002{1}\u0002", cmd.Name, cmd.Description);
SendResponse(command.MessageType, command.Location, command.Nick.Nickname, editMessage);
ConfigLock.ExitWriteLock();
break;
case "view":
string viewMessage = string.Format("{0} Description: \u0002{1}\u0002", cmd.Name, cmd.Description);
SendResponse(command.MessageType, command.Location, command.Nick.Nickname, viewMessage);
break;
}
break;
case "enabled":
switch (action.ToLower())
{
case "edit":
ConfigLock.EnterWriteLock();
cmd.Enabled = (bool) command.Arguments["Value"];
mod.SaveConfig();
string editMessage = string.Format("\u0002{0}\u0002 Enabled is now: \u0002{1}\u0002", cmd.Name, cmd.Enabled);
SendResponse(command.MessageType, command.Location, command.Nick.Nickname, editMessage);
ConfigLock.ExitWriteLock();
break;
case "view":
string viewMessage = string.Format("{0} Enabled: \u0002{1}\u0002", cmd.Name, cmd.Enabled);
SendResponse(command.MessageType, command.Location, command.Nick.Nickname, viewMessage);
break;
}
break;
case "channelblacklist":
switch (action.ToLower())
{
case "add":
ConfigLock.EnterWriteLock();
if (!cmd.ChannelBlacklist.Contains(command.Arguments["Value"]))
{
cmd.ChannelBlacklist.Add(command.Arguments["Value"]);
mod.SaveConfig();
}
string addMessage = string.Format("\u0002{0}\u0002 Channel Blacklist is now: \u0002{1}\u0002", cmd.Name, string.Join(", ", cmd.ChannelBlacklist));
SendResponse(command.MessageType, command.Location, command.Nick.Nickname, addMessage);
ConfigLock.ExitWriteLock();
break;
case "del":
ConfigLock.EnterWriteLock();
if (cmd.ChannelBlacklist.Contains(command.Arguments["Value"]))
{
cmd.ChannelBlacklist.Remove(command.Arguments["Value"]);
mod.SaveConfig();
}
string delMessage = string.Format("\u0002{0}\u0002 Channel Blacklist is now: \u0002{1}\u0002", cmd.Name, string.Join(", ", cmd.ChannelBlacklist));
SendResponse(command.MessageType, command.Location, command.Nick.Nickname, delMessage);
ConfigLock.ExitWriteLock();
break;
case "view":
string viewMessage = string.Format("{0} Channel Blacklist: \u0002{1}\u0002", cmd.Name, string.Join(", ", cmd.ChannelBlacklist));
SendResponse(command.MessageType, command.Location, command.Nick.Nickname, viewMessage);
break;
}
break;
case "nickblacklist":
switch (action.ToLower())
{
case "add":
ConfigLock.EnterWriteLock();
if (!cmd.NickBlacklist.Contains(command.Arguments["Value"]))
{
cmd.NickBlacklist.Add(command.Arguments["Value"]);
mod.SaveConfig();
}
string addMessage = string.Format("\u0002{0}\u0002 Nickname Blacklist is now: \u0002{1}\u0002", cmd.Name, string.Join(", ", cmd.NickBlacklist));
SendResponse(command.MessageType, command.Location, command.Nick.Nickname, addMessage);
ConfigLock.ExitWriteLock();
break;
case "del":
ConfigLock.EnterWriteLock();
if (cmd.NickBlacklist.Contains(command.Arguments["Value"]))
{
cmd.NickBlacklist.Remove(command.Arguments["Value"]);
mod.SaveConfig();
}
string delMessage = string.Format("\u0002{0}\u0002 Nickname Blacklist is now: \u0002{1}\u0002", cmd.Name, string.Join(", ", cmd.NickBlacklist));
SendResponse(command.MessageType, command.Location, command.Nick.Nickname, delMessage);
ConfigLock.ExitWriteLock();
break;
case "view":
string viewMessage = string.Format("{0} Nickname Blacklist: \u0002{1}\u0002", cmd.Name, string.Join(", ", cmd.NickBlacklist));
SendResponse(command.MessageType, command.Location, command.Nick.Nickname, viewMessage);
break;
}
break;
case "triggers":
switch (action.ToLower())
{
case "add":
ConfigLock.EnterWriteLock();
if (!cmd.Triggers.Contains(command.Arguments["Value"]))
{
cmd.Triggers.Add(command.Arguments["Value"]);
mod.SaveConfig();
}
string addMessage = string.Format("\u0002{0}\u0002 Triggers are now: \u0002{1}\u0002", cmd.Name, string.Join(", ", cmd.Triggers));
SendResponse(command.MessageType, command.Location, command.Nick.Nickname, addMessage);
ConfigLock.ExitWriteLock();
break;
case "del":
ConfigLock.EnterWriteLock();
if (cmd.Triggers.Contains(command.Arguments["Value"]))
{
cmd.Triggers.Remove(command.Arguments["Value"]);
mod.SaveConfig();
}
string delMessage = string.Format("\u0002{0}\u0002 Triggers are now: \u0002{1}\u0002", cmd.Name, string.Join(", ", cmd.Triggers));
SendResponse(command.MessageType, command.Location, command.Nick.Nickname, delMessage);
ConfigLock.ExitWriteLock();
break;
case "view":
string viewMessage = string.Format("{0} Triggers: \u0002{1}\u0002", cmd.Name, string.Join(", ", cmd.Triggers));
SendResponse(command.MessageType, command.Location, command.Nick.Nickname, viewMessage);
break;
}
break;
case "arguments":
switch (action.ToLower())
{
case "add":
CommandArgument addArg = JsonConvert.DeserializeObject<CommandArgument>(command.Arguments["Value"]);
if (addArg != null)
{
ConfigLock.EnterWriteLock();
if (!cmd.Arguments.Contains(addArg))
{
cmd.Arguments.Add(addArg);
mod.SaveConfig();
}
string addMessage = string.Format("\u0002{0}\u0002 Arguments are now:", cmd.Name);
SendResponse(command.MessageType, command.Location, command.Nick.Nickname, addMessage);
foreach (CommandArgument argument in cmd.Arguments)
{
addMessage = string.Format("Argument: \u0002{0}\u0002", JsonConvert.SerializeObject(argument));
SendResponse(command.MessageType, command.Location, command.Nick.Nickname, addMessage);
}
ConfigLock.ExitWriteLock();
}
else
{
string notValid = string.Format("\u0002{0}\u000F is not a valid argument.", command.Arguments["Value"]);
SendResponse(command.MessageType, command.Location, command.Nick.Nickname, notValid);
}
break;
case "del":
CommandArgument delArg = JsonConvert.DeserializeObject<CommandArgument>(command.Arguments["Value"]);
if (delArg != null)
{
ConfigLock.EnterWriteLock();
if (cmd.Arguments.Contains(delArg))
{
cmd.Arguments.Remove(delArg);
mod.SaveConfig();
}
string delMessage = string.Format("\u0002{0}\u0002 Arguments are now:", cmd.Name);
SendResponse(command.MessageType, command.Location, command.Nick.Nickname, delMessage);
foreach (CommandArgument argument in cmd.Arguments)
{
delMessage = string.Format("Argument: \u0002{0}\u0002", JsonConvert.SerializeObject(argument));
SendResponse(command.MessageType, command.Location, command.Nick.Nickname, delMessage);
}
ConfigLock.ExitWriteLock();
}
else
{
string notValid = string.Format("\u0002{0}\u000F is not a valid argument.", command.Arguments["Value"]);
SendResponse(command.MessageType, command.Location, command.Nick.Nickname, notValid);
}
break;
case "view":
foreach (CommandArgument argument in cmd.Arguments)
{
string viewMessage = string.Format("{0} Argument: \u0002{1}\u0002", cmd.Name, JsonConvert.SerializeObject(argument));
SendResponse(command.MessageType, command.Location, command.Nick.Nickname, viewMessage);
}
break;
}
break;
case "allowedmessagetypes":
switch (action.ToLower())
{
case "add":
MessageType addType;
bool addValid = Enum.TryParse(command.Arguments["Value"], out addType);
if (addValid)
{
ConfigLock.EnterWriteLock();
if (!cmd.AllowedMessageTypes.Contains(addType))
{
cmd.AllowedMessageTypes.Add(addType);
mod.SaveConfig();
}
mod.SaveConfig();
List<string> addAllowedTypes = new List<string>();
cmd.AllowedMessageTypes.ForEach(type => addAllowedTypes.Add(type.ToString()));
string addMessage = string.Format("\u0002{0}\u0002 Allowed Message Types are now: \u0002{1}\u0002", cmd.Name, string.Join(", ", addAllowedTypes));
SendResponse(command.MessageType, command.Location, command.Nick.Nickname, addMessage);
ConfigLock.ExitWriteLock();
}
else
{
string notValid = string.Format("\u0002{0}\u000F is not a valid message type.", command.Arguments["Value"]);
SendResponse(command.MessageType, command.Location, command.Nick.Nickname, notValid);
}
break;
case "del":
MessageType delType;
bool delValid = Enum.TryParse(command.Arguments["Value"], out delType);
if (delValid)
{
ConfigLock.EnterWriteLock();
if (cmd.AllowedMessageTypes.Contains(delType))
{
cmd.AllowedMessageTypes.Remove(delType);
mod.SaveConfig();
}
List<string> delAllowedTypes = new List<string>();
<