Пример #1
0
        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();
                        }
                    }
                }
            }
        }
Пример #2
0
        /// <summary>
        /// Аналитика по доходности в группе.
        /// </summary>
        /// <param name="analiticsPhrases"></param>
        public static void GetAnaliticsIncomeChannel(IncomeChannel[] incomes, TelegramBotClient botClient, CallbackQuery _message, User user)
        {
            DataBase db = Singleton.GetInstance().Context;
            //создание файла
            String    files     = AppDomain.CurrentDomain.BaseDirectory + "\\newdoc.xls";
            Workbook  workbook  = new Workbook();
            Worksheet worksheet = new Worksheet("Аналитика доходов");

            worksheet.Cells[0, 0] = new Cell("Группа");
            worksheet.Cells[0, 1] = new Cell("Доход");
            worksheet.Cells[0, 2] = new Cell("Дата");
            worksheet.Cells[0, 3] = new Cell("Общая доходность за все группы");

            Int32  count         = 1;
            Single incomeChannel = 0;

            IQueryable <IncomeChannel> temp = incomes.OrderByDescending(p => p.DateTime).AsQueryable();


            foreach (IncomeChannel income in temp)
            {
                Channel channel = db.GetChannel(income.ChannelId);
                worksheet.Cells[count + 1, 0] = new Cell(channel.ChannelName.ToString());
                worksheet.Cells[count + 1, 1] = new Cell(income.SumIncome.ToString());
                worksheet.Cells[count + 1, 2] = new Cell(income.DateTime.ToString("d"));
                incomeChannel += income.SumIncome;
                count++;
            }
            worksheet.Cells[1, 3] = new Cell(incomeChannel.ToString());
            workbook.Worksheets.Add(worksheet);
            workbook.Save(files);
            SendMessage(botClient, _message, user, "Аналитика доходов");
        }
        private Boolean SearchChannel(Message _message)
        {
            DataBase db = Singleton.GetInstance().Context;


            channel = db.GetChannel(_message.Text.Split(" ")[0]);
            if (channel != null)
            {
                return(false);
            }

            return(true);
        }
Пример #4
0
        private void AddAnaliticsPharase(TelegramBotClient botClient, Message _message, Settings settings)
        {
            DataBase db      = Singleton.GetInstance().Context;
            Channel  channel = db.GetChannel(_message);

            String clean = "";

            String analiticsText = "";

            foreach (System.String word in _message.Text.Split(" "))
            {
                clean += word.Trim(new System.Char[] { '!', '@', '#', '$', '%', '^', '&', '*', '(', ')', '-', '_', '=', '+', '|', '\\', ']', '}', '[', '{', '\'', '\"', ';', ':', '/', '?', '.', '>', '<', ',', ' ' }) + " ";
            }
            AnaliticsPhraseAllChat[] analiticsPhraseAllChats = db.GetAnaliticsPhraseAllChats();
            if (analiticsPhraseAllChats.Length != 0)
            {
                if (_message.Chat.Type == Telegram.Bot.Types.Enums.ChatType.Private)
                {
                    foreach (AnaliticsPhraseAllChat text in analiticsPhraseAllChats)
                    {
                        if (CalculateFuzzyEqualValue(clean.ToLower(), text.NameId, settings) >= settings.ProcentMessage)
                        {
                            AnaliticsPhrase[]            analyticsText = db.GetAnaliticsPharse(text.NameId);
                            IQueryable <AnaliticsPhrase> temp          = analyticsText.OrderByDescending(p => p.Count).AsQueryable();
                            foreach (AnaliticsPhrase item in temp)
                            {
                                analiticsText += "\nГруппа: " + item.channel.ChannelName + ";\nФраза: " + text.NameId + ";\nКоличество использования: " + item.Count + "\n";
                            }
                            break;
                        }
                    }
                }
            }

            if (analiticsText.Length != 0)
            {
                analitics += analiticsText;
            }
            else
            {
                analitics += "\nПо Вашему запросу нет совподений.";
            }
            SendMessage(botClient, _message);
        }
Пример #5
0
        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);
        }
Пример #6
0
        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();
        }
 private Boolean SelectedUser(Int64 idUser)
 {
     channel = db.GetChannel(idUser);
     return(channel == null);
 }
Пример #8
0
        /// <summary>
        /// Аналитика по добавленых пользователей
        /// </summary>
        /// <param name="analiticsPhrases"></param>
        public static async void GetAnaliticsInUserAdd(InvitedUser[] invitedUsers, TelegramBotClient botClient, CallbackQuery _message, User user)
        {
            DataBase db = Singleton.GetInstance().Context;
            //

            /*var client = new TLSharp.Core.TelegramClient(833968, "a6c65fd9460c44e42c5268b5601c849f");
             * var isAuth = client.IsUserAuthorized();
             * Console.WriteLine($"Файл авторизации существует: {isAuth}");
             * client.ConnectAsync().Wait();
             *
             * ModelParserInfo temp2 = WorkingTelegramClient.ParserInfoAboutChannelAndSuperGroup("BuySellCarUBC", client).GetAwaiter().GetResult();
             *
             * foreach (var u2s in temp2.ChannelInfo.Users)
             * {
             *      Console.WriteLine(u2s.FirstName);
             * }*/

            //

            //создание файла
            String    files     = AppDomain.CurrentDomain.BaseDirectory + "\\newdoc.xls";
            Workbook  workbook  = new Workbook();
            Worksheet worksheet = new Worksheet("Аналитика по добавлению человек");

            worksheet.Cells[0, 0] = new Cell("Добавленый пользователь");
            worksheet.Cells[0, 1] = new Cell("Кто добавил");
            worksheet.Cells[0, 2] = new Cell("Группа");

            Int32 count = 1;

            Channel[] channels = db.GetChannels();

            IQueryable <InvitedUser> temp = invitedUsers.OrderByDescending(p => p.UserAddedId).AsQueryable();


            foreach (InvitedUser invitedUser in temp)
            {
                User Added    = db.GetUser(invitedUser.UserAddedId);
                User WhoAdded = db.GetUser(invitedUser.UserWhoAddedId);

                if (Added != null)
                {
                    worksheet.Cells[count, 0] = new Cell(value: Added.FIO + " " + Added.ID);
                }

                if (WhoAdded != null)
                {
                    worksheet.Cells[count, 1] = new Cell(value: WhoAdded.FIO + " " + WhoAdded.ID);
                }

                if (invitedUser.ChannelId != null)
                {
                    Channel channel = db.GetChannel(invitedUser.ChannelId);
                    if (channel != null)
                    {
                        worksheet.Cells[count, 2] = new Cell(channel.ChannelName);
                    }
                }


                count++;
            }

            workbook.Worksheets.Add(worksheet);
            workbook.Save(files);
            SendMessage(botClient, _message, user, "Аналитика по добавлению человек");
        }
        public async void ChekRegister(TelegramBotClient bot, System.Object message)
        {
            _message  = message as Message;
            db        = Singleton.GetInstance().Context;
            botClient = bot;

            try
            {
                Channel channel = db.GetChannel(_message);
                if (channel == null && _message.Chat.Type == Telegram.Bot.Types.Enums.ChatType.Supergroup)
                {
                    Channel[] channels = db.GetChannels();

                    Chat chat = await botClient.GetChatAsync(_message.Chat.Id);

                    System.String NewChannel = $"Здравствуйте у нас появился новая группа @{_message.Chat.Username}!\n{chat.Description}";

                    foreach (Channel ch in channels)
                    {
                        botClient.SendText(ch.IDChannel, NewChannel);
                    }

                    db.SetChannel(chat);
                    db.Save();

                    channel = db.GetChannel(_message);

                    await Task.Run(() => AddNewChannel.SetTmessage());
                }

                User user = db.GetUser(_message.From.Id);

                TMessage tmessage = db.GetMessage(_message);
                Settings settings = db.GetSettings();

                if ((user == null || user.FIO == null || user.Number == "0") && _message.Chat.Type != ChatType.Private)
                {
                    botClient.DeleteMessage(_message.Chat.Id, _message.MessageId, "Невозможно удалить сообщение так как оно не было отправленное!");

                    System.String textChannel = $"❗Здравствуйте, что бы писать в чатах UBC - пройдите регистрацию в боте, это занимает меньше 1 минуты.\nСсылка на бота/регистрацию: @{botClient.GetMeAsync().Result.Username}\n\n📜Полный список чатов UBC @allUBC";


                    try
                    {
                        if ((_message.Type != MessageType.Photo) || (_message.Caption != null))
                        {
                            await botClient.SendTextMessageAsync(_message.From.Id, textChannel,
                                                                 replyMarkup : _inlineButton.Register);
                        }
                    }
                    catch
                    {
                        Message mes = null;

                        if ((channel.IDMessage == 0 && _message.Type != MessageType.Photo) ||
                            (_message.Caption != null && channel.IDMessage == 0))
                        {
                            mes = await botClient.SendTextMessageAsync(_message.Chat.Id, textChannel);

                            channel.IDMessage = mes.MessageId;
                            db.SetValue(new ChannelMessage()
                            {
                                ChannelID         = channel.IDChannel,
                                MessageId         = mes.MessageId,
                                DateMessageDelete = DateTime.Now.AddSeconds(20)
                            });

                            db.Save();
                        }
                    }
                }
                else if (user.Chain > 0 && user.Chain < (System.Int32)Advertising.SetChain.GetPayments && _message.Chat.Type == Telegram.Bot.Types.Enums.ChatType.Private)
                {
                    FIO fIO = new FIO();
                    fIO.SetNext(
                        new Number()).SetNext(
                        new ChaingeFIO()).SetNext(
                        new ChaingeNumber()).SetNext(
                        new SetReviewsName()).SetNext(
                        new SearchIDUser()).SetNext(
                        new SearchNumberUser()).SetNext(
                        new ChangeReviewsName()).SetNext(
                        new SetSendComplaint()).SetNext(
                        new SetSendAppeal()).SetNext(
                        new Admin()).SetNext(
                        new SetAdminPassword()).SetNext(
                        new Ban()).SetNext(
                        new KickUser()).SetNext(
                        new AdminAdd()).SetNext(
                        new AdminDelete()).SetNext(
                        new PostCount()).SetNext(
                        new WordAdd()).SetNext(
                        new AddUsers()).SetNext(
                        new FludUser()).SetNext(
                        new ChannelAdd()).SetNext(
                        new NewAdmin2Lvl()).SetNext(
                        new WordDelete());

                    ChainOfResposnsibility(botClient, fIO, message, user);
                }
                else if (user.Chain >= (System.Int32)Advertising.SetChain.GetPayments && _message.Chat.Type == Telegram.Bot.Types.Enums.ChatType.Private)
                {
                    Advertising.Payments payments = new Advertising.Payments();
                    payments.SetNext(
                        new AddPhotoAdvertising()).SetNext(
                        new ContentEditorText()).SetNext(
                        new SetUserInTransaction()).SetNext(
                        new SetBlockChain()).SetNext(
                        new SetDiscriptionInTransaction()).SetNext(
                        new SetIdTransaction()).SetNext(
                        new SetPublicKeyUserTwo()).SetNext(
                        new AddPhotoChannel()).SetNext(
                        new AddCategotyInDataBase()).SetNext(
                        new AddChannelInCategoryInDataBase()).SetNext(
                        new LinkChat()).SetNext(
                        new LinkChatPharase()).SetNext(
                        new AnaliticsPhraseUser()).SetNext(
                        new AdminCallBlockchainUser()).SetNext(
                        new MessageUserBot()).SetNext(
                        new AddAccauntBotUser()).SetNext(
                        new AddAccauntCode()).SetNext(
                        new PostCountChannel()).SetNext(
                        new ThisRegulationsUBC()).SetNext(
                        new ThisDeleteChat()).SetNext(
                        new ThisDeleteCategory()).SetNext(
                        new SetPriceTime()).SetNext(
                        new SetPriceStandartMessage()).SetNext(
                        new SetStaticTimePinnedPrice()).SetNext(
                        new SetPriceStatic()).SetNext(
                        new SetStaticTimePinnedNotificationPrice()).SetNext(
                        new NotificationTextChain()).SetNext(
                        new NotificationButtonChain()).SetNext(
                        new PictureNotificationChain());

                    payments.Handle(user.Chain, botClient, message);
                }
                else
                {
                    FludChain fludChain = new FludChain();
                    fludChain.SetNext(
                        new AddPeopleChain()).SetNext(
                        new PostNullChain()).SetNext(
                        new CheckChannelChain()).SetNext(
                        new CheckWordAdnLinkChain()).SetNext(
                        new CheckInviteChain()).SetNext(
                        new CheckPhotoChain());

                    fludChain.Handle(botClient, message, user, settings, tmessage, channel);
                }
            }
            catch (System.Exception ex)
            {
                Log.Logging("Класс Analize - " + ex);
            }
        }
 private Boolean SetChannel()
 {
     channel = db.GetChannel();
     return(channel == null);
 }