本文整理匯總了C#中Bot.Connect方法的典型用法代碼示例。如果您正苦於以下問題:C# Bot.Connect方法的具體用法?C# Bot.Connect怎麽用?C# Bot.Connect使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Bot
的用法示例。
在下文中一共展示了Bot.Connect方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: Main
static void Main()
{
using (var bot = new Bot())
{
bot.AddPlugin(new TriviaPlugin());
bot.Connect("irc.quakenet.org", "GinnTrivia", "GinnTrivia", "GinnTrivia");
Console.WriteLine("Connected...");
bot.Join("#ginnunga");
bot.Message +=
(channel, sender, text) => Console.WriteLine(string.Format("{0}/{1}: {2}", channel.Name, sender, text));
Console.ReadKey();
}
}
示例2: Main
private static void Main(String[] args)
{
// Find out if in portable mode.
String portablePath = AppDomain.CurrentDomain.BaseDirectory;
String applicationDataPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData),
_applicationDataDirectory);
String portableStorage = Path.Combine(portablePath, _storagePath, _globalStorageFile);
String applicationDataStorage = Path.Combine(applicationDataPath, _storagePath, _globalStorageFile);
bool portable = File.Exists(portableStorage);
bool nonPortable = File.Exists(applicationDataStorage);
Portable = portable || !nonPortable;
if(Portable)
{
BasePath = portablePath;
}
else
{
BasePath = applicationDataPath;
}
// Add file logging
FileTarget fileTarget = new FileTarget();
fileTarget.Layout =
"${longdate}|${level:uppercase=true}|${logger}|${message}|${exception:maxInnerExceptionLevel=5}";
fileTarget.FileName = Path.Combine(BasePath, _logFile);
LoggingRule fileRule = new LoggingRule("*", LogLevel.Warn, fileTarget);
LogManager.Configuration.AddTarget("File", fileTarget);
LogManager.Configuration.LoggingRules.Add(fileRule);
LogManager.Configuration.Reload();
// Bootstrap dependencies
_bootstrapper = new AppBootstrapper();
// Open configuration
IStorageManager storage = CompositionManager.Get<IStorageManager>(new NamedParameter("path",
Path.Combine(BasePath, _storagePath)), new NamedParameter("extension", _storageExtension),
new NamedParameter("globalFile", _globalStorageFile));
// Create command manager
ICommandManager command = CompositionManager.Get<ICommandManager>();
command.Add(CommandBuilder.CreateConverter<String, ICommand, ConversionContext>(
(str, context) => context.Bot.Command.GetUnambigousCommand(str))
);
command.Add(CommandBuilder.CreateConverter<String, IEnumerable<ICommand>, ConversionContext>(
(str, context) => context.Bot.Command.GetUnambigousCommands(str))
);
command.Add(CommandBuilder.CreateConverter<String, IPlugin, ConversionContext>(
(str, context) => context.Bot.Plugin.Get(str))
);
command.Add(CommandBuilder.CreateConverter<String, IChannel, ConversionContext>(
(str, context) => context.Message.Connection.GetExistingChannel(str))
);
command.Add(CommandBuilder.CreateConverter<String, IUser, ConversionContext>(
(str, context) => context.Message.Connection.GetExistingUser(str))
);
command.Add(CommandBuilder.CreateConverter<String, IChannelUser, ConversionContext>(
(str, context) => (context.Message.Receiver as IChannel).GetUser(str))
);
command.Add(CommandBuilder.CreateConverter<String, IdentityMask, ConversionContext>(
(str, context) => IdentityMask.Parse(str))
);
command.Add(CommandBuilder.CreateConverter<String, IIdentity, ConversionContext>(
(str, context) => Identity.Parse(str))
);
command.Add(CommandBuilder.CreateConverter<String, IBotGroup, ConversionContext>(
(str, context) => context.Bot.Authentication.GetGroup(str))
);
command.Add(CommandBuilder.CreateConverter<String, IBotUser, ConversionContext>(
(str, context) => context.Bot.Authentication.GetUser(str))
);
// Create authentication manager
IAuthenticationManager authentication = CompositionManager.Get<IAuthenticationManager>();
// Create permission manager
IPermissionManager permission = CompositionManager.Get<IPermissionManager>();
// Create plugin manager
IPluginManager plugin = CompositionManager.Get<IPluginManager>();
// Create bot
IClient client = CompositionManager.Get<IClient>();
Bot bot = new Bot(client, storage, command, plugin, authentication, permission);
GetAssemblies().Do(x => plugin.Load(x, bot));
bot.Init();
if(bot.Connections.IsEmpty())
{
Console.WriteLine("No connections have been set up yet, adding a connection now.");
Console.WriteLine("Server address?");
String address = Console.ReadLine();
Console.WriteLine("Server port?");
ushort port = Convert.ToUInt16(Console.ReadLine());
Console.WriteLine("Nickname?");
String nickname = Console.ReadLine();
Console.WriteLine("Username?");
String username = Console.ReadLine();
//.........這裏部分代碼省略.........
示例3: Update
public void Update()
{
if (_connectStarted.Elapsed.TotalSeconds > 120)
{
if (_bot != null)
_bot.Disconnect();
Status = ConnectionStatus.Disconnected;
}
if (Status != ConnectionStatus.Disconnected)
return;
_hasConnected = false;
_connectStarted.Restart();
Program.Logger.Info("Connecting");
_bot = new Bot(Program.Settings.Username, Program.Settings.Password);
_bot.OnConnected += sender =>
{
_hasConnected = true;
_connectStarted.Stop();
_bot.PersonaName = Program.Settings.PersonaName;
_bot.PersonaState = EPersonaState.Online;
Status = ConnectionStatus.Connected;
Program.Logger.Info("Connected");
};
_bot.OnDisconnected += (sender, reason) =>
{
if (_hasConnected)
{
Program.Logger.Info("Disconnected");
_hasConnected = false;
}
Status = ConnectionStatus.Disconnected;
};
_bot.OnFriendRequest += (sender, user) => _bot.AddFriend(user.Id);
_bot.OnPrivateEnter += (sender, chat) =>
{
chat.OnMessage += (chatSender, messageSender, message) =>
Command.Handle(new CommandTarget(chatSender, messageSender.Id), message, "");
};
_bot.OnChatInvite += (sender, chat, @by) =>
{
if (chat.Id.IsIndividualAccount)
_bot.Join(chat.Id);
};
_bot.Connect();
Status = ConnectionStatus.Connecting;
}