示例#1
0
        private async Task HandleGroupMessage(Message message)
        {
            _metrics.HandleGroupMessage(message.Chat.Id, string.IsNullOrEmpty(message.Text) ? 0 : message.Text.Length);
            if (!_validator.GroupMessageValid(message))
            {
                Log.Information("Message by {ChatId} | {From} is not valid", message.Chat.Id, message.From);
                return;
            }

            if (await _groupsBlacklist.InBlacklist(message.Chat.Id))
            {
                Log.Information("Group {ChatId} | {From} is in the blacklist", message.Chat.Id, message.From);
                return;
            }

            if (message.IsCommand())
            {
                Log.Information("Message by {ChatId} | {From} is a command", message.Chat.Id, message.From);
                await HandleCommand(message);

                return;
            }

            if (message.Text.StartsWith($"@{_botUsername} set:"))
            {
                Log.Information("Message by {ChatId} | {From} is a setting changing", message.Chat.Id, message.From);
                await HandleSettingChanging(message);

                return;
            }

            switch (await _settingsProcessor.GetTranslationMode(message.Chat.Id))
            {
            case TranslationMode.Forwards:
                Log.Information("Group {ChatId} | {From} is using Forwards translation mode", message.Chat.Id, message.From);
                if (message.ForwardSenderName == null)
                {
                    return;
                }
                break;

            case TranslationMode.Manual:
                Log.Information("Group {ChatId} | {From} is using Manual translation mode", message.Chat.Id, message.From);
                if (message.ReplyToMessage == null)
                {
                    return;
                }
                if (message.Text == _botUsername || message.Text == "!translate" || await RequireTranslation(message.Text, await _settingsProcessor.GetGroupLanguage(message.Chat.Id)))
                {
                    await HandleTranslation(message.ReplyToMessage);
                }

                return;
            }

            if (await RequireTranslation(message.Text, await _settingsProcessor.GetGroupLanguage(message.Chat.Id)))
            {
                await HandleTranslation(message);
            }
        }