Comparing version 2.0.0-rc.4 to 2.0.0-rc.5
{ | ||
"name": "retrocord", | ||
"version": "2.0.0-rc.4", | ||
"version": "2.0.0-rc.5", | ||
"description": "", | ||
@@ -26,2 +26,3 @@ "main": "src/index.js", | ||
"discord.js": "github:hydrabolt/discord.js", | ||
"emoji-regex": "^6.5.1", | ||
"erlpack": "github:hammerandchisel/erlpack", | ||
@@ -28,0 +29,0 @@ "jaro-winkler": "^0.2.8", |
const Storage = require('./Storage'); | ||
const userLookup = require('./util/userLookup'); | ||
const lookup = require('./util/lookup'); | ||
@@ -33,3 +33,3 @@ module.exports = { | ||
if (!channel) { | ||
channel = userLookup(query); | ||
channel = lookup.user(query); | ||
if (channel) { | ||
@@ -43,9 +43,9 @@ channel = await channel.createDM().catch((err) => { | ||
} else { | ||
scope = scope ? | ||
ctx.discord.guilds.find((g) => g.name.toLowerCase() === scope.toLowerCase()) : | ||
ctx.current.scope; | ||
scope = scope ? lookup.guild(scope) : ctx.current.scope; | ||
if (!scope) return ctx.gui.put('{bold}Invalid Guild{/bold}'); | ||
channel = scope.channels | ||
.filter((c) => c.type === 'text') | ||
.find((c) => c.name.toLowerCase() === channel.toLowerCase()); | ||
channel = channel ? | ||
scope.channels | ||
.filter((c) => c.type === 'text') | ||
.find((c) => c.name.toLowerCase() === channel.toLowerCase()) : | ||
scope.defaultChannel; | ||
} | ||
@@ -69,3 +69,3 @@ if (!channel) return ctx.gui.put('{bold}Invalid Channel{/bold}'); | ||
channel.fetchMessages({ limit: 5 }).then((messages) => { | ||
ctx.gui.putMessages(messages.array().reverse()); | ||
ctx.gui.putMessages(messages.array().reverse(), { mdy: true }); | ||
}); | ||
@@ -119,2 +119,15 @@ ctx.current.channel = channel; | ||
}, | ||
guilds: { | ||
run: (ctx) => { | ||
ctx.gui.put('{bold}Available Guilds:{/bold}'); | ||
ctx.gui.put(ctx.discord.guilds.map((g) => g.name).join(', ')); | ||
}, | ||
}, | ||
channels: { | ||
run: (ctx) => { | ||
if (!ctx.current.scope || ctx.current.scope === 'dm') return; | ||
ctx.gui.put('{bold}Available Channels:{/bold}'); | ||
ctx.gui.put(ctx.current.scope.channels.filter((c) => c.type === 'text').map((g) => g.name).join(', ')); | ||
}, | ||
}, | ||
}; | ||
@@ -121,0 +134,0 @@ |
const Discord = require('discord.js'); | ||
const Storage = require('../Storage'); | ||
const timestamp = require('../util/timestamp'); | ||
const client = new Discord.Client({ | ||
// some options | ||
http: process.snekv ? { | ||
api: process.snekv.api, | ||
cdn: process.snekv.cdn, | ||
invite: process.snekv.invites, | ||
} : undefined, | ||
}); | ||
@@ -12,2 +15,3 @@ | ||
function run(ctx) { | ||
const Storage = require('../Storage'); | ||
client.on('ready', () => { | ||
@@ -14,0 +18,0 @@ if (client.user.bot) { |
@@ -34,6 +34,10 @@ const request = require('snekfetch'); | ||
if (await Storage.hasFile(id)) return makeImage({ path: Storage.getFilePath(id), width, height }); | ||
const data = await request.get(url) | ||
.then((r) => resize(r.body, width, height)); | ||
await Storage.setFile(id, data); | ||
return makeImage({ path: Storage.getFilePath(id), width, height }); | ||
try { | ||
const data = await request.get(url) | ||
.then((r) => resize(r.body, width, height)); | ||
await Storage.setFile(id, data); | ||
return makeImage({ path: Storage.getFilePath(id), width, height }); | ||
} catch (err) { | ||
return null; | ||
} | ||
} | ||
@@ -40,0 +44,0 @@ |
@@ -45,12 +45,16 @@ const emoji = require('node-emoji'); | ||
let images; | ||
const IMAGE_RE = /(jpe?g|png|gif)$/; | ||
let files; | ||
if (Storage.rc.attachments !== 'false') { | ||
images = await Promise.all(message.attachments.map(async(a) => { | ||
const short = a.url.replace('https://cdn.discordapp.com/attachments/', '').split('/'); | ||
const ansi = await imageElement({ id: a.id, url: a.proxyURL, width: a.width, height: a.height }); | ||
return `${a.filename} (${a.width}x${a.height}) ${shortlink(short[2], short[0], short[1])}\n${ansi}`; | ||
files = await Promise.all(message.attachments.map(async(a) => { | ||
let short = a.url.replace(/^.+?\/attachments\//, '').split('/'); | ||
short = shortlink(short[2], short[0], short[1]); | ||
const i = IMAGE_RE.test(a.proxyURL); | ||
const ansi = i ? | ||
await imageElement({ id: a.id, url: a.proxyURL, width: a.width, height: a.height }) : null; | ||
return `${a.filename}${i ? ` (${a.width}x${a.height})` : ''} ${short}\n${ansi || ''}`.trim(); | ||
})); | ||
} | ||
let attachments = [...images]; | ||
let attachments = [...files]; | ||
@@ -57,0 +61,0 @@ if (!content) content = '{bold}(No Content){/bold}'; |
#!/usr/bin/env node | ||
const snekparse = require('snekparse'); | ||
process.snekv = snekparse(process.argv); | ||
const emoji = require('node-emoji'); | ||
@@ -9,4 +12,3 @@ const Storage = require('./Storage'); | ||
const discord = require('./discord'); | ||
const snekparse = require('snekparse'); | ||
const userLookup = require('./util/userLookup'); | ||
const lookup = require('./util/lookup'); | ||
@@ -27,2 +29,3 @@ const ctx = { | ||
gui.on('input', (message) => { | ||
if (!message.length) return; | ||
const prefix = ctx.rc.prefix || '/'; | ||
@@ -40,3 +43,3 @@ if (message.startsWith(prefix)) { | ||
ctx.discord.users; | ||
const user = userLookup(args[word].slice(1), users); | ||
const user = lookup.user(args[word].slice(1), users); | ||
if (user) args[word] = user.toString(); | ||
@@ -43,0 +46,0 @@ } else if (args[word].startsWith('#')) { |
@@ -0,1 +1,2 @@ | ||
const discord = require('./discord'); | ||
const fs = require('fs'); | ||
@@ -5,2 +6,4 @@ const path = require('path'); | ||
const SCOPE = discord.client.options.http.api; | ||
const readFileAsync = util.promisify(fs.readFile); | ||
@@ -56,6 +59,6 @@ const writeFileAsync = util.promisify(fs.writeFile); | ||
get(key) { | ||
return cache.storage[key]; | ||
return cache.storage[SCOPE][key]; | ||
}, | ||
set(key, value) { | ||
const ret = cache.storage[key] = value; | ||
const ret = cache.storage[SCOPE][key] = value; | ||
fs.writeFileSync(STORAGE_PATH, JSON.stringify(cache.storage)); | ||
@@ -65,6 +68,6 @@ return ret; | ||
has(key) { | ||
return Reflect.has(cache.storage, key); | ||
return Reflect.has(cache.storage[SCOPE], key); | ||
}, | ||
delete(key) { | ||
const ret = delete cache.storage[key]; | ||
const ret = delete cache.storage[SCOPE][key]; | ||
fs.writeFileSync(STORAGE_PATH, JSON.stringify(cache.storage)); | ||
@@ -93,2 +96,4 @@ return ret; | ||
if (!cache.storage[SCOPE]) cache.storage[SCOPE] = {}; | ||
function getOSStoragePath() { | ||
@@ -95,0 +100,0 @@ switch (process.platform) { |
const { encode } = require('tinyint'); | ||
function shortlink(name, ...ids) { | ||
return `https://retro.lol/${ids.map(encode).join('/')}/${name}`; | ||
return `https://retro.lol/${ids.filter((i) => i).map(encode).join('/')}/${name}`; | ||
} | ||
module.exports = shortlink; |
152851
783
13
+ Addedemoji-regex@^6.5.1
+ Addedemoji-regex@6.5.1(transitive)