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

Fix Spotify URI support and misc fixes #1

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 4 additions & 23 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,6 @@
# coffea-starter
# 6697-bot

_coffea starter kit / boilerplate to quickly develop a chat bot_


## Starting a new project

```
git clone https://github.com/coffea-bots/coffea-starter PROJECT_NAME
```
This is a bot for #lounge on Telegram.


## Setup
Expand All @@ -26,23 +19,11 @@ While this is running, you can create a `config.json`, which will be passed to
{
"protocol": "telegram",
"token": "INSERT_TELEGRAM_TOKEN_HERE"
},
{
"protocol": "slack",
"token": "INSERT_TELEGRAM_TOKEN_HERE"
}
]
}]
```

**Important:** Don't forget to install the protocols via `npm install coffea-PROTOCOLNAME`,
e.g. `npm install coffea-telegram coffea-slack` (in this case)

Feel free to add as few or as many networks/protocols as you'd like. Currently,
only [slack](https://github.com/caffeinery/coffea-slack), [telegram](https://github.com/caffeinery/coffea-telegram) and [irc](https://github.com/caffeinery/coffea-irc) are supported.
**Important:** Don't forget to install the protocol via `npm install coffea-telegram`.

Lastly, you should take a look at `src/index.js`. Feel free to adjust the code
to your liking. As your bot grows, make sure to split it up into separate
files.


## Running
Expand Down
22 changes: 9 additions & 13 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "coffea-starter",
"version": "0.0.0",
"description": "coffea starter kit / boilerplate to quickly develop a chat bot",
"name": "6697-bot",
"version": "0.3.1",
"description": "Bot for #lounge on Telegram",
"bin": {
"bot": "build/index.js"
},
Expand All @@ -17,26 +17,21 @@
},
"repository": {
"type": "git",
"url": "git+https://github.com/caffeinery/coffea-starter.git"
"url": "git+https://github.com/6697/6697-bot.git"
},
"keywords": [
"coffea",
"starter",
"kit",
"boilerplate",
"chat",
"bot",
"messaging",
"slack",
"irc",
"telegram"
],
"author": "Daniel Bugl <[email protected]>",
"author": "Micheal Harker <[email protected]>",
"license": "ISC",
"bugs": {
"url": "https://github.com/caffeinery/coffea-starter/issues"
"url": "https://github.com/6697/6697-bot/issues"
},
"homepage": "https://github.com/caffeinery/coffea-starter#readme",
"homepage": "https://github.com/6697/6697-bot#readme",
"devDependencies": {
"babel-cli": "^6.8.0",
"babel-core": "^6.5.1",
Expand All @@ -50,6 +45,7 @@
},
"dependencies": {
"coffea": "1.0.0-beta18",
"debug-dude": "^1.0.3"
"debug-dude": "^1.0.3",
"cheerio": "^1.0.0-rc.1"
}
}
43 changes: 33 additions & 10 deletions rules.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,33 @@
» This is a *safe-for-work* chat (we have [#nsfw](https://t.me/nsfw6697) for porn and stuff)
» *Only speak in English*
» *No spam* (this includes advertising, repeating things over and over again, or spamming bot commands)
» *Don't flood the chat*, it will result in a kick
» *Please be inclusive.* This doesn't mean you can't express your opinion, but don't be an asshole about it
» *Please try our games*, but don't cheat - it ruins the experience for everybody

[#lounge](https://t.me/lounge6697) (sfw, non-anonymous chat)
[/gen/ BETA](https://t.me/generalloungebot) (sfw, anonymous chat)
[#nsfw](https://t.me/nsfw6697) (nsfw, non-anonymous chat)
» This is a *safe-for-work* chat. Pornographic content is only allowed in chats marked *[NSFW]*.
» *Only speak in English*. We also have some German chats, though.
» *No spam* (this includes advertising, repeating things over and over again, or spamming bot commands).
» *Don't flood the chat*, it will result in a kick.
» *Please be inclusive.* This doesn't mean you can't express your opinion, but don't be an asshole about it.
» *Please try our games*, but don't cheat – it ruins the experience for everybody.

*#lounge community*

*Groups*
[#lounge](https://t.me/lounge6697) – General chat
[#nsfw](https://t.me/nsfw6697) – Porn *[NSFW]*
[#mc](https://t.me/mclounge) – Minecraft servers
[#lounge-de](https://t.me/joinchat/BrliRj6tra4BssLoLW9qgA) – German (Deutsch)

*Channels*
[#quotes](https://t.me/loungequotes) – Funny quotes from the community
[#lounge community channels](https://t.me/loungequotes)

*Anonymous chats* (BETA)
[/gen/](https://t.me/generalloungebot) – General chat
[/b/](https://t.me/secretloungebot) – Random *[NSFW]*
[/a/](https://t.me/animeloungebot) – Anime *[NSFW]*
[/fur/](https://t.me/furryloungebot) – Furry *[NSFW]*
[/lgbt/](https://t.me/lgbtloungebot) – Chat for LGBT people and supporters *[NSFW]*
[/de/](https://t.me/germanloungebot) – German (Deutsch)

*Other platforms*
IRC: irc.6697.eu (see \`/list\` for available channels)
Discord: https://discord.gg/WYASmAC

*Miscellaneous*
[#lounge birthdays](https://docs.google.com/spreadsheets/d/15HyoywzsUduy7jbG75cCMQ8ud6R-cajSHnVAJeppJ4k/edit) (spreadsheet)
44 changes: 32 additions & 12 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@ import fs from 'fs'
import path from 'path'
import request from 'request'

import cheerio from 'cheerio'

import dude from 'debug-dude'
const { /*debug,*/ log, info, warn /*, error*/ } = dude('bot')

import { version } from '../package.json'
info(`coffea-starter bot v${version} starting`)
info(`#lounge bot v${version} starting`)

import config from '../config.json'

Expand All @@ -23,10 +25,10 @@ networks.on('error', ({ err }) =>

networks.on('new_chat_participant', (evt, reply) => {
log('Received new_chat_participant event: %o', evt)
let name = evt && evt.raw && evt.raw.new_chat_participant && [ evt.raw.new_chat_participant.first_name, evt.raw.new_chat_participant.last_name ].join(' ')
let name = evt && evt.raw && evt.raw.new_chat_participant && [ evt.raw.new_chat_participant.first_name, evt.raw.new_chat_participant.last_name ].join(' ').trim()
reply({
type: 'message',
text: `Welcome to #lounge, *${name}*. Please read the rules (/rules) and enjoy your time here!`,
text: `Welcome to ${evt.raw.chat.title}, *${name}*. Please read the rules (/rules) and enjoy your time here!`,
options: {
parse_mode: 'markdown',
reply_to_message_id: evt && evt.raw && evt.raw.message_id
Expand All @@ -39,15 +41,33 @@ networks.on('message', (evt, reply) => {
if (/spotify:track:([A-z0-9]+)/.test(evt.text)) {
let matches = evt.text.match(/spotify:track:([A-z0-9]+)/)
let id = matches[1]
request(`https://api.spotify.com/v1/tracks/${id}`, function (err, res, body) {
if (!err && res.statusCode === 200) {
let data = JSON.parse(body);
let title = data && data.name;
let artists = data && data.album && data.album.artists && data.album.artists.map(artist => artist.name).join(', ')
let album = data && data.album && data.album.name
let image_url = data && data.album.images && data.album.images[0] && data.album.images[0].url
let minutes = Math.floor(data && data.duration_ms / 60000)
let seconds = ((data && data.duration_ms % 60000) / 1000).toFixed(0)
let track_url = `https://open.spotify.com/track/${id}`

request(track_url, (err, res, body) => {
if (err) {
throw(err)
}

let $ = cheerio.load(body)
let album_url = $('meta[property="music:album"]').attr('content')

request(album_url, (err, res, body) => {
if (err) {
throw(err)
}

let $ = cheerio.load(body)
cb($('meta[property="og:title"]').attr('content'))
})

let cb = (album) => {
let title = $('meta[property="og:title"]').attr('content')
let artists = $('meta[property="twitter:audio:artist_name"]').attr('content')
let image_url = $('meta[property="og:image"]').attr('content')
let duration_s = $('meta[property="music:duration"]').attr('content')
let minutes = Math.floor(duration_s / 60)
let seconds = ((duration_s % 60)).toFixed(0)

reply({
type: 'message',
text: `*${title}* (${minutes}:${seconds < 10 ? '0' : ''}${seconds}) by *${artists}* - in album *${album}*.[​](${image_url})`,
Expand Down