render.cpp 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. #include "render.h"
  2. void render(std::vector<std::string> irc_msg, door::Door &door,
  3. ircClient &irc) {
  4. // std::vector<std::string> irc_msg = *msg;
  5. if (irc_msg.size() == 1) {
  6. // system message
  7. door << "(" << irc_msg[0] << ")" << door::nl;
  8. return;
  9. }
  10. std::string cmd = irc_msg[1];
  11. if (irc_msg[0] == "ERROR") {
  12. std::string tmp = irc_msg[1];
  13. if (tmp[0] == ':')
  14. tmp.erase(0, 1);
  15. door << "* ERROR: " << tmp << door::nl;
  16. }
  17. if (cmd == "366") {
  18. // end of names, output and clear
  19. std::string channel = split_limit(irc_msg[3], 2)[0];
  20. irc.channels_lock.lock();
  21. door << "* users on " << channel << " : ";
  22. for (auto name : irc.channels[channel]) {
  23. door << name << " ";
  24. }
  25. irc.channels_lock.unlock();
  26. door << door::nl;
  27. // names.clear();
  28. }
  29. if (cmd == "372") {
  30. // MOTD
  31. std::string temp = irc_msg[3];
  32. temp.erase(0, 1);
  33. door << "* " << temp << door::nl;
  34. }
  35. // 400 and 500 are errors? should show those.
  36. if ((cmd[0] == '4') or (cmd[0] == '5')) {
  37. std::string tmp = irc_msg[3];
  38. if (tmp[0] == ':')
  39. tmp.erase(0, 1);
  40. door << "* " << tmp << door::nl;
  41. }
  42. if (cmd == "NOTICE") {
  43. std::string tmp = irc_msg[3];
  44. tmp.erase(0, 1);
  45. door << parse_nick(irc_msg[0]) << " NOTICE " << tmp << door::nl;
  46. }
  47. if (cmd == "ACTION") {
  48. if (irc_msg[2][0] == '#') {
  49. door << "* " << parse_nick(irc_msg[0]) << "/" << irc_msg[2] << " "
  50. << irc_msg[3] << door::nl;
  51. } else {
  52. door << "* " << parse_nick(irc_msg[0]) << " " << irc_msg[3] << door::nl;
  53. }
  54. }
  55. if (cmd == "TOPIC") {
  56. std::string tmp = irc_msg[3];
  57. tmp.erase(0, 1);
  58. door << parse_nick(irc_msg[0]) << " set topic of " << irc_msg[2] << " to "
  59. << tmp << door::nl;
  60. }
  61. if (cmd == "PRIVMSG") {
  62. door::ANSIColor nick_color{door::COLOR::WHITE, door::COLOR::BLUE};
  63. if (irc_msg[2][0] == '#') {
  64. std::string tmp = irc_msg[3];
  65. tmp.erase(0, 1);
  66. door::ANSIColor channel_color{door::COLOR::WHITE, door::COLOR::BLUE};
  67. if (irc_msg[2] == irc.talkto()) {
  68. channel_color = door::ANSIColor{door::COLOR::YELLOW, door::COLOR::BLUE,
  69. door::ATTR::BOLD};
  70. }
  71. door << nick_color << parse_nick(irc_msg[0])
  72. << door::ANSIColor(door::COLOR::CYAN) << "/" << channel_color
  73. << irc_msg[2] << door::reset << " " << tmp << door::nl;
  74. } else {
  75. std::string tmp = irc_msg[3];
  76. tmp.erase(0, 1);
  77. door << nick_color << parse_nick(irc_msg[0]) << door::reset << " " << tmp
  78. << door::nl;
  79. }
  80. }
  81. }