Пример #1
0
        public async Task SendResponseAsync(IMessageDetail message, Response response)
        {
            bool isFromConsole = message is ConsoleMessageDetail;
            bool isFromSocket  = message is SocketMessageWrapper;

            if (response.ResponseType == ResponseType.None)
            {
                // Nothing to do.
            }
            else if (isFromConsole || response.ResponseType == ResponseType.LogOnly)
            {
                SendMessageToConsole(response);
            }
            else
            {
                if (isFromSocket)
                {
                    try
                    {
                        SocketMessageWrapper socketMessageWrapper = (SocketMessageWrapper)message;

                        // If private response, get the DM channel to the user, otherwise use the current channel.
                        IMessageChannel responseChannel =
                            response.ResponseType == ResponseType.Private ?
                            (await socketMessageWrapper.User.GetOrCreateDMChannelAsync()) :
                            (IMessageChannel)socketMessageWrapper.Channel;

                        if (response.ResponseType != ResponseType.Default_React)
                        {
                            SendMessage(response, responseChannel);
                        }
                        else
                        {
                            await socketMessageWrapper.socketMessage.AddReactionAsync(new Emoji(response.Message)).ConfigureAwait(false);
                        }
                    }
                    catch (Exception ex)
                    {
                        ErrorLogger.LogException(ex, ErrorSeverity.Error);
                        ErrorLogger.LogDebug($"Cannot reply to channel {message?.ChannelName} ({message?.ChannelId}) by user {message?.Username} ({message?.UserId}) with response {response?.Message}, Type {response?.ResponseType}, as the message sending threw an exception.");
                    }
                }
                else
                {
                    ErrorLogger.LogError(new Error(ErrorCode.NotImplemented, ErrorSeverity.Error, $"Cannot reply to channel {message.ChannelName} ({message.ChannelId}) by user {message.Username} ({message.UserId}) as the message is not from the socket."));
                }
            }
        }
Пример #2
0
        internal void HandleMessageReceived(SocketMessageWrapper socketMessage)
        {
            // Don't respond to bots (includes us!)
            if (socketMessage.User.IsBot)
            {
                return;
            }

            // First, get the server settings for the guild this message is from.
            ServerSettings serverSettings = serverSettingsHandler.GetOrCreateServerSettings(socketMessage.GuildId);

            // And the user settings for the user this message is from.
            UserSettings userSettings = userSettingsHandler.GetOrCreateUserSettings(socketMessage.UserId);

            // Handle the command
            HandleCommandReceived(new SenderSettings(serverSettings, userSettings), socketMessage);
        }