Advertisement
Guest User

Untitled

a guest
Mar 12th, 2016
1,560
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.97 KB | None | 0 0
  1. <script src="//cdn.tmijs.org/js/0.0.27/tmi.js"></script>
  2. <script>
  3.  
  4. var mysql = require('mysql');
  5. var database_options = {
  6. host : 'localhost',
  7. user : '********',
  8. password : '********',
  9. database : '********'
  10. };
  11.  
  12. var connection = mysql.createConnection(database_options);
  13.  
  14. function logChat(channel, user, message){
  15. connection.beginTransaction(function(err) {
  16. if (err) { throw err; }
  17.  
  18. connection.query(
  19. 'INSERT INTO chat_log (channel, user_name, action, message, datetime) VALUES (?,?,?,?,?)',
  20. [channel, user.username, action, message, now()],
  21. function(err, result) {
  22. if(!err){
  23.  
  24. }else{
  25. return connection.rollback(function() {throw err; });
  26. }
  27. }
  28. );
  29. connection.commit(function(err) {
  30. if (err) {
  31. return connection.rollback(function() {
  32. throw err;
  33. });
  34. }
  35. console.log("Logged: ["+channel+"]["+user.username+"] " + message );
  36. });
  37. });
  38. }
  39.  
  40. var irc = require("tmi.js");
  41. var options = {
  42. options: {
  43. debug: true
  44. },
  45. connection: {
  46. cluster: "main",
  47. reconnect: true
  48. },
  49. identity: {
  50. username: "********",
  51. password: "********"
  52. },
  53. channels: ["#********"]
  54. };
  55.  
  56. var client = new irc.client(options);
  57.  
  58. // Connect the client to the server..
  59. client.connect();
  60.  
  61.  
  62.  
  63.  
  64.  
  65.  
  66. client.on("chat", function (channel, user, message, self) {
  67. logChat(channel, user, message);
  68. // IF IS MAIN CHANNEL
  69. if(channel.replace("#", "") === "********"){
  70. if(message === "!join"){
  71. client.say(channel, "Joining "+user["username"]+"!");
  72. client.join(user["username"]);
  73. }
  74. //IF IS CHANNEL OWNER
  75. if(channel.replace("#", "") === user["username"]){
  76. // IF !LEAVE, DISCONECT BOT FROM CHANNEL!
  77. if(message === "!leave"){
  78. client.say(channel, "Disconecting!");
  79. client.part(channel);
  80. }
  81.  
  82. }else if(client.isMod(channel, user["username"])){
  83. //IF !MESSAGE {MESSAGE}, Sends Global Message!
  84. if(message === "!message"){
  85. var chan = client.getChannels();
  86. client.say(chan, "test");
  87.  
  88. }
  89. }
  90. //GLOBAL COMMANDS IN MAIN CHANNEL ONLY
  91. if(message === "!help"){
  92. client.say(channel, "Commands: !join - Joins me to your channel. | !help - Displays my current commands.");
  93. }
  94. }else{
  95. //IF IS CHANNEL OWNER
  96. if(channel.replace("#", "") === user["username"]){
  97. // IF !LEAVE, DISCONECT BOT FROM CHANNEL!
  98. if(message === "!leave"){
  99. client.say(channel, "Disconecting!");
  100. client.part(channel);
  101. }
  102. }
  103. //IF IS MOD
  104. if(client.isMod(channel, user["username"])){
  105. /*if(message === ""){
  106.  
  107. }*/
  108. }else{
  109. /*if(message === ""){
  110. client.say(channel, "Hello, I am ********. You can learn more about me at ********");
  111. }*/
  112. }
  113. }
  114. //GLOBAL COMMANDS
  115. if(message === "!bot"){
  116. client.say(channel, "Hello, I am ********. You can learn more about me at *********");
  117. }
  118.  
  119.  
  120.  
  121. });
  122.  
  123. </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement