Browse Source

Fixed rules being able to be added by anyone.

Fixed rules not checking channel access.
Fixed privalege being added for nick in all channels when message type was for a channel.
Added handling of exceptions for Mysql database.
master
Teknikode 7 years ago
parent
commit
968e7649e7
  1. 31
      Combot/Bot.cs
  2. 21
      Combot/Databases/Database.cs
  3. 38
      Modules/Channel Rules/Channel_Rules.cs
  4. 47
      Modules/Channel Rules/Module.config

31
Combot/Bot.cs

@ -571,15 +571,34 @@ namespace Combot @@ -571,15 +571,34 @@ namespace Combot
CommandMessage newCommand = new CommandMessage();
newCommand.Nick.Copy(sender);
bool nickFound = false;
IRC.Channels.ForEach(channel => channel.Nicks.ForEach(nick =>
if (messageType == MessageType.Channel)
{
if (nick.Nickname == newCommand.Nick.Nickname)
Channel foundChannel = IRC.Channels.Find(chan => chan.Name == location);
if (foundChannel != null)
{
nickFound = true;
newCommand.Nick.AddModes(nick.Modes);
newCommand.Nick.AddPrivileges(nick.Privileges);
foundChannel.Nicks.ForEach(nick =>
{
if (nick.Nickname == newCommand.Nick.Nickname)
{
nickFound = true;
newCommand.Nick.AddModes(nick.Modes);
newCommand.Nick.AddPrivileges(nick.Privileges);
}
});
}
}));
}
else
{
IRC.Channels.ForEach(channel => channel.Nicks.ForEach(nick =>
{
if (nick.Nickname == newCommand.Nick.Nickname)
{
nickFound = true;
newCommand.Nick.AddModes(nick.Modes);
newCommand.Nick.AddPrivileges(nick.Privileges);
}
}));
}
// Nickname has not been found, so need to run a query for nick's modes
if (!nickFound)
{

21
Combot/Databases/Database.cs

@ -50,6 +50,13 @@ namespace Combot.Databases @@ -50,6 +50,13 @@ namespace Combot.Databases
MysqlErrorEvent(this, exception.Message);
}
}
catch (Exception exception)
{
if (MysqlErrorEvent != null)
{
MysqlErrorEvent(this, exception.Message);
}
}
DatabaseLock.ExitWriteLock();
}
return rows;
@ -74,6 +81,13 @@ namespace Combot.Databases @@ -74,6 +81,13 @@ namespace Combot.Databases
MysqlErrorEvent(this, exception.Message);
}
}
catch (Exception exception)
{
if (MysqlErrorEvent != null)
{
MysqlErrorEvent(this, exception.Message);
}
}
DatabaseLock.ExitWriteLock();
return result;
}
@ -98,6 +112,13 @@ namespace Combot.Databases @@ -98,6 +112,13 @@ namespace Combot.Databases
MysqlErrorEvent(this, exception.Message);
}
}
catch (Exception exception)
{
if (MysqlErrorEvent != null)
{
MysqlErrorEvent(this, exception.Message);
}
}
DatabaseLock.ExitWriteLock();
}
}

38
Modules/Channel Rules/Channel_Rules.cs

@ -14,12 +14,28 @@ namespace Combot.Modules.Plugins @@ -14,12 +14,28 @@ namespace Combot.Modules.Plugins
public override void ParseCommand(CommandMessage command)
{
string channel = command.Arguments.ContainsKey("Channel") ? command.Arguments["Channel"] : command.Location;
Command foundCommand = Commands.Find(c => c.Triggers.Contains(command.Command));
switch (foundCommand.Name)
{
case "Rules":
string channel = command.Arguments.ContainsKey("Channel") ? command.Arguments["Channel"] : command.Location;
if (command.Arguments.ContainsKey("Action"))
case "Rules Display":
List<Dictionary<string, object>> foundRules = GetRuleList(channel);
if (foundRules.Any())
{
int index = 1;
foundRules.ForEach(rule =>
{
SendResponse(command.MessageType, command.Location, command.Nick.Nickname, string.Format("Rule \u0002#{0}\u0002: {1}", index, rule["rule"]));
index++;
});
}
else
{
SendResponse(command.MessageType, command.Location, command.Nick.Nickname, string.Format("There are no rules for \u0002{0}\u0002", channel));
}
break;
case "Rules Modification":
if (Bot.CheckChannelAccess(channel, command.Nick.Nickname, command.Access))
{
string action = command.Arguments["Action"].ToString();
switch (action.ToLower())
@ -37,20 +53,8 @@ namespace Combot.Modules.Plugins @@ -37,20 +53,8 @@ namespace Combot.Modules.Plugins
}
else
{
List<Dictionary<string, object>> foundRules = GetRuleList(channel);
if (foundRules.Any())
{
int index = 1;
foundRules.ForEach(rule =>
{
SendResponse(command.MessageType, command.Location, command.Nick.Nickname, string.Format("Rule \u0002#{0}\u0002: {1}", index, rule["rule"]));
index++;
});
}
else
{
SendResponse(command.MessageType, command.Location, command.Nick.Nickname, string.Format("There are no rules for \u0002{0}\u0002", channel));
}
string noAccessMessage = string.Format("You do not have access to \u0002{0}\u000F on \u0002{1}\u000F.", command.Command, channel);
SendResponse(command.MessageType, command.Location, command.Nick.Nickname, noAccessMessage);
}
break;
}

47
Modules/Channel Rules/Module.config

@ -6,7 +6,7 @@ @@ -6,7 +6,7 @@
"NickBlacklist": [],
"Commands": [
{
"Name": "Rules",
"Name": "Rules Display",
"Description": "Displays the rules for a given channel.",
"Enabled": true,
"ChannelBlacklist": [],
@ -14,6 +14,45 @@ @@ -14,6 +14,45 @@
"Triggers": [
"rules"
],
"Arguments": [
{
"Name": "Channel",
"Description": "The channel the rules are for.",
"AllowedValues": [],
"DependentArguments": [],
"MessageTypes": [
1,
2
],
"Required": true
}
],
"AllowedMessageTypes": [
0,
1,
2
],
"AllowedAccess": [
0,
1,
2,
3,
4,
5,
6
],
"ShowHelp": true,
"SpamCheck": true
},
{
"Name": "Rules Modification",
"Description": "Displays the rules for a given channel.",
"Enabled": true,
"ChannelBlacklist": [],
"NickBlacklist": [],
"Triggers": [
"rule"
],
"Arguments": [
{
"Name": "Channel",
@ -39,7 +78,7 @@ @@ -39,7 +78,7 @@
1,
2
],
"Required": false
"Required": true
},
{
"Name": "ID",
@ -88,10 +127,6 @@ @@ -88,10 +127,6 @@
2
],
"AllowedAccess": [
0,
1,
2,
3,
4,
5,
6

Loading…
Cancel
Save