From fc7bcf62aee7e204b52e98e84c47991473ad9a12 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Patrick=20M=C3=BCller?= Date: Mon, 19 Apr 2021 13:43:54 +0200 Subject: [PATCH] Initial commit --- .gitignore | 3 ++ bot.js | 52 +++++++++++++++++++++++++++++++ package-lock.json | 78 +++++++++++++++++++++++++++++++++++++++++++++++ package.json | 18 +++++++++++ 4 files changed, 151 insertions(+) create mode 100644 .gitignore create mode 100644 bot.js create mode 100644 package-lock.json create mode 100644 package.json diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..9c15c11 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +.idea/ +node_modules/ +*.iml diff --git a/bot.js b/bot.js new file mode 100644 index 0000000..b5ea9b7 --- /dev/null +++ b/bot.js @@ -0,0 +1,52 @@ +const tmi = require('tmi.js'); + +// Define configuration options +const opts = { + identity: { + username: "", + password: "" + }, + channels: [ + "yiggalow" + ] +}; + +// Create a client with our options +const client = new tmi.client(opts); + +// Register our event handlers (defined below) +client.on('message', onMessageHandler); +client.on('connected', onConnectedHandler); + +// Connect to Twitch: +client.connect(); + +// Called every time a message comes in +function onMessageHandler(target, context, msg, self) { + if (self) { + return; + } // Ignore messages from the bot + + // Remove whitespace from chat message + const commandName = msg.trim(); + + // If the command is known, let's execute it + if (commandName === '!dice') { + const num = rollDice(); + client.say(target, `You rolled a ${num}`); + console.log(`* Executed ${commandName} command`); + } else { + console.log(`* Unknown command ${commandName}`); + } +} + +// Function called when the "dice" command is issued +function rollDice() { + const sides = 6; + return Math.floor(Math.random() * sides) + 1; +} + +// Called every time the bot connects to Twitch chat +function onConnectedHandler(addr, port) { + console.log(`* Connected to ${addr}:${port}`); +} diff --git a/package-lock.json b/package-lock.json new file mode 100644 index 0000000..91f662f --- /dev/null +++ b/package-lock.json @@ -0,0 +1,78 @@ +{ + "name": "npm", + "version": "1.0.0", + "lockfileVersion": 2, + "requires": true, + "packages": { + "": { + "name": "npm", + "version": "1.0.0", + "license": "ISC", + "dependencies": { + "tmi.js": "^1.8.2" + } + }, + "node_modules/node-fetch": { + "version": "2.6.1", + "resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.6.1.tgz", + "integrity": "sha512-V4aYg89jEoVRxRb2fJdAg8FHvI7cEyYdVAh94HH0UIK8oJxUfkjlDQN9RbMx+bEjP7+ggMiFRprSti032Oipxw==", + "engines": { + "node": "4.x || >=6.0.0" + } + }, + "node_modules/tmi.js": { + "version": "1.8.2", + "resolved": "https://registry.npmjs.org/tmi.js/-/tmi.js-1.8.2.tgz", + "integrity": "sha512-af1wcF7AQmEB0laylCHswTw/QD9Q51MLZhCNA/V0shn0CyxsBXWPtiSOHdgkGI88ix7moDsr4Mbl6NeVg8rf5Q==", + "dependencies": { + "node-fetch": "^2.6.1", + "ws": "^7.4.3" + }, + "engines": { + "node": ">=10.0.0" + } + }, + "node_modules/ws": { + "version": "7.4.5", + "resolved": "https://registry.npmjs.org/ws/-/ws-7.4.5.tgz", + "integrity": "sha512-xzyu3hFvomRfXKH8vOFMU3OguG6oOvhXMo3xsGy3xWExqaM2dxBbVxuD99O7m3ZUFMvvscsZDqxfgMaRr/Nr1g==", + "engines": { + "node": ">=8.3.0" + }, + "peerDependencies": { + "bufferutil": "^4.0.1", + "utf-8-validate": "^5.0.2" + }, + "peerDependenciesMeta": { + "bufferutil": { + "optional": true + }, + "utf-8-validate": { + "optional": true + } + } + } + }, + "dependencies": { + "node-fetch": { + "version": "2.6.1", + "resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.6.1.tgz", + "integrity": "sha512-V4aYg89jEoVRxRb2fJdAg8FHvI7cEyYdVAh94HH0UIK8oJxUfkjlDQN9RbMx+bEjP7+ggMiFRprSti032Oipxw==" + }, + "tmi.js": { + "version": "1.8.2", + "resolved": "https://registry.npmjs.org/tmi.js/-/tmi.js-1.8.2.tgz", + "integrity": "sha512-af1wcF7AQmEB0laylCHswTw/QD9Q51MLZhCNA/V0shn0CyxsBXWPtiSOHdgkGI88ix7moDsr4Mbl6NeVg8rf5Q==", + "requires": { + "node-fetch": "^2.6.1", + "ws": "^7.4.3" + } + }, + "ws": { + "version": "7.4.5", + "resolved": "https://registry.npmjs.org/ws/-/ws-7.4.5.tgz", + "integrity": "sha512-xzyu3hFvomRfXKH8vOFMU3OguG6oOvhXMo3xsGy3xWExqaM2dxBbVxuD99O7m3ZUFMvvscsZDqxfgMaRr/Nr1g==", + "requires": {} + } + } +} diff --git a/package.json b/package.json new file mode 100644 index 0000000..524e5d5 --- /dev/null +++ b/package.json @@ -0,0 +1,18 @@ +{ + "name": "npm", + "version": "1.0.0", + "description": "Highlight Timestamp Marker that listens to messages in a twitch stream chat", + "main": "bot.js", + "scripts": { + "test": "test" + }, + "repository": { + "type": "git", + "url": "https://git.plutodev.de/DHBW/Twitch_Highlight_Marker" + }, + "author": "Patrick Müller, David Huh", + "license": "ISC", + "dependencies": { + "tmi.js": "^1.8.2" + } +}