rng
This commit is contained in:
parent
315b11fa41
commit
e138f0eecf
150
node/boto.js
150
node/boto.js
|
@ -17,53 +17,81 @@ const client = new tmi.Client({
|
||||||
channels: [ process.env.TTV_CHANNELS ]
|
channels: [ process.env.TTV_CHANNELS ]
|
||||||
});
|
});
|
||||||
|
|
||||||
// RNG User
|
|
||||||
const rp = require('request-promise'); // For RNG
|
|
||||||
function getChatters(channelName, _attemptCount = 0) {
|
|
||||||
return rp({
|
|
||||||
uri: `https://tmi.twitch.tv/group/user/sarimoko/chatters`,
|
|
||||||
json: true
|
|
||||||
})
|
|
||||||
.then(data => {
|
|
||||||
return Object.entries(data.chatters)
|
|
||||||
.reduce((p, [ type, list ]) => p.concat(list.map(name => {
|
|
||||||
if(name === channelName) type = 'broadcaster';
|
|
||||||
return { name, type };
|
|
||||||
})), []);
|
|
||||||
})
|
|
||||||
.catch(err => {
|
|
||||||
if(_attemptCount < 3) {
|
|
||||||
return getChatters(channelName, _attemptCount + 1);
|
|
||||||
}
|
|
||||||
throw err;
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
function getRandomChatter(channelName, opts = {}) {
|
|
||||||
let {
|
|
||||||
onlyViewers = false,
|
|
||||||
noBroadcaster = false,
|
|
||||||
skipList = []
|
|
||||||
} = opts;
|
|
||||||
return getChatters(channelName)
|
|
||||||
.then(data => {
|
|
||||||
let chatters = data
|
|
||||||
.filter(({ name, type }) =>
|
|
||||||
!(
|
|
||||||
(onlyViewers && type !== 'viewers') ||
|
|
||||||
(noBroadcaster && type === 'broadcaster') ||
|
|
||||||
skipList.includes(name)
|
|
||||||
)
|
|
||||||
);
|
|
||||||
return chatters.length === 0 ?
|
|
||||||
null :
|
|
||||||
chatters[Math.floor(Math.random() * chatters.length)];
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
client.connect();
|
client.connect();
|
||||||
|
|
||||||
|
// RNG User
|
||||||
|
const rp = require('request-promise'); // For RNG
|
||||||
|
function getChatters(channelName, _attemptCount = 0) {
|
||||||
|
return rp({
|
||||||
|
uri: `https://tmi.twitch.tv/group/user/sarimoko/chatters`,
|
||||||
|
json: true
|
||||||
|
})
|
||||||
|
.then(data => {
|
||||||
|
return Object.entries(data.chatters)
|
||||||
|
.reduce((p, [ type, list ]) => p.concat(list.map(name => {
|
||||||
|
if(name === channelName) type = 'broadcaster';
|
||||||
|
return { name, type };
|
||||||
|
})), []);
|
||||||
|
})
|
||||||
|
.catch(err => {
|
||||||
|
if(_attemptCount < 3) {
|
||||||
|
return getChatters(channelName, _attemptCount + 1);
|
||||||
|
}
|
||||||
|
throw err;
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
function getRandomChatter(channelName, opts = {}) {
|
||||||
|
let {
|
||||||
|
onlyViewers = false,
|
||||||
|
noBroadcaster = false,
|
||||||
|
skipList = []
|
||||||
|
} = opts;
|
||||||
|
return getChatters(channelName)
|
||||||
|
.then(data => {
|
||||||
|
let chatters = data
|
||||||
|
.filter(({ name, type }) =>
|
||||||
|
!(
|
||||||
|
(onlyViewers && type !== 'viewers') ||
|
||||||
|
(noBroadcaster && type === 'broadcaster') ||
|
||||||
|
skipList.includes(name)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
return chatters.length === 0 ?
|
||||||
|
null :
|
||||||
|
chatters[Math.floor(Math.random() * chatters.length)];
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
client.on('message', (channel, tags, message, self) => {
|
||||||
|
if(self) return;
|
||||||
|
const badges = tags.badges || {}; // Scan Badges
|
||||||
|
const isBroadcaster = badges.broadcaster; // Define Streamer
|
||||||
|
const isMod = badges.moderator; // Define Mod
|
||||||
|
const isModUp = isBroadcaster || isMod; // Permission Merge = Mod+Streamer
|
||||||
|
const isSub = badges.subscriber || badges.founder; // Define Subs
|
||||||
|
const botUserState = client.userstate[channel]; // MOD Status Check
|
||||||
|
const amMod = botUserState !== undefined && botUserState.mod === true; // Define Mod Status
|
||||||
|
|
||||||
|
if(self || !message.startsWith('!')) return; // Command Parser
|
||||||
|
const args = message.slice(1).split(' ');
|
||||||
|
const command = args.shift().toLowerCase(); // !COMMAND => command
|
||||||
|
if(command === 'rnguser') {
|
||||||
|
// Get a random user but skip the user requesting a random user
|
||||||
|
getRandomChatter(channel, { skipList: [ tags.username ] })
|
||||||
|
.then(user => {
|
||||||
|
if(user === null) {
|
||||||
|
client.say(channel, `Sorry ${tags.username}, this is embarrassing... There was no one to choose from! #smallstreamerproblems Bleep-Bloop!`);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
let { name, type } = user;
|
||||||
|
client.say(channel, `${tags.username} exluded, at random I choose "${name}" cuz they're such an amazing ${type}!`);
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.catch(err => console.log('[ERR]', err));
|
||||||
|
}
|
||||||
|
|
||||||
|
});
|
||||||
// ALERTS START
|
// ALERTS START
|
||||||
// ================================
|
// ================================
|
||||||
// --------------------------------
|
// --------------------------------
|
||||||
|
@ -334,34 +362,4 @@ client.on("whisper", (from, userstate, message, self) => {
|
||||||
client.say(channel, `/me [+1] Inbox | Received a new SEXT message from: @`+ from +`!`);
|
client.say(channel, `/me [+1] Inbox | Received a new SEXT message from: @`+ from +`!`);
|
||||||
});
|
});
|
||||||
// ALERTS STOP
|
// ALERTS STOP
|
||||||
// ================================
|
// ================================
|
||||||
|
|
||||||
client.on('message', (channel, tags, message, self) => {
|
|
||||||
if(self) return;
|
|
||||||
const badges = tags.badges || {}; // Scan Badges
|
|
||||||
const isBroadcaster = badges.broadcaster; // Define Streamer
|
|
||||||
const isMod = badges.moderator; // Define Mod
|
|
||||||
const isModUp = isBroadcaster || isMod; // Permission Merge = Mod+Streamer
|
|
||||||
const isSub = badges.subscriber || badges.founder; // Define Subs
|
|
||||||
const botUserState = client.userstate[channel]; // MOD Status Check
|
|
||||||
const amMod = botUserState !== undefined && botUserState.mod === true; // Define Mod Status
|
|
||||||
|
|
||||||
if(self || !message.startsWith('!')) return; // Command Parser
|
|
||||||
const args = message.slice(1).split(' ');
|
|
||||||
const command = args.shift().toLowerCase(); // !COMMAND => command
|
|
||||||
if(command === 'rnguser') {
|
|
||||||
// Get a random user but skip the user requesting a random user
|
|
||||||
getRandomChatter(channel, { skipList: [ tags.username ] })
|
|
||||||
.then(user => {
|
|
||||||
if(user === null) {
|
|
||||||
client.say(channel, `Sorry ${tags.username}, this is embarrassing... There was no one to choose from! #smallstreamerproblems Bleep-Bloop!`);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
let { name, type } = user;
|
|
||||||
client.say(channel, `${tags.username} exluded, at random I choose "${name}" cuz they're such an amazing ${type}!`);
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.catch(err => console.log('[ERR]', err));
|
|
||||||
}
|
|
||||||
|
|
||||||
});
|
|
Loading…
Reference in New Issue