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)); } } }
private void BanUser(TelegramBotClient botClient) { userTwo.BanDate = DateTime.Now.AddDays(2); userTwo.BanDescript = "Вы были забанены администрацией UBC!"; userTwo.PayConfirm = false; userTwo.PayDate = System.DateTime.Today; db.Save(); IsBanUser.ThisBan(botClient, _message, userTwo, db.GetSettings()); }
private void BanUser(TelegramBotClient botClient) { userTwo.BanDate = DateTime.Now.AddDays(2); userTwo.BanDescript = "Вы были забанены администрацией UBC!"; userTwo.PayConfirm = false; userTwo.PayDate = System.DateTime.Today; db.Save(); IsMute.ThisMut(botClient, user); }
private async Task <Boolean> SendNotificationAllUsers(TelegramBotClient botClient) { User[] users = db.GetUsers(); InlineButton inlineButton = new InlineButton(); var temp = inlineButton.PublishNotification(CollectionNotification); var picture = db.GetListCollectionPictureNotification(TextAndButton); /*List<IAlbumInputMedia> pictureList = new List<IAlbumInputMedia>(); * if (picture.Count > 1) * { * pictureList.Add(new InputMediaPhoto() { Media = picture[0].Picture}); * }*/ foreach (var ThisUser in users) { if (ThisUser.ID == user.ID) { if (picture == null) { await botClient.SendTextMessageAsync(ThisUser.ID, TextAndButton.Text.Text, replyMarkup : temp); } else { await botClient.SendPhotoAsync(ThisUser.ID, picture[0].Picture, TextAndButton.Text.Text, replyMarkup : temp); } } } var tempList = db.GetListCollectionButtonNotification(); foreach (CollectionButtonNotification collectionButtonNotification in tempList) { db.Remove(collectionButtonNotification); } foreach (CollectionPictureNotification collectionPictureNotification in picture) { db.Remove(collectionPictureNotification); } var TextTemp = db.GetTextNotification(TextAndButton.Text); db.Remove(TextAndButton); db.Remove(TextTemp); db.Save(); return(true); }
private void ChangeChannel(Message _message) { DataBase db = Singleton.GetInstance().Context; channel.PhotoLink = _message.Text.Split(" ")[1]; db.Save(); }
private void ChangeSettings() { Settings settings = db.GetSettings(); settings.Coin += 1; db.Save(); }
private void SetIncomeChannelAdmin(List <ChannelInfo> channel, Single total) { if (channel == null) { throw new ArgumentNullException(nameof(channel)); } DataBase db = Singleton.GetInstance().Context; total = (total * 20) / 100; foreach (var item in channel) { Int32 temp = item.Admins.Count; foreach (var admin in item.Admins) { IncomeChannelAdmin income = db.GetIncomeChannelsAdmin(admin.Id, ((item.Channel.Id + 1000000000000) * -1)); if (admin.Id != BotClient.BotId) { if (income == null) { db.SetValue <IncomeChannelAdmin>(new IncomeChannelAdmin() { ChannelId = (item.Channel.Id + 1000000000000) * -1, UserId = admin.Id, DateTime = System.DateTime.Today, SumIncome = total / temp }); } else { income.SumIncome = (total / temp) + income.SumIncome; } } } } db.Save(); }
public async void Execute(TelegramBotClient botClient, System.Object message) { Message _message = message as Message; try { DataBase db = Singleton.GetInstance().Context; User user = db.GetUser(_message.From.Id); if (IsNullDataBase.IsNull(botClient, _message, user)) { return; } try { await botClient.DeleteMessageAsync(_message.Chat.Id, _message.MessageId); } catch { } if (user.IsAdmin >= 2) { Singleton.GetInstance().Context._channels.Add(new Channel() { IDChannel = _message.Chat.Id }); db.Save(); await botClient.SendTextMessageAsync(_message.From.Id, "Чат добавлен!"); } } catch (System.Exception ex) { Log.Logging(ex); } }
public void Execute(TelegramBotClient botClient, System.Object message) { Message _message = message as Message; 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, "376"); if (user.IsAdmin >= 2) { user.Chain = 1006; botClient.SendText(_message.From.Id, "Перешлите сообщение от канала: ", user, replyMarkup: inlineButton.BackToAccauntMenu); db.Save(); } } catch (System.Exception ex) { Log.Logging(ex); } }
public async void Execute(TelegramBotClient botClient, System.Object message) { Message _message = message as Message; DataBase db = Singleton.GetInstance().Context; try { User user = db.GetUser(_message.From.Id); if (IsNullDataBase.IsNull(botClient, _message, user)) { return; } botClient.DeleteMessage(_message.Chat.Id, _message.MessageId, "413"); botClient.DeleteMessage(_message.Chat.Id, user.MessageID, "414"); user.Chain = 1008; Message mes = await botClient.SendTextMessageAsync(_message.From.Id, "Введите пароль от админки: ", replyMarkup : inlineButton.BackToAccauntMenu); user.MessageID = mes.MessageId; db.Save(); } catch (System.Exception ex) { Log.Logging(ex); } }
public async Task Execute(IJobExecutionContext context) { DataBase db = Singleton.GetInstance().Context; db.RemoveRangePhotoData(); db.Save(); }
public async Task Execute(IJobExecutionContext context) { BotClient = new TelegramBotClient("1046277477:AAHxIx5MkmYSEH9qIiGYlLMTEUcz5Nage6E"); DataBase db = Singleton.GetInstance().Context; ChannelMessage[] channels = db.GetChannelMessages(); DateTime date = DateTime.Now; if (channels.Any(p => p.DateMessageDelete <= date)) { foreach (ChannelMessage channel in channels) { if (channel.DateMessageDelete <= date) { if (channel.MessageId != 0) { BotClient.DeleteMessage(channel.ChannelID, channel.MessageId, "Не удалось удалить сообщение в канале! Класс UpdateMessageChat!"); Channel thisChannel = db.GetChannel(channel.ChannelID); thisChannel.IDMessage = 0; db._channelMessages.Remove(channel); db.Save(); } } } } }
private void ChangeUser() { DataBase db = Singleton.GetInstance().Context; user.Chain = (Int32)SetChain.MessageUserInBot; db.Save(); }
private void Selected(Int32 idUser) { FeaturedUserNew featured = db.GetFeaturedUsers(idUser); db._featuredUserNews.Remove(featured); db.Save(); SelectedUser(featured.UserId); }
private void SetMessage(Message _message) { DataBase db = Singleton.GetInstance().Context; user.MessageComplaint = _message.Text; user.IDRecipient = userTwo.ID; db.Save(); }
private void Add() { db.SetValue <FeaturedUserNew>(new FeaturedUserNew() { UserId = userTwo.ID, UserWhoAddedId = user.ID }); db.Save(); }
public void SetNewCategoty(Message _message) { DataBase db = Singleton.GetInstance().Context; channel.CategoryId = category.Id; user.Chain = (Int32)SetChain.MessageUserInBot; db.Save(); }
public static async void SendText(this TelegramBotClient botClient, System.Int64 ChatOrFromId, System.String text, User user = null, System.Boolean isBan = false, IReplyMarkup replyMarkup = null, System.Boolean IsMarkdown = false) { try { DataBase db = Singleton.GetInstance().Context; Message mes; if (replyMarkup == null) { if (IsMarkdown) { mes = await botClient.SendTextMessageAsync(ChatOrFromId, text, Telegram.Bot.Types.Enums.ParseMode.Markdown); } else { mes = await botClient.SendTextMessageAsync(ChatOrFromId, text, Telegram.Bot.Types.Enums.ParseMode.Html); } } else { if (IsMarkdown) { mes = await botClient.SendTextMessageAsync(ChatOrFromId, text, Telegram.Bot.Types.Enums.ParseMode.Markdown, replyMarkup : replyMarkup); } else { mes = await botClient.SendTextMessageAsync(ChatOrFromId, text, Telegram.Bot.Types.Enums.ParseMode.Html, replyMarkup : replyMarkup); } } if (user != null && isBan == false) { user.MessageID = mes.MessageId; db.Save(); } else if (user != null && isBan == true) { user.MessageBan = mes.MessageId; db.Save(); } } catch { } }
private void ChangeSettings() { Settings settings = db.GetSettings(); if (settings.Coin != 0) { settings.Coin -= 1; db.Save(); } }
public void SetNewCategoty(Message _message) { DataBase db = Singleton.GetInstance().Context; db.SetValue <Category>(new Category() { Name = _message.Text }); user.Chain = (Int32)SetChain.MessageUserInBot; db.Save(); }
private void SetLimited() { TMessage[] message = db.GetTMessages(); channel.PostCount = 999999; foreach (TMessage item in message) { if (item.channel.IDChannel == channel.IDChannel) { item.Post = channel.PostCount; } } db.Save(); }
public async Task Execute(IJobExecutionContext context) { DataBase db = Singleton.GetInstance().Context; TMessage[] tmessages = db.GetTMessages(); Channel[] channels = db.GetChannels(); foreach (Channel item in channels) { foreach (TMessage message in tmessages) { if (message.channel.IDChannel == item.IDChannel) { if (message.dateTime == System.DateTime.Today || message.Post == item.PostCount) { continue; } message.Post = item.PostCount; message.dateTime = System.DateTime.Today; } } } db.Save(); UserMessage[] userMessages = db.GetUserMessages(); foreach (UserMessage userMessage in userMessages) { if (userMessage.dateTime == System.DateTime.Today) { continue; } Singleton.GetInstance().Context._userMessages.Remove(userMessage); } db.Save(); }
public async Task Execute(IJobExecutionContext context) { DataBase db = Singleton.GetInstance().Context; User[] users = db.GetUsers(); foreach (User user in users) { if (user.DateRegister.Month + 1 == System.DateTime.Today.Month) { user.CountReviews = 3; user.DateRegister = System.DateTime.Today; } } db.Save(); }
private async void ChekTextAsync(TelegramBotClient botClient, Message _message, User user, Settings settings) { DataBase db = Singleton.GetInstance().Context; try { await Task.Run(() => AddAnaliticsPharase(botClient, _message, settings)); db.Save(); } catch (System.Exception ex) { Log.Logging(ex); } }
public static Boolean SetCode(TelegramBotClient botClient, Message _message, String code, User user, DataBase db) { try { session.CreateSession(code).Wait(); return(false); } catch { InlineButton inlineButton = new InlineButton(); user.Chain = (Int32)SetChain.AddAccauntUser; db.Save(); botClient.DeleteMessage(_message.From.Id, _message.MessageId, "50 - StartSession"); botClient.EditMessage(_message.From.Id, user.MessageID, "Этот номер уже используется, введите пожалуйста другой!", "45 - StartSession", replyMarkup: inlineButton.BackToSetting); return(true); } }
private void SetUserName(Message message, DataBase db) { User user = db.GetUser(message.From.Id); try { if (user != null) { if (user.Username == null || message.From.Username != user.Username) { user.Username = message.From.Username; db.Save(); } } } catch (Exception e) { Log.Logging(e); } }
private void SetIncomeChannel(Int32 id, Single total, PostTemplate postTemplate = null) { DataBase db = Singleton.GetInstance().Context; List <ChannelInfo> channel = null; if (postTemplate == null) { channel = StartSession.Test(db.GetChannelsList(), id); } else { List <Channel> channels = new List <Channel>(); foreach (var item in postTemplate.PostChannel) { Channel Thischannel = db.GetChannel(item.ChannelId); channels.Add(Thischannel); } channel = StartSession.Test(channels, id); } Int32 temp = channel.Count; foreach (var item in channel) { IncomeChannel incomeChannel = db.GetIncomeChannels((item.Channel.Id + 1000000000000) * -1); if (incomeChannel == null) { db.SetValue <IncomeChannel>(new IncomeChannel() { ChannelId = (item.Channel.Id + 1000000000000) * -1, DateTime = System.DateTime.Today, SumIncome = total / temp }); } else { incomeChannel.SumIncome = (total / temp) + incomeChannel.SumIncome; } } db.Save(); SetIncome(channel, id, total); SetIncomeChannelAdmin(channel, total); }
public static async void EditMessage(this TelegramBotClient botClient, System.Int64 ChatOrFromId, System.Int32 messageId, System.String text, System.String ex, User user = null, InlineKeyboardMarkup replyMarkup = null, System.Boolean IsMarkdown = false) { DataBase db = Singleton.GetInstance().Context; try { Message mes; if (replyMarkup == null) { if (IsMarkdown) { mes = await botClient.EditMessageTextAsync(ChatOrFromId, messageId, text, Telegram.Bot.Types.Enums.ParseMode.Markdown); } else { mes = await botClient.EditMessageTextAsync(ChatOrFromId, messageId, text, Telegram.Bot.Types.Enums.ParseMode.Html); } } else { if (IsMarkdown) { mes = await botClient.EditMessageTextAsync(ChatOrFromId, messageId, text, Telegram.Bot.Types.Enums.ParseMode.Markdown, replyMarkup : replyMarkup); } else { mes = await botClient.EditMessageTextAsync(ChatOrFromId, messageId, text, Telegram.Bot.Types.Enums.ParseMode.Html, replyMarkup : replyMarkup); } } if (user != null) { user.MessageID = mes.MessageId; db.Save(); } } catch (System.Exception exception) { Log.Logging("Не удалось изменить текст: " + ex + " " + exception); } }
private void SetIncome(List <ChannelInfo> channel, Int32 id, Single total) { DataBase db = Singleton.GetInstance().Context; Int32 temp = channel.Count; foreach (var item in channel) { Income income = db.GetIncome(id, ((item.Channel.Id + 1000000000000) * -1)); if (income == null) { db.SetValue <Income>(new Income() { ChannelId = (item.Channel.Id + 1000000000000) * -1, UserId = id, dateTime = System.DateTime.Today, SumIncome = total / temp }); } else { income.SumIncome = (total / temp) + income.SumIncome; } } db.Save(); }
private void ChangeNotificationChat() { Channel channel = db.GetChannel(KeyChannel); ButtonAndTextNotication buttonAndTextNotication = db.GetButtonAndTextNotication(user); NotificationChat[] notificationChats = db.GetNotificationChats(); NotificationChat notificationChat = notificationChats.FirstOrDefault(p => p.IdChannel == channel && p.IdNotification == buttonAndTextNotication.Id); if (notificationChat == null) { db.SetValue(new NotificationChat() { IdChannel = channel, IdNotification = buttonAndTextNotication.Id }); } else { db.Remove(notificationChat); } db.Save(); }