Tweaks and fixes

This commit is contained in:
root 2021-08-29 22:07:22 +02:00
parent a8f79d06a6
commit 9c5ec6f9d5
3 changed files with 14 additions and 11 deletions

1
.gitignore vendored
View File

@ -1,4 +1,5 @@
.env
twitch.config
buttsbot.config
node_modules/

21
bot.js
View File

@ -20,8 +20,6 @@ let defaultConfig = {
ignoredUsers: []
};
console.log(`* Startup: Loaded config: ${config}`);
// Client
client.on('message', onMessageHandler);
client.on('connected', onConnectedHandler);
@ -44,32 +42,37 @@ function isNumeric(n) {
// Event handlers
function onMessageHandler (channel, userstate, message, self) {
var message = message.trim();
var messageChannel = userstate['username'];
var messageChannel = "#" + userstate['username'];
if (channel === "#butt5b0t") {
if (message === "!subscribe") {
client.join("#" + messageChannel);
client.join(messageChannel);
client.say(channel, "Joined channel " + messageChannel);
if (!opts.channels.includes(messageChannel)) {
opts.channels.push(messageChannel);
fs.writeFileSync('twitch.config', opts);
fs.writeFileSync('twitch.config', JSON.stringify(opts));
}
if (!(messageChannel in configurations)) {
configurations[messageChannel] = defaultConfig;
fs.writeFileSync('buttsbot.config');
fs.writeFileSync('buttsbot.config', JSON.stringify(configurations));
}
}
if (message === "!unsubscribe") {
client.part("#" + messageChannel);
client.part(messageChannel);
client.say(channel, "Left channel " + messageChannel);
if (opts.channels.includes(messageChannel)) {
var indexChannel = opts.channels.indexOf(messageChannel);
opts.splice(indexChannel, 1);
fs.writeFileSync('twitch.config', opts);
opts.channels.splice(indexChannel, 1);
fs.writeFileSync('twitch.config', JSON.stringify(opts));
}
if (messageChannel in configurations) {
delete configurations[messageChannel];
fs.writeFileSync('buttsbot.config', JSON.stringify(configurations));
}
}
} else {

View File

@ -1,2 +1 @@
{
}
{"#drmcmarco":{"word":"butt","chance":20,"limit":10,"ignoredUsers":[]}}