Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <script src="//cdn.tmijs.org/js/0.0.27/tmi.js"></script>
- <script>
- var mysql = require('mysql');
- var database_options = {
- host : 'localhost',
- user : '********',
- password : '********',
- database : '********'
- };
- var connection = mysql.createConnection(database_options);
- function logChat(channel, user, message){
- connection.beginTransaction(function(err) {
- if (err) { throw err; }
- connection.query(
- 'INSERT INTO chat_log (channel, user_name, action, message, datetime) VALUES (?,?,?,?,?)',
- [channel, user.username, action, message, now()],
- function(err, result) {
- if(!err){
- }else{
- return connection.rollback(function() {throw err; });
- }
- }
- );
- connection.commit(function(err) {
- if (err) {
- return connection.rollback(function() {
- throw err;
- });
- }
- console.log("Logged: ["+channel+"]["+user.username+"] " + message );
- });
- });
- }
- var irc = require("tmi.js");
- var options = {
- options: {
- debug: true
- },
- connection: {
- cluster: "main",
- reconnect: true
- },
- identity: {
- username: "********",
- password: "********"
- },
- channels: ["#********"]
- };
- var client = new irc.client(options);
- // Connect the client to the server..
- client.connect();
- client.on("chat", function (channel, user, message, self) {
- logChat(channel, user, message);
- // IF IS MAIN CHANNEL
- if(channel.replace("#", "") === "********"){
- if(message === "!join"){
- client.say(channel, "Joining "+user["username"]+"!");
- client.join(user["username"]);
- }
- //IF IS CHANNEL OWNER
- if(channel.replace("#", "") === user["username"]){
- // IF !LEAVE, DISCONECT BOT FROM CHANNEL!
- if(message === "!leave"){
- client.say(channel, "Disconecting!");
- client.part(channel);
- }
- }else if(client.isMod(channel, user["username"])){
- //IF !MESSAGE {MESSAGE}, Sends Global Message!
- if(message === "!message"){
- var chan = client.getChannels();
- client.say(chan, "test");
- }
- }
- //GLOBAL COMMANDS IN MAIN CHANNEL ONLY
- if(message === "!help"){
- client.say(channel, "Commands: !join - Joins me to your channel. | !help - Displays my current commands.");
- }
- }else{
- //IF IS CHANNEL OWNER
- if(channel.replace("#", "") === user["username"]){
- // IF !LEAVE, DISCONECT BOT FROM CHANNEL!
- if(message === "!leave"){
- client.say(channel, "Disconecting!");
- client.part(channel);
- }
- }
- //IF IS MOD
- if(client.isMod(channel, user["username"])){
- /*if(message === ""){
- }*/
- }else{
- /*if(message === ""){
- client.say(channel, "Hello, I am ********. You can learn more about me at ********");
- }*/
- }
- }
- //GLOBAL COMMANDS
- if(message === "!bot"){
- client.say(channel, "Hello, I am ********. You can learn more about me at *********");
- }
- });
- </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement