Added possibilty for multiple configurations
This commit is contained in:
parent
f43cfcb370
commit
a8f79d06a6
51
bot.js
51
bot.js
|
|
@ -11,7 +11,14 @@ const client = tmi.client(opts);
|
||||||
const syllableRegex = /[^aeiouy]*[aeiouy]+(?:[^aeiouy]*$|[^aeiouy](?=[^aeiouy]))?/gi;
|
const syllableRegex = /[^aeiouy]*[aeiouy]+(?:[^aeiouy]*$|[^aeiouy](?=[^aeiouy]))?/gi;
|
||||||
|
|
||||||
let configFile = fs.readFileSync('buttsbot.config')
|
let configFile = fs.readFileSync('buttsbot.config')
|
||||||
let config = JSON.parse(configFile);
|
let configurations = JSON.parse(configFile);
|
||||||
|
|
||||||
|
let defaultConfig = {
|
||||||
|
word: "butt",
|
||||||
|
chance: 20,
|
||||||
|
limit: 10,
|
||||||
|
ignoredUsers: []
|
||||||
|
};
|
||||||
|
|
||||||
console.log(`* Startup: Loaded config: ${config}`);
|
console.log(`* Startup: Loaded config: ${config}`);
|
||||||
|
|
||||||
|
|
@ -37,22 +44,39 @@ function isNumeric(n) {
|
||||||
// Event handlers
|
// Event handlers
|
||||||
function onMessageHandler (channel, userstate, message, self) {
|
function onMessageHandler (channel, userstate, message, self) {
|
||||||
var message = message.trim();
|
var message = message.trim();
|
||||||
|
var messageChannel = userstate['username'];
|
||||||
|
|
||||||
if (channel === "#butt5b0t") {
|
if (channel === "#butt5b0t") {
|
||||||
var messageChannel = "#" + userstate['username'];
|
|
||||||
|
|
||||||
if (message === "!subscribe") {
|
if (message === "!subscribe") {
|
||||||
client.join(messageChannel);
|
client.join("#" + messageChannel);
|
||||||
client.say(channel, "Joined channel " + messageChannel);
|
client.say(channel, "Joined channel " + messageChannel);
|
||||||
|
|
||||||
|
if (!opts.channels.includes(messageChannel)) {
|
||||||
|
opts.channels.push(messageChannel);
|
||||||
|
fs.writeFileSync('twitch.config', opts);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!(messageChannel in configurations)) {
|
||||||
|
configurations[messageChannel] = defaultConfig;
|
||||||
|
fs.writeFileSync('buttsbot.config');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (message === "!unsibscribe") {
|
if (message === "!unsubscribe") {
|
||||||
client.part(messageChannel);
|
client.part("#" + messageChannel);
|
||||||
client.say(channel, "Left channel " + 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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (self) return;
|
if (self) return;
|
||||||
|
|
||||||
|
let config = (messageChannel in configurations) ? configurations[messageChannel] : defaultConfig;
|
||||||
|
|
||||||
if (message.startsWith("!buttsbot")) {
|
if (message.startsWith("!buttsbot")) {
|
||||||
if (userstate['room-id'] === userstate['user-id'] || userstate['mod']) {
|
if (userstate['room-id'] === userstate['user-id'] || userstate['mod']) {
|
||||||
|
|
||||||
|
|
@ -66,7 +90,8 @@ function onMessageHandler (channel, userstate, message, self) {
|
||||||
break;
|
break;
|
||||||
case "word":
|
case "word":
|
||||||
config.word = value;
|
config.word = value;
|
||||||
fs.writeFileSync('buttsbot.config', JSON.stringify(config));
|
configurations[messageChannel] = config;
|
||||||
|
fs.writeFileSync('buttsbot.config', JSON.stringify(configurations));
|
||||||
client.say(channel, "Word set to " + value);
|
client.say(channel, "Word set to " + value);
|
||||||
break;
|
break;
|
||||||
case "chance":
|
case "chance":
|
||||||
|
|
@ -76,7 +101,8 @@ function onMessageHandler (channel, userstate, message, self) {
|
||||||
if (value < 0)
|
if (value < 0)
|
||||||
value = 0;
|
value = 0;
|
||||||
config.chance = parseInt(value);
|
config.chance = parseInt(value);
|
||||||
fs.writeFileSync('buttsbot.config', JSON.stringify(config));
|
configurations[messageChannel] = config;
|
||||||
|
fs.writeFileSync('buttsbot.config', JSON.stringify(configurations));
|
||||||
client.say(channel, "Chance set to " + value + "%");
|
client.say(channel, "Chance set to " + value + "%");
|
||||||
} else {
|
} else {
|
||||||
client.say(channel, "Expected a number, got " + value);
|
client.say(channel, "Expected a number, got " + value);
|
||||||
|
|
@ -89,7 +115,8 @@ function onMessageHandler (channel, userstate, message, self) {
|
||||||
if (!config.ignoredUsers.includes(value)) {
|
if (!config.ignoredUsers.includes(value)) {
|
||||||
console.log(`* ignore: value not already ignored`);
|
console.log(`* ignore: value not already ignored`);
|
||||||
config.ignoredUsers.push(value);
|
config.ignoredUsers.push(value);
|
||||||
fs.writeFileSync('buttsbot.config', JSON.stringify(config));
|
configurations[messageChannel] = config;
|
||||||
|
fs.writeFileSync('buttsbot.config', JSON.stringify(configurations));
|
||||||
}
|
}
|
||||||
client.say(channel, "User " + value + " will be ignored from now on.");
|
client.say(channel, "User " + value + " will be ignored from now on.");
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -105,8 +132,9 @@ function onMessageHandler (channel, userstate, message, self) {
|
||||||
|
|
||||||
let index = config.ignoredUsers.indexOf(value);
|
let index = config.ignoredUsers.indexOf(value);
|
||||||
config.ignoredUsers.splice(index, 1);
|
config.ignoredUsers.splice(index, 1);
|
||||||
|
configurations[messageChannel] = config;
|
||||||
|
|
||||||
fs.writeFileSync('buttsbot.config', JSON.stringify(config));
|
fs.writeFileSync('buttsbot.config', JSON.stringify(configurations));
|
||||||
}
|
}
|
||||||
client.say(channel, "User " + value + " will no longer be ignored.");
|
client.say(channel, "User " + value + " will no longer be ignored.");
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -116,7 +144,8 @@ function onMessageHandler (channel, userstate, message, self) {
|
||||||
case "limit":
|
case "limit":
|
||||||
if (isNumeric(value)) {
|
if (isNumeric(value)) {
|
||||||
config.limit = parseInt(value);
|
config.limit = parseInt(value);
|
||||||
fs.writeFileSync('buttsbot.config', JSON.stringify(config));
|
configurations[messageChannel] = config;
|
||||||
|
fs.writeFileSync('buttsbot.config', JSON.stringify(configurations));
|
||||||
client.say(channel, "Set new limit: 1 butt per " + value + " words");
|
client.say(channel, "Set new limit: 1 butt per " + value + " words");
|
||||||
} else {
|
} else {
|
||||||
client.say(channel, "Expected a number, got " + value);
|
client.say(channel, "Expected a number, got " + value);
|
||||||
|
|
|
||||||
|
|
@ -1 +1,2 @@
|
||||||
{"word":"butt","chance":20,"limit":10,"ignoredUsers":["StreamElements","Nightbot"]}
|
{
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue
Block a user