commit ca56ef9fcf04d37e414234a9fa040a557d2cba17
parent 40304172679f6534e1862dd08334a6aee7f05e69
Author: Demonstrandum <moi@knutsen.co>
Date: Thu, 28 May 2020 15:39:01 +0100
Add CLIENT to homescope, use on_message for cron.
Diffstat:
8 files changed, 65 insertions(+), 69 deletions(-)
diff --git a/lib/commands/code.ts b/lib/commands/code.ts
@@ -19,16 +19,12 @@ const file_authors = async (filename: string): Promise<Authors> => {
for (let i = 0; i < blame.getHunkCount(); i++) {
// Hunk has bad type signatures, someone should tell `nodegit'.
const hunk: any = blame.getHunkByIndex(i);
- for (let j = 0; j < hunk.linesInHunk(); j++) {
- const oid = hunk.finalCommitId();
- const commit = await repo.getCommit(oid);
- const name = commit.author().name();
+ const oid = hunk.finalCommitId();
+ const commit = await repo.getCommit(oid);
+ const name = commit.author().name();
- if (authors.hasOwnProperty(name))
- authors[name] += 1;
- else
- authors[name] = 1;
- }
+ if (authors.hasOwnProperty(name)) authors[name] += 1;
+ else authors[name] = 1;
}
return authors;
@@ -57,9 +53,9 @@ export default async (homescope : HomeScope) => {
const source = read_file(`${process.cwd()}/${filename}`)
.toString();
const authors = await file_authors(filename);
- const author_str = "\n**Authors**: " + Object.keys(authors)
+ const author_str = "\n**Author(s)**: " + Object.keys(authors)
.map(author => `(\`${authors[author]}\`) ${author}`)
- .join(',');
+ .join(', ');
const msg = `Source code for \`${p}${command}\`:\n`;
diff --git a/lib/commands/cron.ts b/lib/commands/cron.ts
@@ -174,9 +174,10 @@ export class Timer {
this.homescope.message.answer("Ran cron #" + job.id);
- this.homescope.main.process_command(
+ // `on_message` does important expansions.
+ this.homescope.main.on_message(
this.homescope.message,
- true
+ this.homescope.CLIENT
);
}
diff --git a/lib/extensions.ts b/lib/extensions.ts
@@ -1,4 +1,5 @@
import { SimpOMatic } from './main';
+import { Client } from '@typeit/discord';
// Global Extensions:
declare global {
@@ -9,7 +10,7 @@ declare global {
HELP_SECTIONS: string[] , ALL_HELP: string[],
CONFIG: Types.Config, SECRETS: any, KNOWN_COMMANDS: string[],
expand_alias: (operator: string, args: string[], message: Message) => string,
- main: SimpOMatic;
+ CLIENT: Client, main: SimpOMatic;
};
namespace Types {
diff --git a/lib/main.ts b/lib/main.ts
@@ -327,7 +327,8 @@ Would you like to slow down a little?`.squeeze());
HELP_MESSAGES, HELP_SECTIONS, ALL_HELP,
CONFIG, SECRETS, KNOWN_COMMANDS,
expand_alias: this.expand_alias,
- main: this };
+ CLIENT: SimpOMatic._CLIENT, main: this
+ };
const commands = read_dir(`${__dirname}/commands`)
.map(n => n.slice(0, -3));
diff --git a/lib/web.ts b/lib/web.ts
@@ -81,6 +81,15 @@ export default (GLOBAL_CONFIG : Types.GlobalConfig, handle_post) => {
res.write(content);
res.end();
} catch {}
+ } else if (url.endsWith('.css')) {
+ try {
+ const content = read_file(relative);
+ res.writeHead(200, {
+ 'Content-Type': 'text/css'
+ });
+ res.write(content);
+ res.end();
+ } catch {}
}
const favicons = read_file('./web/favicons.html');
diff --git a/web/404.html b/web/404.html
@@ -5,30 +5,8 @@
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>404 — Not Found!</title>
{{FAVICONS}}
- <link href="https://fonts.googleapis.com/css2?family=Baloo+2:wght@800&display=swap" rel="stylesheet">
- <link href="https://fonts.googleapis.com/css2?family=Exo+2:wght@100;300&display=swap" rel="stylesheet">
+ <link href="/main.css" rel="stylesheet">
<style>
- :root {
- --grey: #666472;
- --pink: #ef88c5;
- }
- * {
- vertical-align: middle;
- box-sizing: border-box;
- }
- body, html {
- font-size: 16px;
- font-family: "Baloo 2", cursive;
- padding: 0;
- margin: 0;
- height: 100%;
- }
- body {
- max-width: 100vw;
- min-height: calc(100vh - 3px);
- overflow-y: visible;
- overflow-x: hidden;
- }
#content {
height: 100vh;
display: flex;
diff --git a/web/index.html b/web/index.html
@@ -5,30 +5,8 @@
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Simp'O'Matic — Discord Bot</title>
{{FAVICONS}}
- <link href="https://fonts.googleapis.com/css2?family=Baloo+2:wght@800&display=swap" rel="stylesheet">
- <link href="https://fonts.googleapis.com/css2?family=Exo+2:wght@100;300&display=swap" rel="stylesheet">
+ <link href="/main.css" rel="stylesheet">
<style>
- :root {
- --grey: #666472;
- --pink: #ef88c5;
- }
- * {
- vertical-align: middle;
- box-sizing: border-box;
- }
- body, html {
- font-size: 16px;
- font-family: "Baloo 2", cursive;
- padding: 0;
- margin: 0;
- height: 100%;
- }
- body {
- max-width: 100vw;
- min-height: calc(100vh - 3px);
- overflow-y: visible;
- overflow-x: hidden;
- }
#content {
height: 100vh;
display: flex;
@@ -51,7 +29,6 @@
}
.center p {
letter-spacing: -1px;
- font-weight: bold;
width: 16em;
display: inline-block;
margin: 0;
@@ -76,15 +53,9 @@
border-radius: 3px;
background: var(--pink);
}
- .grey {
- color: var(--grey);
- }
- .pink {
- color: var(--pink);
- }
.simp {
font-family: "Baloo 2";
- font-weight: 300
+ font-weight: 800;
}
.matic, .o {
font-family: "Exo 2";
diff --git a/web/main.css b/web/main.css
@@ -0,0 +1,39 @@
+@import url('https://fonts.googleapis.com/css2?family=Baloo+2:wght@500;800&family=Exo+2:wght@100;300&display=swap');
+
+:root {
+ --grey: #666472;
+ --pink: #ef88c5;
+}
+
+::selection {
+ background-color: var(--pink);
+ color: white;
+}
+
+* {
+ vertical-align: middle;
+ box-sizing: border-box;
+}
+
+body, html {
+ font-size: 16px;
+ font-family: "Baloo 2", cursive;
+ font-weight: 500;
+ padding: 0;
+ margin: 0;
+ height: 100%;
+}
+
+body {
+ max-width: 100vw;
+ min-height: calc(100vh - 3px);
+ overflow-y: visible;
+ overflow-x: hidden;
+}
+
+.grey {
+ color: var(--grey);
+}
+.pink {
+ color: var(--pink);
+}