feat: make everything cleaner and a youtube notification system

This commit is contained in:
2022-10-31 15:15:56 +01:00
parent 661d746c05
commit 097a1ee91e
10 changed files with 66 additions and 77 deletions

View File

@@ -1,3 +0,0 @@
{
"dotenv.enableAutocloaking": true
}

View File

@@ -2,7 +2,7 @@ import { commandModule, CommandType } from '@sern/handler'
import { publish } from "../../src/plugins/publish.js";
import { ownerOnly } from "../../src/plugins/ownerOnly.js"
import { ActionRowBuilder, ApplicationCommandOptionType, ChannelType, Collection, EmbedBuilder, Role, SelectMenuBuilder, TextChannel } from "discord.js";
import { Resolver } from "../../resolver.js";
import { Resolver } from "../../util/resolver.js";
export default commandModule({
name: 'rolemenu',

View File

@@ -6,6 +6,7 @@ import 'dotenv/config'
import mongoose from 'mongoose'
import youtube from 'discord-bot-youtube-notifications'
import express from 'express'
import youtubenotifications from "./util/youtubenotifications.js";
const app = express();
const client = new Client({
@@ -52,34 +53,6 @@ app.get("/", function (req, res) {
app.listen(process.env.PORT || 7272,
() => console.log("The webserver is listening"));
/*async function nowPlayingRadio() {
const getAPI = await axios.get("https://opml.radiotime.com/Describe.ashx?id=s67006", {validateStatus: function (status) {return status === 200|| status === 403}}).then((res) => res.data).catch((err) => {console.log("now playing radio errored out? diesofcringe")})
var parser = new DOMParser()
var XMLDoc = parser.parseFromString(getAPI, "text/xml");
let getsong, getartist;
try {
getsong = XMLDoc.getElementsByTagName("current_song").item(0)!.textContent
getartist = XMLDoc.getElementsByTagName("current_artist").item(0)!.textContent
} catch (err) {
getsong = "Anuncios o cambio de canción"
getartist = "catJAM"
}
const embed = new EmbedBuilder()
.setColor("Blurple")
.setTitle(`Ahora reproduciendo: ${getsong}`)
.setAuthor({name: 'Rock FM', iconURL: 'https://cdn-profiles.tunein.com/s67006/images/logoq.png'})
.setDescription(`Artista: ${getartist}`)
.setFooter({text: `El nombre no cambia al instante, aparece 10 segundos después de terminar una canción.`})
const guild = await client.guilds.fetch("928018226330337280");
const channel = await guild.channels.fetch("1008730592835281009");
const edit = (await channel.messages.fetch("1008778179252596736"))
await edit.edit({content: '', embeds: [embed]})
}
client.login(process.env.TOKEN);
function nowPlayingInterval() {
setInterval(nowPlayingRadio, 4000)
}
nowPlayingInterval()*/
client.login(process.env.TOKEN);
setInterval(async () => await youtubenotifications(client), 180000)

View File

@@ -1,43 +0,0 @@
[ OneButton ] [ TwoButton ]
button customId = 'yes' button customId = 'no'
collector
options : {
max:1
},
filter : interaction.isButton() && interaction.customId === 'yes' || interaction.customId === 'no'
collect interactions
if interaction.customId === 'yes'
this would be yes button
else
this would be the no button
if (interaction.customId === 'langChooserSpanish') {
ctx.reply("spanish")
}
else {
ctx.reply("english")
}
const got = require('got')
const { MessageEmbed } = require('discord.js')
module.exports = {
name: 'meme',
aliases: ['m', 'memes'],
description: 'Get a random meme from reddit',
execute(message, args) {
got(https://srizan.ml).then(res => {
});
}
}

7
schemas/youtube.js Normal file
View File

@@ -0,0 +1,7 @@
import mongoose from 'mongoose'
const schema = new mongoose.Schema({
id: {type: String, required: true},
user: {type: String, required: true}
});
const db = mongoose.model('youtube', schema, 'youtube');
export default db

32
util/nowplayingradio.ts Normal file
View File

@@ -0,0 +1,32 @@
import axios from "axios";
import { Client, EmbedBuilder, TextChannel } from "discord.js";
export async function nowPlayingRadio(client: Client) {
const getAPI = await axios.get("https://opml.radiotime.com/Describe.ashx?id=s67006", {validateStatus: function (status) {return status === 200|| status === 403}}).then((res) => res.data).catch((err) => {console.log("now playing radio errored out? diesofcringe")})
var parser = new DOMParser()
var XMLDoc = parser.parseFromString(getAPI, "text/xml");
let getsong, getartist;
try {
getsong = XMLDoc.getElementsByTagName("current_song").item(0)!.textContent
getartist = XMLDoc.getElementsByTagName("current_artist").item(0)!.textContent
} catch (err) {
getsong = "Anuncios o cambio de canción"
getartist = "catJAM"
}
const embed = new EmbedBuilder()
.setColor("Blurple")
.setTitle(`Ahora reproduciendo: ${getsong}`)
.setAuthor({name: 'Rock FM', iconURL: 'https://cdn-profiles.tunein.com/s67006/images/logoq.png'})
.setDescription(`Artista: ${getartist}`)
.setFooter({text: `El nombre no cambia al instante, aparece 10 segundos después de terminar una canción.`})
const guild = await client.guilds.fetch("928018226330337280");
const channel = await guild.channels.fetch("1008730592835281009");
const edit = await (channel as TextChannel).messages.fetch("1008778179252596736")
await edit.edit({content: '', embeds: [embed]})
}
function nowPlayingInterval() {
setInterval(nowPlayingRadio, 4000)
}
nowPlayingInterval()

View File

@@ -0,0 +1,23 @@
import { Client, EmbedBuilder, TextChannel } from "discord.js";
import axios from 'axios'
import schema from '../schemas/youtube.js'
export default async function youtubenotifications(client: Client) {
const db = await schema.findOne({name: 'elpady'})
const request = await axios.get('https://decapi.me/youtube/latest_video?id=UC9G2yvrtrPeJFEzwlshg5HA&format={id}').then(res => res.data)
const noembed = await axios.get(`https://noembed.com/embed?url=https://youtube.com/watch?v=${request}`).then(res => res.data)
const fetchTextChannel = await (await client.guilds.fetch('928018226330337280')).channels.fetch('948690278498320404') as TextChannel
if (request === db!.id) return
else {
db!.id = request
await db?.save()
const embed = new EmbedBuilder()
.setAuthor({name: 'Mara Turing', iconURL: 'https://yt3.ggpht.com/ytc/AMLnZu8rf3ZxWKKv9Dr6UjmWiDuKkaK06J5lDZ8WwwCg=s88-c-k-c0x00ffffff-no-rj'})
.setColor('Random')
.setTitle(`${noembed.title}`)
.setURL('https://youtu.be/' + request)
.setImage(`${noembed.thumbnail_url}`)
const message = await fetchTextChannel.send({content: 'Nuevo vídeo de Mara Turing, corre a verlo!', embeds: [embed]})
message.react('<:Pog:1030169609178976346>')
}
}