Exemple #1
0
        private bool getDashboardStatus(Message message)
        {
            DashboardUserLogic dul = new DashboardUserLogic();

            DashboardUser user = dul.GetByTelegramUserId(message.From.Id);

            if (user == null)
            {
                return(false);
            }

            DashboardPermissionLogic dpl        = new DashboardPermissionLogic();
            DashboardPermission      permission = dpl.GetByUserId(user.DashboardUserId,
                                                                  CacheData.Groups[message.Chat.Id].GroupId);

            if (permission == null)
            {
                return(false);
            }

            if (permission.State == DashboardPermission.Status.Active)
            {
                return(true);
            }

            return(false);
        }
Exemple #2
0
        private void toggleDashboard(CallbackQuery callbackQuery)
        {
            Message            message = callbackQuery.Message;
            DashboardUserLogic dul     = new DashboardUserLogic();
            DashboardUser      user    = dul.GetByTelegramUserId(callbackQuery.From.Id);

            if (user == null)
            {
                string profilePic = "";
                var    photos     = Manager.BotClient.GetUserProfilePhotosAsync(callbackQuery.From.Id).Result;
                if (photos.TotalCount > 0)
                {
                    profilePic = photos.Photos[0][0].FileId;
                }

                user = dul.Add(callbackQuery.From.Id,
                               callbackQuery.From.FirstName + " " + callbackQuery.From.LastName,
                               profilePic, -2);
                if (user == null)
                {
                    MessageQueueManager.EnqueueMessage(
                        new Models.ChatMessage()
                    {
                        Timestamp = DateTime.UtcNow,
                        Chat      = message.Chat,
                        ParseMode = ParseMode.Markdown,
                        Text      = "*[Report]*\n" +
                                    "Error enabling dashboard!"
                    });
                    return;
                }
            }

            DashboardPermissionLogic dpl        = new DashboardPermissionLogic();
            DashboardPermission      permission = dpl.GetByUserId(user.DashboardUserId,
                                                                  CacheData.Groups[message.Chat.Id].GroupId);

            if (permission == null)
            {
                if (dpl.Add(CacheData.Groups[message.Chat.Id].GroupId,
                            user.DashboardUserId, DashboardPermission.Status.Active,
                            -2) == null)
                {
                    MessageQueueManager.EnqueueMessage(
                        new Models.ChatMessage()
                    {
                        Timestamp = DateTime.UtcNow,
                        Chat      = message.Chat,
                        ParseMode = ParseMode.Markdown,
                        Text      = "*[Report]*\n" +
                                    "Error enabling dashboard!"
                    });
                    return;
                }

                MessageQueueManager.EnqueueMessage(
                    new Models.ChatMessage()
                {
                    Timestamp = DateTime.UtcNow,
                    Chat      = message.Chat,
                    ParseMode = ParseMode.Markdown,
                    Text      = "Dashboard enabled!"
                });
                callbackQuery.Message.From.Id = callbackQuery.From.Id;
                Execute(callbackQuery.Message, true);
                return;
            }

            if (permission.State == DashboardPermission.Status.Banned)
            {
                MessageQueueManager.EnqueueMessage(
                    new Models.ChatMessage()
                {
                    Timestamp = DateTime.UtcNow,
                    Chat      = message.Chat,
                    ParseMode = ParseMode.Markdown,
                    Text      = "*[Report]*\n" +
                                "Error: you are banned from the dashboard!"
                });
                return;
            }
            else if (permission.State == DashboardPermission.Status.Active)
            {
                permission.State = DashboardPermission.Status.Inactive;
            }
            else if (permission.State == DashboardPermission.Status.Inactive)
            {
                permission.State = DashboardPermission.Status.Active;
            }

            if (dpl.Update(permission, -2) == null)
            {
                MessageQueueManager.EnqueueMessage(
                    new Models.ChatMessage()
                {
                    Timestamp = DateTime.UtcNow,
                    Chat      = message.Chat,
                    ParseMode = ParseMode.Markdown,
                    Text      = "*[Report]*\n" +
                                "Error enabling dashboard!"
                });
            }
            else
            {
                MessageQueueManager.EnqueueMessage(
                    new Models.ChatMessage()
                {
                    Timestamp = DateTime.UtcNow,
                    Chat      = message.Chat,
                    ParseMode = ParseMode.Markdown,
                    Text      = "Dashboard status updated!"
                });

                callbackQuery.Message.From.Id = callbackQuery.From.Id;
                Execute(callbackQuery.Message, true);
            }
        }