-
Notifications
You must be signed in to change notification settings - Fork 3
/
drama.json
144 lines (144 loc) · 4.61 KB
/
drama.json
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
{
"name": "drama.funnyguilds.net",
"nodes": [
{
"parameters": {},
"name": "Start",
"type": "n8n-nodes-base.start",
"typeVersion": 1,
"position": [
-760,
160
]
},
{
"parameters": {
"triggerTimes": {
"item": [
{
"hour": 0
}
]
}
},
"name": "Cron",
"type": "n8n-nodes-base.cron",
"typeVersion": 1,
"position": [
-760,
320
]
},
{
"parameters": {
"url": "https://raw.githubusercontent.com/FunnyGuilds/FunnyDrama/master/data/elements.json",
"options": {}
},
"name": "Fetch elements.json",
"type": "n8n-nodes-base.httpRequest",
"typeVersion": 1,
"position": [
-560,
240
]
},
{
"parameters": {
"url": "https://raw.githubusercontent.com/FunnyGuilds/FunnyDrama/master/data/sentences.json",
"options": {}
},
"name": "Fetch sentences.json",
"type": "n8n-nodes-base.httpRequest",
"typeVersion": 1,
"position": [
-360,
240
]
},
{
"parameters": {
"functionCode": "// noinspection PointlessBitwiseExpressionJS\n\nconst sentences = $(\"Fetch sentences.json\").first().json;\nconst elements = $(\"Fetch elements.json\").first().json;\nconst fieldPattern = /\\[(?<name>[a-zA-Z0-9_]+)\\]/;\n\nconst alreadyUsed = [];\nlet sentence = sentences[Math.random() * sentences.length | 0];\nlet matcher;\n\nwhile ((matcher = fieldPattern.exec(sentence)) !== null) {\n\n const fieldFull = matcher[0];\n const fieldType = matcher[1];\n\n if (!(fieldType in elements)) {\n return {sentence: `Unknown element type: ${fieldType}`}\n }\n\n let randomValue;\n do {\n randomValue = elements[fieldType][Math.random() * elements[fieldType].length | 0];\n }\n while (randomValue in alreadyUsed);\n\n alreadyUsed.push(randomValue);\n sentence = sentence.replace(fieldFull, randomValue);\n}\n\nreturn {sentence};"
},
"name": "Generate drama",
"type": "n8n-nodes-base.function",
"typeVersion": 1,
"position": [
-160,
240
]
},
{
"parameters": {
"webhookUri": "WEBHOOK_URL",
"text": "=",
"options": {
"embeds": "=[{\n\t\"title\": \"Latest Drama News\",\n\t\"description\": {{JSON.stringify($('Generate drama').first().json['sentence'])}},\n\t\"color\": 16723502\n}]"
}
},
"name": "Dispatch webhook",
"type": "n8n-nodes-base.discord",
"typeVersion": 1,
"position": [
40,
240
]
}
],
"connections": {
"Start": {
"main": [
[
{
"node": "Fetch elements.json",
"type": "main",
"index": 0
}
]
]
},
"Cron": {
"main": [
[
{
"node": "Fetch elements.json",
"type": "main",
"index": 0
}
]
]
},
"Fetch elements.json": {
"main": [
[
{
"node": "Fetch sentences.json",
"type": "main",
"index": 0
}
]
]
},
"Fetch sentences.json": {
"main": [
[
{
"node": "Generate drama",
"type": "main",
"index": 0
}
]
]
},
"Generate drama": {
"main": [
[
{
"node": "Dispatch webhook",
"type": "main",
"index": 0
}
]
]
}
}
}