command access restriction

This commit is contained in:
Joonas 2023-02-03 00:37:42 +02:00
parent 9a22ecbeb3
commit 3317cf98a6
20 changed files with 37 additions and 3 deletions

3
.gitignore vendored
View File

@ -1 +1,2 @@
node_modules
node_modules
ecosystem.config.js

View File

@ -3,6 +3,7 @@ const fs = require("fs");
const command = {
name: "commands",
desc: "get list of commands",
restricted: false,
run: async (client, msg) => {
const commandFiles = fs
.readdirSync("./commands")

View File

@ -1,6 +1,7 @@
const command = {
name: "fill",
desc: "fill the chat with something",
restricted: false,
run: async (client, msg, splitted) => {
if (!splitted[2]) {
client

View File

@ -1,6 +1,7 @@
const command = {
name: "fm",
desc: "get last played track from last.fm with your username",
restricted: false,
run: async (client, msg, splitted) => {
if (splitted[2] === undefined) {
client.say(

View File

@ -1,6 +1,7 @@
const command = {
name: "hn",
desc: "fetch hacker news",
restricted: false,
run: async (client, msg) => {
const data = await fetch(
`https://hn.algolia.com/api/v1/search?tags=front_page`

View File

@ -1,6 +1,7 @@
const command = {
name: "join",
desc: "make the bot listen to a channel",
restricted: false,
run: async (client, msg) => {
await client
.join(msg.senderUsername)

View File

@ -1,6 +1,7 @@
const command = {
name: "love",
desc: "get the amount of love between two people!",
restricted: false,
run: async (client, msg, splitted) => {
if (splitted[2] === undefined || splitted[3] === undefined) {
client.say(msg.channelName, `${msg.displayName}, supply 2 args PoroSad`);

View File

@ -1,6 +1,7 @@
const command = {
name: "mail",
desc: "temporary email using dropmail.me",
restricted: false,
run: async (client, msg, splitted) => {
switch (splitted[2]) {
case "create": {

View File

@ -1,6 +1,7 @@
const command = {
name: "massping",
desc: "ping every chatter in the room (this one also blocks the thread until it's done)",
restricted: true,
run: async (client, msg, splitted) => {
let channel = msg.channelName;
if (splitted[2]) channel = splitted[2];

View File

@ -1,6 +1,7 @@
const command = {
name: "ping",
desc: "uptime",
restricted: false,
run: async (client, msg) => {
await client
.say(

View File

@ -1,6 +1,7 @@
const command = {
name: "pyramid",
desc: "make a pyramid (this blocks the thread and no other command will execute until it's done)",
restricted: true,
run: async (client, msg, splitted) => {
if (
isNaN(splitted[2]) ||

View File

@ -1,6 +1,7 @@
const command = {
name: "rd",
desc: "get post from reddit subreddit",
restricted: false,
run: async (client, msg, splitted) => {
const data = await fetch(
`https://teddit.namazso.eu/r/${

View File

@ -1,6 +1,7 @@
const command = {
name: "rl",
desc: "get a random line from a channel",
restricted: false,
run: async (client, msg, splitted) => {
const data = await fetch(
`https://logs.ivr.fi/channel/${

View File

@ -1,6 +1,7 @@
const command = {
name: "short",
desc: "shorten an url",
restricted: false,
run: async (client, msg, splitted) => {
if (!splitted[2]) {
client

View File

@ -1,6 +1,7 @@
const command = {
name: "sketch",
desc: "make a suspicious link",
restricted: false,
run: async (client, msg, splitted) => {
if (!splitted[2]) {
client.say(

View File

@ -1,6 +1,7 @@
const command = {
name: "twitter",
desc: "fetch latest tweet from user",
restricted: false,
run: async (client, msg, splitted) => {
const data = await fetch(
`https://api.rss2json.com/v1/api.json?rss_url=https://nitter.namazso.eu/${

View File

@ -1,6 +1,7 @@
const command = {
name: "user",
desc: "get info about a certain user",
restricted: false,
run: async (client, msg, splitted) => {
const data = await fetch(
`https://api.ivr.fi/v2/twitch/user?login=${

View File

@ -1,6 +1,7 @@
const command = {
name: "weather",
desc: "get the weather from wttr.in",
restricted: false,
run: async (client, msg, splitted) => {
if (splitted[2] === undefined) {
client

View File

@ -1,6 +1,7 @@
const command = {
name: "yts",
desc: "search youtube for a video",
restricted: false,
run: async (client, msg, splitted) => {
if (splitted[2] === undefined) {
client
@ -13,10 +14,13 @@ const command = {
`https://invidious.epicsite.xyz/api/v1/search?type=video&q=${splitted
.slice(2)
.join(" ")
.replaceAll(/\W/g, "")}`
.replaceAll("?", "")
.replaceAll("/", "")
.replaceAll("\\", "")
.replaceAll("&", "")}`
)
.then((res) => res.json())
.then((data) => data[Math.floor(Math.random() * data.length)])
.then((data) => data[0])
.catch((err) => console.log(err));
await client

View File

@ -21,6 +21,18 @@ client.on("PRIVMSG", async (msg) => {
if (splitted[0] === process.env.BOT_PREFIX) {
try {
if (commands[splitted[1]].restricted) {
if (!msg.badges.hasBroadcaster) {
if (!msg.isMod) {
client.say(
msg.channelName,
`${msg.displayName}, need to be a mod or brodcaster to use`
);
return;
}
}
}
await commands[splitted[1]].run(client, msg, splitted);
} catch (err) {
client