Open DammitDave opened 11 years ago
What is the use case here for being able to access a list of moderators via API?
The case here is wanting to be able to list moderators because, occasionally IRC messes up, meaning some moderators aren't recognised as ops in IRC, so I think that being able to list them via the API would make my life a whole lot easier for my bot, because on startup, for each channel the bot is connecting to I can list the moderators to prevent any problems.
Hi,
this sounds like a valid reason. From our point of view, however, the API returns data from a data source that it owns. There are cases, streams for example, where it returns data from data sources that it doesn't own. In this case the IRC server (or TMI as we call it internally) is what owns this data so if it is giving you stale information it is just as likely that our API will do that. This has a lot to do with the layers of caching we have in our architecture needed to keep performance where we want it.
Really what you're asking for is to find out why data is stale and make it not be so.
On Fri, Jun 7, 2013 at 8:20 AM, Dave notifications@github.com wrote:
The case here is wanting to be able to list moderators because, occasionally IRC messes up, meaning some moderators aren't recognised as ops in IRC, so I think that being able to list them via the API would make my life a whole lot easier for my bot, because on startup, for each channel the bot is connecting to I can list the moderators to prevent any problems.
— Reply to this email directly or view it on GitHubhttps://github.com/justintv/Twitch-API/issues/103#issuecomment-19113516 .
Alright, that seems fair enough; hindering performance for this would be a bad plan. I suppose I could just send .mods on connect, which will send me back a message with all mods - that should suffice. Thanks for considering this, though.
@ossareh it should be noted that these bots almost always rely on OP detection in irc, which the chat server itself doesn't seem to care about(?) as even when the server is having issues +o'ing users, you can still freely use mod commands like 'ban' and 'timeout' without issue. This lends to the data not being stale, just the +o process being a lower priority on the server, since the server knows you're a moderator, but clients don't. The ability to check if a user ( especially yourself ) is a mod via api would be welcome, the alternative being channel context in the chat server's response to the 'mods' command, since it's impossible to tell what room you're getting a response for when you're in multiple ( this issue also applies to other messages from 'jtv' though, so it's a larger problem )
This will reply with a list of users and their levels: tmi.twitch.tv/group/user/channel_name/chatters
Apart from what AlcaDesign has suggested, I would like to be able to get the full list of chat moderators(not just those currently viewing the stream) for a specific stream via the OAUTH api
I have a bot the keeps track of various stats about a streams' chat userbase. One of those stats being the last time a user viewed the stream. Its been requested a few times that I use that stat to help cleanup each streams' chat moderator list for moderators that haven't been in chat for a specified amount of time -- for example, remove moderators that have not logged into the stream's chat in the last 30days.
You have to send the "mods" command to the channel in order to get a full list
@AlcaDesign I understand that, BUT twitches implementation has two issues
1: There is no stream identification sent with the moderator list to be used for determining which stream the list relates to. (Unless using TWITCHCLIENT 3+ which results in joins and part events not being sent to the client) 2: Depending on how large the list is, the list does not conform to the IRC RFC standard of 512bytes per message, causing bot libraries meant for the IRC standard to become errorous when attempting to process the list.
The messages are sent to the channel in which you request from after sending a raw TWITCHCLIENT 3
@Fire- This is true, except afaik when using any of the current TWITCHCLIENT versions, join and part events are no longer sent.
Though this is off topic, as the OP requested a way to get the full moderator list specifically via the webapi and mpoon asked for a use-case of such
+1 would really like this endpoint. I'm making a website interface for a chat bot, so I would like to be able to figure out what permission level any user has for any particular channel. I'm doing it in PHP, so trying to get the mod list through IRC is really not ideal. An endpoint that would allow me to check either a) the list of channels a user is moderator in or b) the list of moderators for a particular channel, would be fantastic.
In php you can do the following: (taken straight from my website)
<?php
// required scope: chat_login
$IRCuser = /*Your username*/;
$IRCauth = /*Your oauth*/;
function getURL($link) {
$ch = curl_init($link);
curl_setopt($ch, CURLOPT_TCP_NODELAY, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$info = curl_exec($ch);
curl_close($ch);
$info = trim($info);
if (empty($info))
return getURL($link);
else
return json_decode($info,true);
}
function arrayOut($array) {
// Print in json
$json = json_encode($array);
// Output the array
echo $json;
}
function error($code, $message) {
$error = array(
"status" => $code,
"message" => $message
);
return arrayOut($error);
}
function userExists($channel) {
$data = getURL("https://api.twitch.tv/kraken/channels/".$channel);
if (isset($data["status"]) && $data["status"] === 404)
if (isset($data["error"]) && $data["error"] === "Not Found")
return false;
return true;
}
function mods() {
global $IRCuser, $IRCauth;
if (!isset($_GET["channel"])) return error(400, "You have not set a channel");
$channel = strtolower($_GET["channel"]);
if (!userExists($channel)) return error(404, "Cannot find that channel");
$socket = fsockopen("irc.twitch.tv", 80);
fputs($socket, "PASS ".$IRCauth."\n");
fputs($socket, "NICK ".$IRCuser."\n");
fputs($socket, "JOIN #".$channel."\n");
fputs($socket, "PRIVMSG #".$channel." :.mods\n");
$regex = "~:[a-z0-9_!@.]+ PRIVMSG [a-z0-9_]+ : ?(?:The moderators of this room are: (.*)|There are no moderators of this room.)~is";
$gotMods = false;
while (!$gotMods) {
$rawInput = fgets($socket);
if (preg_match($regex, $rawInput, $m) == 1) {
$mods = array();
if (isset($m[1]) && $m[1] != null) {
foreach(explode(",", $m[1]) as $mod) {
$mods[] = trim($mod);
}
}
if (!in_array($channel, $mods))
$mods[] = $channel;
$gotMods = true;
}
}
fputs($socket, "PART #".$channel."\n");
fclose($socket);
return arrayOut(array("mods" => $mods));
}
mods();
?>
I find this to be rather clunky but it works for me.
Hope this helps, scagood
Hey, Is it possible to list moderators of a stream with authentication (e.g oauth)? Sorry if it is, but if it isn't, any chance of implementation?
Thanks.