Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const Mixer = require('@mixer/client-node');
- const ws = require('ws');
- const config = require('./config.json')
- const botUserName = process.argv[2]
- const channelName = process.argv[3]
- let userInfo;
- const client = new Mixer.Client(new Mixer.DefaultRequestRunner());
- if (botUserName === 'me') {
- client.use(new Mixer.OAuthProvider(client, {
- tokens: {
- access: config.token.mackem_dan,
- expires: Date.now() + (365 * 24 * 60 * 60 * 1000)
- },
- }));
- } else if (botUserName === 'm2d2') {
- client.use(new Mixer.OAuthProvider(client, {
- tokens: {
- access: config.token.m2d2,
- expires: Date.now() + (365 * 24 * 60 * 60 * 1000)
- },
- }));
- } else if (botUserName === 'sole') {
- client.use(new Mixer.OAuthProvider(client, {
- tokens: {
- access: config.token.sole,
- expires: Date.now() + (365 * 24 * 60 * 60 * 1000)
- },
- }));
- } else {
- console.log('account not defined ending')
- process.exit()
- }
- client.request('GET', `channels/${channelName}`)
- .then(res => {
- const user2ID = res.body.id;
- client.request('GET', 'users/current')
- .then(response => {
- userInfo = response.body;
- return new Mixer.ChatService(client).join(user2ID);
- })
- .then(response => {
- const body = response.body;
- return createChatSocket(userInfo.id, user2ID, body.endpoints, body.authkey);
- })
- .catch(error => {
- console.error('Something went wrong.');
- console.error(error);
- });
- })
- .catch(error => {
- console.log('Check User Name');
- console.log(error)
- });
- function createChatSocket(userId, channelId, endpoints, authkey) {
- // Chat connection
- const socket = new Mixer.Socket(ws, endpoints).boot();
- // socket.on('ChatMessage', data => {
- // console.log(data.message);
- // })
- socket.on('ChatMessage', data => {
- if (data.message.message[0].text.toLowerCase().startsWith('?party')) {
- socket.call('msg', ["o//"]);
- setTimeout(() => {
- socket.call('msg', ["\\\\o"]);
- setTimeout(() => {
- socket.call('msg', ["o//"]);
- setTimeout(() => {
- socket.call('msg', ['\\\\o']);
- setTimeout(() => {
- socket.call('msg', ["o//"]);
- setTimeout(() => {
- socket.call('msg', ["\\\\o"]);
- }, (1000))
- }, (1000))
- }, (1000))
- }, (1000))
- }, (1000))
- }
- });
- socket.on('ChatMessage', data => {
- if (data.message.message[0].text.toLowerCase().startsWith('?m2d2')) {
- socket.call('msg', ["@M2D2 is a custom bot made my @Mackem_Dan this is a bot that is still in development"])
- console.log(`${data.user_name} is ${data.user_level} and ${data.user_roles} and ${data.id}`)
- }
- });
- socket.on('ChatMessage', data => {
- if (data.message.message[0].text.toLowerCase().startsWith('?kill')) {
- if (data.user_roles = "Mod") {
- socket.call('msg', ['Bot is going offline bye bye'])
- console.log(`${data.user_name} has closed the bot`)
- setTimeout(() => {
- process.exit()
- }, 2000)
- } else if (data.user_roles === 'Owner') {
- socket.call('msg', ['Bot is going offline bye bye'])
- console.log(`${data.user_name} has closed the bot`)
- setTimeout(() => {
- process.exit()
- }, 2000)
- } else {
- socket.call('msg', [`@${data.user_name} You are not authorised to do that`])
- console.log(`${data.user_name} has tried to turn off the bot`)
- }
- }
- });
- socket.on('ChatMessage', data => {
- if (data.message.message[0].text.toLowerCase().startsWith('?sobad')) {
- if (botUserName === 'me') {
- socket.call('msg', [':bad :shirobring :boi'])
- console.log(`${data.user_name} requested so bad,bringit `)
- } else {
- socket.call('msg', ['So bad bring it boi ;) '])
- console.log(`${data.user_name} requested so bad,bringit `)
- }
- }
- });
- // Handle errors
- socket.on('error', error => {
- console.error('Socket error');
- console.error(error);
- });
- return socket.auth(channelId, userId, authkey)
- .then(() => {
- console.log('Login successful');
- if (botUserName === 'me') {
- return socket.call('msg', [':howdy']);
- } else {
- return socket.call('msg', ['Hi']);
- }
- });
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement