protected override void DoConnect() { socket = new DiscordWebsocket(); socket.Token = Config.BotToken; socket.Status = Config.Status; socket.GetStatus = GetStatusMessage; socket.OnReady = HandleReadyEvent; socket.OnMessageCreate = HandleMessageEvent; socket.OnChannelCreate = HandleChannelEvent; socket.Connect(); }
protected override void OnStop() { socket = null; if (api != null) { api.StopAsync(); api = null; } base.OnStop(); OnPlayerConnectEvent.Unregister(HandlePlayerConnect); OnPlayerDisconnectEvent.Unregister(HandlePlayerDisconnect); OnPlayerActionEvent.Unregister(HandlePlayerAction); }
protected override void DoConnect() { socket = new DiscordWebsocket(); socket.Session = session; socket.Token = Config.BotToken; socket.Presence = Config.PresenceEnabled; socket.Status = Config.Status; socket.Activity = Config.Activity; socket.GetStatus = GetStatusMessage; socket.OnReady = HandleReadyEvent; socket.OnResumed = HandleResumedEvent; socket.OnMessageCreate = HandleMessageEvent; socket.OnChannelCreate = HandleChannelEvent; socket.Connect(); }
void DoUpdateStatus(SchedulerTask task) { DateTime now = DateTime.UtcNow; // OK to queue next status update now lock (updateLocker) { updateScheduled = false; nextUpdate = now.AddSeconds(0.5); // ensures status update can't be sent more than once every 0.5 seconds } DiscordWebsocket s = socket; // websocket gets disconnected with code 4003 if tries to send data before identifying // https://discord.com/developers/docs/topics/opcodes-and-status-codes if (s == null || !s.SentIdentify) { return; } try { s.UpdateStatus(); } catch { } }
protected override void DoConnect() { // TODO implement properly socket = new DiscordWebsocket(); disconnecting = false; disconnected = false; Channels = Config.Channels.SplitComma(); OpChannels = Config.OpChannels.SplitComma(); operatorIds = Config.OperatorUsers.SplitComma(); socket.Token = Config.BotToken; socket.Handler = HandleEvent; socket.GetStatus = GetStatus; socket.OnReady = OnReady; Thread worker = new Thread(IOThread); worker.Name = "DiscordRelayBot"; worker.IsBackground = true; worker.Start(); }