added temporary mail command and twitter command

This commit is contained in:
Joonas 2023-02-02 14:32:56 +02:00
parent 41e7e4102c
commit b81681f59c
3 changed files with 113 additions and 7 deletions

68
commands/mail.js Normal file
View File

@ -0,0 +1,68 @@
const command = {
name: "mail",
desc: "temporary email using dropmail.me",
run: async (client, msg, splitted) => {
switch (splitted[2]) {
case "create": {
const data = await fetch(
`https://dropmail.me/api/graphql/gj3489g389gj4wegj3qj890fg23j89j82g?query=mutation%20%7BintroduceSession%20%7Bid%2C%20expiresAt%2C%20addresses%20%7Baddress%7D%7D%7D`
)
.then((res) => res.json())
.then((data) => data.data.introduceSession)
.catch((err) => console.log(err));
await client
.say(
msg.channelName,
`${msg.displayName}, your temporary email has been created! Use the ID to fetch new mails! ID: ${data.id} Address: ${data.addresses[0].address}`
)
.catch((err) => console.log(err));
break;
}
case "fetch": {
const data = await fetch(
`https://dropmail.me/api/graphql/gj3489g389gj4wegj3qj890fg23j89j82g?query=query%20(%24id%3A%20ID!)%20%7Bsession(id%3A%24id)%20%7B%20addresses%20%7Baddress%7D%2C%20mails%7BrawSize%2C%20fromAddr%2C%20toAddr%2C%20downloadUrl%2C%20text%2C%20headerSubject%7D%7D%20%7D&variables=%7B%22id%22%3A%22${splitted[3]}%22%7D`
)
.then((res) => res.json())
.then((data) => data.data.session)
.catch((err) => console.log(err));
if (data.mails.length === 0) {
await client
.say(msg.channelName, `${msg.displayName}, no mails found`)
.catch((err) => console.log(err));
return;
}
await client
.say(
msg.channelName,
`${msg.displayName}, newest mail from ${data.addresses[0].address}: Title: ${data.mails[0].headerSubject} `
)
.catch((err) => console.log(err));
await client
.say(
msg.channelName,
`${msg.displayName}, Body: ${data.mails[0].text
.replaceAll("\n", " ")
.substring(0, 400)}`
)
.catch((err) => console.log(err));
break;
}
default: {
client.say(
msg.channelName,
`${msg.displayName}, supply an action (create or fetch)`
);
break;
}
}
},
};
module.exports = { command };

38
commands/twitter.js Normal file
View File

@ -0,0 +1,38 @@
const command = {
name: "twitter",
desc: "fetch latest tweet from user",
run: async (client, msg, splitted) => {
const data = await fetch(
`https://api.rss2json.com/v1/api.json?rss_url=https://nitter.namazso.eu/${
splitted[2] ? splitted[2] : "forsen"
}/rss`
)
.then((res) => res.json())
.then((data) => data.items[0])
.catch((err) => console.log(err));
if (!data) {
client
.say(
msg.channelName,
`${msg.displayName}, invalid name or api's are down`
)
.catch((err) => console.log(err));
return;
}
await client
.say(
msg.channelName,
`${msg.displayName}, Latest tweet for ${
splitted[2] ? splitted[2] : "forsen"
}: "${data.title}" Media: ${data.description
.split('"')
.filter((item) => item.startsWith("https://"))
.join(" ")} Link: ${data.link}`
)
.catch((err) => console.log(err));
},
};
module.exports = { command };

View File

@ -1,8 +1,7 @@
const { client } = require("./clients/twitch.js");
const fs = require("fs");
const { getCommands } = require("./utils/commands.js");
const commands = getCommands();
client.on("ready", async () => console.log("Successfully connected to chat"));
client.on("close", async (error) => {
if (error != null) {
@ -20,14 +19,15 @@ client.on("PRIVMSG", async (msg) => {
splitted.splice(1, 1);
}
console.log(commands);
if (splitted[0] === "%") {
if (splitted[0] === process.env.BOT_PREFIX) {
try {
await commands[splitted[1]].run(client, msg, splitted);
} catch {
} catch (err) {
client
.say(msg.channelName, `${msg.displayName}, not a command PoroSad`)
.say(
msg.channelName,
`${msg.displayName}, not a command or something went wrong`
)
.catch((err) => console.log(err));
}
}