|
@@ -2,6 +2,8 @@ using System;
|
|
|
using System.Threading.Tasks;
|
|
|
using MafiaTelegramBot.Controllers;
|
|
|
using MafiaTelegramBot.DataBase.EntityDao;
|
|
|
+using MafiaTelegramBot.Game;
|
|
|
+using MafiaTelegramBot.Other;
|
|
|
using MafiaTelegramBot.Resources;
|
|
|
using Telegram.Bot.Types;
|
|
|
|
|
@@ -15,16 +17,19 @@ namespace MafiaTelegramBot.Models.Commands
|
|
|
{
|
|
|
var command = update.Message.Text.Split(' ');
|
|
|
var player = await UserDao.GetPlayerById(UserId);
|
|
|
- Console.WriteLine(player.isAdmin);
|
|
|
+ if (command.Length == 2)
|
|
|
+ {
|
|
|
+ var values = command[1].Split('=');
|
|
|
+ return values[0] switch
|
|
|
+ {
|
|
|
+ "giveaway_id" => await GiveawayCommand(player, int.Parse(values[1])),
|
|
|
+ "room_key" => await ConnectToGameCommand(player, values[1]),
|
|
|
+ _ => new Message()
|
|
|
+ };
|
|
|
+ }
|
|
|
if (player.GetRoomName() != "")
|
|
|
return await Bot.SendWithMarkdown2(ChatId, $"{strings.prefer_leave_from_room} {player.GetRoomName()}");
|
|
|
- if (command.Length <= 1)
|
|
|
- return await Bot.SendWithMarkdown2(ChatId, strings.start_message, player.IsAdmin ? Keyboard.AdminMainMenu : Keyboard.MainMenu);
|
|
|
- var code = await RoomController.ConnectToGame(player, command[1]);
|
|
|
- var result = code == ResultCode.CodeOk
|
|
|
- ? Bot.SendWithMarkdown2(ChatId, strings.successful_entry_into_room, Keyboard.PlayerGameMenu)
|
|
|
- : Utilities.GetResultCodeMessage(code, ChatId);
|
|
|
- return await result;
|
|
|
+ return await Bot.SendWithMarkdown2(ChatId, strings.start_message, player.IsAdmin ? Keyboard.AdminMainMenu : Keyboard.MainMenu);
|
|
|
}
|
|
|
|
|
|
protected override bool IsMatches(string command)
|
|
@@ -32,5 +37,30 @@ namespace MafiaTelegramBot.Models.Commands
|
|
|
var commandPart = command.Split(' ')[0];
|
|
|
return base.IsMatches(commandPart);
|
|
|
}
|
|
|
+
|
|
|
+ private async Task<Message> GiveawayCommand(Player player, int id)
|
|
|
+ {
|
|
|
+ try
|
|
|
+ {
|
|
|
+ var giveaway = GiveAway.OpenedGiveaways[id];
|
|
|
+ return await giveaway.GivePrizeTo(player) == ResultCode.NowYouGetPrizeFromThisGiveaway
|
|
|
+ ? await Bot.SendWithMarkdown2(player.ChatId, strings.now_you_get_prize_from_this_giveaway)
|
|
|
+ : new Message();
|
|
|
+ }
|
|
|
+ catch (Exception)
|
|
|
+ {
|
|
|
+ return await Bot.SendWithMarkdown2(ChatId, strings.giveaway_now_ended, Keyboard.PlayerGameMenu);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private async Task<Message> ConnectToGameCommand(Player player, string roomKey)
|
|
|
+ {
|
|
|
+ if (player.GetRoomName() != "")
|
|
|
+ return await Bot.SendWithMarkdown2(ChatId, $"{strings.prefer_leave_from_room} {player.GetRoomName()}");
|
|
|
+ var code = await RoomController.ConnectToGame(player, roomKey);
|
|
|
+ return code == ResultCode.CodeOk
|
|
|
+ ? await Bot.SendWithMarkdown2(ChatId, strings.successful_entry_into_room, Keyboard.PlayerGameMenu)
|
|
|
+ : await Utilities.GetResultCodeMessage(code, ChatId);
|
|
|
+ }
|
|
|
}
|
|
|
}
|