Timeout a user in the Twitch Chat. !timeout <username> <duration> <reason>
const lib = require('lib')({token: process.env.STDLIB_SECRET_TOKEN});
let content = context.params.event.content;
let author = context.params.event.author.username;
let mentionedUser = content.split(' ')[1]; //username
let duration = content.split(' ')[2]; //duration in seconds max 2weeks - 1,209,600 seconds
let reason = content.split(' ')[3]; //reason for the timeout
let isMod = context.params.event.author.mod;
let isStreamer = context.params.event.author.broadcaster;
if (isMod || isStreamer) {
if (mentionedUser === undefined) {
let missingUser = await lib.twitch.chat['@release'].messages.create({
channel_id: `${context.params.event.channel.id}`,
content: `${author} you need to provide a user! Syntax: !timeout `,
});
return;
}
if (duration === undefined) {
let missingDuration = await lib.twitch.chat['@release'].messages.create({
channel_id: `${context.params.event.channel.id}`,
content: `${author} you need to provide a duration! Syntax: !timeout `,
});
return;
}
if (reason === undefined) {
let missingReason = await lib.twitch.chat['@release'].messages.create({
channel_id: `${context.params.event.channel.id}`,
content: `${author} you need to provide a reason! Syntax: !timeout `,
});
return;
}
let user = await lib.twitch.users['@release'].retrieve({
login: `${mentionedUser}`,
});
let timeoutMember = await lib.twitch.moderation['@release'].timeouts.create({
channel_id: `${context.params.event.channel.id}`,
duration: duration,
reason: `${reason}`,
user_id: user.id,
});
let success = await lib.twitch.chat['@release'].messages.create({
channel_id: `${context.params.event.channel.id}`,
content: `I timeouted ${user.username} for ${duration} Seconds!`,
});
return 'Done';
} else {
let missingPermission = await lib.twitch.chat['@release'].messages.create({
channel_id: `${context.params.event.channel.id}`,
content: `${author} you dont have permission to timeout this user`,
});
return;
}