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.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. /*
  2. * Copyright (c) 2006-2015 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.util.Date;
  26. import java.util.EnumMap;
  27. import java.util.Map;
  28. import java.util.Optional;
  29. /**
  30. * Event raised when detailed user info has been received for a user.
  31. */
  32. public class UserInfoEvent extends ParserEvent {
  33. private final ClientInfo client;
  34. private final Map<UserInfoType, String> info;
  35. public UserInfoEvent(final Parser parser, final Date date, final ClientInfo client,
  36. final Map<UserInfoType, String> info) {
  37. super(parser, date);
  38. this.client = client;
  39. this.info = new EnumMap<>(info);
  40. }
  41. /**
  42. * Gets the client that the event is for.
  43. *
  44. * @return The client this event is for.
  45. */
  46. public ClientInfo getClient() {
  47. return client;
  48. }
  49. /**
  50. * Gets a specific piece of information about the user.
  51. *
  52. * @param type The type of information to return.
  53. * @return An optional containing the information, if it was provided.
  54. */
  55. public Optional<String> getInfo(final UserInfoType type) {
  56. return Optional.ofNullable(info.get(type));
  57. }
  58. /**
  59. * The types of user info that may be returned by the server.
  60. */
  61. public enum UserInfoType {
  62. /** The user's full address. */
  63. ADDRESS,
  64. /** The user's real name. */
  65. REAL_NAME,
  66. /** The list of group chats the user is in. */
  67. GROUP_CHAT_LIST,
  68. /** The name of the server the user is connected to. */
  69. SERVER_NAME,
  70. /** Information about the server the user is connected to. */
  71. SERVER_INFO,
  72. /** The account the user is authenticated as. */
  73. ACCOUNT_NAME,
  74. /** The current idle time for the user. */
  75. IDLE_TIME,
  76. /** The time the user connected at. */
  77. CONNECTION_TIME,
  78. /** The user's current away message. */
  79. AWAY_MESSAGE,
  80. /** The user's server operator status. */
  81. SERVER_OPER,
  82. /** Information about the security of the user's connection to the server. */
  83. CONNECTION_SECURITY,
  84. /** The language the user uses. */
  85. LANGUAGE,
  86. }
  87. }