commit f5ca3541b7c3559830a2b2b522122cdcb5699051
parent 4bb7036c626cf146eaf0d87dcf81988cad90198f
Author: Demonstrandum <moi@knutsen.co>
Date: Sun, 22 Mar 2020 19:45:49 +0000
Fix ship.
Diffstat:
5 files changed, 27 insertions(+), 22 deletions(-)
diff --git a/lib/commands/pat.ts b/lib/commands/pat.ts
@@ -5,15 +5,10 @@ import Jimp from 'jimp';
const TEMPLATE = "./lib/resources/templates/pat.png";
-interface Scope {
- message: Message;
- args: any;
-}
-
-export default (home_scope: Scope) => {
+export default (home_scope: HomeScope) => {
const { message, args } = home_scope;
- if (args.length == 0 || message.mentions.users.size == 0) {
+ if (args.length === 0 || message.mentions.users.size === 0) {
message.channel.send(
"Pat someone!\n" + ".pat [@user-name]".format(FORMATS.block)
);
@@ -23,10 +18,10 @@ export default (home_scope: Scope) => {
const [x, y] = [200, 108];
const filename = "patted.png";
- const description =
+ const description =
`${message.mentions.users.first().username}`.format(FORMATS.bold)
+ ', you got a pat from '
- + `${message.author.username}`.format(FORMATS.bold)
+ + `${message.author.username}`.format(FORMATS.bold)
+ ' :blush:';
const pat = async (image: string) => {
diff --git a/lib/commands/ship.ts b/lib/commands/ship.ts
@@ -22,19 +22,20 @@ const RESPONSES = [
{ range: [93, 97], message: "They deeply love each other! :blush:" },
{ range: [97, 100], message: "Lovey-dovey couple!! :kissing_heart: :heart: :two_hearts:" },
];
-function read512bitsBigIntBigEndian(buffer){
- let biiiiiiiigInt = BigInt(0);
- for (var i = 512 + 64; i -= 64;)
- biiiiiiiigInt += cryptoBuffer.readBigUInt64BE(i / 8 - 8) * BigInt(Math.pow(2, i));
- return biiiiiiiigInt;
-}
-export default home_scope => {
+
+const BIG_ZERO = BigInt(0)
+
+const read512bitsBigIntBigEndian = (buffer : Buffer) : bigint => {
+ let val = BIG_ZERO;
+ for (let i = 512 + 64; i -= 64;)
+ val += buffer.readBigUInt64BE(i / 8 - 8) * BigInt(Math.pow(2, i));
+ return val;
+};
+
+export default (home_scope : HomeScope) => {
const { message, args,
HELP_SECTIONS,
- KNOWN_COMMANDS }
- : { message: Message, args: string[],
- HELP_SECTIONS: string[],
- KNOWN_COMMANDS: string[] } = home_scope;
+ KNOWN_COMMANDS } = home_scope;
if (args.length === 0 || args[0] === 'help'
|| message.mentions.users.size === 0
diff --git a/lib/extensions.ts b/lib/extensions.ts
@@ -1,5 +1,14 @@
// Global Extensions:
declare global {
+ type HomeScope = {
+ message: Message, args: string[],
+ HELP_SOURCE: string, HELP_KEY: string,
+ GIT_URL: string, HELP_MESSAGES: string[],
+ HELP_SECTIONS: string[] , ALL_HELP: string[],
+ CONFIG: any, SECRETS: any, KNOWN_COMMANDS: string[],
+ expand_alias: (operator: string, args: string[]) => string
+ };
+
interface Array<T> {
head(): T;
tail(): T[];
diff --git a/lib/main.ts b/lib/main.ts
@@ -88,7 +88,7 @@ export class SimpOMatic {
console.log('Known commands:', pp(KNOWN_COMMANDS));
}
- expand_alias(operator, args) {
+ expand_alias(operator: string, args: string[]) {
const expander = unexpanded => {
let expansion = unexpanded;
if (CONFIG.commands.aliases.hasOwnProperty(unexpanded))
diff --git a/lib/utils.ts b/lib/utils.ts
@@ -8,7 +8,7 @@ export const deep_copy = deep_clone;
// would ever be greater than 2000 characters long.
export const glue_strings = (arr: any[], limit: number = 2000) => {
let acc = "";
- const new_strings = [];
+ const new_strings: string[] = [];
for (const msg of arr)
if (acc.length + msg.length >= limit) {
new_strings.push(acc);