|
| 1 | +using CounterStrikeSharp.API; |
| 2 | +using Cs2Telegram.Enums; |
| 3 | +using Cs2Telegram.Models; |
| 4 | +using Cs2Telegram.TelegramEvents; |
| 5 | +using PRTelegramBot.Attributes; |
| 6 | +using PRTelegramBot.Helpers.TG; |
| 7 | +using PRTelegramBot.Models.InlineButtons; |
| 8 | +using PRTelegramBot.Models.Interface; |
| 9 | +using PRTelegramBot.Models; |
| 10 | +using System; |
| 11 | +using System.Collections.Generic; |
| 12 | +using System.Linq; |
| 13 | +using System.Text; |
| 14 | +using System.Threading.Tasks; |
| 15 | +using Telegram.Bot.Types; |
| 16 | +using Telegram.Bot; |
| 17 | +using PRTelegramBot.Extensions; |
| 18 | +using PRTelegramBot.Models.CallbackCommands; |
| 19 | +using CounterStrikeSharp.API.Modules.Utils; |
| 20 | + |
| 21 | +namespace Cs2Telegram.Commands |
| 22 | +{ |
| 23 | + public static class PlayerCommands |
| 24 | + { |
| 25 | + const string PLAYER_NOT_VALID = "Player not found or player is no valid"; |
| 26 | + |
| 27 | + [ReplyMenuHandler(Constants.SERVER_PLAYERS_INFO_BUTTON)] |
| 28 | + [InlineCallbackHandler<HeaderCommand>(HeaderCommand.PlayerInfoList)] |
| 29 | + public static async Task PlayersInfo(ITelegramBotClient botClient, Update update) |
| 30 | + { |
| 31 | + if (!botClient.IsAdmin(update.GetChatId())) |
| 32 | + { |
| 33 | + await CommonEvents.AccessDenied(botClient, update); |
| 34 | + return; |
| 35 | + } |
| 36 | + |
| 37 | + var inlineMenuItems = new List<IInlineContent>(); |
| 38 | + Server.NextFrame(() => |
| 39 | + { |
| 40 | + var players = Utilities.GetPlayers(); |
| 41 | + foreach (var player in players) |
| 42 | + { |
| 43 | + var commandItem = new InlineCallback<EntityTCommand<int>>($"{player.PlayerName}{(player.IsBot ? " [Bot]" : "")}", HeaderCommand.PlayerInfo, new EntityTCommand<int>(player.UserId != null ? player.UserId.Value : -1)); |
| 44 | + inlineMenuItems.Add(commandItem); |
| 45 | + } |
| 46 | + |
| 47 | + var options = new OptionMessage(); |
| 48 | + string msg = "Players not found"; |
| 49 | + if (inlineMenuItems.Count > 0) |
| 50 | + { |
| 51 | + msg = "Players on server:"; |
| 52 | + options.MenuInlineKeyboardMarkup = MenuGenerator.InlineKeyboard(MenuGenerator.InlineButtons(1, inlineMenuItems)); |
| 53 | + } |
| 54 | + else |
| 55 | + { |
| 56 | + options.MenuReplyKeyboardMarkup = botClient.GenerateOnlyMenu(update.GetChatId()); |
| 57 | + } |
| 58 | + var command = InlineCallback<EntityTCommand<int>>.GetCommandByCallbackOrNull(update.CallbackQuery?.Data ?? ""); |
| 59 | + if(command != null) |
| 60 | + { |
| 61 | + Helper.EditMessage(botClient, update, msg, options); |
| 62 | + } |
| 63 | + else |
| 64 | + { |
| 65 | + Helper.SendMessage(botClient, update, msg, options); |
| 66 | + } |
| 67 | + |
| 68 | + }); |
| 69 | + } |
| 70 | + |
| 71 | + [InlineCallbackHandler<HeaderCommand>(HeaderCommand.PlayerInfo)] |
| 72 | + public static async Task PlayerInfoHandler(ITelegramBotClient botClient, Update update) |
| 73 | + { |
| 74 | + if (!botClient.IsAdmin(update.GetChatId())) |
| 75 | + { |
| 76 | + await CommonEvents.AccessDenied(botClient, update); |
| 77 | + return; |
| 78 | + } |
| 79 | + |
| 80 | + var command = InlineCallback<EntityTCommand<int>>.GetCommandByCallbackOrNull(update.CallbackQuery.Data); |
| 81 | + if (command != null && command.Data.EntityId != -1) |
| 82 | + { |
| 83 | + Server.NextFrame(() => |
| 84 | + { |
| 85 | + int userId = command.Data.EntityId; |
| 86 | + string msg = PLAYER_NOT_VALID; |
| 87 | + var options = new OptionMessage(); |
| 88 | + var player = Utilities.GetPlayerFromUserid(userId); |
| 89 | + if (player != null && player.IsValid) |
| 90 | + { |
| 91 | + msg = |
| 92 | + $"Player name:{player.PlayerName}\n" + |
| 93 | + $"Clan name: {player.ClanName}\n" + |
| 94 | + $"Score: {player.Score}\n" + |
| 95 | + $"IP: {player.IpAddress ?? ""}\n" + |
| 96 | + //$"Time: {TimeSpan.FromSeconds(player.).ToReadableString()}\n" + |
| 97 | + $"Ping: {player.Ping}\n" + |
| 98 | + $"SteamId: {player.AuthorizedSteamID?.ToString()}\n"; |
| 99 | + |
| 100 | + //var changeTeamTButton = new InlineCallback<ChangeTeamPlayerCommand>($"Team T", HeaderCommand.PlayerChangeTeam, new ChangeTeamPlayerCommand(player.UserId != null ? player.UserId.Value : -1, CsTeam.Terrorist)); |
| 101 | + //var changeTeamCTButton = new InlineCallback<ChangeTeamPlayerCommand>($"Team CT", HeaderCommand.PlayerChangeTeam, new ChangeTeamPlayerCommand(player.UserId != null ? player.UserId.Value : -1, CsTeam.CounterTerrorist)); |
| 102 | + //var changeTeamSpectatorButton = new InlineCallback<ChangeTeamPlayerCommand>($"Team Spectator", HeaderCommand.PlayerChangeTeam, new ChangeTeamPlayerCommand(player.UserId != null ? player.UserId.Value : -1, CsTeam.Spectator)); |
| 103 | + var kickCommandItem = new InlineCallback<EntityTCommand<int>>($"Kick", HeaderCommand.PlayerKick, new EntityTCommand<int>(player.UserId != null ? player.UserId.Value : -1)); |
| 104 | + var BackCommandItem = new InlineCallback<EntityTCommand<int>>($"Back", HeaderCommand.PlayerInfoList, new EntityTCommand<int>(-1)); |
| 105 | + //var killCommandItem = new InlineCallback<EntityTCommand<int>>($"Kill", HeaderCommand.PlayerKill, new EntityTCommand<int>(player.UserId != null ? player.UserId.Value : -1)); |
| 106 | + var menuTeamButtons = MenuGenerator.InlineButtons(2,new List<IInlineContent> { kickCommandItem, BackCommandItem }); |
| 107 | + var menu = MenuGenerator.InlineKeyboard(menuTeamButtons); |
| 108 | + options.MenuInlineKeyboardMarkup = menu; |
| 109 | + |
| 110 | + } |
| 111 | + |
| 112 | + Helper.EditMessage(botClient, update, msg, options); |
| 113 | + }); |
| 114 | + } |
| 115 | + } |
| 116 | + |
| 117 | + [InlineCallbackHandler<HeaderCommand>(HeaderCommand.PlayerKick)] |
| 118 | + public static async Task PlayerKickHandler(ITelegramBotClient botClient, Update update) |
| 119 | + { |
| 120 | + if (!botClient.IsAdmin(update.GetChatId())) |
| 121 | + { |
| 122 | + await CommonEvents.AccessDenied(botClient, update); |
| 123 | + return; |
| 124 | + } |
| 125 | + |
| 126 | + var command = InlineCallback<EntityTCommand<int>>.GetCommandByCallbackOrNull(update.CallbackQuery.Data); |
| 127 | + if (command != null && command.Data.EntityId != -1) |
| 128 | + { |
| 129 | + Server.NextFrame(() => |
| 130 | + { |
| 131 | + int userId = command.Data.EntityId; |
| 132 | + string msg = PLAYER_NOT_VALID; |
| 133 | + var options = new OptionMessage(); |
| 134 | + var player = Utilities.GetPlayerFromUserid(userId); |
| 135 | + if (player != null && player.IsValid) |
| 136 | + { |
| 137 | + msg = $"Server kicked {player.PlayerName}"; |
| 138 | + Server.ExecuteCommand($"kickid {player.UserId}"); |
| 139 | + } |
| 140 | + |
| 141 | + Helper.EditMessage(botClient, update, msg, options); |
| 142 | + }); |
| 143 | + } |
| 144 | + } |
| 145 | + |
| 146 | + //[InlineCallbackHandler<HeaderCommand>(HeaderCommand.PlayerKill)] |
| 147 | + //public static async Task PlayerKillHandler(ITelegramBotClient botClient, Update update) |
| 148 | + //{ |
| 149 | + // if (!botClient.IsAdmin(update.GetChatId())) |
| 150 | + // { |
| 151 | + // await CommonEvents.AccessDenied(botClient, update); |
| 152 | + // return; |
| 153 | + // } |
| 154 | + |
| 155 | + // var command = InlineCallback<EntityTCommand<int>>.GetCommandByCallbackOrNull(update.CallbackQuery.Data); |
| 156 | + // if (command != null && command.Data.EntityId != -1) |
| 157 | + // { |
| 158 | + // Server.NextFrame(() => |
| 159 | + // { |
| 160 | + // int userId = command.Data.EntityId; |
| 161 | + // string msg = PLAYER_NOT_VALID; |
| 162 | + // var options = new OptionMessage(); |
| 163 | + // var player = Utilities.GetPlayerFromUserid(userId); |
| 164 | + // if (player != null && player.IsValid) |
| 165 | + // { |
| 166 | + // if(player.PawnIsAlive) |
| 167 | + // { |
| 168 | + // msg = $"Player {player.PlayerName} kill"; |
| 169 | + // player.CommitSuicide(false, true); |
| 170 | + // } |
| 171 | + // else |
| 172 | + // { |
| 173 | + // msg = $"Player {player.PlayerName} already dead"; |
| 174 | + // } |
| 175 | + // } |
| 176 | + |
| 177 | + // Helper.EditMessage(botClient, update, msg, options); |
| 178 | + // }); |
| 179 | + // } |
| 180 | + //} |
| 181 | + |
| 182 | + |
| 183 | + //[InlineCallbackHandler<HeaderCommand>(HeaderCommand.PlayerChangeTeam)] |
| 184 | + //public static async Task PlayerChangeTeamHandler(ITelegramBotClient botClient, Update update) |
| 185 | + //{ |
| 186 | + // if (!botClient.IsAdmin(update.GetChatId())) |
| 187 | + // { |
| 188 | + // await CommonEvents.AccessDenied(botClient, update); |
| 189 | + // return; |
| 190 | + // } |
| 191 | + |
| 192 | + // var command = InlineCallback<ChangeTeamPlayerCommand>.GetCommandByCallbackOrNull(update.CallbackQuery.Data); |
| 193 | + // if (command != null && command.Data.UserId != -1) |
| 194 | + // { |
| 195 | + // Server.NextFrame(() => |
| 196 | + // { |
| 197 | + // int userId = command.Data.UserId; |
| 198 | + // string msg = PLAYER_NOT_VALID; |
| 199 | + // var options = new OptionMessage(); |
| 200 | + // var player = Utilities.GetPlayerFromUserid(userId); |
| 201 | + // if (player != null && player.IsValid) |
| 202 | + // { |
| 203 | + // msg = "ChangeTeam"; |
| 204 | + // player.ChangeTeam(CsTeam.CounterTerrorist); |
| 205 | + // } |
| 206 | + |
| 207 | + // Helper.SendMessage(botClient, update, msg, options); |
| 208 | + // }); |
| 209 | + // } |
| 210 | + //} |
| 211 | + } |
| 212 | +} |
0 commit comments