forked from cory/tildefriends
179 lines
4.4 KiB
JavaScript
179 lines
4.4 KiB
JavaScript
|
"use strict";
|
||
|
|
||
|
//! {"require": ["smtp"], "permissions": ["network"]}
|
||
|
|
||
|
let administrator = core.user.name == core.user.packageOwner;
|
||
|
|
||
|
function lameHash(value) {
|
||
|
let result = 12945;
|
||
|
for (let i = 0; i < value.length; i++) {
|
||
|
result += value.charCodeAt(i);
|
||
|
result *= 31;
|
||
|
result &= 0x7fffffff;
|
||
|
}
|
||
|
return result;
|
||
|
}
|
||
|
|
||
|
terminal.setEcho(false);
|
||
|
if (administrator) {
|
||
|
terminal.print({style: "font-size: x-large", value: "Edit", command: "command:" + JSON.stringify("command")});
|
||
|
}
|
||
|
|
||
|
let gInvite = null;
|
||
|
|
||
|
function display() {
|
||
|
return database.get("invite").then(function(data) {
|
||
|
if (data) {
|
||
|
let invite = JSON.parse(data);
|
||
|
let promises = [];
|
||
|
for (let i in invite.emails) {
|
||
|
promises.push(database.get("rsvp." + lameHash(invite.emails[i])));
|
||
|
}
|
||
|
return Promise.all(promises).then(function(rsvps) {
|
||
|
for (let i in rsvps) {
|
||
|
if (rsvps[i]) {
|
||
|
rsvps[i] = JSON.parse(rsvps[i]);
|
||
|
}
|
||
|
}
|
||
|
terminal.print({style: "font-size: xx-large", value: invite.title});
|
||
|
terminal.print(invite.message);
|
||
|
for (let i in invite.food) {
|
||
|
let line = [invite.food[i], "?", " ", "+", " ", "-"];
|
||
|
// hi
|
||
|
terminal.print({style: "font-size: x-large", value: line});
|
||
|
}
|
||
|
gInvite = invite;
|
||
|
});
|
||
|
}
|
||
|
}).catch(function(error) {
|
||
|
terminal.print(error);
|
||
|
});
|
||
|
}
|
||
|
|
||
|
core.register("hashChange", function(event) {
|
||
|
let hash = event.hash;
|
||
|
if (hash && hash.charAt(0) == '#') {
|
||
|
hash = hash.substring(1);
|
||
|
}
|
||
|
if (hash) {
|
||
|
let invite = gInvite || {};
|
||
|
for (let i in invite.emails) {
|
||
|
let email = invite.emails[i];
|
||
|
if (lameHash(email).toString() == hash) {
|
||
|
terminal.print("hash match!", email);
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
})
|
||
|
|
||
|
core.register("submit", function(event) {
|
||
|
let invite = event.value;
|
||
|
invite.emails = invite.emails.split(",");
|
||
|
invite.food = invite.food.split(",");
|
||
|
for (let i in invite.emails) {
|
||
|
let url = "https://www.tildefriends.net/~cory/invite2#" + lameHash(invite.emails[i]).toString();
|
||
|
terminal.print({href: url});
|
||
|
}
|
||
|
database.set("invite", JSON.stringify(invite));
|
||
|
});
|
||
|
|
||
|
display();
|
||
|
|
||
|
core.register("onInput", function(input) {
|
||
|
if (input.substring(0, "command:".length) == "command:") {
|
||
|
command = JSON.parse(input.substring("command:".length));
|
||
|
if (command == "create") {
|
||
|
let invite = gInvite || {};
|
||
|
terminal.print("Title:", {input: "text", name: "title", style: "width: 512px", value: invite.title});
|
||
|
terminal.print("Message:", {input: "text", name: "message", style: "width: 512px", value: invite.message});
|
||
|
terminal.print("Email Addresses:", {input: "text", name: "emails", style: "width: 512px", value: invite.emails.join(",")});
|
||
|
terminal.print("Food:", {input: "text", name: "food", style: "width: 512px", value: invite.food.join(",")});
|
||
|
terminal.print({input: "submit", name: "Create", value: "Create"});
|
||
|
}
|
||
|
}
|
||
|
});
|
||
|
|
||
|
/*
|
||
|
require("smtp").sendMail({
|
||
|
from: core.user.name + "@unprompted.com",
|
||
|
to: "test1@unprompted.com",
|
||
|
subject: input,
|
||
|
body: input,
|
||
|
}).then(function() {
|
||
|
terminal.print("sent");
|
||
|
}).catch(function(error) {
|
||
|
terminal.print("error: ", error);
|
||
|
});
|
||
|
*/
|
||
|
|
||
|
let kEmojis = [
|
||
|
"🍇 Grapes",
|
||
|
"🍈 Melon",
|
||
|
"🍉 Watermelon",
|
||
|
"🍊 Tangerine",
|
||
|
"🍋 Lemon",
|
||
|
"🍌 Banana",
|
||
|
"🍍 Pineapple",
|
||
|
"🍎 Red Apple",
|
||
|
"🍏 Green Apple",
|
||
|
"🍐 Pear",
|
||
|
"🍑 Peach",
|
||
|
"🍒 Cherries",
|
||
|
"🍓 Strawberry",
|
||
|
"🍅 Tomato",
|
||
|
"🍆 Aubergine",
|
||
|
"🌽 Ear of Maize",
|
||
|
"🌶 Hot Pepper",
|
||
|
"🍄 Mushroom",
|
||
|
"🌰 Chestnut",
|
||
|
"🍞 Bread",
|
||
|
"🧀 Cheese Wedge",
|
||
|
"🍖 Meat on Bone",
|
||
|
"🍗 Poultry Leg",
|
||
|
"🍔 Hamburger",
|
||
|
"🍟 French Fries",
|
||
|
"🍕 Slice of Pizza",
|
||
|
"🌭 Hot Dog",
|
||
|
"🌮 Taco",
|
||
|
"🌯 Burrito",
|
||
|
"🍳 Cooking",
|
||
|
"🍲 Pot of Food",
|
||
|
"🍿 Popcorn",
|
||
|
"🍱 Bento Box",
|
||
|
"🍘 Rice Cracker",
|
||
|
"🍙 Rice Ball",
|
||
|
"🍚 Cooked Rice",
|
||
|
"🍛 Curry and Rice",
|
||
|
"🍜 Steaming Bowl",
|
||
|
"🍝 Spaghetti",
|
||
|
"🍠 Roasted Sweet Potato",
|
||
|
"🍢 Oden",
|
||
|
"🍣 Sushi",
|
||
|
"🍤 Fried Shrimp",
|
||
|
"🍥 Fish Cake With Swirl Design",
|
||
|
"🍡 Dango",
|
||
|
"🍦 Soft Ice Cream",
|
||
|
"🍧 Shaved Ice",
|
||
|
"🍨 Ice Cream",
|
||
|
"🍩 Doughnut",
|
||
|
"🍪 Cookie",
|
||
|
"🎂 Birthday Cake",
|
||
|
"🍰 Shortcake",
|
||
|
"🍫 Chocolate Bar",
|
||
|
"🍬 Candy",
|
||
|
"🍭 Lollipop",
|
||
|
"🍮 Custard",
|
||
|
"🍯 Honey Pot",
|
||
|
"🍼 Baby Bottle",
|
||
|
"☕ Hot Beverage",
|
||
|
"🍵 Teacup Without Handle",
|
||
|
"🍶 Sake Bottle and Cup",
|
||
|
"🍾 Bottle With Popping Cork",
|
||
|
"🍷 Wine Glass",
|
||
|
"🍸 Cocktail Glass",
|
||
|
"🍹 Tropical Drink",
|
||
|
"🍺 Beer Mug",
|
||
|
"🍻 Clinking Beer Mugs",
|
||
|
"🍽 Fork and Knife With Plate",
|
||
|
"🍴 Fork and Knife",
|
||
|
];
|