Exemplo n.º 1
0
 public bool IsCommand(GatewayMessage message)
 {
     return(message.Content.Length > 0 &&
            message.Content.TrimStart()[0] == '?' &&
            message.Author.Id != _clientInfoRepository.GetClientInfo().User.Id);
     // Disable bot possibility to handle own commands
 }
Exemplo n.º 2
0
        public async Task HandleAsync(object @event)
        {
            if (_clientInfoRepository.GetClientInfo() != null)
            {
                _clientInfoRepository.DeleteClientInfo();
            }

            _clientInfoRepository.AddClientInfo(JsonConvert.DeserializeObject <ClientInfo>(@event.ToString()));

            await _discordRestClient.PostMessage("764840399696822322", "Ready to serve");
        }
Exemplo n.º 3
0
        public async Task CreateConnectionAsync(WebSocketCloseStatus socketCloseStatus)
        {
            var clientInfo = _clientInfoRepository.GetClientInfo();
            var gatewayUrl = await _discordRestClient.GetGatewayUrlAsync();

            if (clientInfo?.SessionId != null)
            {
                // Resume session
                await _discordSocketClient.DisconnectAsync(socketCloseStatus);

                await _discordSocketClient.ConnectAsync(new Uri(gatewayUrl));
                await ResumeSession(clientInfo.SessionId);
            }
            else
            {
                // Create new session
                // Disconnect client for safety (could be in connected state after InvalidSession event)
                await _discordSocketClient.DisconnectAsync(socketCloseStatus);

                await _discordSocketClient.ConnectAsync(new Uri(gatewayUrl));
                await IdentifyClient();
            }
        }