예제 #1
0
        private void ChangeNotificztionText()
        {
            _Text = new TextNotification {
                Text = _message.Text
            };

            TextNotification TextTemp = db.GetTextNotification(_Text);

            if (TextTemp == null)
            {
                db.SetValue(_Text);
            }

            ButtonAndTextNotication temp = db.GetButtonAndTextNotication(user);

            ButtonAndTextNotication tempText = db.GetButtonAndTextNotication(_Text.Text);

            if (tempText == null)
            {
                temp.Text = _Text;
            }
            else
            {
                temp.isWork     = false;
                tempText.isWork = true;
                tempText.User   = user;
            }

            db.Save();
        }
예제 #2
0
        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);
        }
예제 #3
0
        private async Task <Boolean> SendNotificationAllUsers(TelegramBotClient botClient)
        {
            Channel[]    channels     = db.GetChannels();
            InlineButton inlineButton = new InlineButton();
            var          temp         = inlineButton.PublishNotification(CollectionNotification, true);
            var          picture      = db.GetListCollectionPictureNotification(TextAndButton);

            NotificationChat[] notificationChats = db.GetNotificationChats();
            Int32 Count = 0;

            foreach (var ThisUser in channels)
            {
                if (notificationChats == null)
                {
                    if (notificationChats.Any(p => p.IdChannel == ThisUser && p.IdNotification == TextAndButton.Id))
                    {
                        if (picture == null)
                        {
                            try
                            {
                                var mes = await botClient.SendTextMessageAsync(ThisUser.IDChannel, TextAndButton.Text.Text,
                                                                               replyMarkup : temp);

                                await botClient.PinChatMessageAsync(ThisUser.IDChannel, mes.MessageId, false);
                            }
                            catch (Exception e)
                            {
                            }
                        }
                        else
                        {
                            try
                            {
                                var mes = await botClient.SendPhotoAsync(ThisUser.IDChannel, picture[0].Picture,
                                                                         TextAndButton.Text.Text, replyMarkup : temp);

                                await botClient.PinChatMessageAsync(ThisUser.IDChannel, mes.MessageId, false);
                            }
                            catch (Exception e)
                            {
                            }
                        }
                    }
                }
                else
                {
                    if (picture == null)
                    {
                        try
                        {
                            var mes = await botClient.SendTextMessageAsync(ThisUser.IDChannel, TextAndButton.Text.Text,
                                                                           replyMarkup : temp);

                            await botClient.PinChatMessageAsync(ThisUser.IDChannel, mes.MessageId, false);
                        }
                        catch (Exception e)
                        {
                        }
                    }
                    else
                    {
                        try
                        {
                            var mes = await botClient.SendPhotoAsync(ThisUser.IDChannel, picture[0].Picture,
                                                                     TextAndButton.Text.Text, replyMarkup : temp);

                            await botClient.PinChatMessageAsync(ThisUser.IDChannel, mes.MessageId, false);
                        }
                        catch (Exception e)
                        {
                        }
                    }
                }
            }

            var tempList = db.GetListCollectionButtonNotification();

            foreach (CollectionButtonNotification collectionButtonNotification in tempList)
            {
                db.Remove(collectionButtonNotification);
            }

            foreach (CollectionPictureNotification collectionPictureNotification in picture)
            {
                db.Remove(collectionPictureNotification);
            }

            foreach (NotificationChat notificationChat in notificationChats)
            {
                db.Remove(notificationChat);
            }

            var TextTemp = db.GetTextNotification(TextAndButton.Text);

            db.Remove(TextAndButton);
            db.Remove(TextTemp);
            db.Save();

            return(true);
        }