예제 #1
0
        private async void BotClient_OnUpdate(System.Object sender, Telegram.Bot.Args.UpdateEventArgs e)
        {
            DataBase db = Singleton.GetInstance().Context;

            if (e.Update.PreCheckoutQuery != null)
            {
                await BotClient.AnswerPreCheckoutQueryAsync(e.Update.PreCheckoutQuery.Id);

                if (e.Update.PreCheckoutQuery.InvoicePayload == "Pay is correct")
                {
                    User user = db.GetUser(e.Update.PreCheckoutQuery.From.Id);
                    user.BanDate = System.DateTime.Now;
                    db.Save();
                    IsUnBan.ThisUnBan(BotClient, user);
                    await Task.Run(() => SetIncomeChannel(e.Update.PreCheckoutQuery.From.Id, e.Update.PreCheckoutQuery.TotalAmount / 100));
                }
                else if (e.Update.PreCheckoutQuery.InvoicePayload == "Balance is correct")
                {
                    AdUser adUser = db.GetAdUser(e.Update.PreCheckoutQuery.From.Id);
                    adUser.Balance += e.Update.PreCheckoutQuery.TotalAmount / 100;
                    db.Save();
                    await Task.Run(() => SetIncomeChannel(e.Update.PreCheckoutQuery.From.Id, e.Update.PreCheckoutQuery.TotalAmount / 100));
                }
                else if (e.Update.PreCheckoutQuery.InvoicePayload == "PostTemplate is correct")
                {
                    AdUser       adUser       = db.GetAdUser(e.Update.PreCheckoutQuery.From.Id);
                    PostTemplate postTemplate = db.GetTempalte(adUser.User.ID, adUser.EditingPostTemplateId);
                    postTemplate.IsPaid = true;
                    System.Object ob = await AdController.AssemblyTemplate(BotClient, postTemplate);

                    if (ob is Message)
                    {
                        Message       mes  = (Message)ob;
                        System.String text = mes.Text;
                        await BotClient.SendTextMessageAsync(CommandText.bufferChannelId, text);
                    }
                    else
                    {
                        List <InputMediaBase> inputMedias = (List <InputMediaBase>)ob;

                        await BotClient.SendMediaGroupAsync(CommandText.bufferChannelId, inputMedias);
                    }
                    IsDataTaken.IsCheck(BotClient, e.Update.PreCheckoutQuery.From.Id, postTemplate.PostTime.ToList());
                    db.Save();

                    await Task.Run(() => SetIncomeChannel(e.Update.PreCheckoutQuery.From.Id, e.Update.PreCheckoutQuery.TotalAmount / 100, postTemplate));
                }
                else if (e.Update.PreCheckoutQuery.InvoicePayload == "Pay Confirm User")
                {
                    User user = db.GetUser(e.Update.PreCheckoutQuery.From.Id);
                    user.PayConfirm = true;
                    user.PayDate    = System.DateTime.Today.AddMonths(1);
                    db.Save();

                    await Task.Run(() => SetIncomeChannel(e.Update.PreCheckoutQuery.From.Id, e.Update.PreCheckoutQuery.TotalAmount / 100));
                }
            }
        }
        public async void Execute(TelegramBotClient botClient, System.Object message)
        {
            Message      _message     = message as Message;
            InlineButton inlineButton = new InlineButton();

            try
            {
                DataBase db   = Singleton.GetInstance().Context;
                User     user = db.GetUser(_message.From.Id); if (IsNullDataBase.IsNull(botClient, _message, user))
                {
                    return;
                }

                botClient.DeleteMessage(_message.Chat.Id, _message.MessageId, "258");

                if (Text != null && user.IsAdmin > 0)
                {
                    User userTwo = db.GetUser(System.Convert.ToInt64(Text));

                    if (userTwo != null)
                    {
                        userTwo.BanDate = System.DateTime.Now;
                        IsUnBan.ThisUnBan(botClient, userTwo);
                        db.Save();

                        IsUnBan.ThisUnBan(botClient, userTwo);

                        Settings setting = db.GetSettings();

                        System.String temp = "Администратор " + user.IsAdmin + " уровня: @" + user.Username + " разбанил пользователя!" + "\nID: " + userTwo.ID + "\nФИО: " + userTwo.FIO + "\nНомер: " + user.Number;
                        await botClient.SendTextMessageAsync(setting.ChannelAdmin, temp);
                    }
                    else
                    {
                        try
                        {
                            Message mes = await botClient.EditMessageTextAsync(user.ID, user.MessageID, "Пользователь не найден!", replyMarkup : inlineButton.BackToSettingAdmin);

                            user.MessageID = mes.MessageId;
                        }
                        catch
                        {
                            Message mes = await botClient.SendTextMessageAsync(user.ID, "Пользователь не найден!", replyMarkup : inlineButton.BackToSettingAdmin);

                            user.MessageID = mes.MessageId;
                        }
                        db.Save();
                    }
                }
                else if (user.IsAdmin > 0)
                {
                    try
                    {
                        Message mes = await botClient.EditMessageTextAsync(user.ID, user.MessageID, "Перешлите сообщения от пользователя которого хотите разбанить!", replyMarkup : inlineButton.BackToSettingAdmin);

                        user.Chain     = 1150;
                        user.MessageID = mes.MessageId;
                    }
                    catch
                    {
                        Message mes = await botClient.SendTextMessageAsync(user.ID, "Перешлите сообщения от пользователя которого хотите разбанить!", replyMarkup : inlineButton.BackToSettingAdmin);

                        user.Chain     = 1150;
                        user.MessageID = mes.MessageId;
                    }

                    db.Save();
                }
            }
            catch (System.Exception ex)
            {
                Log.Logging(ex);
            }
        }