Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/stwalkerster/ircbot-commandlib
C# IRC bot command parsing library
https://github.com/stwalkerster/ircbot-commandlib
Last synced: 1 day ago
JSON representation
C# IRC bot command parsing library
- Host: GitHub
- URL: https://github.com/stwalkerster/ircbot-commandlib
- Owner: stwalkerster
- Created: 2021-05-30T00:16:10.000Z (over 3 years ago)
- Default Branch: master
- Last Pushed: 2024-08-14T23:48:17.000Z (3 months ago)
- Last Synced: 2024-08-15T01:22:43.590Z (3 months ago)
- Language: C#
- Homepage:
- Size: 189 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
An IRC bot command-handling library.
## Usage
In-depth knowledge of [Castle Windsor](https://github.com/castleproject/Windsor/blob/master/docs/README.md) is assumed here. It's also assumed you know how to use `Stwalkerster.IrcClient`.Grab yourself the following [NuGet](https://docs.microsoft.com/en-us/nuget/what-is-nuget) packages:
```xml
```I'll assume you're using a root namespace of `MyBot`.
Create yourself a basic [installer](https://github.com/castleproject/Windsor/blob/master/docs/installers.md) (this can be the same installer as the IRC client installer):
```csharp
namespace MyBot.Startup
{
public class Installer : IWindsorInstaller
{
public void Install(IWindsorContainer container, IConfigurationStore store)
{
container.AddFacility(f => f.LogUsing().WithConfig("log4net.xml"));
container.AddFacility();
container.AddFacility(f => f.DeferredStart());
container.AddFacility();container.Install(
new Stwalkerster.IrcClient.Startup.Installer()
);container.Register(
Classes.FromThisAssembly().InNamespace("MyBot.Services").WithServiceAllInterfaces(),
Classes.FromThisAssembly().InNamespace("MyBot.Commands").LifestyleTransient(),
Component.For().ImplementedBy(),
Component.For().Instance(new IrcConfiguration(/* ... */)),
Component.For().ImplementedBy().Start()
);
}
}
}
```Configure log4net.
Create your main class:
```csharp
namespace MyBot.Services
{
public class Program : IApplication
{
public static void Main()
{
var container = new WindsorContainer();
container.Install(FromAssembly.This());
var app = container.Resolve();
}public Program(IIrcClient client)
{
client.JoinChannel("##stwalkerster-development");
}
public void Stop() {}
public void Run() {}
}
}
```Implement `IConfigurationProvider` and `IFlagService`:
```csharp
namespace MyBot.Services
{
public class ConfigProvider : IConfigurationProvider
{
public string CommandPrefix { get { return "!"; } }
public string DebugChannel { get { return "##stwalkerster-development"; } }
}public class BasicFlagService : IFlagService
{
public bool UserHasFlag(IUser user, string flag) { return true; }
public IEnumerable GetFlagsForUser(IUser user) { return new[] {"A", "D", "P", "O", "B", "C"}; }
}
}
```
The string array is a list of flags for which the user should be reported as having access to - the implementation above is very basic, but should be extended into your own access control system.Finally, implement your commands in the `MyBot.Command` namespace, using `Stwalkerster.Bot.CommandLib.Commands.CommandUtilities.CommandBase` as a base class, and using the two attributes:
```csharp
[CommandInvocation("whoami")]
[CommandFlag("B")]
````CommandInvocation` determines what you'll use to execute the command - in the above example, you'd run `!whoami`. `CommandFlag` determines what is passed to `IFlagService` for access control. This is a simple string, though there are some predefined single-letter flags in `Stwalkerster.Bot.CommandLib.Model.Flag`.