Browse Source

Added initial Module and Access class. Modified class initialization sequence

tags/3.0.0
Teknikode 5 years ago
parent
commit
2bf841fd34
8 changed files with 195 additions and 6 deletions
  1. 12
    0
      Access.cs
  2. 20
    0
      Bot.cs
  3. 7
    0
      Combot.csproj
  4. 28
    0
      Config.cs
  5. 4
    2
      IRC/IRCService.cs
  6. 3
    1
      IRC/IRCTypes.cs
  7. 108
    3
      IRC/Messages.cs
  8. 13
    0
      Module.cs

+ 12
- 0
Access.cs View File

@@ -0,0 +1,12 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Combot
{
class Access
{
}
}

+ 20
- 0
Bot.cs View File

@@ -0,0 +1,20 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Combot
{
class Bot
{
public Config Config;

private IRCService _ircService;

internal Bot()
{
_ircService = new IRCService(this);
}
}
}

+ 7
- 0
Combot.csproj View File

@@ -39,15 +39,22 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Access.cs" />
<Compile Include="Bot.cs" />
<Compile Include="Config.cs" />
<Compile Include="IRC\IRCService.cs" />
<Compile Include="IRC\IRCTypes.cs" />
<Compile Include="IRC\Messages.cs" />
<Compile Include="Methods.cs" />
<Compile Include="Module.cs" />
<Compile Include="Properties.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="TCP\TCPInterface.cs" />
<Compile Include="TCP\TCPTypes.cs" />
</ItemGroup>
<ItemGroup>
<Folder Include="Modules\" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- 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.

+ 28
- 0
Config.cs View File

@@ -0,0 +1,28 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Combot
{
class Config
{
private Nick _nick;
public Nick Nick
{
get
{
return _nick;
}

set
{
if (value != _nick)
{
_nick = value;
}
}
}
}
}

+ 4
- 2
IRC/IRCService.cs View File

@@ -11,13 +11,15 @@ namespace Combot
{
public Action<BotError> ErrorEvent;

private Bot _bot;
private TCPInterface _tcp;
private Messages _messages;

internal IRCService()
internal IRCService(Bot bot)
{
_bot = bot;
_tcp = new TCPInterface();
_messages = new Messages(_tcp);
_messages = new Messages(_tcp, _bot);
}

internal bool Connect(IPAddress IP, int port, int readTimeout, int allowedFailedCount = 0)

+ 3
- 1
IRC/IRCTypes.cs View File

@@ -19,7 +19,9 @@ namespace Combot
{
Service = 0,
Channel = 1,
Query = 2
Query = 2,
Notice = 3,
CTCP = 4
}

public enum ChannelMode

+ 108
- 3
IRC/Messages.cs View File

@@ -12,14 +12,119 @@ namespace Combot
public event Action<Message> MessageSentEvent;

private TCPInterface _tcp;
private static Queue<Message> _messageQueue;
private Bot _bot;

internal Messages(TCPInterface tcp)
internal Messages(TCPInterface tcp, Bot bot)
{
_tcp = tcp;
_messageQueue = new Queue<Message>();
_bot = bot;
}

private void MessageParser()
{
while(_tcp.Connected)
{
string response = _tcp.Read();
}
}

internal void SendMessage(Message message)
{
if (message.Type == MessageType.Channel || message.Type == MessageType.Query)
{
if (MessageSentEvent != null)
{
MessageSentEvent(message);
}
}
}

internal void SendMessage(Nick nick, string message)
{
Message msg = new Message();
msg.Receiver = nick;
msg.Type = MessageType.Query;
msg.Sender = _bot.Config.Nick;
msg.Message = message;
SendMessage(msg);
}

internal void SendMessage(Channel channel, string message)
{
Message msg = new Message();
msg.Channel = channel;
msg.Type = MessageType.Channel;
msg.Sender = _bot.Config.Nick;
msg.Message = message;
SendMessage(msg);
}

internal void SendNotice(Message message)
{
if (message.Type == MessageType.Notice)
{
if (MessageSentEvent != null)
{
MessageSentEvent(message);
}
}
}

internal void SendNotice(Nick nick, string message)
{
Message msg = new Message();
msg.Receiver = nick;
msg.Type = MessageType.Notice;
msg.Sender = _bot.Config.Nick;
msg.Message = message;
SendNotice(msg);
}

internal void SendNotice(Channel channel, string message)
{
Message msg = new Message();
msg.Channel = channel;
msg.Type = MessageType.Notice;
msg.Sender = _bot.Config.Nick;
msg.Message = message;
SendNotice(msg);
}

internal void SendCTCP(Message message)
{
if (message.Type == MessageType.CTCP)
{
if (MessageSentEvent != null)
{
MessageSentEvent(message);
}
}
}

internal void SendCTCP(Nick nick, string message)
{
Message msg = new Message();
msg.Receiver = nick;
msg.Type = MessageType.CTCP;
msg.Sender = _bot.Config.Nick;
msg.Message = message;
SendCTCP(msg);
}

internal void SendCTCP(Channel channel, string message)
{
Message msg = new Message();
msg.Channel = channel;
msg.Type = MessageType.CTCP;
msg.Sender = _bot.Config.Nick;
msg.Message = message;

SendCTCP(msg);
}
}
}

+ 13
- 0
Module.cs View File

@@ -0,0 +1,13 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Combot
{
class Module
{
internal virtual void Initialize() { }
}
}

Loading…
Cancel
Save