Example #1
0
        private static async Task MainMethod2(object sender, MessageEventArgs e)
        {
            TelegramBotClient telegramBotClientBot = null;

            if (sender is TelegramBotClient tmp)
            {
                telegramBotClientBot = tmp;
            }

            if (telegramBotClientBot == null)
            {
                return;
            }

            var telegramBotClient = TelegramBotAbstract.GetFromRam(telegramBotClientBot);

            var toExit = await ModerationCheck.CheckIfToExitAndUpdateGroupList(telegramBotClient, e);

            if (toExit)
            {
                await LeaveChat.ExitFromChat(telegramBotClient, e);

                return;
            }

            var toExitBecauseUsernameAndNameCheck = await ModerationCheck.CheckUsernameAndName(e, telegramBotClient);

            if (toExitBecauseUsernameAndNameCheck)
            {
                return;
            }

            var checkSpam = ModerationCheck.CheckSpam(e);

            if (checkSpam != SpamType.ALL_GOOD)
            {
                await ModerationCheck.AntiSpamMeasure(telegramBotClient, e, checkSpam);

                return;
            }

            if (e.Message.Text != null && e.Message.Text.StartsWith("/"))
            {
                await CommandDispatcher.CommandDispatcherMethod(telegramBotClient, e);
            }
            else
            {
                await TextConversation.DetectMessage(telegramBotClient, e);
            }
        }
Example #2
0
        private static async Task MainMethod2(object sender, MessageEventArgs e)
        {
            TelegramBotClient   telegramBotClientBot = null;
            TelegramBotAbstract telegramBotClient    = null;

            try
            {
                if (sender is TelegramBotClient tmp)
                {
                    telegramBotClientBot = tmp;
                }

                if (telegramBotClientBot == null)
                {
                    return;
                }

                telegramBotClient = TelegramBotAbstract.GetFromRam(telegramBotClientBot);

                var toExit = await ModerationCheck.CheckIfToExitAndUpdateGroupList(telegramBotClient, e);

                if (toExit.Item1 == ToExit.EXIT)
                {
                    var itemToPrint     = MemberListToString(toExit.Item2);
                    var itemToPrint2    = ListIntToString(toExit.Item3);
                    var itemToPrint3    = StringToStringToBePrinted(toExit.Item4);
                    var itemToPrintFull = itemToPrint + "\n" + e?.Message?.Chat?.Title;
                    itemToPrintFull += "\n----\n" + itemToPrint2 + "\n----\nS:" + itemToPrint3;
                    itemToPrintFull += "\n----\n" + e?.Message?.Chat?.Id;
                    itemToPrintFull += "\n@@@@@@";

                    throw new ToExitException(itemToPrintFull);
                }

                var NotAuthorizedBotHasBeenAddedBool =
                    await ModerationCheck.CheckIfNotAuthorizedBotHasBeenAdded(e, telegramBotClient);

                if (NotAuthorizedBotHasBeenAddedBool != null && NotAuthorizedBotHasBeenAddedBool.Count > 0)
                {
                    foreach (var bot in NotAuthorizedBotHasBeenAddedBool)
                    {
                        await RestrictUser.BanUserFromGroup(telegramBotClient, e, bot, e.Message.Chat.Id, null);
                    }
                }

                //todo: send messagge "Bots not allowed here!"

                if (banMessageDetected(e))
                {
                    CommandDispatcher.banMessageActions(telegramBotClient, e);
                    return;
                }

                var toExitBecauseUsernameAndNameCheck =
                    await ModerationCheck.CheckUsernameAndName(e, telegramBotClient);

                if (toExitBecauseUsernameAndNameCheck)
                {
                    return;
                }

                var checkSpam = ModerationCheck.CheckSpam(e);
                if (checkSpam != SpamType.ALL_GOOD && checkSpam != SpamType.SPAM_PERMITTED)
                {
                    await ModerationCheck.AntiSpamMeasure(telegramBotClient, e, checkSpam);

                    return;
                }

                if (checkSpam == SpamType.SPAM_PERMITTED)
                {
                    await ModerationCheck.PermittedSpamMeasure(telegramBotClient, e, checkSpam);

                    return;
                }

                if (e.Message.Text != null && e.Message.Text.StartsWith("/"))
                {
                    await CommandDispatcher.CommandDispatcherMethod(telegramBotClient, e);
                }
                else
                {
                    await TextConversation.DetectMessage(telegramBotClient, e);
                }
            }
            catch (Exception exception)
            {
                Console.WriteLine(exception.Message);

                await NotifyUtil.NotifyOwners(exception, telegramBotClient);
            }
        }