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.

IRCDataInEvent.java 2.8KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. /*
  2. * Copyright (c) 2006-2014 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.irc.events;
  23. import com.dmdirc.parser.events.DataInEvent;
  24. import com.dmdirc.parser.interfaces.Parser;
  25. import com.dmdirc.parser.irc.IRCParser;
  26. import com.dmdirc.parser.irc.IRCReader.ReadLine;
  27. import java.time.LocalDateTime;
  28. import static com.google.common.base.Preconditions.checkNotNull;
  29. /**
  30. * Called on every incoming line BEFORE parsing.
  31. *
  32. * This extends the standard DataInEvent to provide access to IRC-Specific bits.
  33. */
  34. public class IRCDataInEvent extends DataInEvent {
  35. private final ReadLine line;
  36. private final String[] tokenisedData;
  37. private final String action;
  38. public IRCDataInEvent(final IRCParser parser, final LocalDateTime date, final ReadLine line) {
  39. super(parser, date, checkNotNull(line).getLine());
  40. this.line = line;
  41. tokenisedData = line.getTokens();
  42. // Action is slightly more complicated than for DataOut
  43. if (tokenisedData.length > 1) {
  44. if (tokenisedData[0].length() > 0 && tokenisedData[0].charAt(0) == ':') {
  45. if (tokenisedData[1].equalsIgnoreCase("NOTICE") && !parser.got001) {
  46. action = "NOTICE AUTH";
  47. } else {
  48. action = tokenisedData[1].toUpperCase();
  49. }
  50. } else if (tokenisedData[0].equalsIgnoreCase("NOTICE")) {
  51. action = "NOTICE AUTH";
  52. } else {
  53. action = tokenisedData[0].toUpperCase();
  54. }
  55. } else {
  56. action = "";
  57. }
  58. }
  59. public String[] getTokenisedData() {
  60. return tokenisedData;
  61. }
  62. public ReadLine getLine() {
  63. return line;
  64. }
  65. public String getAction() {
  66. return action;
  67. }
  68. }