This commit is contained in:
Sarimoko 2022-02-14 15:52:11 -08:00
parent 315b11fa41
commit e138f0eecf
1 changed files with 74 additions and 76 deletions

View File

@ -17,9 +17,11 @@ const client = new tmi.Client({
channels: [ process.env.TTV_CHANNELS ]
});
client.connect();
// RNG User
const rp = require('request-promise'); // For RNG
function getChatters(channelName, _attemptCount = 0) {
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
@ -37,9 +39,9 @@ const client = new tmi.Client({
}
throw err;
})
}
}
function getRandomChatter(channelName, opts = {}) {
function getRandomChatter(channelName, opts = {}) {
let {
onlyViewers = false,
noBroadcaster = false,
@ -59,11 +61,37 @@ const client = new tmi.Client({
null :
chatters[Math.floor(Math.random() * chatters.length)];
});
}
}
client.connect();
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
// ================================
// --------------------------------
@ -335,33 +363,3 @@ client.on("whisper", (from, userstate, message, self) => {
});
// 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));
}
});