From 2bfa510156245735582227b881c2115958abc64b Mon Sep 17 00:00:00 2001 From: Bryson Steck Date: Fri, 11 Mar 2022 23:13:00 -0700 Subject: fixed help command --- follow-src/source.py | 4 +++- follow-src/source_output.txt | 0 run.sh | 2 +- twitch-bot/bot.js | 43 ++++++++++++++++++++++--------------------- 4 files changed, 26 insertions(+), 23 deletions(-) create mode 100644 follow-src/source_output.txt diff --git a/follow-src/source.py b/follow-src/source.py index b17b9ac..0ecd5ce 100644 --- a/follow-src/source.py +++ b/follow-src/source.py @@ -1,6 +1,7 @@ import requests import time import json +import os with open('settings.json') as f: settings = json.load(f) @@ -11,7 +12,7 @@ WRITE_FILE = settings['write_file'] USER = settings['username'] UPDATE = settings['seconds_interval'] -print("Running!") +print("* Follower/sub goal is now running. To add to your stream, add a text source and open the file " + os.path.abspath(WRITE_FILE) + " to display on your stream.") while(True): followers = open(WRITE_FILE, 'w') url_follows = "https://api.crunchprank.net/twitch/followcount/" + USER @@ -23,3 +24,4 @@ while(True): print(f"Subs: {read_subs.text}/{SUB_GOAL}\nFollower goal: {read_follows.text}/{FOLLOWER_GOAL}\n", end='', file=followers) followers.close() time.sleep(UPDATE) + diff --git a/follow-src/source_output.txt b/follow-src/source_output.txt new file mode 100644 index 0000000..e69de29 diff --git a/run.sh b/run.sh index 052da27..fc59f5a 100755 --- a/run.sh +++ b/run.sh @@ -5,7 +5,7 @@ cd ../follow-src python3 source.py & SCRIPT_PID=$! -echo "The Twitch bot and Source script is now running. You can stop this script by typing \"stop\"" +echo "The Twitch bot and Source script is now running. You can stop this script by typing \"stop\" or pressing ^C" while read input; do case $input in diff --git a/twitch-bot/bot.js b/twitch-bot/bot.js index 1a21c8d..9c874a0 100644 --- a/twitch-bot/bot.js +++ b/twitch-bot/bot.js @@ -5,7 +5,7 @@ const fs = require('fs'); try { var settings = JSON.parse(fs.readFileSync('./settings.json', 'utf8')); var reacts = JSON.parse(fs.readFileSync('./reacts.json', 'utf8')); - var commands = JSON.parse(fs.readFileSync('./commands.json', 'utf8')); + var chat_commands = JSON.parse(fs.readFileSync('./commands.json', 'utf8')); var mod_commands = JSON.parse(fs.readFileSync('./mod_commands.json', 'utf8')); } catch (err) { console.error("An error occured trying to read the files for the Twitch bot: " + err); @@ -23,7 +23,7 @@ var modString = ""; var mods; try { - modString = fs.readFileSync('', 'utf8'); + modString = fs.readFileSync('mods.txt', 'utf8'); modString = modString.replace(/(\r\n|\n|\r)/gm, ""); mods = modString.split(","); } catch (err) { @@ -32,21 +32,6 @@ try { var modCommand = false; -// Twitch bot initialization -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(); - -// Notify when connected -function onConnectedHandler (addr, port) { - console.log(`* Main Bot successfully connected to ${addr}:${port}`); -} - function onMessageHandler (target, context, msg, self) { if (self) { return; } // Ignore messages from the bot const user = context.username; @@ -70,16 +55,17 @@ function commands (target, commandName, user, mods) { if (commandName === "help") { var allCommands = []; var finalString = ""; - commands.forEach(command => { + chat_commands.forEach(command => { allCommands.push(command.command); }); allCommands.forEach(command => { - finalString = finalString + command.command; + finalString = finalString + settings.command_char + command.command + " "; }); client.say(target, `Here is the list of commands: ${finalString}`); + valid = true; } else { - commands.forEach(command => { - if (message.search(command.command) !== -1) { + chat_commands.forEach(command => { + if (commandName.search(command.command) !== -1) { client.say(target, `${command.reply}`); valid = true; return true; @@ -128,4 +114,19 @@ function reactions (target, message, user) { }); } +// Twitch bot initialization +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(); + +// Notify when connected +function onConnectedHandler (addr, port) { + console.log(`* Main Bot successfully connected to ${addr}:${port}`); +} + -- cgit v1.2.3