-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add the video distribution logic
The first version is for configuring the parameters for sending videos to contacts. Only a part is ready now
- Loading branch information
Showing
4 changed files
with
161 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,146 @@ | ||
using Telegram.Bot; | ||
using Telegram.Bot.Types; | ||
using DataBase; | ||
using MediaTelegramBot.Utils; | ||
using TelegramMediaRelayBot; | ||
|
||
|
||
namespace MediaTelegramBot; | ||
|
||
public class ProcessVideoDC : IUserState | ||
{ | ||
public UsersGroupState currentState; | ||
public string link { get; set; } | ||
public Message statusMessage { get; set; } | ||
public string text { get; set; } | ||
private string action = ""; | ||
private List<long> targetUserIds = new List<long>(); | ||
|
||
public ProcessVideoDC(string Link, Message StatusMessage, string Text) | ||
{ | ||
link = Link; | ||
statusMessage = StatusMessage; | ||
text = Text; | ||
currentState = UsersGroupState.ProcessAction; | ||
} | ||
|
||
public string GetCurrentState() | ||
{ | ||
return currentState.ToString(); | ||
} | ||
|
||
public async Task ProcessState(ITelegramBotClient botClient, Update update, CancellationToken cancellationToken) | ||
{ | ||
long chatId = Utils.Utils.GetIDfromUpdate(update); | ||
if (!TelegramBot.userStates.TryGetValue(chatId, out IUserState? value)) | ||
return; | ||
|
||
var userState = (ProcessVideoDC)value; | ||
|
||
switch (userState.currentState) | ||
{ | ||
case UsersGroupState.ProcessAction: | ||
if (update.CallbackQuery != null) | ||
{ | ||
string callbackData = update.CallbackQuery.Data!; | ||
switch (callbackData) | ||
{ | ||
case "send_to_all_contacts": | ||
userState.action = "send_to_all_contacts"; | ||
await PrepareTargetUserIds(chatId, userState); | ||
await botClient.EditMessageText(statusMessage.Chat.Id, statusMessage.MessageId, Config.GetResourceString("ConfirmDecision"), replyMarkup: KeyboardUtils.GetConfirmForActionKeyboardMarkup(), cancellationToken: cancellationToken); | ||
break; | ||
case "send_to_default_groups": | ||
userState.action = "send_to_default_groups"; | ||
await PrepareTargetUserIds(chatId, userState); | ||
break; | ||
case "send_to_specified_groups": | ||
userState.action = "send_to_specified_groups"; | ||
await botClient.SendMessage(chatId, "Please enter group IDs separated by spaces:", cancellationToken: cancellationToken); | ||
userState.currentState = UsersGroupState.ProcessData; | ||
break; | ||
case "send_to_specified_users": | ||
userState.action = "send_to_specified_users"; | ||
await botClient.SendMessage(chatId, "Please enter user IDs separated by spaces:", cancellationToken: cancellationToken); | ||
userState.currentState = UsersGroupState.ProcessData; | ||
break; | ||
case "send_only_to_me": | ||
userState.action = "send_only_to_me"; | ||
await botClient.EditMessageText(statusMessage.Chat.Id, statusMessage.MessageId, Config.GetResourceString("ConfirmDecision"), replyMarkup: KeyboardUtils.GetConfirmForActionKeyboardMarkup(), cancellationToken: cancellationToken); | ||
userState.currentState = UsersGroupState.Finish; | ||
break; | ||
case "main_menu": | ||
await Utils.Utils.HandleStateBreakCommand(botClient, update, chatId, removeReplyMarkup: false); | ||
break; | ||
} | ||
} | ||
break; | ||
|
||
case UsersGroupState.ProcessData: | ||
if (update.Message != null) | ||
{ | ||
string input = update.Message.Text!; | ||
if (input.Contains(" ")) | ||
{ | ||
string[] ids = input.Split(' '); | ||
if (ids.All(id => long.TryParse(id, out _))) | ||
{ | ||
targetUserIds = ids.Select(long.Parse).ToList(); | ||
await PrepareTargetUserIds(chatId, userState); | ||
} | ||
else | ||
{ | ||
await botClient.SendMessage(chatId, "Invalid input. Please enter numbers separated by spaces.", cancellationToken: cancellationToken); | ||
} | ||
} | ||
else | ||
{ | ||
if (long.TryParse(input, out long id)) | ||
{ | ||
targetUserIds.Add(id); | ||
await PrepareTargetUserIds(chatId, userState); | ||
} | ||
else | ||
{ | ||
await botClient.SendMessage(chatId, "Invalid input. Please enter a number.", cancellationToken: cancellationToken); | ||
} | ||
} | ||
} | ||
break; | ||
|
||
case UsersGroupState.Finish: | ||
if (update.CallbackQuery != null && update.CallbackQuery.Data == "main_menu" || | ||
update.Message != null) | ||
{ | ||
await botClient.EditMessageText(statusMessage.Chat.Id, statusMessage.MessageId, Config.GetResourceString("VideoDistributionQuestion"), replyMarkup: KeyboardUtils.GetVideoDistributionKeyboardMarkup(), cancellationToken: cancellationToken); | ||
userState.currentState = UsersGroupState.ProcessAction; | ||
return; | ||
} | ||
await botClient.EditMessageText(statusMessage.Chat.Id, statusMessage.MessageId, Config.GetResourceString("WaitDownloadingVideo"), cancellationToken: cancellationToken); | ||
TelegramBot.userStates.Remove(chatId); | ||
_ = TelegramBot.HandleVideoRequest(botClient, link, chatId, statusMessage, targetUserIds, caption: text); | ||
break; | ||
} | ||
} | ||
|
||
private async Task PrepareTargetUserIds(long chatId, ProcessVideoDC userState) | ||
{ | ||
int userId = DBforGetters.GetUserIDbyTelegramID(chatId); | ||
switch (userState.action) | ||
{ | ||
case "send_to_all_contacts": | ||
List<long> contactUserTGIds = await CoreDB.GetAllContactUserTGIds(userId); | ||
List<long> mutedByUserIds = DBforGetters.GetUsersIdForMuteContactId(userId); | ||
targetUserIds = contactUserTGIds.Except(mutedByUserIds).ToList(); | ||
break; | ||
case "send_to_default_groups": | ||
targetUserIds = new List<long>(); | ||
break; | ||
case "send_to_specified_groups": | ||
case "send_to_specified_users": | ||
break; | ||
} | ||
|
||
userState.currentState = UsersGroupState.Finish; | ||
} | ||
} |