Exemplo n.º 1
0
        private static void _WelcomeChatMember(TelegramBotClient client, Chat chat, User user)
        {
            _BanInChat(user, client, chat.Id);

            BotDbContext.Get().GetUserInfo(user); // добавить информацию о юзере в базу

            var button = new InlineKeyboardButton();

            button.Text         = "Принимаю";
            button.CallbackData = Bot.ACCEPT_AGREEMENT_CALLBACK;

            var    keyboard  = new InlineKeyboardMarkup(button);
            string agreement = BotDbContext.Get().Agreements.FirstOrDefault(a => a.ChatId.Equals(chat.Id))?.Text; //WebConfigurationManager.AppSettings.Get("MemberAgreement");

            agreement = agreement ?? "Я не в курсе о правилах чата, так что просто нажми кнопку.";
            client.SendTextMessageAsync(chat.Id, $"{user.GetMension()}\n{agreement}",
                                        parseMode: ParseMode.Markdown,
                                        replyMarkup: keyboard);
        }
Exemplo n.º 2
0
        private static void _BanInChat(TelegramBotClient client, Chat chat, User user, int replyMessageId = 0,
                                       DateTime untilDate = default)
        {
            var permissions = new ChatPermissions()
            {
                CanSendMediaMessages = false,
                CanSendMessages      = false,
                CanSendOtherMessages = false
            };

            client.RestrictChatMemberAsync(chat.Id, user.Id, permissions, untilDate);

            if (replyMessageId > 0)
            {
                client.SendTextMessageAsync(chat.Id, $"{user.GetMension()} будет забанен!",
                                            replyToMessageId: replyMessageId, parseMode: ParseMode.Markdown);
            }

            var member = BotDbContext.Get().GetMember(chat.Id, user.Id);

            member.Warns = 0;
            BotDbContext.Get().Entry(member).State = System.Data.Entity.EntityState.Modified;
            BotDbContext.Get().SaveChanges();
        }