Skip to content

Commit 83cf80a

Browse files
author
Vivien Mouret
committed
📦️ mobbot full online
1 parent d881681 commit 83cf80a

1 file changed

Lines changed: 161 additions & 12 deletions

File tree

core/mobbot.js

Lines changed: 161 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,12 @@
33
const { Client } = require('tmi.js'),
44
{ ActivityType } = require('discord.js'),
55
{ parse } = require('json2csv'),
6+
axios = require('axios'),
67
fs = require('node:fs'),
8+
path = require('node:path'),
79
{ clientId, identity, channels } = require('./config.json'),
8-
{ getCurrentDatetime, randomColor } = require('./function.js');
10+
{ getCurrentDatetime, randomColor } = require('./utils.js'),
11+
{ users: regular_users } = require('../resx/regular_users.json');
912

1013
const oauth = {
1114
options: {
@@ -19,29 +22,150 @@ const oauth = {
1922
secure: true,
2023
}
2124
};
25+
const params = {
26+
headers: {
27+
Authorization: `Bearer ${identity.password}`,
28+
'Client-ID': clientId
29+
}
30+
};
2231

2332
var dataToExport = [];
2433

2534
class MobBot {
2635
constructor() {
2736
this.mbClient = new Client(oauth);
37+
38+
this.mbCommands = new Map();
39+
40+
this._count = 0 | this._count;
2841
};
2942

30-
onConnect() {
31-
this.mbClient.connect()
43+
async onConnect() {
44+
this.setCollection();
45+
46+
await this.mbClient.connect()
3247
.catch(console.error);
3348
this.mbClient.on('connected', this.onConnectedHandler);
34-
this.onDataImport();
35-
// this.onMessageListen();
49+
50+
await this.onDataImport();
51+
await this.onMessageListen();
52+
await this.onSubscription();
53+
await this.onGiftSubscription();
54+
await this.onReSubsciption();
55+
await this.onCheers();
56+
await this.onYeeetTheChild();
57+
};
58+
59+
setCollection() {
60+
const commandsPath = path.join(__dirname, './subcommands'),
61+
commandFiles = fs.readdirSync(commandsPath).filter(file => file.endsWith('.js'));
62+
63+
for (let file of commandFiles) {
64+
var filePath = path.join(commandsPath, file),
65+
command = require(filePath);
66+
if ('data' in command && 'execute' in command) { this.mbCommands.set(command.data.name, command); }
67+
else { console.log(`[ERROR_FILE_COMMAND] The command at ${filePath} is missing a required "data" or "execute" property.`); };
68+
};
69+
};
70+
71+
async onMessageListen() {
72+
this.mbClient.on('message', async (channel, userstate, message, self) => {
73+
if (self || userstate.username === 'mobbot_') return;
74+
var _rdm = Math.random();
75+
76+
if (message.startsWith('!')) {
77+
let msg = message.trim().toLowerCase(),
78+
args = msg.slice(1).split(' '),
79+
command = args.shift().toLowerCase(),
80+
checkCollection;
81+
82+
this.mbCommands.has(command) ? checkCollection = this.mbCommands.get(command).data.name : checkCollection = false;
83+
84+
switch (command) {
85+
case checkCollection:
86+
await this.mbCommands
87+
.get(checkCollection)
88+
.execute(this.mbClient,
89+
channel,
90+
message,
91+
userstate,
92+
await this.onLastVideo(),
93+
await this.onTimeStamp(),
94+
false);
95+
break;
96+
case 'test':
97+
this.mbClient.reply(channel, 'Can not send message (-&?. undefined)', userstate.id)
98+
.catch(e => console.log(e));
99+
break;
100+
};
101+
};
102+
103+
for (let i in message.split(' ')) {
104+
if (message.split(' ')[i].toLowerCase() === '@mobbot_') {
105+
this.mbClient.reply(channel, 'Qu\'est-ce ?', userstate.id)
106+
.catch(e => console.log(e));
107+
};
108+
};
109+
110+
this._count++;
111+
if (_rdm < .33 && this._count % 2 === 0 && this._count > 8) {
112+
await this.mbCommands
113+
.get('timer')
114+
.execute(this.mbClient,
115+
channel,
116+
message,
117+
userstate,
118+
await this.onLastVideo(),
119+
await this.onTimeStamp(),
120+
true);
121+
};
122+
123+
if (regular_users.includes(userstate.username) && _rdm < .33) {
124+
this.mbClient.reply(channel, `salu twa PixelBob`, userstate.id)
125+
.catch(e => console.log(e));
126+
};
127+
});
128+
};
129+
130+
async onSubscription() {
131+
this.mbClient.on("subscription", (channel, username, method, message, userstate) => {
132+
this.mbClient.say(channel, `eh @${username} fais maintenant parti des recrues, merci !`)
133+
.catch(e => console.log(e));
134+
});
36135
};
37136

38-
onMessageListen() {
39-
// In Progress
137+
async onReSubsciption() {
138+
this.mbClient.on("resub", (channel, username, months, message, userstate, methods) => {
139+
let cumulativeMonths = userstate["msg-param-cumulative-months"];
140+
this.mbClient.say(channel, `un exploit GlitchCat @${username} est revenu pour le ${cumulativeMonths} mois consécutif`)
141+
.catch(e => console.log(e));
142+
});
40143
};
41144

42-
onDataImport() {
145+
async onCheers() {
146+
this.mbClient.on("cheer", (channel, userstate, message) => {
147+
this.mbClient.say(channel, `trop généreux !! @${username} m'envoie ${userstate.bits} bits RyuChamp`)
148+
.catch(e => console.log(e));
149+
});
150+
};
151+
152+
async onGiftSubscription() {
153+
this.mbCommandslient.on("submysterygift", (channel, username, numbOfSubs, methods, userstate) => {
154+
this.mbClient.say(channel, `ok ok... @${username} offre ${numbOfSubs} sub PogChamp PogChamp`)
155+
.catch(e => console.log(e));
156+
});
157+
};
158+
159+
async onYeeetTheChild() {
160+
this.mbClient.on("ban", (channel, username, reason, userstate) => {
161+
this.mbClient.say(channel, `YEEEEEEEEEEEEEEEEEEET THE ${username} !! FBPass`)
162+
.catch(e => console.log(e));
163+
});
164+
}
165+
166+
async onDataImport() {
43167
this.mbClient.on('message', (channel, userstate, message, self) => {
44-
if (self || userstate['username'] === 'moobot') return;
168+
if (self || userstate['username'] === 'moobot_') return;
45169

46170
let data = {
47171
'id': Number(userstate['user-id']),
@@ -58,7 +182,7 @@ class MobBot {
58182
});
59183
};
60184

61-
onDataExport(message, client) {
185+
async onDataExport(message, client) {
62186
if (dataToExport.length === 0) {
63187
let emoji = client.emojis.cache.find(emoji => emoji.name === 'sadpepe');
64188
message
@@ -90,7 +214,7 @@ class MobBot {
90214
.catch(err => { console.log(`[${getCurrentDatetime('comm')}] Error during file send ${err}`); });
91215
};
92216

93-
onLive(message, client, language, gD, axios) {
217+
async onLive(message, client, language, gD, axios) {
94218
if (gD == undefined || axios == undefined) {
95219
console.log(`[${getCurrentDatetime('comm')}] Error function liveNotif() : GUID = ${gD} and/or AXIOS = ${axios}`);
96220
return;
@@ -111,6 +235,16 @@ class MobBot {
111235
console.log(`[${getCurrentDatetime('comm')}] Can't get guid and dot : `, err);
112236
};
113237

238+
this.mbCommands
239+
.get('timer')
240+
.execute(this.mbClient,
241+
channels[0],
242+
undefined,
243+
undefined,
244+
await this.onLastVideo(),
245+
await this.onTimeStamp(),
246+
true);
247+
114248
for (let chan in channelTwitch) {
115249
var channelSend = client.channels.cache.find(channel => channel.name == channelTwitch[chan]);
116250
if (channelSend.id == undefined) break;
@@ -145,7 +279,7 @@ class MobBot {
145279
},
146280
'footer': {
147281
'text': `Viewers : ${axios.data.data[0].viewer_count}`,
148-
'icon_url': `https://cdn-icons-png.flaticon.com/512/4299/4299106.png`,
282+
'icon_url': `https://em-content.zobj.net/thumbs/120/microsoft/319/busts-in-silhouette_1f465.png`,
149283
'proxy_icon_url': `https://twitch.tv/${axios.data.data[0].user_login}`
150284
},
151285
'url': `https://twitch.tv/${axios.data.data[0].user_login}`
@@ -222,6 +356,21 @@ class MobBot {
222356
};
223357
};
224358

359+
async onLastVideo() {
360+
let fe = await fetch(`https://www.youtube.com/feeds/videos.xml?channel_id=UCreItrEewfO6IPZYPu4C7pA`)
361+
.catch(err => { console.log(`[${getCurrentDatetime('comm')}] Error FETCH ${err}`); }),
362+
fetched = await fe.text();
363+
return String(fetched.split(new RegExp(`(\:[^.]*\<\/)`, 'giu'))[3].split(new RegExp(`(\<[^.]*?\>)`, 'giu'))[10]);
364+
};
365+
366+
async onTimeStamp() {
367+
let ax = await axios.get(`http://api.twitch.tv/helix/streams?user_login=` + channels[0].slice(1), params)
368+
.catch(err => { console.log(`[${getCurrentDatetime('comm')}] Error GET AXIOS ${err}`); });
369+
return ax.data.data.length != 0 ?
370+
new Date(new Date().getTime() - new Date(ax.data.data[0].started_at).getTime()).toUTCString().slice(17, -4) :
371+
'00:00:00';
372+
};
373+
225374
onConnectedHandler(addr, port) { console.log(`* Connected to ${addr}:${port} *`); };
226375
};
227376

0 commit comments

Comments
 (0)