This commit is contained in:
Ben Harris 2019-02-06 01:18:03 -05:00
commit f7dd14f08c
5 changed files with 118 additions and 0 deletions

34
.gitignore vendored Normal file
View File

@ -0,0 +1,34 @@
*.swp
*.*~
project.lock.json
.DS_Store
*.pyc
nupkg/
# Visual Studio Code
.vscode
# User-specific files
*.suo
*.user
*.userosscache
*.sln.docstates
# Build results
[Dd]ebug/
[Dd]ebugPublic/
[Rr]elease/
[Rr]eleases/
x64/
x86/
build/
bld/
[Bb]in/
[Oo]bj/
[Oo]ut/
msbuild.log
msbuild.err
msbuild.wrn
# Visual Studio 2015
.vs/

12
App.config Normal file
View File

@ -0,0 +1,12 @@
<configuration>
<appSettings>
<add key="irc_host" value="localhost"/>
<add key="irc_port" value="6667"/>
<add key="irc_ssl" value="false"/>
<add key="bot_nick" value="agrajag"/>
<add key="bot_user" value="agrajag"/>
<add key="bot_owner" value="ben"/>
<add key="channels" value="#zaphod"/>
</appSettings>
</configuration>

54
Program.cs Normal file
View File

@ -0,0 +1,54 @@
using ChatSharp;
using System;
using System.Configuration;
using System.Collections.Specialized;
using System.Linq;
namespace agrajag
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("starting agrajag");
NameValueCollection cfg = ConfigurationManager.AppSettings;
var client = new IrcClient(
$"{cfg.Get("irc_host")}:{cfg.Get("irc_port")}",
new IrcUser(cfg.Get("bot_nick"), cfg.Get("bot_user")),
cfg.Get("irc_ssl") == "true"
);
client.ConnectionComplete += (s, e) => {
Console.WriteLine($"connected. joining {cfg.Get("channels")}");
cfg.Get("channels")
.Split(',')
.ToList()
.ForEach(c => client.JoinChannel(c));
};
client.ChannelMessageReceived += (s, e) =>
{
var channel = client.Channels[e.PrivateMessage.Source];
if (e.PrivateMessage.Message == ".list")
channel.SendMessage(string.Join(", ", channel.Users.Select(u => u.Nick)));
else if (e.PrivateMessage.Message.StartsWith(".ban "))
{
if (!channel.UsersByMode['@'].Contains(client.User))
{
channel.SendMessage("I'm not an op here!");
return;
}
var target = e.PrivateMessage.Message.Substring(5);
client.WhoIs(target, whois => channel.ChangeMode("+b *!*@" + whois.User.Hostname));
}
};
client.ConnectAsync();
while (true) ; // Waste CPU cycles
}
}
}

18
agrajag.csproj Normal file
View File

@ -0,0 +1,18 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp2.2</TargetFramework>
</PropertyGroup>
<ItemGroup>
<Reference Include="ChatSharp">
<HintPath>./chatsharp.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup>
<PackageReference Include="System.Configuration.ConfigurationManager" Version="4.5.0" />
</ItemGroup>
</Project>

BIN
chatsharp.dll Normal file

Binary file not shown.