Retrieving a list of moderators through the API

You could easily make this holy endpoint yourself:

const tmi = require('tmi.js');
const express = require('express');

const app = express();
const client = new tmi.client({
		connection: {
			reconnect: true,
			secure: true
		},
		identity: {
			username: 'some_account',
			password: 'Chat OAuth token'
		}
	});

client.connect()
.then(() => {
	console.log('Connected');
});

app.listen(8058, err => {
	if(!err) {
		console.log('Listening');
	}
	else {
		console.log(err);
	}
});

app.get('/mods-api/channels/:channel', (req, res) => {
	if(client.readyState() !== 'OPEN') {
		return res.json({
			error: 'Service Unavailable',
			status: 503,
			message: 'Not ready'
		});
	}
	let channel = req.params.channel.toLowerCase();
	client.mods(channel)
	.then(moderators => {
		res.json({
			channel,
			moderators
		});
	})
	.catch(err => {
		res.json({
			error: 'Internal Server Error',
			status: 500,
			message: 'Some error occurred'
		})
	});
});

http://localhost:8058/mods-api/channels/Xangold

1 Like