Guest User

Untitled

a guest
Nov 23rd, 2017
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.25 KB | None | 0 0
  1. #include "all.h"
  2. #include <string>
  3. #include <iostream>
  4. using namespace std;
  5. using namespace pircbot;
  6.  
  7. class Keybored : public PircBot
  8. {
  9. public:
  10.  
  11. /**
  12. * Default constructor
  13. * in which we set the name
  14. * of our bot.
  15. */
  16. Keybored()
  17. {
  18. this->setName("Keybored");
  19. }
  20.  
  21. /**
  22. * We override the onMessage here
  23. * so that we respond to someone
  24. * saying "time".
  25. *
  26. * @param channel The channel to which the message was sent.
  27. * @param sender The nick of the person who sent the message.
  28. * @param login The login of the person who sent the message.
  29. * @param hostname The hostname of the person who sent the message.
  30. * @param message The actual message sent to the channel.
  31. *
  32. * @throws Exception Inherit from Exception and throw any type
  33. * of exception you would like.
  34. */
  35. void onMessage(const char * const channel,
  36. const char * const sender,
  37. const char * const login,
  38. const char * const hostname,
  39. const char * const message)
  40. throw(Exception &)
  41. {
  42. //The message that someone from the server said.
  43. string messageString(message);
  44.  
  45. //Create a string of the sender of the message from
  46. //the sender *char
  47. string senderString(sender);
  48.  
  49. //Look to see if the message string is equal to time
  50. if(messageString == "time")
  51. {
  52. //Create our time string and sppend the name
  53. //of the person asking for the time to it.
  54. string time = "Time for you to get a watch";
  55. senderString += ": The time is now ";
  56. senderString += time;
  57.  
  58. //Okay, so send to the channel our message
  59. sendMessage(channel, senderString.c_str());
  60. }
  61. }
  62. };
  63.  
  64. /**
  65. * Our standard C++ main
  66. */
  67. int main(int argc, char* argv[])
  68. {
  69. try
  70. {
  71. //Create new instance of our custom bot
  72. PircBot *p = new Keybored;
  73.  
  74. //We want verbose messages turned on.
  75. p->setVerbose(true);
  76.  
  77. //Connect to our irc server
  78. p->connect("irc.rizon.net");
  79.  
  80. //Join our channel
  81. p->joinChannel("#arflux-rpg");
  82.  
  83. //Wait until all the threads are destroyed
  84. //before letting main exit.
  85. p->join();
  86. }
  87. catch(Exception &e)
  88. {
  89. //Error, so let's print it and exit 1
  90. cout << e.what() << endl;
  91. return 1;
  92. }
  93.  
  94. //No errors, so we return with 0
  95. return 0;
  96. }
Add Comment
Please, Sign In to add comment