private void GetStatus(long chatId) { TelegramPlayer player = null; if (Players.ContainsKey(chatId)) { player = Players[chatId]; } if (player == null) { var shortStatus = string.Join("\n", $"Aktive spillere: *{_currentGame.PlayersThisRound}*", _currentGame.GetLocationString(player.Location)); _botClient.SendTextMessageAsync(chatId, shortStatus, ParseMode.Markdown); return; } var status = string.Join("\n", $"Aktive spillere: *{_currentGame.PlayersThisRound}*", $"Din level: *{player?.Level ?? 0}*", $"Du er her: *{player.Location.Name}*", _currentGame.GetLocationString(player.Location)); player.Message(status); }
private void BotMessage(MessageEventArgs e) { Console.WriteLine(e.Message.From?.FirstName + "> " + e.Message.Text); if (e.Message.From?.Id == adminId) { if (HandleAdminMessage(e.Message)) { return; } } if (e.Message.Text == "/start") { _botClient.SendTextMessageAsync(e.Message.Chat.Id, _welcomeMessage); } if (e.Message.Text == "/regler") { _botClient.SendTextMessageAsync(e.Message.Chat.Id, rules, parseMode: Telegram.Bot.Types.Enums.ParseMode.Markdown); } if (e.Message.Text == "/status") { GetStatus(e.Message.Chat.Id); } if (Players.ContainsKey(e.Message.Chat.Id)) { Players[e.Message.Chat.Id].ParseMessage(e.Message); return; } switch (e.Message.Text) { case "/notify": if (_currentGame?.Started == false) { _botClient.SendTextMessageAsync(e.Message.Chat.Id, "Spillet er allerede i påmeldings-fasen. For å bli med, send /join"); } else { _playersToNotify.Add(e.Message.Chat.Id); SavePlayersToNotify(); _botClient.SendTextMessageAsync(e.Message.Chat.Id, "Du vil få beskjed før neste runde starter"); } break; case "/join": { if (_currentGame == null) { _botClient.SendTextMessageAsync(e.Message.Chat.Id, "Spillet har ikke startet. For å få beskjed når en ny runde starter, send /notify"); return; } if (_currentGame.Started) { // already started, please wait _botClient.SendTextMessageAsync(e.Message.Chat.Id, "Spillet er allerede i gang. Vennligst vent. For å få beskjed når en ny runde starter, send /notify"); return; } TelegramPlayer player = new TelegramPlayer(_currentGame, e.Message.Chat.Id, _botClient, $"{e.Message.From?.FirstName} {e.Message.From?.LastName}"); _currentGame.Players.Add(player); _botClient.SendTextMessageAsync(e.Message.Chat.Id, "Du er med i neste runde.\nRunden starter snart."); foreach (var actor in _currentGame.Players.OfType <TelegramPlayer>()) { _botClient.SendTextMessageAsync(actor.Id, $"{player.Name} ble med.\n{_currentGame.Players.Count} spillere", disableNotification: true); } Logger.Log(_currentGame, $"{player.Name} ble med.\n{_currentGame.Players.Count} spillere"); break; } } }