T1ckbase commited on
Commit
b1c7ce8
·
1 Parent(s): 5bd50b7
Files changed (3) hide show
  1. deno.json +2 -1
  2. discord.ts +28 -0
  3. main.ts +9 -1
deno.json CHANGED
@@ -13,7 +13,8 @@
13
  "@std/path": "jsr:@std/path",
14
  "@std/fs": "jsr:@std/fs",
15
  "ai": "npm:ai@^4.2.8",
16
- "dedent": "npm:dedent@^1.5.3"
 
17
  },
18
  "lock": false,
19
  "fmt": {
 
13
  "@std/path": "jsr:@std/path",
14
  "@std/fs": "jsr:@std/fs",
15
  "ai": "npm:ai@^4.2.8",
16
+ "dedent": "npm:dedent@^1.5.3",
17
+ "discord-api-types": "npm:discord-api-types@^0.37.119"
18
  },
19
  "lock": false,
20
  "fmt": {
discord.ts ADDED
@@ -0,0 +1,28 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import { RESTPostAPIWebhookWithTokenJSONBody } from 'discord-api-types/v10';
2
+
3
+ export async function executeWebhook(webhookUrl: string, imageBlob: Blob, filename: string = 'image.jpg') {
4
+ const formData = new FormData();
5
+
6
+ const payload: RESTPostAPIWebhookWithTokenJSONBody = {
7
+ avatar_url: 'https://upload.wikimedia.org/wikipedia/commons/thumb/f/f0/Facebook_AI_slop%2C_%22Shrimp_Jesus%22_2.jpg/1024px-Facebook_AI_slop%2C_%22Shrimp_Jesus%22_2.jpg',
8
+ username: '𒐫',
9
+ attachments: [
10
+ {
11
+ id: 0,
12
+ description: 'ai slop',
13
+ filename,
14
+ },
15
+ ],
16
+ };
17
+
18
+ formData.append('payload_json', JSON.stringify(payload));
19
+
20
+ formData.append('files[0]', imageBlob, filename);
21
+
22
+ const response = await fetch(webhookUrl, {
23
+ method: 'post',
24
+ body: formData,
25
+ });
26
+
27
+ return response;
28
+ }
main.ts CHANGED
@@ -5,11 +5,13 @@ import { randomIntegerBetween } from '@std/random';
5
  import * as hub from '@huggingface/hub';
6
  import { generateImage } from './ai.ts';
7
  import { getDirectoryStructureString, getFilesInDirectory, randomString } from './utils.ts';
 
8
 
9
  const HUGGINGFACE_ACCESS_TOKEN = Deno.env.get('HUGGINGFACE_ACCESS_TOKEN')!;
10
  assertExists(HUGGINGFACE_ACCESS_TOKEN);
11
  const REPO_ID = Deno.env.get('REPO_ID')!;
12
  assertExists(REPO_ID);
 
13
 
14
  ensureDirSync('./images');
15
 
@@ -47,7 +49,13 @@ async function main() {
47
  num_inference_steps: 4,
48
  },
49
  });
50
- Deno.writeFileSync(`./images/${Date.now()}.jpg`, new Uint8Array(imgArrayBuffer), { create: true });
 
 
 
 
 
 
51
  }
52
 
53
  while (true) {
 
5
  import * as hub from '@huggingface/hub';
6
  import { generateImage } from './ai.ts';
7
  import { getDirectoryStructureString, getFilesInDirectory, randomString } from './utils.ts';
8
+ import { executeWebhook } from './discord.ts';
9
 
10
  const HUGGINGFACE_ACCESS_TOKEN = Deno.env.get('HUGGINGFACE_ACCESS_TOKEN')!;
11
  assertExists(HUGGINGFACE_ACCESS_TOKEN);
12
  const REPO_ID = Deno.env.get('REPO_ID')!;
13
  assertExists(REPO_ID);
14
+ const WEBHOOK_URL = Deno.env.get('WEBHOOK_URL');
15
 
16
  ensureDirSync('./images');
17
 
 
49
  num_inference_steps: 4,
50
  },
51
  });
52
+ const now = Date.now();
53
+ Deno.writeFileSync(`./images/${now}.jpg`, new Uint8Array(imgArrayBuffer), { create: true });
54
+ try {
55
+ WEBHOOK_URL && await executeWebhook(WEBHOOK_URL, new Blob([imgArrayBuffer]), `${now}.jpg`);
56
+ } catch (e) {
57
+ console.error(e);
58
+ }
59
  }
60
 
61
  while (true) {