Skip to content
Permalink
Browse files

Custom bank images / couple changes (#145)

* deprecate peepolove to skyra

* tell ppl how to open

* add custom bank images

* fix new util
  • Loading branch information
gc committed Feb 24, 2020
1 parent a0b9928 commit bd0f1031472055843c1fca81329888a8f1041f8d
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -90,7 +90,9 @@ export default class extends BotCommand {

return msg.send(
`${openable.emoji} You opened a ${openable.name} and received: ${
Object.keys(loot).length > 0 ? createReadableItemListFromBank(loot) : 'Nothing! Sad'
Object.keys(loot).length > 0
? createReadableItemListFromBank(this.client, loot)
: 'Nothing! Sad'
}.`
);
}
@@ -1,40 +1,7 @@
const { Command } = require('klasa');
const { MessageAttachment } = require('discord.js');
const { Canvas } = require('canvas-constructor');
const fs = require('fs');
const peepoBody = fs.readFileSync('./resources/images/peepoBody.png');
const peepoHands = fs.readFileSync('./resources/images/peepoHands.png');

module.exports = class extends Command {
constructor(...args) {
super(...args, {
description: 'Generates a peepoLove image from a given image/avatar.',
cooldown: 7,
usage: '<image:image>',
requiredPermissions: ['ATTACH_FILES']
});
}

async run(msg, [[imageBuffer]]) {
const imageBuff = new Canvas(512, 512)
.addImage(peepoBody, 0, 0)
.rotate(-0.4)
.addImage(imageBuffer, -210, 512 - 241, 330, 330, {
type: 'round',
radius: 330 / 2,
restore: true
})
.rotate(0.4)
.addImage(peepoHands, 0, 0)
.toBufferAsync();

const finishedImage = new MessageAttachment(await imageBuff, `peepoLove.png`);

let text = '';
if (msg.mentions.users.size > 0) {
text = `You can now use this command with any images, just upload the image or type the command after someone has sent an image.`;
}

return msg.send(text, finishedImage);
async run(msg) {
throw `This command has been removed from Old School Bot. **However:** The exact same command is available in a bot called Skyra. Invite link: <http://invite.skyra.pw/>`;
}
};
@@ -136,7 +136,8 @@ export default class extends Command {
true,
{
...msg.flagArgs
}
},
msg.author.settings.get(UserSettings.BankBackground)
);
return msg.send(new MessageAttachment(image, 'osbot.png'));
}
@@ -152,7 +153,8 @@ export default class extends Command {
{
...msg.flagArgs,
page: page - 1
}
},
msg.author.settings.get(UserSettings.BankBackground)
);

if (msg.flagArgs.full) {
@@ -52,6 +52,8 @@ export default class extends BotCommand {
`${Emoji.BirthdayPresent} ${msg.author.username} just gave a gift to ${user.username}!`
);

return msg.send(`You gave a present to ${user} ${Emoji.BirthdayPresent}!`);
return msg.send(
`You gave a present to ${user} ${Emoji.BirthdayPresent}! You can open this present with \`${msg.cmdPrefix}open present\``
);
}
}
@@ -10,6 +10,7 @@ export function T<TCustom>(k: string): CustomGet<string, TCustom> {
export namespace UserSettings {
export const GP = T<number>('GP');
export const Bank = T<BankType>('bank');
export const BankBackground = T<number>('bankBackground');
export const Pets = T<BankType>('pets');
export const CollectionLogBank = T<BankType>('collectionLogBank');
export const MonsterScores = T<BankType>('monsterScores');
@@ -15,6 +15,7 @@ Client.defaultUserSchema
.add('collectionLogBank', 'any', { default: {} })
.add('monsterScores', 'any', { default: {} })
.add('clueScores', 'any', { default: {} })
.add('bankBackground', 'integer', { default: 1 })
.add('minion', folder =>
folder
.add('name', 'string')
@@ -31,7 +31,8 @@ declare module 'klasa' {
bank: Bank,
title?: string,
showValue?: boolean,
flags?: { [key: string]: string | number }
flags?: { [key: string]: string | number },
bankBackgroundID = 1
): Promise<Buffer>;
generateCollectionLogImage(
collectionLog: Bank,
@@ -139,3 +139,5 @@ export interface ClueTier {
scrollID: number;
timeToFinish: number;
}

export type ItemTuple = [number, number, number];
@@ -267,3 +267,7 @@ export function itemNameFromID(itemID: number | string) {
export function floatPromise(ctx: { client: Client }, promise: Promise<unknown>) {
if (util.isThenable(promise)) promise.catch(error => ctx.client.emit(Events.Wtf, error));
}

export function addArrayOfNumbers(arr: number[]) {
return arr.reduce((a, b) => a + b, 0);
}
@@ -1,8 +1,11 @@
import { Items } from 'oldschooljs';
import { KlasaClient } from 'klasa';

import createTupleOfItemsFromBank from './createTupleOfItemsFromBank';
import { Bank } from '../types';

export default function createReadableItemListFromBank(itemBank: Bank) {
return createTupleOfItemsFromBank(itemBank)
.map(([name, qty]) => `${qty.toLocaleString()}x ${name}`)
export default function createReadableItemListFromBank(client: KlasaClient, itemBank: Bank) {
return createTupleOfItemsFromBank(client, itemBank)
.map(([name, qty]) => `${qty.toLocaleString()}x ${Items.get(name)!.name}`)
.join(', ');
}
@@ -1,12 +1,15 @@
import { KlasaClient } from 'klasa';
import { Items } from 'oldschooljs';

import { Bank } from '../types';
import { Bank, ItemTuple } from '../types';
import getItemPrice from './getItemPrice';

export default function createTupleOfItemsFromBank(bank: Bank) {
const readableTuple: [string, number][] = [];
export default function createTupleOfItemsFromBank(client: KlasaClient, bank: Bank) {
const readableTuple: ItemTuple[] = [];

for (const [itemID, qty] of Object.entries(bank)) {
readableTuple.push([Items.get(parseInt(itemID))!.name, qty]);
const item = Items.get(parseInt(itemID));
readableTuple.push([item!.id, qty, getItemPrice(client, itemID) * qty]);
}

return readableTuple;
@@ -0,0 +1,14 @@
import { KlasaClient } from 'klasa';

import getItemPrice from './getItemPrice';

export default async function ensureAllPricesCachedInArr(
client: KlasaClient,
itemIDs: (number | string)[]
) {
for (const itemID of itemIDs) {
if (!getItemPrice(client, itemID)) {
await client.fetchItemPrice(itemID);
}
}
}
@@ -0,0 +1,11 @@
export function fillTextXTimesInCtx(
ctx: CanvasRenderingContext2D,
text: string,
x: number,
y: number,
numberOfTimes = 3
) {
for (let i = 0; i < numberOfTimes; i++) {
ctx.fillText(text, x, y);
}
}
@@ -0,0 +1,16 @@
import { Items } from 'oldschooljs';

import { ItemTuple } from '../types';
import { cleanString } from '../util';

export default function filterItemTupleByQuery(query: string, items: ItemTuple[]) {
const filtered: ItemTuple[] = [];

for (const item of items) {
if (cleanString(Items.get(item[0])!.name).includes(cleanString(query))) {
filtered.push(item);
}
}

return filtered;
}
@@ -0,0 +1,8 @@
import { KlasaClient } from 'klasa';

import { ClientSettings } from '../ClientSettings';

export default function getItemPrice(client: KlasaClient, itemID: number | string) {
if (!client.production) return 73;
return client.settings.get(ClientSettings.Prices)[itemID].price;
}

0 comments on commit bd0f103

Please sign in to comment.
You can’t perform that action at this time.