Added execute command as nick. Added check for positive time for timed ban.tags/3.1.0
@@ -381,6 +381,11 @@ namespace Combot | |||
ParseCommandMessage(DateTime.Now, message, new Nick { Nickname = IRC.Nickname }, location, type); | |||
} | |||
public void ExecuteCommand(string message, string location, MessageType type, Nick nick) | |||
{ | |||
ParseCommandMessage(DateTime.Now, message, nick, location, type); | |||
} | |||
public bool IsCommand(string message) | |||
{ | |||
bool isCommand = false; |
@@ -311,7 +311,7 @@ namespace Combot.Modules.Plugins | |||
private void TimedBan(Command curCommand, CommandMessage command) | |||
{ | |||
double timeout; | |||
if (double.TryParse(command.Arguments["Time"], out timeout)) | |||
if (double.TryParse(command.Arguments["Time"], out timeout) && timeout >= 0) | |||
{ | |||
BanNick(true, curCommand, command); | |||
Timer unban_trigger = new Timer(); |
@@ -0,0 +1,62 @@ | |||
{ | |||
"Name": "Timer", | |||
"ClassName": "Timer", | |||
"Enabled": true, | |||
"ChannelBlacklist": [ ], | |||
"NickBlacklist": [ ], | |||
"Commands": [ | |||
{ | |||
"Name": "Timer", | |||
"Description": "Adds a timer for the specified message.", | |||
"Enabled": true, | |||
"ChannelBlacklist": [ ], | |||
"NickBlacklist": [ ], | |||
"Triggers": [ | |||
"t", | |||
"timer" | |||
], | |||
"Arguments": [ | |||
{ | |||
"Name": "Time", | |||
"Description": "The time you want the timer set to in seconds.", | |||
"AllowedValues": [ ], | |||
"DependentArguments": [ ], | |||
"MessageTypes": [ | |||
0, | |||
1, | |||
2 | |||
], | |||
"Required": true | |||
}, | |||
{ | |||
"Name": "Message", | |||
"Description": "The message you want said to you when the timer expires.", | |||
"AllowedValues": [ ], | |||
"MessageTypes": [ | |||
0, | |||
1, | |||
2 | |||
], | |||
"Required": false | |||
} | |||
], | |||
"AllowedMessageTypes": [ | |||
0, | |||
1, | |||
2 | |||
], | |||
"AllowedAccess": [ | |||
0, | |||
1, | |||
2, | |||
3, | |||
4, | |||
5, | |||
6 | |||
], | |||
"ShowHelp": true, | |||
"SpamCheck": true | |||
} | |||
], | |||
"Options": [] | |||
} |
@@ -0,0 +1,33 @@ | |||
using System.Reflection; | |||
using System.Runtime.CompilerServices; | |||
using System.Runtime.InteropServices; | |||
// General Information about an assembly is controlled through the following | |||
// set of attributes. Change these attribute values to modify the information | |||
// associated with an assembly. | |||
[assembly: AssemblyTitle("Timer Module")] | |||
[assembly: AssemblyDescription("")] | |||
[assembly: AssemblyConfiguration("")] | |||
[assembly: AssemblyCompany("Teknik")] | |||
[assembly: AssemblyProduct("Combot")] | |||
[assembly: AssemblyCopyright("Copyright © 2015")] | |||
[assembly: AssemblyTrademark("")] | |||
[assembly: AssemblyCulture("")] | |||
// Setting ComVisible to false makes the types in this assembly not visible | |||
// to COM components. If you need to access a type in this assembly from | |||
// COM, set the ComVisible attribute to true on that type. | |||
[assembly: ComVisible(false)] | |||
// The following GUID is for the ID of the typelib if this project is exposed to COM | |||
[assembly: Guid("5c350b8e-5820-4034-9d67-49d2ddbfcc6f")] | |||
// Version information for an assembly consists of the following four values: | |||
// | |||
// Major Version | |||
// Minor Version | |||
// Build Number | |||
// Revision | |||
// | |||
// You can specify all the values or you can default the Build and Revision Numbers | |||
// by using the '*' as shown below: |
@@ -0,0 +1,81 @@ | |||
using System; | |||
using System.Collections.Generic; | |||
using System.Linq; | |||
using System.Threading; | |||
namespace Combot.Modules.Plugins | |||
{ | |||
public class Timer : Module | |||
{ | |||
private List<System.Timers.Timer> timers; | |||
private ReaderWriterLockSlim listLock; | |||
public override void Initialize() | |||
{ | |||
timers = new List<System.Timers.Timer>(); | |||
listLock = new ReaderWriterLockSlim(); | |||
Bot.CommandReceivedEvent += HandleCommandEvent; | |||
} | |||
public override void ParseCommand(CommandMessage command) | |||
{ | |||
Command foundCommand = Commands.Find(c => c.Triggers.Contains(command.Command)); | |||
switch (foundCommand.Name) | |||
{ | |||
case "Timer": | |||
double timeout; | |||
string message = command.Arguments.ContainsKey("Message") ? command.Arguments["Message"] : string.Empty; | |||
if (double.TryParse(command.Arguments["Time"], out timeout) && timeout > 0) | |||
{ | |||
if (message.StartsWith(Bot.ServerConfig.CommandPrefix)) | |||
{ | |||
string cmd = message.Split(new [] { ' ' }, StringSplitOptions.RemoveEmptyEntries).First(); | |||
if (foundCommand.Triggers.Contains(cmd.TrimStart(Bot.ServerConfig.CommandPrefix.ToCharArray()))) | |||
{ | |||
SendResponse(command.MessageType, command.Location, command.Nick.Nickname, "Recursion is bad."); | |||
break; | |||
} | |||
} | |||
System.Timers.Timer newTimer = new System.Timers.Timer(); | |||
newTimer.Interval = (timeout * 1000.0); | |||
newTimer.Enabled = true; | |||
newTimer.AutoReset = false; | |||
newTimer.Elapsed += (sender, e) => TimerElapsed(sender, e, message, command); | |||
listLock.EnterWriteLock(); | |||
timers.Add(newTimer); | |||
listLock.ExitWriteLock(); | |||
string addedTimer = string.Format("Timer added for {0} seconds from now.", timeout); | |||
SendResponse(command.MessageType, command.Location, command.Nick.Nickname, addedTimer); | |||
} | |||
else | |||
{ | |||
string notValid = "Please enter a valid time."; | |||
SendResponse(command.MessageType, command.Location, command.Nick.Nickname, notValid); | |||
} | |||
break; | |||
} | |||
} | |||
private void TimerElapsed(object sender, EventArgs e, string message, CommandMessage command) | |||
{ | |||
System.Timers.Timer timer = (System.Timers.Timer) sender; | |||
timer.Enabled = false; | |||
listLock.EnterWriteLock(); | |||
timers.Remove(timer); | |||
listLock.ExitWriteLock(); | |||
if (message.StartsWith(Bot.ServerConfig.CommandPrefix)) | |||
{ | |||
Bot.ExecuteCommand(message, command.Location, command.MessageType, command.Nick); | |||
} | |||
else | |||
{ | |||
if (string.IsNullOrEmpty(message)) | |||
{ | |||
message = "Your timer has elapsed!"; | |||
} | |||
message = "\u0002RING RING RING\u0002 " + message; | |||
SendResponse(MessageType.Query, command.Location, command.Nick.Nickname, message, false); | |||
} | |||
} | |||
} | |||
} |
@@ -0,0 +1,82 @@ | |||
<?xml version="1.0" encoding="utf-8"?> | |||
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | |||
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" /> | |||
<PropertyGroup> | |||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> | |||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> | |||
<ProjectGuid>{84166880-FC04-4F50-90CD-8486B797948A}</ProjectGuid> | |||
<OutputType>Library</OutputType> | |||
<AppDesignerFolder>Properties</AppDesignerFolder> | |||
<RootNamespace>Timer</RootNamespace> | |||
<AssemblyName>Timer</AssemblyName> | |||
<TargetFrameworkVersion>v4.5.1</TargetFrameworkVersion> | |||
<FileAlignment>512</FileAlignment> | |||
<TargetFrameworkProfile /> | |||
</PropertyGroup> | |||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> | |||
<DebugSymbols>true</DebugSymbols> | |||
<DebugType>full</DebugType> | |||
<Optimize>false</Optimize> | |||
<OutputPath>..\..\Bin\Debug\Modules\Timer\</OutputPath> | |||
<DefineConstants>DEBUG;TRACE</DefineConstants> | |||
<ErrorReport>prompt</ErrorReport> | |||
<WarningLevel>4</WarningLevel> | |||
</PropertyGroup> | |||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> | |||
<DebugType>pdbonly</DebugType> | |||
<Optimize>true</Optimize> | |||
<OutputPath>..\..\Bin\Release\Modules\Timer\</OutputPath> | |||
<DefineConstants>TRACE</DefineConstants> | |||
<ErrorReport>prompt</ErrorReport> | |||
<WarningLevel>4</WarningLevel> | |||
</PropertyGroup> | |||
<ItemGroup> | |||
<Reference Include="System" /> | |||
<Reference Include="System.Core" /> | |||
<Reference Include="System.Xml.Linq" /> | |||
<Reference Include="System.Data.DataSetExtensions" /> | |||
<Reference Include="Microsoft.CSharp" /> | |||
<Reference Include="System.Data" /> | |||
<Reference Include="System.Xml" /> | |||
</ItemGroup> | |||
<ItemGroup> | |||
<Compile Include="Timer.cs" /> | |||
<Compile Include="Properties\AssemblyInfo.cs" /> | |||
</ItemGroup> | |||
<ItemGroup> | |||
<ProjectReference Include="..\..\Combot\Combot.csproj"> | |||
<Project>{23e4c371-16e4-4fac-8b11-44288399bb55}</Project> | |||
<Name>Combot</Name> | |||
</ProjectReference> | |||
<ProjectReference Include="..\..\IRCServices\IRCServices.csproj"> | |||
<Project>{65fcbf1c-8c9e-4688-becc-185d9030899f}</Project> | |||
<Name>IRCServices</Name> | |||
</ProjectReference> | |||
</ItemGroup> | |||
<ItemGroup> | |||
<None Include="Module.Default.json"> | |||
<CopyToOutputDirectory>Always</CopyToOutputDirectory> | |||
</None> | |||
<None Include="packages.config" /> | |||
</ItemGroup> | |||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> | |||
<PropertyGroup> | |||
<PostBuildEvent>md "$(SolutionDir)$(ConfigurationName)\Modules\$(TargetName)" | |||
copy /Y "$(TargetPath)" "$(SolutionDir)$(ConfigurationName)\Modules\$(TargetName)" | |||
copy /Y "$(TargetDir)Module.Default.json" "$(SolutionDir)$(ConfigurationName)\Modules\$(TargetName)"</PostBuildEvent> | |||
</PropertyGroup> | |||
<Import Project="..\..\packages\GitVersionTask.2.0.1\Build\GitVersionTask.targets" Condition="Exists('..\..\packages\GitVersionTask.2.0.1\Build\GitVersionTask.targets')" /> | |||
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild"> | |||
<PropertyGroup> | |||
<ErrorText>This project references NuGet package(s) that are missing on this computer. Enable NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText> | |||
</PropertyGroup> | |||
<Error Condition="!Exists('..\..\packages\GitVersionTask.2.0.1\Build\GitVersionTask.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\..\packages\GitVersionTask.2.0.1\Build\GitVersionTask.targets'))" /> | |||
</Target> | |||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it. | |||
Other similar extension points exist, see Microsoft.Common.targets. | |||
<Target Name="BeforeBuild"> | |||
</Target> | |||
<Target Name="AfterBuild"> | |||
</Target> | |||
--> | |||
</Project> |
@@ -0,0 +1,4 @@ | |||
<?xml version="1.0" encoding="utf-8"?> | |||
<packages> | |||
<package id="GitVersionTask" version="2.0.1" targetFramework="net451" developmentDependency="true" /> | |||
</packages> |