structure commands better
This commit is contained in:
parent
6d0310cdeb
commit
d5dfdd19a1
11 changed files with 268 additions and 272 deletions
18
commands/fill.js
Normal file
18
commands/fill.js
Normal file
|
@ -0,0 +1,18 @@
|
|||
const command = {
|
||||
name: "fill",
|
||||
run: async (client, msg, splitted) => {
|
||||
if (!splitted[2]) {
|
||||
client.say(msg.channelName, `${msg.displayName}, Supply an arg PoroSad`);
|
||||
}
|
||||
|
||||
let str = "";
|
||||
while (true) {
|
||||
if (str.length + splitted.slice(2).join(" ").length >= 450) break;
|
||||
str += `${splitted.slice(2).join(" ")} `;
|
||||
}
|
||||
|
||||
await client.me(msg.channelName, str).catch((err) => console.log(err));
|
||||
},
|
||||
};
|
||||
|
||||
export default { command };
|
33
commands/fm.js
Normal file
33
commands/fm.js
Normal file
|
@ -0,0 +1,33 @@
|
|||
const command = {
|
||||
name: "fm",
|
||||
run: async (client, msg, splitted) => {
|
||||
if (splitted[2] === undefined) {
|
||||
client.say(
|
||||
msg.channelName,
|
||||
`${msg.displayName}, supply your Last.FM username PoroSad`
|
||||
);
|
||||
}
|
||||
|
||||
const data = await fetch(
|
||||
`https://ws.audioscrobbler.com/2.0/?method=user.getrecenttracks&user=${splitted[2]}&api_key=${process.env.LASTFM_KEY}&format=json&limit=1`
|
||||
)
|
||||
.then((res) => res.json())
|
||||
.then((data) => {
|
||||
return data.recenttracks.track[0];
|
||||
})
|
||||
.catch((err) => console.log(err));
|
||||
|
||||
if (data === undefined) {
|
||||
client.say(msg.channelName, `${msg.displayName}, Invalid user PoroSad`);
|
||||
}
|
||||
|
||||
await client
|
||||
.say(
|
||||
msg.channelName,
|
||||
`${msg.displayName}, (Now Playing) Album: ${data.album["#text"]} Track: ${data.name} Artist: ${data.artist["#text"]} | ${data.url}`
|
||||
)
|
||||
.catch((err) => console.log(err));
|
||||
},
|
||||
};
|
||||
|
||||
export default { command };
|
21
commands/love.js
Normal file
21
commands/love.js
Normal file
|
@ -0,0 +1,21 @@
|
|||
const command = {
|
||||
name: "love",
|
||||
run: async (client, msg, splitted) => {
|
||||
if (splitted[2] === undefined || splitted[3] === undefined) {
|
||||
client.say(msg.channelName, `${msg.displayName}, supply 2 args PoroSad`);
|
||||
}
|
||||
|
||||
await client
|
||||
.say(
|
||||
msg.channelName,
|
||||
`${msg.displayName}, ${splitted[2]} and ${
|
||||
splitted[3]
|
||||
} are about ${Math.floor(
|
||||
Math.random() * 100
|
||||
)}% in love with each other!`
|
||||
)
|
||||
.catch((err) => console.log(err));
|
||||
},
|
||||
};
|
||||
|
||||
export default { command };
|
43
commands/massping.js
Normal file
43
commands/massping.js
Normal file
|
@ -0,0 +1,43 @@
|
|||
const command = {
|
||||
name: "massping",
|
||||
run: async (client, msg) => {
|
||||
const data = await fetch(`https://tmi.twitch.tv/group/user/elis/chatters`)
|
||||
.then((res) => res.json())
|
||||
.then((data) => {
|
||||
return data.chatters;
|
||||
})
|
||||
.catch((err) => console.log(err));
|
||||
|
||||
let names = [];
|
||||
function printValues(obj) {
|
||||
for (var key in obj) {
|
||||
if (typeof obj[key] === "object") {
|
||||
printValues(obj[key]);
|
||||
} else {
|
||||
names.push(obj[key]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
printValues(data);
|
||||
let temp = [];
|
||||
for (let name of names) {
|
||||
if (temp.join(" ").length > 450) {
|
||||
client
|
||||
.say(msg.channelName, temp.join(" "))
|
||||
.catch((err) => console.log(err));
|
||||
temp = [];
|
||||
}
|
||||
|
||||
if (names.slice(-1)[0] === name) {
|
||||
client
|
||||
.say(msg.channelName, temp.join(" "))
|
||||
.catch((err) => console.log(err));
|
||||
}
|
||||
|
||||
temp.push(name);
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
export default { command };
|
13
commands/ping.js
Normal file
13
commands/ping.js
Normal file
|
@ -0,0 +1,13 @@
|
|||
const command = {
|
||||
name: "ping",
|
||||
run: async (client, msg) => {
|
||||
await client
|
||||
.say(
|
||||
msg.channelName,
|
||||
`${msg.displayName}, Pong! Uptime: ${Math.floor(process.uptime())}s`
|
||||
)
|
||||
.catch((err) => console.log(err));
|
||||
},
|
||||
};
|
||||
|
||||
export default { command };
|
27
commands/pyramid.js
Normal file
27
commands/pyramid.js
Normal file
|
@ -0,0 +1,27 @@
|
|||
const command = {
|
||||
name: "pyramid",
|
||||
run: async (client, msg, splitted) => {
|
||||
if (isNaN(splitted[2]) || splitted[3] === undefined) {
|
||||
client.say(
|
||||
msg.channelName,
|
||||
`${msg.displayName}, Second arg needs to be a valid number and third arg needs to exist PoroSad`
|
||||
);
|
||||
}
|
||||
let arr = [];
|
||||
for (let i = 0; i < parseInt(splitted[2]); i++) {
|
||||
arr.push(splitted.slice(3).join(" "));
|
||||
client
|
||||
.say(msg.channelName, arr.join(" "))
|
||||
.catch((err) => console.log(err));
|
||||
}
|
||||
|
||||
for (let i = parseInt(splitted[2]); i > 1; i--) {
|
||||
arr.pop();
|
||||
client
|
||||
.say(msg.channelName, arr.join(" "))
|
||||
.catch((err) => console.log(err));
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
export default { command };
|
29
commands/trending.js
Normal file
29
commands/trending.js
Normal file
|
@ -0,0 +1,29 @@
|
|||
const command = {
|
||||
name: "trending",
|
||||
run: async (client, msg, splitted) => {
|
||||
if (!splitted[2]) {
|
||||
await client.say(
|
||||
msg.channelName,
|
||||
`${msg.displayName}, Please append a region PoroSad`
|
||||
);
|
||||
}
|
||||
|
||||
const data = await fetch(
|
||||
`https://api-piped.mha.fi/trending?region=${splitted[2]}`
|
||||
)
|
||||
.then((res) => res.json())
|
||||
.catch((err) => console.log(err));
|
||||
|
||||
if (data[0] === undefined) {
|
||||
client.say(msg.channelName, `${msg.displayName}, Invalid region PoroSad`);
|
||||
}
|
||||
await client
|
||||
.say(
|
||||
msg.channelName,
|
||||
`${msg.displayName}, Currently trending in YouTube at region ${splitted[2]}: Title: ${data[0]?.title} Link: youtu.be${data[0]?.url} Uploaded: ${data[0]?.uploadedDate}`
|
||||
)
|
||||
.catch((err) => console.log(err));
|
||||
},
|
||||
};
|
||||
|
||||
export default { command };
|
34
commands/weather.js
Normal file
34
commands/weather.js
Normal file
|
@ -0,0 +1,34 @@
|
|||
const command = {
|
||||
name: "weather",
|
||||
run: async (client, msg, splitted) => {
|
||||
if (splitted[2] === undefined) {
|
||||
client.say(
|
||||
msg.channelName,
|
||||
`${msg.displayName}, supply a location PoroSad`
|
||||
);
|
||||
}
|
||||
|
||||
const data = await fetch(`https://wttr.in/${splitted[2]}?format=j1`)
|
||||
.then((res) => res.json())
|
||||
.then((data) => {
|
||||
return data.current_condition[0];
|
||||
})
|
||||
.catch((err) => console.log(err));
|
||||
|
||||
if (data === undefined) {
|
||||
client.say(
|
||||
msg.channelName,
|
||||
`${msg.displayName}, Invalid location PoroSad`
|
||||
);
|
||||
}
|
||||
|
||||
await client
|
||||
.say(
|
||||
msg.channelName,
|
||||
`${msg.displayName} Weather for ${splitted[2]} Status: ${data.weatherDesc[0]?.value} Temp: ${data.temp_C}°C Feels like: ${data.FeelsLikeC}°C`
|
||||
)
|
||||
.catch((err) => console.log(err));
|
||||
},
|
||||
};
|
||||
|
||||
export default { command };
|
49
index.js
Normal file
49
index.js
Normal file
|
@ -0,0 +1,49 @@
|
|||
import {
|
||||
AlternateMessageModifier,
|
||||
ChatClient,
|
||||
SlowModeRateLimiter,
|
||||
} from "dank-twitch-irc";
|
||||
import fetch from "node-fetch";
|
||||
import fs from "fs";
|
||||
|
||||
let client = new ChatClient({
|
||||
username: process.env.TWITCH_USERNAME,
|
||||
password: process.env.TWITCH_PASSWORD,
|
||||
|
||||
rateLimits: "default",
|
||||
ignoreUnhandledPromiseRejections: true,
|
||||
});
|
||||
|
||||
client.use(new SlowModeRateLimiter(client));
|
||||
client.use(new AlternateMessageModifier(client));
|
||||
|
||||
client.on("ready", async () => console.log("Successfully connected to chat"));
|
||||
client.on("close", async (error) => {
|
||||
if (error != null) {
|
||||
console.error("Client closed due to error", error);
|
||||
}
|
||||
});
|
||||
|
||||
client.on("PRIVMSG", async (msg) => {
|
||||
if (msg.senderUsername === process.env.TWITCH_USERNAME) return;
|
||||
if (msg.messageText.length < 3) return;
|
||||
const splitted = msg.messageText.split(" ");
|
||||
|
||||
// chatterinos duplicate message bypass fix lol
|
||||
if (splitted[1] === "") {
|
||||
splitted.splice(1, 1);
|
||||
}
|
||||
|
||||
if (splitted[0] === "%") {
|
||||
import(`./commands/${splitted[1]}.js`)
|
||||
.then((command) => command.default.command.run(client, msg, splitted))
|
||||
.catch((err) => console.log(err));
|
||||
}
|
||||
});
|
||||
|
||||
client.connect();
|
||||
client.joinAll([
|
||||
process.env.TWITCH_USERNAME,
|
||||
"rollinjuusto",
|
||||
"juuuuuuuuuuuuunas",
|
||||
]);
|
272
index.mjs
272
index.mjs
|
@ -1,272 +0,0 @@
|
|||
import {
|
||||
AlternateMessageModifier,
|
||||
ChatClient,
|
||||
SlowModeRateLimiter,
|
||||
} from "dank-twitch-irc";
|
||||
import fetch from "node-fetch";
|
||||
|
||||
let client = new ChatClient({
|
||||
username: process.env.TWITCH_USERNAME,
|
||||
password: process.env.TWITCH_PASSWORD,
|
||||
|
||||
rateLimits: "default",
|
||||
ignoreUnhandledPromiseRejections: true,
|
||||
});
|
||||
|
||||
client.use(new SlowModeRateLimiter(client));
|
||||
client.use(new AlternateMessageModifier(client));
|
||||
|
||||
client.on("ready", async () => console.log("Successfully connected to chat"));
|
||||
client.on("close", async (error) => {
|
||||
if (error != null) {
|
||||
console.error("Client closed due to error", error);
|
||||
}
|
||||
});
|
||||
|
||||
client.on("PRIVMSG", async (msg) => {
|
||||
if (msg.senderUsername === process.env.TWITCH_USERNAME) return;
|
||||
if (msg.messageText.length < 3) return;
|
||||
const splitted = msg.messageText.split(" ");
|
||||
|
||||
// chatterinos duplicate message bypass fix lol
|
||||
if (splitted[1] === "") {
|
||||
splitted.splice(1, 1);
|
||||
}
|
||||
|
||||
if (splitted[0] === "%") {
|
||||
switch (splitted[1]) {
|
||||
case "pyramid": {
|
||||
if (isNaN(splitted[2]) || splitted[3] === undefined) {
|
||||
client.say(
|
||||
msg.channelName,
|
||||
`${msg.displayName}, Second arg needs to be a valid number and third arg needs to exist PoroSad`
|
||||
);
|
||||
break;
|
||||
}
|
||||
let arr = [];
|
||||
for (let i = 0; i < parseInt(splitted[2]); i++) {
|
||||
arr.push(splitted.slice(3).join(" "));
|
||||
client
|
||||
.say(msg.channelName, arr.join(" "))
|
||||
.catch((err) => console.log(err));
|
||||
}
|
||||
|
||||
for (let i = parseInt(splitted[2]); i > 1; i--) {
|
||||
arr.pop();
|
||||
client
|
||||
.say(msg.channelName, arr.join(" "))
|
||||
.catch((err) => console.log(err));
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case "ping": {
|
||||
await client
|
||||
.say(
|
||||
msg.channelName,
|
||||
`${msg.displayName}, Pong! Uptime: ${Math.floor(process.uptime())}s`
|
||||
)
|
||||
.catch((err) => console.log(err));
|
||||
break;
|
||||
}
|
||||
|
||||
case "fill": {
|
||||
if (!splitted[2]) {
|
||||
client.say(
|
||||
msg.channelName,
|
||||
`${msg.displayName}, Supply an arg PoroSad`
|
||||
);
|
||||
break;
|
||||
}
|
||||
|
||||
let str = "";
|
||||
while (true) {
|
||||
if (str.length + splitted.slice(2).join(" ").length >= 450) break;
|
||||
str += `${splitted.slice(2).join(" ")} `;
|
||||
}
|
||||
|
||||
await client.me(msg.channelName, str).catch((err) => console.log(err));
|
||||
break;
|
||||
}
|
||||
|
||||
case "weather": {
|
||||
if (splitted[2] === undefined) {
|
||||
client.say(
|
||||
msg.channelName,
|
||||
`${msg.displayName}, supply a location PoroSad`
|
||||
);
|
||||
break;
|
||||
}
|
||||
|
||||
const data = await fetch(`https://wttr.in/${splitted[2]}?format=j1`)
|
||||
.then((res) => res.json())
|
||||
.then((data) => {
|
||||
return data.current_condition[0];
|
||||
})
|
||||
.catch((err) => console.log(err));
|
||||
|
||||
if (data === undefined) {
|
||||
client.say(
|
||||
msg.channelName,
|
||||
`${msg.displayName}, Invalid location PoroSad`
|
||||
);
|
||||
break;
|
||||
}
|
||||
|
||||
await client
|
||||
.say(
|
||||
msg.channelName,
|
||||
`${msg.displayName} Weather for ${splitted[2]} Status: ${data.weatherDesc[0]?.value} Temp: ${data.temp_C}°C Feels like: ${data.FeelsLikeC}°C`
|
||||
)
|
||||
.catch((err) => console.log(err));
|
||||
break;
|
||||
}
|
||||
|
||||
case "trending": {
|
||||
if (!splitted[2]) {
|
||||
await client.say(
|
||||
msg.channelName,
|
||||
`${msg.displayName}, Please append a region PoroSad`
|
||||
);
|
||||
break;
|
||||
}
|
||||
|
||||
const data = await fetch(
|
||||
`https://api-piped.mha.fi/trending?region=${splitted[2]}`
|
||||
)
|
||||
.then((res) => res.json())
|
||||
.catch((err) => console.log(err));
|
||||
|
||||
if (data[0] === undefined) {
|
||||
client.say(
|
||||
msg.channelName,
|
||||
`${msg.displayName}, Invalid region PoroSad`
|
||||
);
|
||||
break;
|
||||
}
|
||||
await client
|
||||
.say(
|
||||
msg.channelName,
|
||||
`${msg.displayName}, Currently trending in YouTube at region ${splitted[2]}: Title: ${data[0]?.title} Link: youtu.be${data[0]?.url} Uploaded: ${data[0]?.uploadedDate}`
|
||||
)
|
||||
.catch((err) => console.log(err));
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
case "love": {
|
||||
if (splitted[2] === undefined || splitted[3] === undefined) {
|
||||
client.say(
|
||||
msg.channelName,
|
||||
`${msg.displayName}, supply 2 args PoroSad`
|
||||
);
|
||||
break;
|
||||
}
|
||||
|
||||
await client
|
||||
.say(
|
||||
msg.channelName,
|
||||
`${msg.displayName}, ${splitted[2]} and ${
|
||||
splitted[3]
|
||||
} are about ${Math.floor(
|
||||
Math.random() * 100
|
||||
)}% in love with each other!`
|
||||
)
|
||||
.catch((err) => console.log(err));
|
||||
break;
|
||||
}
|
||||
|
||||
case "fm": {
|
||||
if (splitted[2] === undefined) {
|
||||
client.say(
|
||||
msg.channelName,
|
||||
`${msg.displayName}, supply your Last.FM username PoroSad`
|
||||
);
|
||||
break;
|
||||
}
|
||||
|
||||
const data = await fetch(
|
||||
`https://ws.audioscrobbler.com/2.0/?method=user.getrecenttracks&user=${splitted[2]}&api_key=${process.env.LASTFM_KEY}&format=json&limit=1`
|
||||
)
|
||||
.then((res) => res.json())
|
||||
.then((data) => {
|
||||
return data.recenttracks.track[0];
|
||||
})
|
||||
.catch((err) => console.log(err));
|
||||
|
||||
if (data === undefined) {
|
||||
client.say(
|
||||
msg.channelName,
|
||||
`${msg.displayName}, Invalid user PoroSad`
|
||||
);
|
||||
break;
|
||||
}
|
||||
|
||||
await client
|
||||
.say(
|
||||
msg.channelName,
|
||||
`${msg.displayName}, (Now Playing) Album: ${data.album["#text"]} Track: ${data.name} Artist: ${data.artist["#text"]} | ${data.url}`
|
||||
)
|
||||
.catch((err) => console.log(err));
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
case "massping": {
|
||||
const data = await fetch(
|
||||
`https://tmi.twitch.tv/group/user/elis/chatters`
|
||||
)
|
||||
.then((res) => res.json())
|
||||
.then((data) => {
|
||||
return data.chatters;
|
||||
})
|
||||
.catch((err) => console.log(err));
|
||||
|
||||
let names = [];
|
||||
function printValues(obj) {
|
||||
for (var key in obj) {
|
||||
if (typeof obj[key] === "object") {
|
||||
printValues(obj[key]);
|
||||
} else {
|
||||
names.push(obj[key]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
printValues(data);
|
||||
let temp = [];
|
||||
for (let name of names) {
|
||||
if (temp.join(" ").length > 450) {
|
||||
client
|
||||
.say(msg.channelName, temp.join(" "))
|
||||
.catch((err) => console.log(err));
|
||||
temp = [];
|
||||
}
|
||||
|
||||
if (names.slice(-1)[0] === name) {
|
||||
client
|
||||
.say(msg.channelName, temp.join(" "))
|
||||
.catch((err) => console.log(err));
|
||||
}
|
||||
|
||||
temp.push(name);
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
default: {
|
||||
await client
|
||||
.say(msg.channelName, `${msg.displayName}, Not a command PoroSad`)
|
||||
.catch((err) => console.log(err));
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
client.connect();
|
||||
client.joinAll([
|
||||
process.env.TWITCH_USERNAME,
|
||||
"rollinjuusto",
|
||||
"juuuuuuuuuuuuunas",
|
||||
]);
|
|
@ -9,6 +9,7 @@
|
|||
"keywords": [],
|
||||
"author": "",
|
||||
"license": "ISC",
|
||||
"type": "module",
|
||||
"dependencies": {
|
||||
"dank-twitch-irc": "^4.3.0",
|
||||
"node-fetch": "^3.3.0",
|
||||
|
|
Loading…
Reference in a new issue