Advertisement
Guest User

Untitled

a guest
Mar 28th, 2020
192
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.21 KB | None | 0 0
  1. using Butterfly.HabboHotel.GameClients;
  2. using Butterfly.Communication.Packets.Outgoing.WebSocket;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Linq;
  6. using System.Text;
  7. using System.Text.RegularExpressions;
  8. using System.Threading.Tasks;
  9. using Butterfly.Communication.Packets.Outgoing.Structure;
  10. using Butterfly.Communication.Packets.Outgoing.WebSocket.Mentions;
  11. using Butterfly.HabboHotel.WebClients;
  12.  
  13. namespace Butterfly.HabboHotel.Rooms.Chat.Mentions
  14. {
  15. public class MentionManager
  16. {
  17. public string MentionPattern = @"@(.*?)(?=\s|$)";
  18.  
  19. public string StylePrefix = "";
  20. public string StyleSuffix = "";
  21.  
  22. public string Parse(GameClient Session, string Message)
  23. {
  24. string StyledMessage = Message;
  25.  
  26. int ChangeLength = StylePrefix.Length + StyleSuffix.Length;
  27. int ChangeCount = 0;
  28.  
  29. foreach (Match m in Regex.Matches(Message, MentionPattern))
  30. {
  31. string TargetUsername = m.Groups[1].Value;
  32. GameClient TargetClient = ButterflyEnvironment.GetGame().GetClientManager().GetClientByUsername(TargetUsername);
  33.  
  34. StyledMessage = StyledMessage.Insert(ChangeCount * ChangeLength + m.Index, StylePrefix);
  35. StyledMessage = StyledMessage.Insert(ChangeCount * ChangeLength + m.Index + StylePrefix.Length + m.Length, StyleSuffix);
  36.  
  37. ChangeCount++;
  38.  
  39. if (TargetClient == null)
  40. {
  41. Session.SendPacket(RoomNotificationComposer.SendBubble("tag", $"Une erreur est survenue quand tu as tenté de mentionner {TargetUsername}, peut-être qu'il est hors ligne !"));
  42. continue;
  43. }
  44.  
  45. if (TargetClient == Session)
  46. {
  47. continue;
  48. }
  49. TargetClient.SendPacket(RoomNotificationComposer.SendBubble("tag", $"Hey, " + Session.GetHabbo().Username + " a tagué ton pseudo.\n\nVoici son message: " + Message + "\n\nClique sur le message pour le rejoindre !", "event:navigator/goto/" + Session.GetHabbo().CurrentRoomId + " "));
  50. }
  51. return StyledMessage;
  52. }
  53. }
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement