Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

idea: DJ chatbot #1669

Open
soichih opened this issue Jun 26, 2021 · 0 comments
Open

idea: DJ chatbot #1669

soichih opened this issue Jun 26, 2021 · 0 comments
Labels
🙏 community-contribution For contributions from our community! <3

Comments

@soichih
Copy link
Contributor

soichih commented Jun 26, 2021

We experimented with a DJ chatbot on venue/loungetable so that anyone can post a youtube link to switch the video being played there. It's probably good to add a bit more restriction on who can change the video, or allow each table to play a different video (currently not possible) but here is the code that I've deployed via pm2 on our server.

#!/usr/bin/env node

const admin = require('firebase-admin');
const config = require('./config');
const now = admin.firestore.Timestamp.now();

admin.initializeApp(config.firebase);
const db = admin.firestore();

const target = "loungetables";

db.collection('venues/'+target+'/chats').onSnapshot(doc=>{
    console.log("listening to messages on ", target);
    doc.docChanges().forEach(change=>{
        const doc = change.doc.data();
        if(doc.ts_utc < now) return; //skip messages posted before we started the bot

        console.log(doc);

        const youtubeV = "youtube.com/watch?v=";
        if(doc.text.includes(youtubeV)) {
            let token = "5BRc5zV4YKU"; //abuse!

            const tokens = doc.text.split(youtubeV);
            if(tokens[1]) {
                //does it look like youtube id?
                let _token = tokens[1].substring(0,11);
                if(_token.length == 11) token = _token; 
            }

            const url = "https://www.youtube.com/embed/"+token;
            console.log("switching iframe:", url);
            db.collection("venues").doc(target).update({ iframeUrl: url });
        }
    });
});

We observed that people really enjoyed this Juke-box-like capability. We mostly played BGM / live clips - mixed with occasional random youtube videos.

@whoaitsaimz whoaitsaimz added the 🙏 community-contribution For contributions from our community! <3 label Jul 14, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🙏 community-contribution For contributions from our community! <3
Projects
None yet
Development

No branches or pull requests

2 participants