|
@@ -1,5 +1,7 @@
|
|
|
using System.Threading.Tasks;
|
|
|
+using MafiaTelegramBot.Controllers;
|
|
|
using MafiaTelegramBot.DataBase;
|
|
|
+using MafiaTelegramBot.Resources;
|
|
|
using Telegram.Bot.Types;
|
|
|
using Telegram.Bot.Types.Enums;
|
|
|
|
|
@@ -14,13 +16,30 @@ namespace MafiaTelegramBot.Models.Commands
|
|
|
await Bot.Get().SendChatActionAsync(chatId, ChatAction.Typing);
|
|
|
var message = update.Message.Text;
|
|
|
var userId = update.Message.From.Id;
|
|
|
- if (Bot.UsersThatChangesNickname.Remove(userId))
|
|
|
+
|
|
|
+ if (Bot.UsersThatChangesNickname.Remove(userId)) return await ChangeNicknameLogic(userId, chatId, message);
|
|
|
+ if (Bot.UsersThatCreatesPublicRoom.Remove(userId)) return await CreatePublicRoomLogic(userId, chatId, message);
|
|
|
+
|
|
|
+ return await Bot.SendWithMarkdown2(chatId, $"{strings.command_not_found} _*\\({message}\\)*_");
|
|
|
+ }
|
|
|
+
|
|
|
+ private static async Task<Message> ChangeNicknameLogic(long userId, long chatId, string message)
|
|
|
+ {
|
|
|
+ var user = await UserDao.GetUserById(userId);
|
|
|
+ await user.UpdateName(message);
|
|
|
+ return await Bot.SendWithMarkdown2(chatId, $"{strings.name_updated} _*{message}*_");
|
|
|
+ }
|
|
|
+
|
|
|
+ private static async Task<Message> CreatePublicRoomLogic(long userId, long chatId, string message)
|
|
|
+ {
|
|
|
+ var user = await UserDao.GetUserById(userId);
|
|
|
+ var resultCode = await RoomController.CreateNewGame(user, message);
|
|
|
+ return resultCode switch
|
|
|
{
|
|
|
- var user = await UserDao.GetUserById(userId);
|
|
|
- await user.UpdateName(message);
|
|
|
- return await Bot.Get().SendTextMessageAsync(chatId, $"{strings.name_updated} {message}");
|
|
|
- }
|
|
|
- return await Bot.Get().SendTextMessageAsync(chatId, $"{strings.command_not_found} _*\\({message}\\)*_", ParseMode.MarkdownV2);
|
|
|
+ Constants.CODE_OK => await Bot.SendWithMarkdown2(chatId, $"{strings.room_with_name} _*{message}*_ {strings.was_created}"),
|
|
|
+ Constants.GAME_EXISTS => await Bot.SendWithMarkdown2(chatId, $"{strings.room} _*{message}*_ {strings.already_exists}"),
|
|
|
+ _ => await Bot.SendWithMarkdown2(chatId, strings.unexpected_error)
|
|
|
+ };
|
|
|
}
|
|
|
}
|
|
|
}
|