public TwitchBot() { channelList = new HashSet<String>(); ConnectionArgs cargs = new ConnectionArgs(Settings.Default.IrcName, Settings.Default.IrcServer) { Port = Settings.Default.Port, ServerPassword = Settings.Default.IrcPassword }; log.Info($"Trying to connect to {cargs.Hostname}:{cargs.Port} as {Settings.Default.IrcName}"); connection = new Connection(cargs, false, false); connection.Listener.OnRegistered += new RegisteredEventHandler(OnRegistered); connection.Listener.OnRegistered += new RegisteredEventHandler(ResetHeartbeatMonitor); connection.Listener.OnPublic += new PublicMessageEventHandler(OnPublic); connection.Listener.OnPublic += new PublicMessageEventHandler((a, b, c) => ResetHeartbeatMonitor()); //Listen for bot commands sent as private messages connection.Listener.OnPrivate += new PrivateMessageEventHandler(OnPrivate); connection.Listener.OnPrivate += new PrivateMessageEventHandler((a, b) => ResetHeartbeatMonitor()); //Listen for notification that an error has ocurred connection.Listener.OnError += new ErrorMessageEventHandler(OnError); //Listen for notification that we are no longer connected. connection.Listener.OnDisconnected += new DisconnectedEventHandler(OnDisconnected); connection.Listener.OnDisconnecting += new DisconnectingEventHandler(OnDisconnecting); connection.Listener.OnPing += new PingEventHandler(OnPing); connection.Listener.OnPing += new PingEventHandler((a) => ResetHeartbeatMonitor()); connection.Listener.OnJoin += new JoinEventHandler(onJoin); connection.Listener.OnJoin += new JoinEventHandler((a, b) => ResetHeartbeatMonitor()); connection.Listener.OnPart += new PartEventHandler(OnPart); connection.Listener.OnPart += new PartEventHandler((a, b, c) => ResetHeartbeatMonitor()); connection.Listener.OnQuit += new QuitEventHandler(OnQuit); connection.Listener.OnInfo += new InfoEventHandler(OnInfo); connection.Listener.OnInfo += new InfoEventHandler((a, b) => ResetHeartbeatMonitor()); heartbeatMonitor = new Timer(TimeSpan.FromSeconds(10).TotalMilliseconds); heartbeatMonitor.AutoReset = true; heartbeatMonitor.Elapsed += HeartbeatMonitor_Elapsed; heartbeatMonitor.Start(); reconnectTimer = new Timer(); reconnectTimer.AutoReset = false; reconnectTimer.Elapsed += ReconnectTimer_Elapsed; reconnectBackoff = new ExponentialBackoff(); }
public SteamBot() { reconnectBackoff = new ExponentialBackoff(); // create our steamclient instance steamClient = new SteamClient(); // create the callback manager which will route callbacks to function calls manager = new CallbackManager(steamClient); // get the steamuser handler, which is used for logging on after successfully connecting steamUser = steamClient.GetHandler<SteamUser>(); // get the steam friends handler, which is used for interacting with friends on the network after logging on steamFriends = steamClient.GetHandler<SteamFriends>(); steamApps = steamClient.GetHandler<SteamApps>(); steamClient.AddHandler(new CustomHandler()); // register a few callbacks we're interested in // these are registered upon creation to a callback manager, which will then route the callbacks // to the functions specified manager.Subscribe<SteamClient.ConnectedCallback>(OnConnected); manager.Subscribe<SteamClient.DisconnectedCallback>(OnDisconnected); manager.Subscribe<SteamUser.LoggedOnCallback>(OnLoggedOn); manager.Subscribe<SteamUser.LoggedOffCallback>(OnLoggedOff); //manager.Subscribe<SteamUser.MarketingMessageCallback>(OnMarketing); // we use the following callbacks for friends related activities manager.Subscribe<SteamUser.AccountInfoCallback>(OnAccountInfo); manager.Subscribe<SteamFriends.FriendsListCallback>(OnFriendsList); manager.Subscribe<SteamFriends.PersonaStateCallback>(OnPersonaState); manager.Subscribe<SteamFriends.FriendAddedCallback>(OnFriendAdded); manager.Subscribe<SteamFriends.FriendMsgCallback>(OnFriendMsg); manager.Subscribe<SteamFriends.FriendMsgEchoCallback>(EchoMsg); manager.Subscribe<SteamFriends.FriendMsgHistoryCallback>(ch_OnOfflineMessage2); manager.Subscribe<SteamFriends.ChatInviteCallback>(OnChatInvite); manager.Subscribe<SteamUser.UpdateMachineAuthCallback>(OnMachineAuth); }