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

Make static maps memes for april fools #835

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
6 changes: 6 additions & 0 deletions src/controllers/controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const TileserverPregen = require('../lib/tileserverPregen')
const replaceAsync = require('../util/stringReplaceAsync')
const HideUriShortener = require('../lib/hideuriUrlShortener')
const ShlinkUriShortener = require('../lib/shlinkUrlShortener')
const MeMeR = require('../lib/getMemes')

const EmojiLookup = require('../lib/emojiLookup')

Expand All @@ -31,6 +32,7 @@ class Controller extends EventEmitter {
// this.controllerData = weatherCacheData || {}
this.tileserverPregen = new TileserverPregen(this.config, this.log)
this.emojiLookup = new EmojiLookup(GameData.utilData.emojis)
this.memer = new MeMeR(this.log)
this.imgUicons = this.config.general.imgUrl ? new Uicons((this.config.general.images && this.config.general.images[this.constructor.name.toLowerCase()]) || this.config.general.imgUrl, 'png', this.log) : null
this.imgUiconsAlt = this.config.general.imgUrlAlt ? new Uicons((this.config.general.imagesAlt && this.config.general.imagesAlt[this.constructor.name.toLowerCase()]) || this.config.general.imgUrlAlt, 'png', this.log) : null
this.stickerUicons = this.config.general.stickerUrl ? new Uicons((this.config.general.stickers && this.config.general.stickers[this.constructor.name.toLowerCase()]) || this.config.general.stickerUrl, 'webp', this.log) : null
Expand Down Expand Up @@ -260,6 +262,10 @@ class Controller extends EventEmitter {
data.staticMap = `https://api.mapbox.com/styles/v1/mapbox/streets-v10/static/url-https%3A%2F%2Fi.imgur.com%2FMK4NUzI.png(${data.longitude},${data.latitude})/${data.longitude},${data.latitude},${this.config.geocoding.zoom},0,0/${this.config.geocoding.width}x${this.config.geocoding.height}?access_token=${this.config.geocoding.staticKey[~~(this.config.geocoding.staticKey.length * Math.random())]}`
break
}
case 'meme': {
data.staticMap = this.memer.getMemes()
break
}
default: {
data.staticMap = ''
}
Expand Down
28 changes: 28 additions & 0 deletions src/lib/getMemes.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
const axios = require('axios')

class GetMemes {
constructor(log) {
this.log = log
}

async getMemes() {
try {
const result = await axios.get('https://meme-api.com/gimme')

if (result.status !== 200) {
this.log.warn(`MeMeR: Failed to get meme. Got ${result.status}. Error: ${result.data ? result.data.reason : '?'}.`)
return 'https://usagif.com/wp-content/uploads/2021/4fh5wi/pepefrg-22.gif'
}
return result.data.url
} catch (error) {
if (error.response) {
this.log.warn(`MeMeR: Failed to get meme. Got ${error.response.status}. Error: ${error.response.data ? error.response.data.reason : '?'}.`)
} else {
this.log.warn(`MeMeR: Failed to get meme. Error: ${error}.`)
}
return 'https://usagif.com/wp-content/uploads/2021/4fh5wi/pepefrg-22.gif'
}
}
}

module.exports = GetMemes