Browse Source

Changed Database queries to synchronous from asynchronous.

Fixed minor bugs.
Added blacklist checking for non-command actions.
master
Teknikode 8 years ago
parent
commit
c187cf53e7
  1. 1
      .gitignore
  2. 3
      Combot.sln
  3. 4
      Combot/Bot.cs
  4. 14
      Combot/Databases/Database.cs
  5. 18
      Combot/Modules/Module.cs
  6. 96
      IRCServices/IRC.cs
  7. 4
      IRCServices/Messaging/Messages.cs
  8. 12
      Modules/Channel Rules/Channel_Rules.cs
  9. 2
      Modules/Configuration/Configuration.cs
  10. 30
      Modules/Introductions/Introductions.cs
  11. 33
      Modules/Introductions/Introductions.csproj
  12. 24
      Modules/Invite/Invite.cs
  13. 134
      Modules/Logging/Logging.cs
  14. 15
      Modules/Messaging/Messaging.cs
  15. 33
      Modules/Messaging/Messaging.csproj
  16. 51
      Modules/Messaging/Module.config
  17. 9
      Modules/Moderation/Moderation.cs
  18. 3
      Modules/Moderation/Moderation.csproj
  19. 48
      Modules/Moderation/Module.config
  20. 39
      Modules/Owner Control/Module.config
  21. 23
      Modules/Owner Control/Owner_Control.cs
  22. 6
      Modules/Quotes/Quotes.cs
  23. 104
      Modules/Sed/Sed.cs
  24. 39
      Modules/Seen/Seen.cs
  25. 96
      Modules/Url Parsing/Url_Parsing.cs
  26. 16
      Modules/YouTube/YouTube.cs

1
.gitignore vendored

@ -214,3 +214,4 @@ pip-log.txt @@ -214,3 +214,4 @@ pip-log.txt
Combot.Servers.config
Combot.Servers.Debug.config
Combot.Servers.Release.config
Packages.dgml

3
Combot.sln

@ -227,4 +227,7 @@ Global @@ -227,4 +227,7 @@ Global
{0DAE9869-DE0E-442F-B8EF-B4F54EDE9559} = {D157677E-4D33-4156-B55E-E21C4B5A3024}
{6CB41404-02E8-4CA3-834C-CE8C30999450} = {D157677E-4D33-4156-B55E-E21C4B5A3024}
EndGlobalSection
GlobalSection(Performance) = preSolution
HasPerformanceSessions = true
EndGlobalSection
EndGlobal

4
Combot/Bot.cs

@ -9,6 +9,7 @@ using System.Threading; @@ -9,6 +9,7 @@ using System.Threading;
using System.Threading.Tasks;
using Combot.IRCServices;
using Combot.Configurations;
using Combot.Databases;
using Combot.IRCServices.Messaging;
using Combot.Modules;
@ -20,6 +21,7 @@ namespace Combot @@ -20,6 +21,7 @@ namespace Combot
public event Action<BotError> ErrorEvent;
public ServerConfig ServerConfig;
public IRC IRC;
public Database Database;
public List<Module> Modules;
public bool Connected = false;
public bool LoggedIn = false;
@ -54,6 +56,8 @@ namespace Combot @@ -54,6 +56,8 @@ namespace Combot
IRC.Message.KickEvent += HandleKickEvent;
IRC.Message.ChannelModeChangeEvent += HandleChannelModeChangeEvent;
Database = new Database(serverConfig.Database);
LoadModules();
}

14
Combot/Databases/Database.cs

@ -1,5 +1,6 @@ @@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Threading;
using Combot.Configurations;
using MySql.Data.MySqlClient;
@ -9,11 +10,13 @@ namespace Combot.Databases @@ -9,11 +10,13 @@ namespace Combot.Databases
{
private bool Connected { get; set; }
private MySqlConnection Connection { get; set; }
private ReaderWriterLockSlim DatabaseLock { get; set; }
public Database(DatabaseConfig config)
{
Connected = false;
Connection = null;
DatabaseLock = new ReaderWriterLockSlim();
Connect(config);
}
@ -22,6 +25,7 @@ namespace Combot.Databases @@ -22,6 +25,7 @@ namespace Combot.Databases
List<Dictionary<string, object>> rows = new List<Dictionary<string, object>>();
if (Connected)
{
DatabaseLock.EnterWriteLock();
MySqlCommand cmd = PrepareQuery(query, args);
MySqlDataReader reader = cmd.ExecuteReader();
while (reader.Read())
@ -34,6 +38,7 @@ namespace Combot.Databases @@ -34,6 +38,7 @@ namespace Combot.Databases
rows.Add(row);
}
reader.Close();
DatabaseLock.ExitWriteLock();
}
return rows;
}
@ -42,8 +47,11 @@ namespace Combot.Databases @@ -42,8 +47,11 @@ namespace Combot.Databases
{
if (Connected)
{
DatabaseLock.EnterWriteLock();
MySqlCommand cmd = PrepareQuery(query, args);
return cmd.ExecuteScalar();
object result = cmd.ExecuteScalar();
DatabaseLock.ExitWriteLock();
return result;
}
return null;
}
@ -52,8 +60,10 @@ namespace Combot.Databases @@ -52,8 +60,10 @@ namespace Combot.Databases
{
if (Connected)
{
DatabaseLock.EnterWriteLock();
MySqlCommand cmd = PrepareQuery(query, args);
cmd.ExecuteNonQuery();
int result = cmd.ExecuteNonQuery();
DatabaseLock.ExitWriteLock();
}
}

18
Combot/Modules/Module.cs

@ -231,59 +231,55 @@ namespace Combot.Modules @@ -231,59 +231,55 @@ namespace Combot.Modules
public void AddServer()
{
Database database = new Database(Bot.ServerConfig.Database);
string search = "SELECT * FROM `servers` WHERE " +
"`name` = {0}";
List<Dictionary<string, object>> results = database.Query(search, new object[] { Bot.ServerConfig.Name });
List<Dictionary<string, object>> results = Bot.Database.Query(search, new object[] { Bot.ServerConfig.Name });
if (!results.Any())
{
string query = "INSERT INTO `servers` SET " +
"`name` = {0}";
database.Execute(query, new object[] { Bot.ServerConfig.Name });
Bot.Database.Execute(query, new object[] { Bot.ServerConfig.Name });
}
}
public void AddChannel(string channel)
{
Database database = new Database(Bot.ServerConfig.Database);
string search = "SELECT * FROM `channels` WHERE " +
"`server_id` = (SELECT `id` FROM `servers` WHERE `name` = {0}) AND " +
"`name` = {1}";
List<Dictionary<string, object>> results = database.Query(search, new object[] { Bot.ServerConfig.Name, channel });
List<Dictionary<string, object>> results = Bot.Database.Query(search, new object[] { Bot.ServerConfig.Name, channel });
if (!results.Any())
{
string query = "INSERT INTO `channels` SET " +
"`server_id` = (SELECT `id` FROM `servers` WHERE `name` = {0}), " +
"`name` = {1}";
database.Execute(query, new object[] { Bot.ServerConfig.Name, channel });
Bot.Database.Execute(query, new object[] { Bot.ServerConfig.Name, channel });
}
}
public void AddNick(string nickname)
{
Database database = new Database(Bot.ServerConfig.Database);
string search = "SELECT * FROM `nicks` WHERE " +
"`server_id` = (SELECT `id` FROM `servers` WHERE `name` = {0}) AND " +
"`nickname` = {1}";
List<Dictionary<string, object>> results = database.Query(search, new object[] { Bot.ServerConfig.Name, nickname });
List<Dictionary<string, object>> results = Bot.Database.Query(search, new object[] { Bot.ServerConfig.Name, nickname });
if (!results.Any())
{
string insert = "INSERT INTO `nicks` SET " +
"`server_id` = (SELECT `id` FROM `servers` WHERE `name` = {0}), " +
"`nickname` = {1}";
database.Execute(insert, new object[] { Bot.ServerConfig.Name, nickname });
Bot.Database.Execute(insert, new object[] { Bot.ServerConfig.Name, nickname });
}
}
public string GetNickname(int id)
{
Database database = new Database(Bot.ServerConfig.Database);
string search = "SELECT `nickname` FROM `nicks` " +
"WHERE `id` = {0}";
List<Dictionary<string, object>> results = database.Query(search, new object[] { id });
List<Dictionary<string, object>> results = Bot.Database.Query(search, new object[] { id });
string nickname = string.Empty;
if (results.Any())
{

96
IRCServices/IRC.cs

@ -280,7 +280,7 @@ namespace Combot.IRCServices @@ -280,7 +280,7 @@ namespace Combot.IRCServices
bool disconnectActivated = false;
while (_TCP.Connected)
{
Thread.Sleep(1000);
Thread.Sleep(5000);
bool stillConnected = NetworkInterface.GetIsNetworkAvailable();
if (stillConnected)
@ -358,56 +358,59 @@ namespace Combot.IRCServices @@ -358,56 +358,59 @@ namespace Combot.IRCServices
case IRCReplyCode.RPL_WHOREPLY:
ChannelRWLock.EnterWriteLock();
string[] msgSplit = msg.Message.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
string target = msgSplit[0];
if (target.StartsWith("&") || target.StartsWith("#"))
if (msgSplit.GetUpperBound(0) > 0)
{
if (msgSplit.GetUpperBound(0) >= 7)
string target = msgSplit[0];
if (target.StartsWith("&") || target.StartsWith("#"))
{
string nickname = msgSplit[4];
string realname = msgSplit[7];
string username = msgSplit[1];
string host = msgSplit[2];
string modeString = msgSplit[5];
Channel channel = Channels.Find(chan => chan.Name == target);
if (channel != null)
if (msgSplit.GetUpperBound(0) >= 7)
{
Nick nick = channel.GetNick(nickname);
bool nickFound = true;
if (nick == null)
string nickname = msgSplit[4];
string realname = msgSplit[7];
string username = msgSplit[1];
string host = msgSplit[2];
string modeString = msgSplit[5];
Channel channel = Channels.Find(chan => chan.Name == target);
if (channel != null)
{
nickFound = false;
nick = new Nick();
}
nick.Nickname = nickname;
nick.Host = host;
nick.Realname = realname;
nick.Username = username;
nick.Modes = new List<UserMode>();
nick.Privileges = new List<PrivilegeMode>();
char[] modeArr = modeString.ToCharArray();
for (int i = 1; i <= modeArr.GetUpperBound(0); i++)
{
if (PrivilegeMapping.ContainsKey(modeArr[i].ToString()))
{
nick.Privileges.Add(PrivilegeMapping[modeArr[i].ToString()]);
}
else if (modeArr[i].ToString() == "*")
Nick nick = channel.GetNick(nickname);
bool nickFound = true;
if (nick == null)
{
nick.Modes.Add(UserMode.o);
nickFound = false;
nick = new Nick();
}
else
nick.Nickname = nickname;
nick.Host = host;
nick.Realname = realname;
nick.Username = username;
nick.Modes = new List<UserMode>();
nick.Privileges = new List<PrivilegeMode>();
char[] modeArr = modeString.ToCharArray();
for (int i = 1; i <= modeArr.GetUpperBound(0); i++)
{
UserMode foundMode;
bool valid = Enum.TryParse(modeArr[i].ToString(), false, out foundMode);
if (valid)
if (PrivilegeMapping.ContainsKey(modeArr[i].ToString()))
{
nick.Privileges.Add(PrivilegeMapping[modeArr[i].ToString()]);
}
else if (modeArr[i].ToString() == "*")
{
nick.Modes.Add(UserMode.o);
}
else
{
nick.Modes.Add(foundMode);
UserMode foundMode;
bool valid = Enum.TryParse(modeArr[i].ToString(), false, out foundMode);
if (valid)
{
nick.Modes.Add(foundMode);
}
}
}
}
if (!nickFound)
{
channel.AddNick(nick);
if (!nickFound)
{
channel.AddNick(nick);
}
}
}
}
@ -418,11 +421,14 @@ namespace Combot.IRCServices @@ -418,11 +421,14 @@ namespace Combot.IRCServices
case IRCReplyCode.RPL_TOPIC:
ChannelRWLock.EnterWriteLock();
string[] topicSplit = msg.Message.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
string topicChan = topicSplit[0];
Channel topicChannel = Channels.Find(chan => chan.Name == topicChan);
if (topicChannel != null)
if (topicSplit.GetUpperBound(0) > 0)
{
topicChannel.Topic = topicSplit[1].Remove(0, 1);
string topicChan = topicSplit[0];
Channel topicChannel = Channels.Find(chan => chan.Name == topicChan);
if (topicChannel != null)
{
topicChannel.Topic = topicSplit[1].Remove(0, 1);
}
}
ChannelRWLock.ExitWriteLock();
break;

4
IRCServices/Messaging/Messages.cs

@ -312,7 +312,7 @@ namespace Combot.IRCServices.Messaging @@ -312,7 +312,7 @@ namespace Combot.IRCServices.Messaging
case "NICK":
NickChangeInfo nickMsg = new NickChangeInfo();
nickMsg.OldNick = new Nick() { Nickname = senderNick, Realname = senderRealname, Host = senderHost };
nickMsg.NewNick = new Nick() { Nickname = recipient.Remove(0, 1) };
nickMsg.NewNick = new Nick() { Nickname = recipient.TrimStart(':') };
await Task.Run(() =>
{
@ -390,7 +390,7 @@ namespace Combot.IRCServices.Messaging @@ -390,7 +390,7 @@ namespace Combot.IRCServices.Messaging
case "QUIT":
QuitInfo quitMsg = new QuitInfo();
quitMsg.Nick = new Nick() { Nickname = senderNick, Realname = senderRealname, Host = senderHost };
quitMsg.Message = recipient.Remove(0, 1);
quitMsg.Message = string.Join(" ", recipient.Remove(0, 1), args);
await Task.Run(() =>
{

12
Modules/Channel Rules/Channel_Rules.cs

@ -62,13 +62,12 @@ namespace Combot.Modules.Plugins @@ -62,13 +62,12 @@ namespace Combot.Modules.Plugins
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 });
Bot.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);
}
@ -83,11 +82,10 @@ namespace Combot.Modules.Plugins @@ -83,11 +82,10 @@ namespace Combot.Modules.Plugins
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 });
Bot.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);
}
@ -114,10 +112,9 @@ namespace Combot.Modules.Plugins @@ -114,10 +112,9 @@ namespace Combot.Modules.Plugins
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 });
Bot.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);
}
@ -136,7 +133,6 @@ namespace Combot.Modules.Plugins @@ -136,7 +133,6 @@ namespace Combot.Modules.Plugins
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` " +
@ -144,7 +140,7 @@ namespace Combot.Modules.Plugins @@ -144,7 +140,7 @@ namespace Combot.Modules.Plugins
"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 });
return Bot.Database.Query(search, new object[] { Bot.ServerConfig.Name, channel });
}
}
}

2
Modules/Configuration/Configuration.cs

@ -397,7 +397,7 @@ namespace Combot.Modules.Plugins @@ -397,7 +397,7 @@ namespace Combot.Modules.Plugins
break;
case "Module Configuration":
string moduleParameter = command.Arguments["Parameter"];
Module foundModule = Bot.Modules.Find(module => module.Commands.Exists(c => c.Triggers.Contains(command.Arguments["Module"]) || c.Name == command.Arguments["Module"]));
Module foundModule = Bot.Modules.Find(module => module.Name == command.Arguments["Module"] || module.ClassName == command.Arguments["Module"]);
if (foundModule != null)
{
string action = command.Arguments["Action"];

30
Modules/Introductions/Introductions.cs

@ -42,13 +42,19 @@ namespace Combot.Modules.Plugins @@ -42,13 +42,19 @@ namespace Combot.Modules.Plugins
private void HandleJoinEvent(object sender, JoinChannelInfo info)
{
List<Dictionary<string, object>> results = GetIntroductionList(info.Channel, info.Nick.Nickname);
if (results.Any())
if (!Bot.ServerConfig.ChannelBlacklist.Contains(info.Channel)
&& !Bot.ServerConfig.NickBlacklist.Contains(info.Nick.Nickname)
&& !ChannelBlacklist.Contains(info.Channel)
&& !NickBlacklist.Contains(info.Nick.Nickname))
{
Random randNum = new Random();
int index = randNum.Next(0, results.Count);
Dictionary<string, object> intro = results[index];
Bot.IRC.SendPrivateMessage(info.Channel, string.Format("\u200B{0}", intro["message"]));
List<Dictionary<string, object>> results = GetIntroductionList(info.Channel, info.Nick.Nickname);
if (results.Any())
{
Random randNum = new Random();
int index = randNum.Next(0, results.Count);
Dictionary<string, object> intro = results[index];
Bot.IRC.SendPrivateMessage(info.Channel, string.Format("\u200B{0}", intro["message"]));
}
}
}
@ -61,14 +67,13 @@ namespace Combot.Modules.Plugins @@ -61,14 +67,13 @@ namespace Combot.Modules.Plugins
{
AddChannel(channel);
AddNick(command.Nick.Nickname);
Database database = new Database(Bot.ServerConfig.Database);
string query = "INSERT INTO `introductions` 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}), " +
"`nick_id` = (SELECT `nicks`.`id` FROM `nicks` INNER JOIN `servers` ON `servers`.`id` = `nicks`.`server_id` WHERE `servers`.`name` = {3} && `nickname` = {4}), " +
"`message` = {5}, " +
"`date_added` = {6}";
database.Execute(query, new object[] { Bot.ServerConfig.Name, Bot.ServerConfig.Name, channel, Bot.ServerConfig.Name, command.Nick.Nickname, command.Arguments["Message"], command.TimeStamp });
Bot.Database.Execute(query, new object[] { Bot.ServerConfig.Name, Bot.ServerConfig.Name, channel, Bot.ServerConfig.Name, command.Nick.Nickname, command.Arguments["Message"], command.TimeStamp });
string introMessage = string.Format("Added introduction. You now have \u0002{0}\u0002 introductions set.", results.Count + 1);
SendResponse(command.MessageType, command.Location, command.Nick.Nickname, introMessage);
}
@ -89,11 +94,10 @@ namespace Combot.Modules.Plugins @@ -89,11 +94,10 @@ namespace Combot.Modules.Plugins
if (results.Count >= num)
{
int id = Convert.ToInt32(results[num - 1]["id"]);
Database database = new Database(Bot.ServerConfig.Database);
string query = "UPDATE `introductions` SET " +
"`message` = {0} " +
"WHERE `id` = {1}";
database.Execute(query, new object[] { command.Arguments["Message"], id });
Bot.Database.Execute(query, new object[] { command.Arguments["Message"], id });
string introMessage = string.Format("Introduction #\u0002{0}\u0002 is now: {1}", num, command.Arguments["Message"]);
SendResponse(command.MessageType, command.Location, command.Nick.Nickname, introMessage);
}
@ -120,10 +124,9 @@ namespace Combot.Modules.Plugins @@ -120,10 +124,9 @@ namespace Combot.Modules.Plugins
if (results.Count >= num)
{
int id = Convert.ToInt32(results[num - 1]["id"]);
Database database = new Database(Bot.ServerConfig.Database);
string query = "DELETE FROM `introductions` " +
"WHERE `id` = {0}";
database.Execute(query, new object[] { id });
Bot.Database.Execute(query, new object[] { id });
string introMessage = string.Format("Introduction #\u0002{0}\u0002 has been deleted.", num);
SendResponse(command.MessageType, command.Location, command.Nick.Nickname, introMessage);
}
@ -186,7 +189,6 @@ namespace Combot.Modules.Plugins @@ -186,7 +189,6 @@ namespace Combot.Modules.Plugins
private List<Dictionary<string, object>> GetIntroductionList(string channel, string nickname)
{
Database database = new Database(Bot.ServerConfig.Database);
// Check to see if they have reached the max number of introductions
string search = "SELECT `introductions`.`id`, `introductions`.`message` FROM `introductions` " +
"INNER JOIN `nicks` " +
@ -196,7 +198,7 @@ namespace Combot.Modules.Plugins @@ -196,7 +198,7 @@ namespace Combot.Modules.Plugins
"INNER JOIN `servers` " +
"ON `nicks`.`server_id` = `servers`.`id` " +
"WHERE `servers`.`name` = {0} AND `channels`.`name` = {1} AND `nicks`.`nickname` = {2}";
return database.Query(search, new object[] { Bot.ServerConfig.Name, channel, nickname });
return Bot.Database.Query(search, new object[] { Bot.ServerConfig.Name, channel, nickname });
}
}
}

33
Modules/Introductions/Introductions.csproj

@ -12,6 +12,21 @@ @@ -12,6 +12,21 @@
<TargetFrameworkVersion>v4.5.1</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<TargetFrameworkProfile />
<PublishUrl>publish\</PublishUrl>
<Install>true</Install>
<InstallFrom>Disk</InstallFrom>
<UpdateEnabled>false</UpdateEnabled>
<UpdateMode>Foreground</UpdateMode>
<UpdateInterval>7</UpdateInterval>
<UpdateIntervalUnits>Days</UpdateIntervalUnits>
<UpdatePeriodically>false</UpdatePeriodically>
<UpdateRequired>false</UpdateRequired>
<MapFileExtensions>true</MapFileExtensions>
<ApplicationRevision>0</ApplicationRevision>
<ApplicationVersion>1.0.0.%2a</ApplicationVersion>
<IsWebBootstrapper>false</IsWebBootstrapper>
<UseApplicationTrust>false</UseApplicationTrust>
<BootstrapperEnabled>true</BootstrapperEnabled>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
@ -56,8 +71,26 @@ @@ -56,8 +71,26 @@
<ItemGroup>
<None Include="Module.config">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
<SubType>Designer</SubType>
</None>
</ItemGroup>
<ItemGroup>
<BootstrapperPackage Include=".NETFramework,Version=v4.5.1">
<Visible>False</Visible>
<ProductName>Microsoft .NET Framework 4.5.1 %28x86 and x64%29</ProductName>
<Install>true</Install>
</BootstrapperPackage>
<BootstrapperPackage Include="Microsoft.Net.Client.3.5">
<Visible>False</Visible>
<ProductName>.NET Framework 3.5 SP1 Client Profile</ProductName>
<Install>false</Install>
</BootstrapperPackage>
<BootstrapperPackage Include="Microsoft.Net.Framework.3.5.SP1">
<Visible>False</Visible>
<ProductName>.NET Framework 3.5 SP1</ProductName>
<Install>false</Install>
</BootstrapperPackage>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<PropertyGroup>
<PostBuildEvent>mkdir "$(SolutionDir)Bin\Interface\$(ConfigurationName)\Modules\$(TargetName)"

24
Modules/Invite/Invite.cs

@ -11,19 +11,23 @@ namespace Combot.Modules.Plugins @@ -11,19 +11,23 @@ namespace Combot.Modules.Plugins
private void HandleInvite(object sender, InviteChannelInfo inviteInfo)
{
if (!Bot.ServerConfig.ChannelBlacklist.Contains(inviteInfo.Channel))
if (!Bot.ServerConfig.NickBlacklist.Contains(inviteInfo.Requester.Nickname)
&& !NickBlacklist.Contains(inviteInfo.Requester.Nickname))
{
Bot.IRC.SendJoin(inviteInfo.Channel);
string helpMessage = string.Empty;
if (Bot.Modules.Exists(module => module.Commands.Exists(cmd => cmd.Triggers.Contains("help") && cmd.Enabled)))
if (!Bot.ServerConfig.ChannelBlacklist.Contains(inviteInfo.Channel) && !ChannelBlacklist.Contains(inviteInfo.Channel))
{
helpMessage = string.Format(" For more information on what I can do, just type: {0}help", Bot.ServerConfig.CommandPrefix);
Bot.IRC.SendJoin(inviteInfo.Channel);
string helpMessage = string.Empty;
if (Bot.Modules.Exists(module => module.Commands.Exists(cmd => cmd.Triggers.Contains("help") && cmd.Enabled)))
{
helpMessage = string.Format(" For more information on what I can do, just type: {0}help", Bot.ServerConfig.CommandPrefix);
}
Bot.IRC.SendPrivateMessage(inviteInfo.Channel, string.Format("{0} has invited me to this channel. If you would like me to leave, just kick me.{1}", inviteInfo.Requester.Nickname, helpMessage));
}
else
{
Bot.IRC.SendNotice(inviteInfo.Requester.Nickname, "I am unable to join that channel.");
}
Bot.IRC.SendPrivateMessage(inviteInfo.Channel, string.Format("{0} has invited me to this channel. If you would like me to leave, just kick me.{1}", inviteInfo.Requester.Nickname, helpMessage));
}
else
{
Bot.IRC.SendNotice(inviteInfo.Requester.Nickname, "I am unable to join that channel.");
}
}
}

134
Modules/Logging/Logging.cs

@ -9,7 +9,6 @@ namespace Combot.Modules.Plugins @@ -9,7 +9,6 @@ namespace Combot.Modules.Plugins
{
public override void Initialize()
{
//Bot.CommandReceivedEvent += HandleCommandEvent;
Bot.IRC.ConnectEvent += AddServer;
Bot.IRC.Message.ChannelMessageReceivedEvent += LogChannelMessage;
Bot.IRC.Message.PrivateMessageReceivedEvent += LogPrivateMessage;
@ -19,89 +18,100 @@ namespace Combot.Modules.Plugins @@ -19,89 +18,100 @@ namespace Combot.Modules.Plugins
Bot.IRC.Message.QuitEvent += LogQuit;
}
public override void ParseCommand(CommandMessage command)
{
Command foundCommand = Commands.Find(c => c.Triggers.Contains(command.Command));
}
private void LogChannelMessage(object sender, ChannelMessage message)
{
AddChannel(message.Channel);
AddNick(message.Sender.Nickname);
Database database = new Database(Bot.ServerConfig.Database);
string query = "INSERT INTO `channelmessages` 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}), " +
"`nick_id` = (SELECT `nicks`.`id` FROM `nicks` INNER JOIN `servers` ON `servers`.`id` = `nicks`.`server_id` WHERE `servers`.`name` = {3} && `nickname` = {4}), " +
"`message` = {5}, " +
"`date_added` = {6}";
database.Execute(query, new object[] {Bot.ServerConfig.Name, Bot.ServerConfig.Name, message.Channel, Bot.ServerConfig.Name, message.Sender.Nickname, message.Message, message.TimeStamp});
if (!ChannelBlacklist.Contains(message.Channel)
&& !NickBlacklist.Contains(message.Sender.Nickname))
{
AddChannel(message.Channel);
AddNick(message.Sender.Nickname);
string query = "INSERT INTO `channelmessages` 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}), " +
"`nick_id` = (SELECT `nicks`.`id` FROM `nicks` INNER JOIN `servers` ON `servers`.`id` = `nicks`.`server_id` WHERE `servers`.`name` = {3} && `nickname` = {4}), " +
"`message` = {5}, " +
"`date_added` = {6}";
Bot.Database.Execute(query, new object[] { Bot.ServerConfig.Name, Bot.ServerConfig.Name, message.Channel, Bot.ServerConfig.Name, message.Sender.Nickname, message.Message, message.TimeStamp });
}
}
private void LogPrivateMessage(object sender, PrivateMessage message)
{
AddNick(message.Sender.Nickname);
Database database = new Database(Bot.ServerConfig.Database);
string query = "INSERT INTO `privatemessages` SET " +
"`server_id` = (SELECT `id` FROM `servers` WHERE `name` = {0}), " +
"`nick_id` = (SELECT `nicks`.`id` FROM `nicks` INNER JOIN `servers` ON `servers`.`id` = `nicks`.`server_id` WHERE `servers`.`name` = {1} && `nickname` = {2}), " +
"`message` = {3}, " +
"`date_added` = {4}";
database.Execute(query, new object[] {Bot.ServerConfig.Name, Bot.ServerConfig.Name, message.Sender.Nickname, message.Message, message.TimeStamp});
if (!NickBlacklist.Contains(message.Sender.Nickname))
{
AddNick(message.Sender.Nickname);
string query = "INSERT INTO `privatemessages` SET " +
"`server_id` = (SELECT `id` FROM `servers` WHERE `name` = {0}), " +
"`nick_id` = (SELECT `nicks`.`id` FROM `nicks` INNER JOIN `servers` ON `servers`.`id` = `nicks`.`server_id` WHERE `servers`.`name` = {1} && `nickname` = {2}), " +
"`message` = {3}, " +
"`date_added` = {4}";
Bot.Database.Execute(query, new object[] { Bot.ServerConfig.Name, Bot.ServerConfig.Name, message.Sender.Nickname, message.Message, message.TimeStamp });
}
}
private void LogChannelJoin(object sender, JoinChannelInfo info)
{
AddChannel(info.Channel);
AddNick(info.Nick.Nickname);
Database database = new Database(Bot.ServerConfig.Database);
string query = "INSERT INTO `channeljoins` 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}), " +
"`nick_id` = (SELECT `nicks`.`id` FROM `nicks` INNER JOIN `servers` ON `servers`.`id` = `nicks`.`server_id` WHERE `servers`.`name` = {3} && `nickname` = {4}), " +
"`date_added` = {5}";
database.Execute(query, new object[] {Bot.ServerConfig.Name, Bot.ServerConfig.Name, info.Channel, Bot.ServerConfig.Name, info.Nick.Nickname, info.TimeStamp});
if (!ChannelBlacklist.Contains(info.Channel)
&& !NickBlacklist.Contains(info.Nick.Nickname))
{
AddChannel(info.Channel);
AddNick(info.Nick.Nickname);
string query = "INSERT INTO `channeljoins` 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}), " +
"`nick_id` = (SELECT `nicks`.`id` FROM `nicks` INNER JOIN `servers` ON `servers`.`id` = `nicks`.`server_id` WHERE `servers`.`name` = {3} && `nicks`.`nickname` = {4}), " +
"`date_added` = {5}";
Bot.Database.Execute(query, new object[] { Bot.ServerConfig.Name, Bot.ServerConfig.Name, info.Channel, Bot.ServerConfig.Name, info.Nick.Nickname, info.TimeStamp });
}
}
private void LogChannelPart(object sender, PartChannelInfo info)
{
AddChannel(info.Channel);
AddNick(info.Nick.Nickname);
Database database = new Database(Bot.ServerConfig.Database);
string query = "INSERT INTO `channelparts` 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}), " +
"`nick_id` = (SELECT `nicks`.`id` FROM `nicks` INNER JOIN `servers` ON `servers`.`id` = `nicks`.`server_id` WHERE `servers`.`name` = {3} && `nickname` = {4}), " +
"`date_added` = {5}";
database.Execute(query, new object[] {Bot.ServerConfig.Name, Bot.ServerConfig.Name, info.Channel, Bot.ServerConfig.Name, info.Nick.Nickname, info.TimeStamp});
if (!ChannelBlacklist.Contains(info.Channel)
&& !NickBlacklist.Contains(info.Nick.Nickname))
{
AddChannel(info.Channel);
AddNick(info.Nick.Nickname);
string query = "INSERT INTO `channelparts` 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}), " +
"`nick_id` = (SELECT `nicks`.`id` FROM `nicks` INNER JOIN `servers` ON `servers`.`id` = `nicks`.`server_id` WHERE `servers`.`name` = {3} && `nickname` = {4}), " +
"`date_added` = {5}";
Bot.Database.Execute(query, new object[] { Bot.ServerConfig.Name, Bot.ServerConfig.Name, info.Channel, Bot.ServerConfig.Name, info.Nick.Nickname, info.TimeStamp });
}
}
private void LogChannelKick(object sender, KickInfo info)
{
AddChannel(info.Channel);
AddNick(info.Nick.Nickname);
AddNick(info.KickedNick.Nickname);
Database database = new Database(Bot.ServerConfig.Database);
string query = "INSERT INTO `channelkicks` 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}), " +
"`nick_id` = (SELECT `nicks`.`id` FROM `nicks` INNER JOIN `servers` ON `servers`.`id` = `nicks`.`server_id` WHERE `servers`.`name` = {3} && `nickname` = {4}), " +
"`kicked_nick_id` = (SELECT `nicks`.`id` FROM `nicks` INNER JOIN `servers` ON `servers`.`id` = `nicks`.`server_id` WHERE `servers`.`name` = {5} && `nickname` = {6}), " +
"`reason` = {7}, " +
"`date_added` = {8}";
database.Execute(query, new object[] {Bot.ServerConfig.Name, Bot.ServerConfig.Name, info.Channel, Bot.ServerConfig.Name, info.Nick.Nickname, Bot.ServerConfig.Name, info.KickedNick.Nickname, info.Reason, info.TimeStamp});
if (!ChannelBlacklist.Contains(info.Channel)
&& !NickBlacklist.Contains(info.KickedNick.Nickname))
{
AddChannel(info.Channel);
AddNick(info.Nick.Nickname);
AddNick(info.KickedNick.Nickname);
string query = "INSERT INTO `channelkicks` 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}), " +
"`nick_id` = (SELECT `nicks`.`id` FROM `nicks` INNER JOIN `servers` ON `servers`.`id` = `nicks`.`server_id` WHERE `servers`.`name` = {3} && `nickname` = {4}), " +
"`kicked_nick_id` = (SELECT `nicks`.`id` FROM `nicks` INNER JOIN `servers` ON `servers`.`id` = `nicks`.`server_id` WHERE `servers`.`name` = {5} && `nickname` = {6}), " +
"`reason` = {7}, " +
"`date_added` = {8}";
Bot.Database.Execute(query, new object[] { Bot.ServerConfig.Name, Bot.ServerConfig.Name, info.Channel, Bot.ServerConfig.Name, info.Nick.Nickname, Bot.ServerConfig.Name, info.KickedNick.Nickname, info.Reason, info.TimeStamp });
}
}
private void LogQuit(object sender, QuitInfo info)
{
AddNick(info.Nick.Nickname);
Database database = new Database(Bot.ServerConfig.Database);
string query = "INSERT INTO `quits` SET " +
"`server_id` = (SELECT `id` FROM `servers` WHERE `name` = {0}), " +
"`nick_id` = (SELECT `nicks`.`id` FROM `nicks` INNER JOIN `servers` ON `servers`.`id` = `nicks`.`server_id` WHERE `servers`.`name` = {1} && `nickname` = {2}), " +
"`message` = {3}, " +
"`date_added` = {4}";
database.Execute(query, new object[] {Bot.ServerConfig.Name, Bot.ServerConfig.Name, info.Nick.Nickname, info.Message, info.TimeStamp});
if (!NickBlacklist.Contains(info.Nick.Nickname))
{
AddNick(info.Nick.Nickname);
string query = "INSERT INTO `quits` SET " +
"`server_id` = (SELECT `id` FROM `servers` WHERE `name` = {0}), " +
"`nick_id` = (SELECT `nicks`.`id` FROM `nicks` INNER JOIN `servers` ON `servers`.`id` = `nicks`.`server_id` WHERE `servers`.`name` = {1} && `nickname` = {2}), " +
"`message` = {3}, " +
"`date_added` = {4}";
Bot.Database.Execute(query, new object[] {Bot.ServerConfig.Name, Bot.ServerConfig.Name, info.Nick.Nickname, info.Message, info.TimeStamp});
}
}
}
}

15
Modules/Messaging/Messaging.cs

@ -55,11 +55,11 @@ namespace Combot.Modules.Plugins @@ -55,11 +55,11 @@ namespace Combot.Modules.Plugins
{
List<Dictionary<string, object>> currentMessages = GetSentMessages(command.Arguments["Nickname"]);
int numMessages = currentMessages.Select(msg => GetNickname((int) msg["nick_id"]) == command.Nick.Nickname).Count();
if (numMessages < (int)GetOptionValue("Max Messages"))
int maxMessages = Convert.ToInt32(GetOptionValue("Max Messages"));
if (numMessages < maxMessages)
{
AddNick(command.Nick.Nickname);
AddNick(command.Arguments["Nickname"]);
Database database = new Database(Bot.ServerConfig.Database);
string query = "INSERT INTO `messages` SET " +
"`server_id` = (SELECT `id` FROM `servers` WHERE `name` = {0}), " +
"`nick_id` = (SELECT `nicks`.`id` FROM `nicks` INNER JOIN `servers` ON `servers`.`id` = `nicks`.`server_id` WHERE `servers`.`name` = {1} && `nickname` = {2}), " +
@ -67,7 +67,7 @@ namespace Combot.Modules.Plugins @@ -67,7 +67,7 @@ namespace Combot.Modules.Plugins
"`message` = {5}, " +
"`anonymous` = {6}, " +
"`date_posted` = {7}";
database.Execute(query, new object[] { Bot.ServerConfig.Name, Bot.ServerConfig.Name, command.Arguments["Nickname"], Bot.ServerConfig.Name, command.Nick.Nickname, command.Arguments["Message"], anonymous, command.TimeStamp });
Bot.Database.Execute(query, new object[] { Bot.ServerConfig.Name, Bot.ServerConfig.Name, command.Arguments["Nickname"], Bot.ServerConfig.Name, command.Nick.Nickname, command.Arguments["Message"], anonymous, command.TimeStamp });
string message = string.Format("I will send your message to \u0002{0}\u0002 as soon as I see them.", command.Arguments["Nickname"]);
SendResponse(command.MessageType, command.Location, command.Nick.Nickname, message);
}
@ -106,34 +106,31 @@ namespace Combot.Modules.Plugins @@ -106,34 +106,31 @@ namespace Combot.Modules.Plugins
private List<Dictionary<string, object>> GetSentMessages(string nick)
{
Database database = new Database(Bot.ServerConfig.Database);
string search = "SELECT `messages`.`message`, `messages`.`nick_id`, `messages`.`date_posted`, `messages`.`anonymous` FROM `messages` " +
"INNER JOIN `nicks` " +
"ON `messages`.`sender_nick_id` = `nicks`.`id` " +
"INNER JOIN `servers` " +
"ON `messages`.`server_id` = `servers`.`id` " +
"WHERE `servers`.`name` = {0} AND `nicks`.`nickname` = {1}";
return database.Query(search, new object[] { Bot.ServerConfig.Name, nick });
return Bot.Database.Query(search, new object[] { Bot.ServerConfig.Name, nick });
}
private List<Dictionary<string, object>> GetReceivedMessages(string nick)
{
Database database = new Database(Bot.ServerConfig.Database);
string search = "SELECT `messages`.`id`, `messages`.`message`, `messages`.`sender_nick_id`, `messages`.`date_posted`, `messages`.`anonymous` FROM `messages` " +
"INNER JOIN `nicks` " +
"ON `messages`.`nick_id` = `nicks`.`id` " +
"INNER JOIN `servers` " +
"ON `messages`.`server_id` = `servers`.`id` " +
"WHERE `servers`.`name` = {0} AND `nicks`.`nickname` = {1}";
return database.Query(search, new object[] { Bot.ServerConfig.Name, nick });
return Bot.Database.Query(search, new object[] { Bot.ServerConfig.Name, nick });
}
private void DeleteMessage(int messageId)
{
Database database = new Database(Bot.ServerConfig.Database);
string query = "DELETE FROM `messages` " +
"WHERE `id` = {0}";
database.Execute(query, new object[] { messageId });
Bot.Database.Execute(query, new object[] { messageId });
}
}
}

33
Modules/Messaging/Messaging.csproj

@ -12,6 +12,21 @@ @@ -12,6 +12,21 @@
<TargetFrameworkVersion>v4.5.1</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<TargetFrameworkProfile />
<PublishUrl>publish\</PublishUrl>
<Install>true</Install>
<InstallFrom>Disk</InstallFrom>
<UpdateEnabled>false</UpdateEnabled>
<UpdateMode>Foreground</UpdateMode>
<UpdateInterval>7</UpdateInterval>
<UpdateIntervalUnits>Days</UpdateIntervalUnits>
<UpdatePeriodically>false</UpdatePeriodically>
<UpdateRequired>false</UpdateRequired>
<MapFileExtensions>true</MapFileExtensions>
<ApplicationRevision>0</ApplicationRevision>
<ApplicationVersion>1.0.0.%2a</ApplicationVersion>
<IsWebBootstrapper>false</IsWebBootstrapper>
<UseApplicationTrust>false</UseApplicationTrust>
<BootstrapperEnabled>true</BootstrapperEnabled>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
@ -56,8 +71,26 @@ @@ -56,8 +71,26 @@
<ItemGroup>
<None Include="Module.config">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
<SubType>Designer</SubType>
</None>
</ItemGroup>
<ItemGroup>
<BootstrapperPackage Include=".NETFramework,Version=v4.5.1">
<Visible>False</Visible>
<ProductName>Microsoft .NET Framework 4.5.1 %28x86 and x64%29</ProductName>
<Install>true</Install>
</BootstrapperPackage>
<BootstrapperPackage Include="Microsoft.Net.Client.3.5">
<Visible>False</Visible>
<ProductName>.NET Framework 3.5 SP1 Client Profile</ProductName>
<Install>false</Install>
</BootstrapperPackage>
<BootstrapperPackage Include="Microsoft.Net.Framework.3.5.SP1">
<Visible>False</Visible>
<ProductName>.NET Framework 3.5 SP1</ProductName>
<Install>false</Install>
</BootstrapperPackage>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<PropertyGroup>
<PostBuildEvent>mkdir "$(SolutionDir)Bin\Interface\$(ConfigurationName)\Modules\$(TargetName)"

51
Modules/Messaging/Module.config

@ -55,6 +55,57 @@ @@ -55,6 +55,57 @@
],
"ShowHelp": true,
"SpamCheck": true
},
{
"Name": "Anonymous Message",
"Description": "Sends an anonymous message to a nick the next time they are seen active.",
"Enabled": true,
"ChannelBlacklist": [],
"NickBlacklist": [],
"Triggers": [
"amsg",
"anonmessage"
],
"Arguments": [
{
"Name": "Nickname",
"Description": "The nickname you want to send a message to.",
"AllowedValues": [],
"MessageTypes": [
0,
1,
2
],
"Required": true
},
{
"Name": "Message",
"Description": "The message you want to send.",
"AllowedValues": [],
"MessageTypes": [
0,
1,
2
],
"Required": true
}
],
"AllowedMessageTypes": [
0,
1,
2
],
"AllowedAccess": [
0,
1,
2,
3,
4,
5,
6
],
"ShowHelp": true,
"SpamCheck": true
}
],
"Options": [

9
Modules/Moderation/Moderation.cs

@ -329,7 +329,14 @@ namespace Combot.Modules.Plugins @@ -329,7 +329,14 @@ namespace Combot.Modules.Plugins
string channel = command.Arguments.ContainsKey("Channel") ? command.Arguments["Channel"] : command.Location;
if (Bot.CheckChannelAccess(channel, command.Nick.Nickname, curCommand.AllowedAccess))
{
Bot.IRC.SendKick(channel, command.Arguments["Nickname"]);
if (command.Arguments.ContainsKey("Reason"))
{
Bot.IRC.SendKick(channel, command.Arguments["Nickname"], command.Arguments["Reason"]);
}
else
{
Bot.IRC.SendKick(channel, command.Arguments["Nickname"]);
}
}
else
{

3
Modules/Moderation/Moderation.csproj

@ -12,6 +12,7 @@ @@ -12,6 +12,7 @@
<TargetFrameworkVersion>v4.5.1</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<TargetFrameworkProfile />
<IsWebBootstrapper>false</IsWebBootstrapper>
<PublishUrl>publish\</PublishUrl>
<Install>true</Install>
<InstallFrom>Disk</InstallFrom>
@ -24,7 +25,6 @@ @@ -24,7 +25,6 @@
<MapFileExtensions>true</MapFileExtensions>
<ApplicationRevision>0</ApplicationRevision>
<ApplicationVersion>1.0.0.%2a</ApplicationVersion>
<IsWebBootstrapper>false</IsWebBootstrapper>
<UseApplicationTrust>false</UseApplicationTrust>
<BootstrapperEnabled>true</BootstrapperEnabled>
</PropertyGroup>
@ -71,6 +71,7 @@ @@ -71,6 +71,7 @@
<ItemGroup>
<None Include="Module.config">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
<SubType>Designer</SubType>
</None>
</ItemGroup>
<ItemGroup>

48
Modules/Moderation/Module.config

@ -1126,19 +1126,21 @@ @@ -1126,19 +1126,21 @@
"Description": "The channel the nick will be kick banned from.",
"AllowedValues": [],
"MessageTypes": [
0
1,
2
],
"Required": false
"Required": true
},
{
"Name": "Channel",
"Description": "The channel the nick will be kick banned from.",
"Name": "Reason",
"Description": "The reason the nick is being kick banned.",
"AllowedValues": [],
"MessageTypes": [
0,
1,
2
],
"Required": true
"Required": false
}
],
"AllowedMessageTypes": [
@ -1262,19 +1264,21 @@ @@ -1262,19 +1264,21 @@
"Description": "The channel the nick will be kick banned from.",
"AllowedValues": [],
"MessageTypes": [
0
1,
2
],
"Required": false
"Required": true
},
{
"Name": "Channel",
"Description": "The channel the nick will be kick banned from.",
"Name": "Reason",
"Description": "The reason the nick is being kick banned.",
"AllowedValues": [],
"MessageTypes": [
0,
1,
2
],
"Required": true
"Required": false
}
],
"AllowedMessageTypes": [
@ -1319,19 +1323,21 @@ @@ -1319,19 +1323,21 @@
"Description": "The channel the nick will be kicked from.",
"AllowedValues": [],
"MessageTypes": [
0
1,
2
],
"Required": false
"Required": true
},
{
"Name": "Channel",
"Description": "The channel the nick will be kicked from.",
"Name": "Reason",
"Description": "The reason the nick is being kicked.",
"AllowedValues": [],
"MessageTypes": [
0,
1,
2
],
"Required": true
"Required": false
}
],
"AllowedMessageTypes": [
@ -1365,19 +1371,21 @@ @@ -1365,19 +1371,21 @@
"Description": "The channel the caller will be kicked from.",
"AllowedValues": [],
"MessageTypes": [
0
1,
2
],
"Required": false
"Required": true
},
{
"Name": "Channel",
"Description": "The channel the caller will be kicked from.",
"Name": "Reason",
"Description": "The reason the you are being kicked.",
"AllowedValues": [],
"MessageTypes": [
0,
1,
2
],
"Required": true
"Required": false
}
],
"AllowedMessageTypes": [

39
Modules/Owner Control/Module.config

@ -5,6 +5,45 @@ @@ -5,6 +5,45 @@
"ChannelBlacklist": [],
"NickBlacklist": [],
"Commands": [
{
"Name": "Owner Identify",
"Description": "Identifies you as a bot owner.",
"Enabled": true,
"ChannelBlacklist": [],
"NickBlacklist": [],
"Triggers": [
"owner"
],
"Arguments": [
{
"Name": "Password",
"Description": "The bot's password.",
"AllowedValues": [],
"MessageTypes": [
0,
1,
2
],
"Required": true
}
],
"AllowedMessageTypes": [
0,
1,
2
],
"AllowedAccess": [
0,
1,
2,
3,
4,
5,
6
],
"ShowHelp": true,
"SpamCheck": true
},
{
"Name": "Change Nick",
"Description": "Changes the bot's nickname.",

23
Modules/Owner Control/Owner_Control.cs

@ -4,6 +4,7 @@ using System.IO; @@ -4,6 +4,7 @@ using System.IO;
using System.Linq;
using System.Reflection;
using System.Threading;
using Combot.IRCServices;
namespace Combot.Modules.Plugins
{
@ -19,6 +20,28 @@ namespace Combot.Modules.Plugins @@ -19,6 +20,28 @@ namespace Combot.Modules.Plugins
Command foundCommand = Commands.Find(c => c.Triggers.Contains(command.Command));
switch (foundCommand.Name)
{
case "Owner Identify":
if (command.Arguments["Password"] == Bot.ServerConfig.Password)
{
if (!Bot.ServerConfig.Owners.Contains(command.Nick.Nickname))
{
Bot.ServerConfig.Owners.Add(command.Nick.Nickname);
SendResponse(command.MessageType, command.Location, command.Nick.Nickname, "You are now identified as an owner.");
}
else
{
SendResponse(command.MessageType, command.Location, command.Nick.Nickname, "You are already identified as an owner.");
}
for (int i = 0; i < Bot.IRC.Channels.Count; i++)
{
Nick foundNick = Bot.IRC.Channels[i].Nicks.Find(nick => nick.Nickname == command.Nick.Nickname);
if (foundNick != null)
{
foundNick.AddMode(UserMode.r);
}
}
}
break;
case "Change Nick":
Bot.IRC.SendNick(command.Arguments["Nickname"]);
break;

6
Modules/Quotes/Quotes.cs

@ -60,7 +60,6 @@ namespace Combot.Modules.Plugins @@ -60,7 +60,6 @@ namespace Combot.Modules.Plugins
private List<Dictionary<string, object>> GetQuoteList(string channel)
{
Database database = new Database(Bot.ServerConfig.Database);
string search = "SELECT `channelmessages`.`message`, `nicks`.`nickname` FROM `channelmessages` " +
"INNER JOIN `nicks` " +
"ON `channelmessages`.`nick_id` = `nicks`.`id` " +
@ -69,12 +68,11 @@ namespace Combot.Modules.Plugins @@ -69,12 +68,11 @@ namespace Combot.Modules.Plugins
"INNER JOIN `servers` " +
"ON `channelmessages`.`server_id` = `servers`.`id` " +
"WHERE `servers`.`name` = {0} AND `channels`.`name` = {1}";
return database.Query(search, new object[] { Bot.ServerConfig.Name, channel });
return Bot.Database.Query(search, new object[] { Bot.ServerConfig.Name, channel });
}
private List<Dictionary<string, object>> GetQuoteList(string channel, string nickname)
{
Database database = new Database(Bot.ServerConfig.Database);
string search = "SELECT `channelmessages`.`message`, `nicks`.`nickname` FROM `channelmessages` " +
"INNER JOIN `nicks` " +
"ON `channelmessages`.`nick_id` = `nicks`.`id` " +
@ -83,7 +81,7 @@ namespace Combot.Modules.Plugins @@ -83,7 +81,7 @@ namespace Combot.Modules.Plugins
"INNER JOIN `servers` " +
"ON `channelmessages`.`server_id` = `servers`.`id` " +
"WHERE `servers`.`name` = {0} AND `channels`.`name` = {1} AND `nicks`.`nickname` = {2}";
return database.Query(search, new object[] { Bot.ServerConfig.Name, channel, nickname });
return Bot.Database.Query(search, new object[] { Bot.ServerConfig.Name, channel, nickname });
}
}
}

104
Modules/Sed/Sed.cs

@ -16,53 +16,64 @@ namespace Combot.Modules.Plugins @@ -16,53 +16,64 @@ namespace Combot.Modules.Plugins
private void HandleChannelMessageEvent(object sender, ChannelMessage message)
{
Regex sedRegex = new Regex(@"^s\/(?<Match>[^\/\\]*(?:\\.[^\/\\]*)*)\/(?<Replace>[^\/\\]*(?:\\.[^\/\\]*)*)\/(?<Option>[g|I|0-9]*)?");
if (sedRegex.IsMatch(message.Message))
if (!Bot.ServerConfig.ChannelBlacklist.Contains(message.Channel)
&& !Bot.ServerConfig.NickBlacklist.Contains(message.Sender.Nickname)
&& !ChannelBlacklist.Contains(message.Channel)
&& !NickBlacklist.Contains(message.Sender.Nickname))
{
Match sedMatch = sedRegex.Match(message.Message);
string match = sedMatch.Groups["Match"].ToString().Replace(@"\/", @"/");
string replace = sedMatch.Groups["Replace"].ToString().Replace(@"\/", @"/");
string option = sedMatch.Groups["Option"].ToString();
string mysqlCase;
RegexOptions matchOptions;
int optionVal;
int replaceNum;
if (int.TryParse(option, out optionVal))
Regex sedRegex = new Regex(@"^s\/(?<Match>[^\/\\]*(?:\\.[^\/\\]*)*)\/(?<Replace>[^\/\\]*(?:\\.[^\/\\]*)*)\/(?<Option>[g|I|0-9]*)?");
if (sedRegex.IsMatch(message.Message))
{
matchOptions = RegexOptions.None;
replaceNum = optionVal;
mysqlCase = "CAST(`channelmessages`.`message` AS BINARY)";
}
else if (option == "g")
{
matchOptions = RegexOptions.None;
replaceNum = 1;
mysqlCase = "CAST(`channelmessages`.`message` AS BINARY)";
}
else if (option == "I")
{
matchOptions = RegexOptions.IgnoreCase;
replaceNum = 1;
mysqlCase = "`channelmessages`.`message`";
}
else
{
matchOptions = RegexOptions.None;
replaceNum = 1;
mysqlCase = "CAST(`channelmessages`.`message` AS BINARY)";
}
string mysqlMatch = match.Replace(@"\s", "[:space:]").Replace(@"\", @"\\");
List<Dictionary<string, object>> resultList = GetMessageList(message.Channel, message.Sender.Nickname, mysqlMatch, mysqlCase);
if (resultList.Any())
{
IEnumerable<Dictionary<string, object>> validList = resultList.Where(item => item["message"].ToString() != message.Message);
if (validList.Any())
Match sedMatch = sedRegex.Match(message.Message);
string match = sedMatch.Groups["Match"].ToString().Replace(@"\/", @"/");
string replace = sedMatch.Groups["Replace"].ToString().Replace(@"\/", @"/");
string option = sedMatch.Groups["Option"].ToString();
string mysqlCase;
RegexOptions matchOptions;
int optionVal;
int replaceNum;
if (int.TryParse(option, out optionVal))
{
matchOptions = RegexOptions.None;
replaceNum = optionVal;
mysqlCase = "CAST(`channelmessages`.`message` AS BINARY)";
}
else if (option == "g")
{
string oldMessage = validList.First()["message"].ToString();
Regex messageRegex = new Regex(match, matchOptions);
string newMessage = messageRegex.Replace(oldMessage, replace, replaceNum);
string replacedMessage = string.Format("\u0002{0}\u0002 meant to say: {1}", message.Sender.Nickname, newMessage);
SendResponse(MessageType.Channel, message.Channel, message.Sender.Nickname, replacedMessage);
matchOptions = RegexOptions.None;
replaceNum = 1;
mysqlCase = "CAST(`channelmessages`.`message` AS BINARY)";
}
else if (option == "I")
{
matchOptions = RegexOptions.IgnoreCase;
replaceNum = 1;
mysqlCase = "`channelmessages`.`message`";
}
else
{
matchOptions = RegexOptions