Browse Source

Changed Database queries to synchronous from asynchronous.

Fixed minor bugs.
Added blacklist checking for non-command actions.
tags/3.0.0
Teknikode 4 years ago
parent
commit
c187cf53e7

+ 1
- 0
.gitignore View File

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

+ 3
- 0
Combot.sln View File

@@ -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
- 0
Combot/Bot.cs View File

@@ -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
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
IRC.Message.KickEvent += HandleKickEvent;
IRC.Message.ChannelModeChangeEvent += HandleChannelModeChangeEvent;

Database = new Database(serverConfig.Database);

LoadModules();
}


+ 12
- 2
Combot/Databases/Database.cs View File

@@ -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
{
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
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
rows.Add(row);
}
reader.Close();
DatabaseLock.ExitWriteLock();
}
return rows;
}
@@ -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
{
if (Connected)
{
DatabaseLock.EnterWriteLock();
MySqlCommand cmd = PrepareQuery(query, args);
cmd.ExecuteNonQuery();
int result = cmd.ExecuteNonQuery();
DatabaseLock.ExitWriteLock();
}
}


+ 7
- 11
Combot/Modules/Module.cs View File

@@ -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())
{

+ 51
- 45
IRCServices/IRC.cs View File

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

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

@@ -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
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(() =>
{

+ 4
- 8
Modules/Channel Rules/Channel_Rules.cs View File

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

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
"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 });
}
}
}

+ 1
- 1
Modules/Configuration/Configuration.cs View File

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

+ 16
- 14
Modules/Introductions/Introductions.cs View File

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

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
"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
- 0
Modules/Introductions/Introductions.csproj View File

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

+ 14
- 10
Modules/Invite/Invite.cs View File

@@ -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.");
}
}
}

+ 72
- 62
Modules/Logging/Logging.cs View File

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

+ 6
- 9
Modules/Messaging/Messaging.cs View File

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

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
- 0
Modules/Messaging/Messaging.csproj View File

@@ -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 @@
<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
- 0
Modules/Messaging/Module.config View File

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

+ 8
- 1
Modules/Moderation/Moderation.cs View File

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

+ 2
- 1
Modules/Moderation/Moderation.csproj View File

@@ -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 @@
<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 @@
<ItemGroup>
<None Include="Module.config">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
<SubType>Designer</SubType>
</None>
</ItemGroup>
<ItemGroup>

+ 28
- 20
Modules/Moderation/Module.config View File

@@ -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 @@
"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 @@
"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 @@
"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
- 0
Modules/Owner Control/Module.config View File

@@ -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
- 0
Modules/Owner Control/Owner_Control.cs View File

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

+ 2
- 4
Modules/Quotes/Quotes.cs View File

@@ -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
"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
"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 });
}
}
}

+ 55
- 49
Modules/Sed/Sed.cs View File

@@ -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.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())
{
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);
}
else
{
string noMatch = string.Format("You do not have any previous messages that match \u0002{0}\u0002.", match);
SendResponse(MessageType.Channel, message.Channel, message.Sender.Nickname, noMatch);
}
}
else
{
@@ -70,11 +81,6 @@ namespace Combot.Modules.Plugins
SendResponse(MessageType.Channel, message.Channel, message.Sender.Nickname, noMatch);
}
}
else
{
string noMatch = string.Format("You do not have any previous messages that match \u0002{0}\u0002.", match);
SendResponse(MessageType.Channel, message.Channel, message.Sender.Nickname, noMatch);
}
}
}


+ 19
- 20
Modules/Seen/Seen.cs View File

@@ -26,12 +26,11 @@ namespace Combot.Modules.Plugins
private void GetLastSeen(CommandMessage command)
{
string channel = command.Arguments.ContainsKey("Channel") ? command.Arguments["Channel"] : null;
Database database = new Database(Bot.ServerConfig.Database);
List<Dictionary<string, object>> channelList = GetChannelList(database, channel, command.Arguments["Nickname"]);
List<Dictionary<string, object>> partList = GetPartList(database, channel, command.Arguments["Nickname"]);
List<Dictionary<string, object>> joinList = GetJoinList(database, channel, command.Arguments["Nickname"]);
List<Dictionary<string, object>> kickList = GetKickList(database, channel, command.Arguments["Nickname"]);
List<Dictionary<string, object>> quitList = GetQuitList(database, command.Arguments["Nickname"]);
List<Dictionary<string, object>> channelList = GetChannelList(channel, command.Arguments["Nickname"]);
List<Dictionary<string, object>> partList = GetPartList(channel, command.Arguments["Nickname"]);
List<Dictionary<string, object>> joinList = GetJoinList(channel, command.Arguments["Nickname"]);
List<Dictionary<string, object>> kickList = GetKickList(channel, command.Arguments["Nickname"]);
List<Dictionary<string, object>> quitList = GetQuitList(command.Arguments["Nickname"]);

List<Dictionary<DateTime, string>> lastSeenList = new List<Dictionary<DateTime, string>>();

@@ -100,7 +99,7 @@ namespace Combot.Modules.Plugins
}
}

private List<Dictionary<string, object>> GetChannelList(Database database, string channel, string nickname)
private List<Dictionary<string, object>> GetChannelList(string channel, string nickname)
{
if (channel != null)
{
@@ -113,7 +112,7 @@ namespace Combot.Modules.Plugins
"ON `channelmessages`.`server_id` = `servers`.`id` " +
"WHERE `servers`.`name` = {0} AND `channels`.`name` = {1} AND `nicks`.`nickname` = {2} " +
"ORDER BY date_added DESC LIMIT 1";
return database.Query(search, new object[] {Bot.ServerConfig.Name, channel, nickname});
return Bot.Database.Query(search, new object[] { Bot.ServerConfig.Name, channel, nickname });
}
else
{
@@ -126,11 +125,11 @@ namespace Combot.Modules.Plugins
"ON `channelmessages`.`server_id` = `servers`.`id` " +
"WHERE `servers`.`name` = {0} AND `nicks`.`nickname` = {1} " +
"ORDER BY date_added DESC LIMIT 1";
return database.Query(search, new object[] { Bot.ServerConfig.Name, nickname });
return Bot.Database.Query(search, new object[] { Bot.ServerConfig.Name, nickname });
}
}

private List<Dictionary<string, object>> GetPartList(Database database, string channel, string nickname)
private List<Dictionary<string, object>> GetPartList(string channel, string nickname)
{
if (channel != null)
{
@@ -143,7 +142,7 @@ namespace Combot.Modules.Plugins
"ON `channelparts`.`server_id` = `servers`.`id` " +
"WHERE `servers`.`name` = {0} AND `channels`.`name` = {1} AND `nicks`.`nickname` = {2} " +
"ORDER BY date_added DESC LIMIT 1";
return database.Query(search, new object[] {Bot.ServerConfig.Name, channel, nickname});
return Bot.Database.Query(search, new object[] { Bot.ServerConfig.Name, channel, nickname });
}
else
{
@@ -156,11 +155,11 @@ namespace Combot.Modules.Plugins
"ON `channelparts`.`server_id` = `servers`.`id` " +
"WHERE `servers`.`name` = {0} AND `nicks`.`nickname` = {1} " +
"ORDER BY date_added DESC LIMIT 1";
return database.Query(search, new object[] { Bot.ServerConfig.Name, nickname });
return Bot.Database.Query(search, new object[] { Bot.ServerConfig.Name, nickname });
}
}

private List<Dictionary<string, object>> GetJoinList(Database database, string channel, string nickname)
private List<Dictionary<string, object>> GetJoinList(string channel, string nickname)
{
if (channel != null)
{
@@ -173,7 +172,7 @@ namespace Combot.Modules.Plugins
"ON `channeljoins`.`server_id` = `servers`.`id` " +
"WHERE `servers`.`name` = {0} AND `channels`.`name` = {1} AND `nicks`.`nickname` = {2} " +
"ORDER BY date_added DESC LIMIT 1";
return database.Query(search, new object[] {Bot.ServerConfig.Name, channel, nickname});
return Bot.Database.Query(search, new object[] { Bot.ServerConfig.Name, channel, nickname });
}
else
{
@@ -186,11 +185,11 @@ namespace Combot.Modules.Plugins
"ON `channeljoins`.`server_id` = `servers`.`id` " +
"WHERE `servers`.`name` = {0} AND `nicks`.`nickname` = {1} " +
"ORDER BY date_added DESC LIMIT 1";
return database.Query(search, new object[] { Bot.ServerConfig.Name, nickname });
return Bot.Database.Query(search, new object[] { Bot.ServerConfig.Name, nickname });
}
}

private List<Dictionary<string, object>> GetKickList(Database database, string channel, string nickname)
private List<Dictionary<string, object>> GetKickList(string channel, string nickname)
{
if (channel != null)
{
@@ -203,7 +202,7 @@ namespace Combot.Modules.Plugins
"ON `channelkicks`.`server_id` = `servers`.`id` " +
"WHERE `servers`.`name` = {0} AND `channels`.`name` = {1} AND `nicks`.`nickname` = {2} " +
"ORDER BY date_added DESC LIMIT 1";
return database.Query(search, new object[] {Bot.ServerConfig.Name, channel, nickname});
return Bot.Database.Query(search, new object[] { Bot.ServerConfig.Name, channel, nickname });
}
else
{
@@ -216,11 +215,11 @@ namespace Combot.Modules.Plugins
"ON `channelkicks`.`server_id` = `servers`.`id` " +
"WHERE `servers`.`name` = {0} AND `nicks`.`nickname` = {1} " +
"ORDER BY date_added DESC LIMIT 1";
return database.Query(search, new object[] { Bot.ServerConfig.Name, nickname });
return Bot.Database.Query(search, new object[] { Bot.ServerConfig.Name, nickname });
}
}

private List<Dictionary<string, object>> GetQuitList(Database database, string nickname)
private List<Dictionary<string, object>> GetQuitList(string nickname)
{
string search = "SELECT `quits`.`date_added` FROM `quits` " +
"INNER JOIN `nicks` " +
@@ -229,7 +228,7 @@ namespace Combot.Modules.Plugins
"ON `quits`.`server_id` = `servers`.`id` " +
"WHERE `servers`.`name` = {0} AND `nicks`.`nickname` = {1} " +
"ORDER BY date_added DESC LIMIT 1";
return database.Query(search, new object[] { Bot.ServerConfig.Name, nickname });
return Bot.Database.Query(search, new object[] { Bot.ServerConfig.Name, nickname });
}

private string ConvertToDifference(TimeSpan time)

+ 61
- 35
Modules/Url Parsing/Url_Parsing.cs View File

@@ -18,47 +18,73 @@ namespace Combot.Modules.Plugins
{
Regex urlRegex = new Regex("(https?)://([\\w-]+\\.)+[\\w-]+(/[\\w-./?%&=]*)?");

if (urlRegex.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))
{
MatchCollection urlMatches = urlRegex.Matches(message.Message);
for (int i = 0; i < urlMatches.Count; i++)
if (urlRegex.IsMatch(message.Message))
{
Match urlMatch = urlMatches[i];
Uri url = new Uri(urlMatch.Value);
WebRequest webRequest = HttpWebRequest.Create(url);
webRequest.Method = "HEAD";
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
ServicePointManager.ServerCertificateValidationCallback = delegate { return true; };

using (WebResponse webResponse = webRequest.GetResponse())
MatchCollection urlMatches = urlRegex.Matches(message.Message);
for (int i = 0; i < urlMatches.Count; i++)
{
string contentType = webResponse.ContentType.Split('/')[0];
long contentLength = webResponse.ContentLength;
switch (contentType)
Match urlMatch = urlMatches[i];
Uri url = new Uri(urlMatch.Value);
HttpWebRequest webRequest = (HttpWebRequest) WebRequest.Create(url);
webRequest.Method = "HEAD";
webRequest.UserAgent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; .NET CLR 1.0.3705;)";
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
ServicePointManager.ServerCertificateValidationCallback = delegate { return true; };

try
{
case "text":
Regex ytRegex = new Regex("(((youtube.*(v=|/v/))|(youtu\\.be/))(?<ID>[-_a-zA-Z0-9]+))");
if (!ytRegex.IsMatch(message.Message) || !Bot.Modules.Exists(mod => mod.Name == "YouTube"))
using (HttpWebResponse webResponse = (HttpWebResponse) webRequest.GetResponse())
{
int code = (int) webResponse.StatusCode;
if (code == 200)
{
string contentType = webResponse.ContentType.Split('/')[0];
long contentLength = webResponse.ContentLength;
switch (contentType)
{
case "text":
Regex ytRegex = new Regex("(((youtube.*(v=|/v/))|(youtu\\.be/))(?<ID>[-_a-zA-Z0-9]+))");
if (!ytRegex.IsMatch(message.Message) || !Bot.Modules.Exists(mod => mod.Name == "YouTube"))
{
WebClient x = new WebClient();
x.Encoding = Encoding.UTF8;
string source = x.DownloadString(urlMatch.ToString());
string title = Regex.Match(source, @"\<title\b[^>]*\>\s*(?<Title>[\s\S]*?)\</title\>", RegexOptions.IgnoreCase).Groups["Title"].Value;
Bot.IRC.SendPrivateMessage(message.Channel, string.Format("[URL] {0} ({1})", HttpUtility.UrlDecode(StripTagsCharArray(title)), url.Host));
}
break;
case "image":
Bot.IRC.SendPrivateMessage(message.Channel, string.Format("[{0}] Size: {1}", webResponse.ContentType, ToFileSize(contentLength)));
break;
case "video":
Bot.IRC.SendPrivateMessage(message.Channel, string.Format("[Video] Type: {0} | Size: {1}", webResponse.ContentType.Split('/')[1], ToFileSize(contentLength)));
break;
case "application":
Bot.IRC.SendPrivateMessage(message.Channel, string.Format("[Application] Type: {0} | Size: {1}", webResponse.ContentType.Split('/')[1], ToFileSize(contentLength)));
break;
case "audio":
Bot.IRC.SendPrivateMessage(message.Channel, string.Format("[Audio] Type: {0} | Size: {1}", webResponse.ContentType.Split('/')[1], ToFileSize(contentLength)));
break;
}
}
else
{
WebClient x = new WebClient();
x.Encoding = Encoding.UTF8;
string source = x.DownloadString(urlMatch.ToString());
string title = Regex.Match(source, @"\<title\b[^>]*\>\s*(?<Title>[\s\S]*?)\</title\>", RegexOptions.IgnoreCase).Groups["Title"].Value;
Bot.IRC.SendPrivateMessage(message.Channel, string.Format("[URL] {0} ({1})", HttpUtility.UrlDecode(StripTagsCharArray(title)), url.Host));
Bot.IRC.SendPrivateMessage(message.Channel, string.Format("[URL] Returned Status Code \u0002{0}\u0002 ({1})", code, url.Host));
}
break;
case "image":
Bot.IRC.SendPrivateMessage(message.Channel, string.Format("[{0}] Size: {1}", webResponse.ContentType, ToFileSize(contentLength)));
break;
case "video":
Bot.IRC.SendPrivateMessage(message.Channel, string.Format("[Video] Type: {0} | Size: {1}", webResponse.ContentType.Split('/')[1], ToFileSize(contentLength)));
break;
case "application":
Bot.IRC.SendPrivateMessage(message.Channel, string.Format("[Application] Type: {0} | Size: {1}", webResponse.ContentType.Split('/')[1], ToFileSize(contentLength)));
break;
case "audio":
Bot.IRC.SendPrivateMessage(message.Channel, string.Format("[Audio] Type: {0} | Size: {1}", webResponse.ContentType.Split('/')[1], ToFileSize(contentLength)));
break;
}
}
catch (WebException ex)
{
if (ex.Response != null)
{
int code = (int) ((HttpWebResponse) ex.Response).StatusCode;
Bot.IRC.SendPrivateMessage(message.Channel, string.Format("[URL] Response Code: \u0002{0}\u0002 ({1})", code, url.Host));
}
}
}
}

+ 11
- 5
Modules/YouTube/YouTube.cs View File

@@ -31,12 +31,18 @@ namespace Combot.Modules.Plugins

private void HandleChannelMessage(object sender, ChannelMessage message)
{
Regex urlRegex = new Regex("(((youtube.*(v=|/v/))|(youtu\\.be/))(?<ID>[-_a-zA-Z0-9]+))");
if (urlRegex.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 urlMatch = urlRegex.Match(message.Message);
string youtubeMessage = GetYoutubeDescription(urlMatch.Groups["ID"].Value);
Bot.IRC.SendPrivateMessage(message.Channel, youtubeMessage);
Regex urlRegex = new Regex("(((youtube.*(v=|/v/))|(youtu\\.be/))(?<ID>[-_a-zA-Z0-9]+))");
if (urlRegex.IsMatch(message.Message))
{
Match urlMatch = urlRegex.Match(message.Message);
string youtubeMessage = GetYoutubeDescription(urlMatch.Groups["ID"].Value);
Bot.IRC.SendPrivateMessage(message.Channel, youtubeMessage);
}
}
}


Loading…
Cancel
Save