You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

UserInfoEvent.java 3.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. /*
  2. * Copyright (c) 2006-2017 DMDirc Developers
  3. *
  4. * Permission is hereby granted, free of charge, to any person obtaining a copy
  5. * of this software and associated documentation files (the "Software"), to deal
  6. * in the Software without restriction, including without limitation the rights
  7. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  8. * copies of the Software, and to permit persons to whom the Software is
  9. * furnished to do so, subject to the following conditions:
  10. *
  11. * The above copyright notice and this permission notice shall be included in
  12. * all copies or substantial portions of the Software.
  13. *
  14. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  19. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  20. * SOFTWARE.
  21. */
  22. package com.dmdirc.parser.events;
  23. import com.dmdirc.parser.interfaces.ClientInfo;
  24. import com.dmdirc.parser.interfaces.Parser;
  25. import java.time.LocalDateTime;
  26. import java.util.Collections;
  27. import java.util.EnumMap;
  28. import java.util.Map;
  29. import java.util.Optional;
  30. /**
  31. * Event raised when detailed user info has been received for a user.
  32. */
  33. public class UserInfoEvent extends ParserEvent {
  34. private final ClientInfo client;
  35. private final Map<UserInfoType, String> info;
  36. public UserInfoEvent(final Parser parser, final LocalDateTime date, final ClientInfo client,
  37. final Map<UserInfoType, String> info) {
  38. super(parser, date);
  39. this.client = client;
  40. this.info = new EnumMap<>(info);
  41. }
  42. /**
  43. * Gets the client that the event is for.
  44. *
  45. * @return The client this event is for.
  46. */
  47. public ClientInfo getClient() {
  48. return client;
  49. }
  50. /**
  51. * Gets a specific piece of information about the user.
  52. *
  53. * @param type The type of information to return.
  54. * @return An optional containing the information, if it was provided.
  55. */
  56. public Optional<String> getInfo(final UserInfoType type) {
  57. return Optional.ofNullable(info.get(type));
  58. }
  59. /**
  60. * Gets all the pieces of information about the user.
  61. *
  62. * @return Map of all information about a user, may be empty
  63. */
  64. public Map<UserInfoType, String> getInfo() {
  65. return Collections.unmodifiableMap(info);
  66. }
  67. /**
  68. * The types of user info that may be returned by the server.
  69. */
  70. public enum UserInfoType {
  71. /** The user's full address. */
  72. ADDRESS,
  73. /** The user's real address. */
  74. REAL_ADDRESS,
  75. /** The user's real name. */
  76. REAL_NAME,
  77. /** The list of group chats the user is in. */
  78. GROUP_CHAT_LIST,
  79. /** The name of the server the user is connected to. */
  80. SERVER_NAME,
  81. /** Information about the server the user is connected to. */
  82. SERVER_INFO,
  83. /** The account the user is authenticated as. */
  84. ACCOUNT_NAME,
  85. /** The current idle time for the user. */
  86. IDLE_TIME,
  87. /** The time the user connected at. */
  88. CONNECTION_TIME,
  89. /** The user's current away message. */
  90. AWAY_MESSAGE,
  91. /** The user's server operator status. */
  92. SERVER_OPER,
  93. /** Information about the security of the user's connection to the server. */
  94. CONNECTION_SECURITY,
  95. /** The language the user uses. */
  96. LANGUAGE,
  97. }
  98. }