internal void Init(NetworkManager.ChatMessage e, PlayerHandler player, ChatManager manager) { id = e.id; type = e.type; this.player = player; this.manager = manager; ChatAvatar.sprite = GD.Avatar(player.Avatar); participants = new List <ChatParticipant>(); bool found = false; foreach (ChatParticipant p in e.participants) { participants.Add(p); if (p.id == player.ID) { found = true; } } // Add the current player if missing if (!found) { participants.Add(new ChatParticipant(player.Name, player.Avatar, player.ID)); } ChatTitle.text = e.chatname; ChatTxt.text = ""; gameObject.SetActive(true); MaxButton.gameObject.SetActive(false); ChatContainer.gameObject.SetActive(true); GetComponent <RectTransform>().sizeDelta = new Vector2(500, 360); }
// If your activity returns a value, derive from CodeActivity<TResult> // and return the value from the Execute method. protected override void Execute(CodeActivityContext context) { // Obtain the runtime value of the Text input argument //string text = context.GetValue(this.Text); TelegramProp telegramDetails = (TelegramProp)context.DataContext.GetProperties()["telegramDetails"].GetValue(context.DataContext); var botToken = telegramDetails.authToken; var messageText = MessageText.Get(context); if (messageText == null) { throw new ArgumentException("MesageText missing"); } var chatID = ChatID.Get(context); var chatID_str = Convert.ToString(chatID); if (chatID_str == null) { throw new ArgumentException("Chat-ID missing"); } var botClient = new TelegramBotClient(botToken); Message message = botClient.SendTextMessageAsync(chatID, messageText).GetAwaiter().GetResult(); }
public void StartChatWith(ulong targetid, string targetname, int targetavatar) { // Generate the ID of the chat and the name string name = "Chat with <sprite=" + targetavatar + "> " + targetname; ChatID chatid = new ChatID(player.ID, targetid); if (!chats.ContainsKey(chatid)) { GameObject chat = Instantiate(ChatTemplate, ChatsGrid); Chat chatScript = chat.GetComponent <Chat>(); NetworkManager.ChatMessage e = new NetworkManager.ChatMessage { id = chatid, type = ChatType.OneToOne, chatname = name, senderid = player.ID, senderavatar = player.Avatar, message = "", participants = new List <ChatParticipant> { new ChatParticipant(player.Name, player.Avatar, player.ID), new ChatParticipant(targetname, targetavatar, targetid) } }; chatScript.Init(e, player, this); chats[chatid] = chatScript; // Send the chat init to the participant (FIXME we should do something similar for the game group chat) GD.instance.networkManager.SendChat(chatid, ChatType.OneToOne, player, e.participants, ""); } Chats.SetActive(true); }
/// <summary> /// Возвращает словарь параметров. /// </summary> public override Dictionary <string, string> GetParameters() { var parameters = base.GetParameters(); parameters["chat_id"] = ChatID.ToString(); parameters["title"] = Title; return(parameters); }
public string _GetOldHintsFor(ChatID chatId, Team team = null, LocationHint locationHint = null, int?hintIndex = null) { string hintsCombo = "Все, що маю для вас:"; for (int i = 0; i < locationHint.Hints.Count && i <= hintIndex; ++i) { hintsCombo += $"\n#{i}:\n{locationHint.Hints[i]}"; } return(hintsCombo); }
public bool IsTeamFinishedForUser(ChatID chatId) { var team = _GetTeamForUser(chatId); if (null == team) { return(false); } return(team.CurrentLocationIndex >= team.Route.Count); }
public override bool Equals(object obj) { if (!(obj is ChatID)) { return(false); } ChatID mys = (ChatID)obj; return(id1 == mys.id1 && id2 == mys.id2); }
public void ChatEnded(ChatID id) { if (chats.ContainsKey(id)) { chats.Remove(id); } if (chats.Count == 0) { Chats.SetActive(false); } }
///<summary> ///returns all hints given before for current location as string. ///If all hints are taken, returns formatted combo of all hints for current location ///</summary> ///<param name="chatId">Used to indicate name of the team that asks for hint.</param> public string GetOldHintsFor(ChatID chatId) { var team = _GetTeamForUser(chatId); var locationHint = _GetLocationHintFor(team); if (null == team || null == locationHint) { return(_internalError + "Немає підходящої підказки або команда невизначена."); } var hintIndex = team.Route[team.CurrentLocationIndex].HintsCounter; return(_GetOldHintsFor(chatId, team, locationHint, hintIndex)); }
/// <summary> /// Возвращает словарь параметров. /// </summary> public override Dictionary <string, string> GetParameters() { var parameters = base.GetParameters(); if (ChatID != 0) { parameters["chat_id"] = ChatID.ToString(); } if (UserID != 0) { parameters["user_id"] = UserID.ToString(); } return(parameters); }
/// <summary> /// Возвращает словарь параметров. /// </summary> public override Dictionary <string, string> GetParameters() { var parameters = base.GetParameters(); if (ChatID != 0) { parameters["chat_id"] = ChatID.ToString(); } else if (UserID != 0) { parameters["user_id"] = UserID.ToString(); } else { parameters["domain"] = Domain; } if (UserIDs != null && UserIDs.Count != 0) { parameters["user_ids"] = String.Join(",", UserIDs); } if (!String.IsNullOrWhiteSpace(Message)) { parameters["message"] = Message; } //if (@Guid != 0) parameters["guid"] = @Guid.ToString(); if (Lat != null) { parameters["lat"] = Lat; } if (Long != null) { parameters["long"] = Long; } if (Attachment != null && Attachment.Count != 0) { parameters["attachment"] = String.Join(",", Attachment); } if (ForwardMessages != null && ForwardMessages.Count != 0) { parameters["forward_messages"] = String.Join(",", ForwardMessages); } if (StickerID != 0) { parameters["sticker_id"] = StickerID.ToString(); } return(parameters); }
/// <summary> /// Отправляет сообщение в беседу. /// </summary> private async Task SendMessage() { var text = EnteredText.Trim(); EnteredText = String.Empty; var msg = new VKMessage { Body = text, Date = DateTime.Now, ChatID = IsChat ? ChatID : 0, UserID = ServiceHelper.SettingsService.AccessToken.UserID, Type = VKMessageType.Sent, SentType = VKSentMessageType.Sending, Attachments = Attachments.ToList() }; Messages.Insert(0, msg); Messages.NewSentMessages.Add(msg); var param = new Dictionary <string, string>(); param["message"] = text; if (IsChat) { param["chat_id"] = ChatID.ToString(); } else { param["user_id"] = UserID.ToString(); } var request = new UniversalVKRequest <ulong>(VKMethodsConstants.MessageSend, param); var response = await request.ExecuteAsync(); if (response.Error.ErrorType == VKErrors.None) { msg.ID = response.Response; msg.SentType = VKSentMessageType.Unread; } else { msg.SentType = VKSentMessageType.Error; } }
// If your activity returns a value, derive from CodeActivity<TResult> // and return the value from the Execute method. protected override void Execute(CodeActivityContext context) { // Obtain the runtime value of the Text input argument //string text = context.GetValue(this.Text); TelegramProp telegramDetails = (TelegramProp)context.DataContext.GetProperties()["telegramDetails"].GetValue(context.DataContext); var botToken = telegramDetails.authToken; var photopath = PhotoPath.Get(context); if (photopath == null) { throw new ArgumentException("Photo-Path missing"); } var chatID = ChatID.Get(context); var chatID_str = Convert.ToString(chatID); if (chatID_str == null) { throw new ArgumentException("Chat-ID missing"); } var image_text = Image_Text.Get(context); if (image_text == null) { image_text = "Image sent from Bot"; } var botClient = new TelegramBotClient(botToken); string file = photopath; var fileName = file.Split(Path.DirectorySeparatorChar).Last(); using (var fileStream = new FileStream(file, FileMode.Open, FileAccess.Read, FileShare.Read)) { Message Photo = botClient.SendPhotoAsync(chatID, fileStream, image_text).GetAwaiter().GetResult(); } }
protected string GetBufferPath() { var path = Platform.GetBuffersPath(SessionUsername); var protocol = Protocol.ToLower(); var network = NetworkID.ToLower(); path = Path.Combine(path, protocol); if (network != protocol) { path = Path.Combine(path, network); } path = IOSecurity.GetFilteredPath(path); if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } var chatId = IOSecurity.GetFilteredFileName(ChatID.ToLower()); return(Path.Combine(path, chatId)); }
/// <summary> /// Возвращает коллекцию параметров. /// </summary> public override Dictionary <string, string> GetParameters() { var parameters = base.GetParameters(); parameters["chat_id"] = ChatID.ToString(); if (X != 0) { parameters["crop_x"] = X.ToString(); } if (Y != 0) { parameters["crop_y"] = Y.ToString(); } if (Width != 0) { parameters["crop_width"] = Width.ToString(); } return(parameters); }
/// <summary> /// Возвращает словарь параметров. /// </summary> public override Dictionary<string, string> GetParameters() { var parameters = base.GetParameters(); if (IsSingle) parameters["chat_id"] = ChatID.ToString(); else parameters["chat_ids"] = String.Join(",", ChatIDs); if (NameCase != VKUserNameCase.nom) parameters["name_case"] = NameCase.ToString(); if (Fields == null) parameters["fields"] = VKMethodsConstants.ExtendedProfileFields; else { var builder = new StringBuilder(); for (int i = 0; i < Fields.Count; i++) builder.Append(Fields[i] + ","); parameters["fields"] = builder.ToString(); } return parameters; }
private Team _GetTeamForUser(ChatID chatId, string phoneNumber = "") { if (_chatToTeamMapping.ContainsKey(chatId)) { return(_data.Teams[_chatToTeamMapping[chatId]]); } if (string.IsNullOrEmpty(phoneNumber)) { return(null); } phoneNumber = Team.PreprocessPhoneNumber(phoneNumber); var userTeam = _data.Teams?.SingleOrDefault(team => team.Members.Contains(phoneNumber)); if (userTeam != null) { _chatToTeamMapping.Add(chatId, _data.Teams.IndexOf(userTeam)); } return(userTeam); }
string GetDatabaseFile() { var dbPath = Platform.GetBuffersPath(SessionUsername); var protocol = Protocol.ToLower(); var network = NetworkID.ToLower(); dbPath = Path.Combine(dbPath, protocol); if (network != protocol) { dbPath = Path.Combine(dbPath, network); } dbPath = IOSecurity.GetFilteredPath(dbPath); if (!Directory.Exists(dbPath)) { Directory.CreateDirectory(dbPath); } var chatId = IOSecurity.GetFilteredFileName(ChatID.ToLower()); dbPath = Path.Combine(dbPath, String.Format("{0}.db4o", chatId)); return(dbPath); }
///<summary> ///returns first unseen hint for current location as string. ///If all hints are taken, returns formatted combo of all hints for current location ///</summary> ///<param name="chatId">Used to indicate name of the team that asks for hint.</param> public string AskNewHintFor(ChatID chatId) { var team = _GetTeamForUser(chatId); var locationHint = _GetLocationHintFor(team); if (null == team || null == locationHint) { return(_internalError + "Немає підходящої підказки або команда невизначена."); } var hintIndex = team.Route[team.CurrentLocationIndex].HintsCounter; if (hintIndex < locationHint.Hints.Count - 1) //hints also include main question { ++team.Route[team.CurrentLocationIndex].HintsCounter; ++locationHint.HintsTaken; return(locationHint.Hints[hintIndex + 1]); } else { return(_GetOldHintsFor(chatId, team, locationHint, hintIndex)); } }
/// <summary> /// Updates data regarding current location of specified team /// </summary> /// <param name="chatId"> Used to specify which team stats should be updated</param> /// <returns></returns> public (string text, bool actionsAvailable) UpdateTeamProgress(ChatID chatId) { var team = _GetTeamForUser(chatId); if (null == team) { return(_internalError + "Rоманда невизначена.", false); } if (++team.CurrentLocationIndex == team.Route.Count) { return("Вітаю! Ви пройшли квест!", false); } var locationHint = _GetLocationHintFor(team); if (null != locationHint) { return(locationHint.Hints[0], true); } return(_internalError + "Локацію не знайдено.", false); }
public void StartChatWith(string gamename, List <ChatParticipant> targets) { // Generate the ID of the chat and the name string name = "Game Chat <b>" + gamename + "</b>"; ChatID chatid = new ChatID(gamename); string introText = "<color=blue>Game chat:</color> "; int num = 1; foreach (ChatParticipant p in targets) { introText += " <sprite=" + p.avatar + "><b>" + p.name + "</b>"; if (num < targets.Count) { introText += ", "; } num++; } if (!chats.ContainsKey(chatid)) { GameObject chat = Instantiate(ChatTemplate, ChatsGrid); Chat chatScript = chat.GetComponent <Chat>(); NetworkManager.ChatMessage e = new NetworkManager.ChatMessage { id = chatid, type = ChatType.Game, chatname = name, senderid = player.ID, senderavatar = player.Avatar, message = "", participants = targets }; chatScript.Init(e, player, this); chats[chatid] = chatScript; // Send the chat init to the participant GD.instance.networkManager.SendChat(chatid, ChatType.Game, player, e.participants, introText); } Chats.SetActive(true); }
public int GetLocationIndexFor(ChatID chatId) => _GetTeamForUser(chatId)?.CurrentLocationIndex ?? -1;
public int GetLocationIdFor(ChatID chatId) => _GetLocationIdFor(_GetTeamForUser(chatId));
///<summary> ///Returns current location for the team of specified user ///</summary> ///<param name = "chatId" > Used to indicate user whose location needs to be identified.</param> public string GetLocationNameFor(ChatID chatId) => _GetLocationHintFor(_GetTeamForUser(chatId))?.LocationName;
///<summary> ///returns name of the team that user belongs to ///</summary> public string GetTeamNameForUser(ChatID chatId, string phoneNumber = "") => _GetTeamForUser(chatId, phoneNumber)?.Name;