forked from Uncled1023/Combot
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
65 lines
1.4 KiB
65 lines
1.4 KiB
8 years ago
|
using System;
|
||
|
using System.Collections.Generic;
|
||
|
using System.Linq;
|
||
|
using System.Text;
|
||
|
using System.Net;
|
||
|
using System.Threading.Tasks;
|
||
|
using Combot.IRCServices;
|
||
|
|
||
|
namespace Combot
|
||
|
{
|
||
|
public class Bot
|
||
|
{
|
||
|
public event Action<BotError> ErrorEvent;
|
||
|
public Config Config;
|
||
|
public IRC IRC;
|
||
|
public bool Connected = false;
|
||
|
|
||
|
public Bot()
|
||
|
{
|
||
|
Config = new Config();
|
||
|
IRC = new IRC();
|
||
|
|
||
|
IRC.DisconnectEvent += HandleDisconnectEvent;
|
||
|
}
|
||
|
|
||
|
public bool Connect()
|
||
|
{
|
||
|
int i = 0;
|
||
|
do
|
||
|
{
|
||
|
if (Config.Server.Hosts.Count > i)
|
||
|
{
|
||
|
Connected = IRC.Connect(Config.Server.Hosts[i].Address, Config.Server.Hosts[i].Port, 5000);
|
||
|
i++;
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
break;
|
||
|
}
|
||
|
}
|
||
|
while (!Connected);
|
||
|
|
||
|
return Connected;
|
||
|
}
|
||
|
|
||
|
public bool Disconnect()
|
||
|
{
|
||
|
IRC.Disconnect();
|
||
|
Connected = false;
|
||
|
|
||
|
return Connected;
|
||
|
}
|
||
|
|
||
|
public void Login()
|
||
|
{
|
||
|
IRC.Login(Config.Server.Name, new Nick() { Nickname = Config.Nick, Host = Dns.GetHostName(), Realname = Config.Realname });
|
||
|
}
|
||
|
|
||
|
private void HandleDisconnectEvent()
|
||
|
{
|
||
|
Connected = false;
|
||
|
}
|
||
|
}
|
||
|
}
|