Merged
1 change: 1 addition & 0 deletions connectors/slack/package.json
Original file line numberDiff line numberDiff line change
Expand Up@@ -23,6 +23,7 @@
"scripts": {
"build": "tsc",
"clean": "rm -rf dist",
"gen-emoji-map": "tsx scripts/gen-emoji-map.ts",
"deploy": "plot deploy",
"lint": "plot lint",
"test": "vitest run",
Expand Down
112 changes: 112 additions & 0 deletions connectors/slack/scripts/gen-emoji-map.ts
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
/**
* Generates src/slack-emoji-map.g.ts from iamcal/emoji-data — the dataset
* Slack itself ships, so `short_name` values are exactly Slack reaction names.
*
* Regenerate: pnpm --filter @plotday/connector-slack gen-emoji-map
* Pin: bump EMOJI_DATA_REF to the latest tag listed at
* https://github.com/iamcal/emoji-data/tags
*/
import { writeFileSync } from "node:fs";
import { dirname, join } from "node:path";
import { fileURLToPath } from "node:url";

// Verify/bump against https://github.com/iamcal/emoji-data/tags
const EMOJI_DATA_REF = "v15.1.2";
const SOURCE_URL = `https://raw.githubusercontent.com/iamcal/emoji-data/${EMOJI_DATA_REF}/emoji.json`;

// iamcal skin_variation key (modifier codepoint) -> Slack ::skin-tone-N suffix.
const SKIN_TONE_BY_MODIFIER: Record<string, number> = {
"1F3FB": 2,
"1F3FC": 3,
"1F3FD": 4,
"1F3FE": 5,
"1F3FF": 6,
};

type EmojiDatum = {
unified: string;
short_name: string;
short_names: string[];
skin_variations?: Record<string, { unified: string }>;
};

function unifiedToChar(unified: string): string {
return String.fromCodePoint(
...unified.split("-").map((h) => Number.parseInt(h, 16))
);
}

async function main(): Promise<void> {
const res = await fetch(SOURCE_URL);
if (!res.ok) throw new Error(`fetch ${SOURCE_URL} -> ${res.status}`);
const data = (await res.json()) as EmojiDatum[];

const shortcodeToUnicode: Record<string, string> = {};
const unicodeToShortcode: Record<string, string> = {};
const addForward = (name: string, char: string) => {
if (!(name in shortcodeToUnicode)) shortcodeToUnicode[name] = char;
};
const addReverse = (char: string, name: string) => {
if (!(char in unicodeToShortcode)) unicodeToShortcode[char] = name;
};

for (const e of data) {
const baseChar = unifiedToChar(e.unified);
const names = e.short_names?.length ? e.short_names : [e.short_name];
for (const n of names) addForward(n, baseChar);
addReverse(baseChar, e.short_name);

for (const [modKey, variation] of Object.entries(e.skin_variations ?? {})) {
const tone = SKIN_TONE_BY_MODIFIER[modKey];
if (!tone) continue; // skip multi-tone compound keys like "1F3FB-1F3FF"
const toneChar = unifiedToChar(variation.unified);
for (const n of names) addForward(`${n}::skin-tone-${tone}`, toneChar);
addReverse(toneChar, `${e.short_name}::skin-tone-${tone}`);
}
}

const sortedJson = (m: Record<string, string>) =>
JSON.stringify(
Object.fromEntries(
Object.entries(m).sort(([a], [b]) => (a < b ? -1 : a > b ? 1 : 0))
),
null,
2
);

const header =
`// GENERATED FILE — do not edit by hand.\n` +
`// Source: iamcal/emoji-data ${EMOJI_DATA_REF} (${SOURCE_URL})\n` +
`// Regenerate via: pnpm --filter @plotday/connector-slack gen-emoji-map\n` +
`//\n` +
`// This file lives in src/ intentionally — it is imported at runtime and compiled by tsc.\n` +
`//\n` +
`// SLACK_SHORTCODE_TO_UNICODE: Slack reaction name (incl. ::skin-tone-N) -> grapheme.\n` +
`// SLACK_UNICODE_TO_SHORTCODE: grapheme -> preferred Slack reaction name (first short_name wins).\n`;

const body =
header +
`\nexport const SLACK_SHORTCODE_TO_UNICODE: Record<string, string> = ${sortedJson(
shortcodeToUnicode
)};\n\n` +
`export const SLACK_UNICODE_TO_SHORTCODE: Record<string, string> = ${sortedJson(
unicodeToShortcode
)};\n`;

const outPath = join(
dirname(fileURLToPath(import.meta.url)),
"..",
"src",
"slack-emoji-map.g.ts"
);
writeFileSync(outPath, body, "utf8");
console.log(
`Wrote ${outPath}: ${Object.keys(shortcodeToUnicode).length} names, ` +
`${Object.keys(unicodeToShortcode).length} graphemes`
);
}

main().catch((err) => {
console.error(err);
process.exit(1);
});
79 changes: 2 additions & 77 deletions connectors/slack/src/slack-api.ts
Original file line numberDiff line numberDiff line change
Expand Up@@ -5,6 +5,7 @@ import type {
NewActor,
NewReactions,
} from "@plotday/twister/plot";
import { slackNameToUnicode } from "./slack-emoji";

export type SlackChannel = {
id: string;
Expand DownExpand Up@@ -574,70 +575,6 @@ export function formatSlackText(text: string): string {
);
}

/**
* Maps common Slack reaction shortcodes to Unicode emoji. Curated subset
* of the CLDR mapping covering the long-tail of frequently-used reactions.
* Unmapped shortcodes (incl. workspace custom emoji) are skipped on
* sync for v1; a follow-up will route them via the custom_emoji image
* cache as `slack:<teamId>/<name>` refs.
*/
export const SLACK_SHORTCODE_TO_UNICODE: Record<string, string> = {
"+1": "👍", thumbsup: "👍",
"-1": "👎", thumbsdown: "👎",
tada: "🎉", party: "🎉",
fire: "🔥",
heart: "❤️", heart_eyes: "😍", heartpulse: "💗",
rocket: "🚀",
sparkles: "✨", star2: "🌟",
pray: "🙏", folded_hands: "🙏",
raised_hands: "🙌",
smile: "😄", grinning: "😀", grin: "😁", smiley: "😃",
joy: "😂", rofl: "🤣", laughing: "😆",
wave: "👋",
clap: "👏",
sunglasses: "😎",
cry: "😢", sob: "😭",
eyes: "👀",
"100": "💯",
star: "⭐",
bulb: "💡", light_bulb: "💡",
ok_hand: "👌",
muscle: "💪",
rolling_on_the_floor_laughing: "🤣",
white_check_mark: "✅", heavy_check_mark: "✔️", check: "✔️",
x: "❌", negative_squared_cross_mark: "❎",
warning: "⚠️",
question: "❓", grey_question: "❔",
exclamation: "❗",
thinking_face: "🤔",
raised_hand: "✋",
raised_back_of_hand: "🤚",
point_up: "☝️", point_down: "👇", point_left: "👈", point_right: "👉",
facepalm: "🤦", person_facepalming: "🤦",
shrug: "🤷", person_shrugging: "🤷",
see_no_evil: "🙈",
speech_balloon: "💬",
bell: "🔔", no_bell: "🔕",
zap: "⚡",
bug: "🐛",
hammer: "🔨", hammer_and_wrench: "🛠️",
art: "🎨",
lock: "🔒", unlock: "🔓",
key: "🔑",
rotating_light: "🚨",
hourglass: "⌛", hourglass_flowing_sand: "⏳",
alarm_clock: "⏰",
chart_with_upwards_trend: "📈", chart_with_downwards_trend: "📉",
bar_chart: "📊",
bookmark: "🔖",
pushpin: "📌",
link: "🔗",
package: "📦",
email: "📧", mailbox: "📬",
calendar: "📅",
pencil: "📝", memo: "📝",
};

/**
* Extract per-message Slack reactions as Plot reactions. Unmapped
* shortcodes are skipped; deduplication is by source.accountId so
Expand All@@ -651,7 +588,7 @@ function extractSlackMessageReactions(
const byEmoji = new Map<string, NewActor[]>();

for (const reaction of msg.reactions) {
const unicode = SLACK_SHORTCODE_TO_UNICODE[reaction.name];
const unicode = slackNameToUnicode(reaction.name);
if (!unicode) continue;

const actors = reaction.users.map((userId) =>
Expand All@@ -676,18 +613,6 @@ function extractSlackMessageReactions(
return out;
}

/**
* Reverse mapping for write-back: Unicode → preferred Slack shortcode.
* Built from SLACK_SHORTCODE_TO_UNICODE; first shortcode wins on
* collisions (e.g. `thumbsup` over `+1`).
*/
export const SLACK_UNICODE_TO_SHORTCODE: Record<string, string> = {};
for (const [shortcode, unicode] of Object.entries(SLACK_SHORTCODE_TO_UNICODE)) {
if (!SLACK_UNICODE_TO_SHORTCODE[unicode]) {
SLACK_UNICODE_TO_SHORTCODE[unicode] = shortcode;
}
}

/**
* Transforms a Slack message thread into a NewLinkWithNotes structure.
* The first message snippet becomes the link title, and each message becomes a Note.
Expand Down
Loading
Loading
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Add copy buttons to all
 blocks\n(function() {\n function addCopyButtons() {\n document.querySelectorAll('pre code').forEach(function(codeBlock) {\n if (codeBlock.parentElement.hasAttribute('data-copy-added')) return;\n codeBlock.parentElement.setAttribute('data-copy-added', 'true');\n \n var btn = document.createElement('button');\n btn.textContent = 'Copy';\n btn.style.cssText = 'position:absolute;top:4px;right:4px;padding:2px 8px;font-size:11px;background:#4ecdc4;border:none;border-radius:4px;color:#1a1a2e;cursor:pointer;opacity:0.7;transition:opacity 0.2s;';\n btn.onmouseover = function() { this.style.opacity = '1'; };\n btn.onmouseout = function() { this.style.opacity = '0.7'; };\n btn.onclick = function() {\n navigator.clipboard.writeText(codeBlock.textContent).then(function() {\n btn.textContent = 'Copied!';\n setTimeout(function() { btn.textContent = 'Copy'; }, 1500);\n });\n };\n codeBlock.parentElement.style.position = 'relative';\n codeBlock.parentElement.appendChild(btn);\n });\n }\n \n addCopyButtons();\n \n // Re-run on dynamic content\n var observer = new MutationObserver(addCopyButtons);\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "Add Copy Buttons to Code Blocks");
}
} catch(__e) { console.warn('[Userscript:Add Copy Buttons to Code Blocks]', __e); }
})();
(function(){
try {
var __m = "github.com";
var __re = new RegExp('^' + "github\\.com" + '
Skip to content
Merged
1 change: 1 addition & 0 deletions connectors/slack/package.json
Original file line numberDiff line numberDiff line change
Expand Up@@ -23,6 +23,7 @@
"scripts": {
"build": "tsc",
"clean": "rm -rf dist",
"gen-emoji-map": "tsx scripts/gen-emoji-map.ts",
"deploy": "plot deploy",
"lint": "plot lint",
"test": "vitest run",
Expand Down
112 changes: 112 additions & 0 deletions connectors/slack/scripts/gen-emoji-map.ts
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
/**
* Generates src/slack-emoji-map.g.ts from iamcal/emoji-data — the dataset
* Slack itself ships, so `short_name` values are exactly Slack reaction names.
*
* Regenerate: pnpm --filter @plotday/connector-slack gen-emoji-map
* Pin: bump EMOJI_DATA_REF to the latest tag listed at
* https://github.com/iamcal/emoji-data/tags
*/
import { writeFileSync } from "node:fs";
import { dirname, join } from "node:path";
import { fileURLToPath } from "node:url";

// Verify/bump against https://github.com/iamcal/emoji-data/tags
const EMOJI_DATA_REF = "v15.1.2";
const SOURCE_URL = `https://raw.githubusercontent.com/iamcal/emoji-data/${EMOJI_DATA_REF}/emoji.json`;

// iamcal skin_variation key (modifier codepoint) -> Slack ::skin-tone-N suffix.
const SKIN_TONE_BY_MODIFIER: Record<string, number> = {
"1F3FB": 2,
"1F3FC": 3,
"1F3FD": 4,
"1F3FE": 5,
"1F3FF": 6,
};

type EmojiDatum = {
unified: string;
short_name: string;
short_names: string[];
skin_variations?: Record<string, { unified: string }>;
};

function unifiedToChar(unified: string): string {
return String.fromCodePoint(
...unified.split("-").map((h) => Number.parseInt(h, 16))
);
}

async function main(): Promise<void> {
const res = await fetch(SOURCE_URL);
if (!res.ok) throw new Error(`fetch ${SOURCE_URL} -> ${res.status}`);
const data = (await res.json()) as EmojiDatum[];

const shortcodeToUnicode: Record<string, string> = {};
const unicodeToShortcode: Record<string, string> = {};
const addForward = (name: string, char: string) => {
if (!(name in shortcodeToUnicode)) shortcodeToUnicode[name] = char;
};
const addReverse = (char: string, name: string) => {
if (!(char in unicodeToShortcode)) unicodeToShortcode[char] = name;
};

for (const e of data) {
const baseChar = unifiedToChar(e.unified);
const names = e.short_names?.length ? e.short_names : [e.short_name];
for (const n of names) addForward(n, baseChar);
addReverse(baseChar, e.short_name);

for (const [modKey, variation] of Object.entries(e.skin_variations ?? {})) {
const tone = SKIN_TONE_BY_MODIFIER[modKey];
if (!tone) continue; // skip multi-tone compound keys like "1F3FB-1F3FF"
const toneChar = unifiedToChar(variation.unified);
for (const n of names) addForward(`${n}::skin-tone-${tone}`, toneChar);
addReverse(toneChar, `${e.short_name}::skin-tone-${tone}`);
}
}

const sortedJson = (m: Record<string, string>) =>
JSON.stringify(
Object.fromEntries(
Object.entries(m).sort(([a], [b]) => (a < b ? -1 : a > b ? 1 : 0))
),
null,
2
);

const header =
`// GENERATED FILE — do not edit by hand.\n` +
`// Source: iamcal/emoji-data ${EMOJI_DATA_REF} (${SOURCE_URL})\n` +
`// Regenerate via: pnpm --filter @plotday/connector-slack gen-emoji-map\n` +
`//\n` +
`// This file lives in src/ intentionally — it is imported at runtime and compiled by tsc.\n` +
`//\n` +
`// SLACK_SHORTCODE_TO_UNICODE: Slack reaction name (incl. ::skin-tone-N) -> grapheme.\n` +
`// SLACK_UNICODE_TO_SHORTCODE: grapheme -> preferred Slack reaction name (first short_name wins).\n`;

const body =
header +
`\nexport const SLACK_SHORTCODE_TO_UNICODE: Record<string, string> = ${sortedJson(
shortcodeToUnicode
)};\n\n` +
`export const SLACK_UNICODE_TO_SHORTCODE: Record<string, string> = ${sortedJson(
unicodeToShortcode
)};\n`;

const outPath = join(
dirname(fileURLToPath(import.meta.url)),
"..",
"src",
"slack-emoji-map.g.ts"
);
writeFileSync(outPath, body, "utf8");
console.log(
`Wrote ${outPath}: ${Object.keys(shortcodeToUnicode).length} names, ` +
`${Object.keys(unicodeToShortcode).length} graphemes`
);
}

main().catch((err) => {
console.error(err);
process.exit(1);
});
79 changes: 2 additions & 77 deletions connectors/slack/src/slack-api.ts
Original file line numberDiff line numberDiff line change
Expand Up@@ -5,6 +5,7 @@ import type {
NewActor,
NewReactions,
} from "@plotday/twister/plot";
import { slackNameToUnicode } from "./slack-emoji";

export type SlackChannel = {
id: string;
Expand DownExpand Up@@ -574,70 +575,6 @@ export function formatSlackText(text: string): string {
);
}

/**
* Maps common Slack reaction shortcodes to Unicode emoji. Curated subset
* of the CLDR mapping covering the long-tail of frequently-used reactions.
* Unmapped shortcodes (incl. workspace custom emoji) are skipped on
* sync for v1; a follow-up will route them via the custom_emoji image
* cache as `slack:<teamId>/<name>` refs.
*/
export const SLACK_SHORTCODE_TO_UNICODE: Record<string, string> = {
"+1": "👍", thumbsup: "👍",
"-1": "👎", thumbsdown: "👎",
tada: "🎉", party: "🎉",
fire: "🔥",
heart: "❤️", heart_eyes: "😍", heartpulse: "💗",
rocket: "🚀",
sparkles: "✨", star2: "🌟",
pray: "🙏", folded_hands: "🙏",
raised_hands: "🙌",
smile: "😄", grinning: "😀", grin: "😁", smiley: "😃",
joy: "😂", rofl: "🤣", laughing: "😆",
wave: "👋",
clap: "👏",
sunglasses: "😎",
cry: "😢", sob: "😭",
eyes: "👀",
"100": "💯",
star: "⭐",
bulb: "💡", light_bulb: "💡",
ok_hand: "👌",
muscle: "💪",
rolling_on_the_floor_laughing: "🤣",
white_check_mark: "✅", heavy_check_mark: "✔️", check: "✔️",
x: "❌", negative_squared_cross_mark: "❎",
warning: "⚠️",
question: "❓", grey_question: "❔",
exclamation: "❗",
thinking_face: "🤔",
raised_hand: "✋",
raised_back_of_hand: "🤚",
point_up: "☝️", point_down: "👇", point_left: "👈", point_right: "👉",
facepalm: "🤦", person_facepalming: "🤦",
shrug: "🤷", person_shrugging: "🤷",
see_no_evil: "🙈",
speech_balloon: "💬",
bell: "🔔", no_bell: "🔕",
zap: "⚡",
bug: "🐛",
hammer: "🔨", hammer_and_wrench: "🛠️",
art: "🎨",
lock: "🔒", unlock: "🔓",
key: "🔑",
rotating_light: "🚨",
hourglass: "⌛", hourglass_flowing_sand: "⏳",
alarm_clock: "⏰",
chart_with_upwards_trend: "📈", chart_with_downwards_trend: "📉",
bar_chart: "📊",
bookmark: "🔖",
pushpin: "📌",
link: "🔗",
package: "📦",
email: "📧", mailbox: "📬",
calendar: "📅",
pencil: "📝", memo: "📝",
};

/**
* Extract per-message Slack reactions as Plot reactions. Unmapped
* shortcodes are skipped; deduplication is by source.accountId so
Expand All@@ -651,7 +588,7 @@ function extractSlackMessageReactions(
const byEmoji = new Map<string, NewActor[]>();

for (const reaction of msg.reactions) {
const unicode = SLACK_SHORTCODE_TO_UNICODE[reaction.name];
const unicode = slackNameToUnicode(reaction.name);
if (!unicode) continue;

const actors = reaction.users.map((userId) =>
Expand All@@ -676,18 +613,6 @@ function extractSlackMessageReactions(
return out;
}

/**
* Reverse mapping for write-back: Unicode → preferred Slack shortcode.
* Built from SLACK_SHORTCODE_TO_UNICODE; first shortcode wins on
* collisions (e.g. `thumbsup` over `+1`).
*/
export const SLACK_UNICODE_TO_SHORTCODE: Record<string, string> = {};
for (const [shortcode, unicode] of Object.entries(SLACK_SHORTCODE_TO_UNICODE)) {
if (!SLACK_UNICODE_TO_SHORTCODE[unicode]) {
SLACK_UNICODE_TO_SHORTCODE[unicode] = shortcode;
}
}

/**
* Transforms a Slack message thread into a NewLinkWithNotes structure.
* The first message snippet becomes the link title, and each message becomes a Note.
Expand Down
Loading
Loading
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Force GitHub README to respect dark mode\n(function() {\n var style = document.createElement('style');\n style.textContent = '\n .markdown-body {\n color-scheme: dark light;\n }\n .markdown-body pre { background: #161b22 !important; }\n .markdown-body code { background: rgba(110, 118, 129, 0.4) !important; }\n .markdown-body table th, .markdown-body table td { border-color: #30363d !important; }\n .markdown-body img { background: #0d1117; }\n .markdown-body blockquote { border-left-color: #8b949e; }\n .markdown-body hr { border-color: #30363d; }\n ';\n document.head.appendChild(style);\n})();", "GitHub Dark Mode README Fix"); } } catch(__e) { console.warn('[Userscript:GitHub Dark Mode README Fix]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content
Merged
1 change: 1 addition & 0 deletions connectors/slack/package.json
Original file line numberDiff line numberDiff line change
Expand Up@@ -23,6 +23,7 @@
"scripts": {
"build": "tsc",
"clean": "rm -rf dist",
"gen-emoji-map": "tsx scripts/gen-emoji-map.ts",
"deploy": "plot deploy",
"lint": "plot lint",
"test": "vitest run",
Expand Down
112 changes: 112 additions & 0 deletions connectors/slack/scripts/gen-emoji-map.ts
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
/**
* Generates src/slack-emoji-map.g.ts from iamcal/emoji-data — the dataset
* Slack itself ships, so `short_name` values are exactly Slack reaction names.
*
* Regenerate: pnpm --filter @plotday/connector-slack gen-emoji-map
* Pin: bump EMOJI_DATA_REF to the latest tag listed at
* https://github.com/iamcal/emoji-data/tags
*/
import { writeFileSync } from "node:fs";
import { dirname, join } from "node:path";
import { fileURLToPath } from "node:url";

// Verify/bump against https://github.com/iamcal/emoji-data/tags
const EMOJI_DATA_REF = "v15.1.2";
const SOURCE_URL = `https://raw.githubusercontent.com/iamcal/emoji-data/${EMOJI_DATA_REF}/emoji.json`;

// iamcal skin_variation key (modifier codepoint) -> Slack ::skin-tone-N suffix.
const SKIN_TONE_BY_MODIFIER: Record<string, number> = {
"1F3FB": 2,
"1F3FC": 3,
"1F3FD": 4,
"1F3FE": 5,
"1F3FF": 6,
};

type EmojiDatum = {
unified: string;
short_name: string;
short_names: string[];
skin_variations?: Record<string, { unified: string }>;
};

function unifiedToChar(unified: string): string {
return String.fromCodePoint(
...unified.split("-").map((h) => Number.parseInt(h, 16))
);
}

async function main(): Promise<void> {
const res = await fetch(SOURCE_URL);
if (!res.ok) throw new Error(`fetch ${SOURCE_URL} -> ${res.status}`);
const data = (await res.json()) as EmojiDatum[];

const shortcodeToUnicode: Record<string, string> = {};
const unicodeToShortcode: Record<string, string> = {};
const addForward = (name: string, char: string) => {
if (!(name in shortcodeToUnicode)) shortcodeToUnicode[name] = char;
};
const addReverse = (char: string, name: string) => {
if (!(char in unicodeToShortcode)) unicodeToShortcode[char] = name;
};

for (const e of data) {
const baseChar = unifiedToChar(e.unified);
const names = e.short_names?.length ? e.short_names : [e.short_name];
for (const n of names) addForward(n, baseChar);
addReverse(baseChar, e.short_name);

for (const [modKey, variation] of Object.entries(e.skin_variations ?? {})) {
const tone = SKIN_TONE_BY_MODIFIER[modKey];
if (!tone) continue; // skip multi-tone compound keys like "1F3FB-1F3FF"
const toneChar = unifiedToChar(variation.unified);
for (const n of names) addForward(`${n}::skin-tone-${tone}`, toneChar);
addReverse(toneChar, `${e.short_name}::skin-tone-${tone}`);
}
}

const sortedJson = (m: Record<string, string>) =>
JSON.stringify(
Object.fromEntries(
Object.entries(m).sort(([a], [b]) => (a < b ? -1 : a > b ? 1 : 0))
),
null,
2
);

const header =
`// GENERATED FILE — do not edit by hand.\n` +
`// Source: iamcal/emoji-data ${EMOJI_DATA_REF} (${SOURCE_URL})\n` +
`// Regenerate via: pnpm --filter @plotday/connector-slack gen-emoji-map\n` +
`//\n` +
`// This file lives in src/ intentionally — it is imported at runtime and compiled by tsc.\n` +
`//\n` +
`// SLACK_SHORTCODE_TO_UNICODE: Slack reaction name (incl. ::skin-tone-N) -> grapheme.\n` +
`// SLACK_UNICODE_TO_SHORTCODE: grapheme -> preferred Slack reaction name (first short_name wins).\n`;

const body =
header +
`\nexport const SLACK_SHORTCODE_TO_UNICODE: Record<string, string> = ${sortedJson(
shortcodeToUnicode
)};\n\n` +
`export const SLACK_UNICODE_TO_SHORTCODE: Record<string, string> = ${sortedJson(
unicodeToShortcode
)};\n`;

const outPath = join(
dirname(fileURLToPath(import.meta.url)),
"..",
"src",
"slack-emoji-map.g.ts"
);
writeFileSync(outPath, body, "utf8");
console.log(
`Wrote ${outPath}: ${Object.keys(shortcodeToUnicode).length} names, ` +
`${Object.keys(unicodeToShortcode).length} graphemes`
);
}

main().catch((err) => {
console.error(err);
process.exit(1);
});
79 changes: 2 additions & 77 deletions connectors/slack/src/slack-api.ts
Original file line numberDiff line numberDiff line change
Expand Up@@ -5,6 +5,7 @@ import type {
NewActor,
NewReactions,
} from "@plotday/twister/plot";
import { slackNameToUnicode } from "./slack-emoji";

export type SlackChannel = {
id: string;
Expand DownExpand Up@@ -574,70 +575,6 @@ export function formatSlackText(text: string): string {
);
}

/**
* Maps common Slack reaction shortcodes to Unicode emoji. Curated subset
* of the CLDR mapping covering the long-tail of frequently-used reactions.
* Unmapped shortcodes (incl. workspace custom emoji) are skipped on
* sync for v1; a follow-up will route them via the custom_emoji image
* cache as `slack:<teamId>/<name>` refs.
*/
export const SLACK_SHORTCODE_TO_UNICODE: Record<string, string> = {
"+1": "👍", thumbsup: "👍",
"-1": "👎", thumbsdown: "👎",
tada: "🎉", party: "🎉",
fire: "🔥",
heart: "❤️", heart_eyes: "😍", heartpulse: "💗",
rocket: "🚀",
sparkles: "✨", star2: "🌟",
pray: "🙏", folded_hands: "🙏",
raised_hands: "🙌",
smile: "😄", grinning: "😀", grin: "😁", smiley: "😃",
joy: "😂", rofl: "🤣", laughing: "😆",
wave: "👋",
clap: "👏",
sunglasses: "😎",
cry: "😢", sob: "😭",
eyes: "👀",
"100": "💯",
star: "⭐",
bulb: "💡", light_bulb: "💡",
ok_hand: "👌",
muscle: "💪",
rolling_on_the_floor_laughing: "🤣",
white_check_mark: "✅", heavy_check_mark: "✔️", check: "✔️",
x: "❌", negative_squared_cross_mark: "❎",
warning: "⚠️",
question: "❓", grey_question: "❔",
exclamation: "❗",
thinking_face: "🤔",
raised_hand: "✋",
raised_back_of_hand: "🤚",
point_up: "☝️", point_down: "👇", point_left: "👈", point_right: "👉",
facepalm: "🤦", person_facepalming: "🤦",
shrug: "🤷", person_shrugging: "🤷",
see_no_evil: "🙈",
speech_balloon: "💬",
bell: "🔔", no_bell: "🔕",
zap: "⚡",
bug: "🐛",
hammer: "🔨", hammer_and_wrench: "🛠️",
art: "🎨",
lock: "🔒", unlock: "🔓",
key: "🔑",
rotating_light: "🚨",
hourglass: "⌛", hourglass_flowing_sand: "⏳",
alarm_clock: "⏰",
chart_with_upwards_trend: "📈", chart_with_downwards_trend: "📉",
bar_chart: "📊",
bookmark: "🔖",
pushpin: "📌",
link: "🔗",
package: "📦",
email: "📧", mailbox: "📬",
calendar: "📅",
pencil: "📝", memo: "📝",
};

/**
* Extract per-message Slack reactions as Plot reactions. Unmapped
* shortcodes are skipped; deduplication is by source.accountId so
Expand All@@ -651,7 +588,7 @@ function extractSlackMessageReactions(
const byEmoji = new Map<string, NewActor[]>();

for (const reaction of msg.reactions) {
const unicode = SLACK_SHORTCODE_TO_UNICODE[reaction.name];
const unicode = slackNameToUnicode(reaction.name);
if (!unicode) continue;

const actors = reaction.users.map((userId) =>
Expand All@@ -676,18 +613,6 @@ function extractSlackMessageReactions(
return out;
}

/**
* Reverse mapping for write-back: Unicode → preferred Slack shortcode.
* Built from SLACK_SHORTCODE_TO_UNICODE; first shortcode wins on
* collisions (e.g. `thumbsup` over `+1`).
*/
export const SLACK_UNICODE_TO_SHORTCODE: Record<string, string> = {};
for (const [shortcode, unicode] of Object.entries(SLACK_SHORTCODE_TO_UNICODE)) {
if (!SLACK_UNICODE_TO_SHORTCODE[unicode]) {
SLACK_UNICODE_TO_SHORTCODE[unicode] = shortcode;
}
}

/**
* Transforms a Slack message thread into a NewLinkWithNotes structure.
* The first message snippet becomes the link title, and each message becomes a Note.
Expand Down
Loading
Loading
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Highlight search terms from Google/DuckDuckGo/Bing referrer\n(function() {\n var ref = document.referrer;\n var terms = [];\n \n if (ref.includes('google.com') || ref.includes('duckduckgo.com') || ref.includes('bing.com')) {\n var url = new URL(ref);\n var q = url.searchParams.get('q') || url.searchParams.get('p');\n if (q) {\n terms = q.split(/\\s+/).filter(function(t) { return t.length > 2; });\n }\n }\n \n if (terms.length === 0) return;\n \n var style = document.createElement('style');\n style.textContent = '.userscript-highlight { background: #fbbf24; color: #1a1a2e; padding: 1px 3px; border-radius: 2px; }';\n document.head.appendChild(style);\n \n function highlight(node) {\n if (node.nodeType === 3) { // text node\n var text = node.textContent;\n var found = false;\n terms.forEach(function(term) {\n var regex = new RegExp('(' + term.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\') + ')', 'gi');\n if (regex.test(text)) {\n found = true;\n var frag = document.createDocumentFragment();\n var parts = text.split(regex);\n parts.forEach(function(part, i) {\n if (i % 2 === 0) {\n frag.appendChild(document.createTextNode(part));\n } else {\n var span = document.createElement('span');\n span.className = 'userscript-highlight';\n span.textContent = part;\n frag.appendChild(span);\n }\n });\n node.parentNode.replaceChild(frag, node);\n }\n });\n } else if (node.nodeType === 1 && node.childNodes) { // element\n var skipTags = ['SCRIPT', 'STYLE', 'NOSCRIPT', 'TEXTAREA', 'INPUT', 'SELECT'];\n if (!skipTags.includes(node.tagName)) {\n Array.from(node.childNodes).forEach(highlight);\n }\n }\n }\n \n highlight(document.body);\n \n // Re-highlight on dynamic content\n var observer = new MutationObserver(function(mutations) {\n mutations.forEach(function(m) {\n m.addedNodes.forEach(function(node) {\n if (node.nodeType === 1 || node.nodeType === 3) highlight(node);\n });\n });\n });\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "Highlight Search Terms"); } } catch(__e) { console.warn('[Userscript:Highlight Search Terms]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content
Merged
1 change: 1 addition & 0 deletions connectors/slack/package.json
Original file line numberDiff line numberDiff line change
Expand Up@@ -23,6 +23,7 @@
"scripts": {
"build": "tsc",
"clean": "rm -rf dist",
"gen-emoji-map": "tsx scripts/gen-emoji-map.ts",
"deploy": "plot deploy",
"lint": "plot lint",
"test": "vitest run",
Expand Down
112 changes: 112 additions & 0 deletions connectors/slack/scripts/gen-emoji-map.ts
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
/**
* Generates src/slack-emoji-map.g.ts from iamcal/emoji-data — the dataset
* Slack itself ships, so `short_name` values are exactly Slack reaction names.
*
* Regenerate: pnpm --filter @plotday/connector-slack gen-emoji-map
* Pin: bump EMOJI_DATA_REF to the latest tag listed at
* https://github.com/iamcal/emoji-data/tags
*/
import { writeFileSync } from "node:fs";
import { dirname, join } from "node:path";
import { fileURLToPath } from "node:url";

// Verify/bump against https://github.com/iamcal/emoji-data/tags
const EMOJI_DATA_REF = "v15.1.2";
const SOURCE_URL = `https://raw.githubusercontent.com/iamcal/emoji-data/${EMOJI_DATA_REF}/emoji.json`;

// iamcal skin_variation key (modifier codepoint) -> Slack ::skin-tone-N suffix.
const SKIN_TONE_BY_MODIFIER: Record<string, number> = {
"1F3FB": 2,
"1F3FC": 3,
"1F3FD": 4,
"1F3FE": 5,
"1F3FF": 6,
};

type EmojiDatum = {
unified: string;
short_name: string;
short_names: string[];
skin_variations?: Record<string, { unified: string }>;
};

function unifiedToChar(unified: string): string {
return String.fromCodePoint(
...unified.split("-").map((h) => Number.parseInt(h, 16))
);
}

async function main(): Promise<void> {
const res = await fetch(SOURCE_URL);
if (!res.ok) throw new Error(`fetch ${SOURCE_URL} -> ${res.status}`);
const data = (await res.json()) as EmojiDatum[];

const shortcodeToUnicode: Record<string, string> = {};
const unicodeToShortcode: Record<string, string> = {};
const addForward = (name: string, char: string) => {
if (!(name in shortcodeToUnicode)) shortcodeToUnicode[name] = char;
};
const addReverse = (char: string, name: string) => {
if (!(char in unicodeToShortcode)) unicodeToShortcode[char] = name;
};

for (const e of data) {
const baseChar = unifiedToChar(e.unified);
const names = e.short_names?.length ? e.short_names : [e.short_name];
for (const n of names) addForward(n, baseChar);
addReverse(baseChar, e.short_name);

for (const [modKey, variation] of Object.entries(e.skin_variations ?? {})) {
const tone = SKIN_TONE_BY_MODIFIER[modKey];
if (!tone) continue; // skip multi-tone compound keys like "1F3FB-1F3FF"
const toneChar = unifiedToChar(variation.unified);
for (const n of names) addForward(`${n}::skin-tone-${tone}`, toneChar);
addReverse(toneChar, `${e.short_name}::skin-tone-${tone}`);
}
}

const sortedJson = (m: Record<string, string>) =>
JSON.stringify(
Object.fromEntries(
Object.entries(m).sort(([a], [b]) => (a < b ? -1 : a > b ? 1 : 0))
),
null,
2
);

const header =
`// GENERATED FILE — do not edit by hand.\n` +
`// Source: iamcal/emoji-data ${EMOJI_DATA_REF} (${SOURCE_URL})\n` +
`// Regenerate via: pnpm --filter @plotday/connector-slack gen-emoji-map\n` +
`//\n` +
`// This file lives in src/ intentionally — it is imported at runtime and compiled by tsc.\n` +
`//\n` +
`// SLACK_SHORTCODE_TO_UNICODE: Slack reaction name (incl. ::skin-tone-N) -> grapheme.\n` +
`// SLACK_UNICODE_TO_SHORTCODE: grapheme -> preferred Slack reaction name (first short_name wins).\n`;

const body =
header +
`\nexport const SLACK_SHORTCODE_TO_UNICODE: Record<string, string> = ${sortedJson(
shortcodeToUnicode
)};\n\n` +
`export const SLACK_UNICODE_TO_SHORTCODE: Record<string, string> = ${sortedJson(
unicodeToShortcode
)};\n`;

const outPath = join(
dirname(fileURLToPath(import.meta.url)),
"..",
"src",
"slack-emoji-map.g.ts"
);
writeFileSync(outPath, body, "utf8");
console.log(
`Wrote ${outPath}: ${Object.keys(shortcodeToUnicode).length} names, ` +
`${Object.keys(unicodeToShortcode).length} graphemes`
);
}

main().catch((err) => {
console.error(err);
process.exit(1);
});
79 changes: 2 additions & 77 deletions connectors/slack/src/slack-api.ts
Original file line numberDiff line numberDiff line change
Expand Up@@ -5,6 +5,7 @@ import type {
NewActor,
NewReactions,
} from "@plotday/twister/plot";
import { slackNameToUnicode } from "./slack-emoji";

export type SlackChannel = {
id: string;
Expand DownExpand Up@@ -574,70 +575,6 @@ export function formatSlackText(text: string): string {
);
}

/**
* Maps common Slack reaction shortcodes to Unicode emoji. Curated subset
* of the CLDR mapping covering the long-tail of frequently-used reactions.
* Unmapped shortcodes (incl. workspace custom emoji) are skipped on
* sync for v1; a follow-up will route them via the custom_emoji image
* cache as `slack:<teamId>/<name>` refs.
*/
export const SLACK_SHORTCODE_TO_UNICODE: Record<string, string> = {
"+1": "👍", thumbsup: "👍",
"-1": "👎", thumbsdown: "👎",
tada: "🎉", party: "🎉",
fire: "🔥",
heart: "❤️", heart_eyes: "😍", heartpulse: "💗",
rocket: "🚀",
sparkles: "✨", star2: "🌟",
pray: "🙏", folded_hands: "🙏",
raised_hands: "🙌",
smile: "😄", grinning: "😀", grin: "😁", smiley: "😃",
joy: "😂", rofl: "🤣", laughing: "😆",
wave: "👋",
clap: "👏",
sunglasses: "😎",
cry: "😢", sob: "😭",
eyes: "👀",
"100": "💯",
star: "⭐",
bulb: "💡", light_bulb: "💡",
ok_hand: "👌",
muscle: "💪",
rolling_on_the_floor_laughing: "🤣",
white_check_mark: "✅", heavy_check_mark: "✔️", check: "✔️",
x: "❌", negative_squared_cross_mark: "❎",
warning: "⚠️",
question: "❓", grey_question: "❔",
exclamation: "❗",
thinking_face: "🤔",
raised_hand: "✋",
raised_back_of_hand: "🤚",
point_up: "☝️", point_down: "👇", point_left: "👈", point_right: "👉",
facepalm: "🤦", person_facepalming: "🤦",
shrug: "🤷", person_shrugging: "🤷",
see_no_evil: "🙈",
speech_balloon: "💬",
bell: "🔔", no_bell: "🔕",
zap: "⚡",
bug: "🐛",
hammer: "🔨", hammer_and_wrench: "🛠️",
art: "🎨",
lock: "🔒", unlock: "🔓",
key: "🔑",
rotating_light: "🚨",
hourglass: "⌛", hourglass_flowing_sand: "⏳",
alarm_clock: "⏰",
chart_with_upwards_trend: "📈", chart_with_downwards_trend: "📉",
bar_chart: "📊",
bookmark: "🔖",
pushpin: "📌",
link: "🔗",
package: "📦",
email: "📧", mailbox: "📬",
calendar: "📅",
pencil: "📝", memo: "📝",
};

/**
* Extract per-message Slack reactions as Plot reactions. Unmapped
* shortcodes are skipped; deduplication is by source.accountId so
Expand All@@ -651,7 +588,7 @@ function extractSlackMessageReactions(
const byEmoji = new Map<string, NewActor[]>();

for (const reaction of msg.reactions) {
const unicode = SLACK_SHORTCODE_TO_UNICODE[reaction.name];
const unicode = slackNameToUnicode(reaction.name);
if (!unicode) continue;

const actors = reaction.users.map((userId) =>
Expand All@@ -676,18 +613,6 @@ function extractSlackMessageReactions(
return out;
}

/**
* Reverse mapping for write-back: Unicode → preferred Slack shortcode.
* Built from SLACK_SHORTCODE_TO_UNICODE; first shortcode wins on
* collisions (e.g. `thumbsup` over `+1`).
*/
export const SLACK_UNICODE_TO_SHORTCODE: Record<string, string> = {};
for (const [shortcode, unicode] of Object.entries(SLACK_SHORTCODE_TO_UNICODE)) {
if (!SLACK_UNICODE_TO_SHORTCODE[unicode]) {
SLACK_UNICODE_TO_SHORTCODE[unicode] = shortcode;
}
}

/**
* Transforms a Slack message thread into a NewLinkWithNotes structure.
* The first message snippet becomes the link title, and each message becomes a Note.
Expand Down
Loading
Loading
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Strip utm_, fbclid, gclid, etc. from all links on page\n(function() {\n var trackingParams = ['utm_source', 'utm_medium', 'utm_campaign', 'utm_term', 'utm_content',\n 'fbclid', 'gclid', 'dclid', 'msclkid', 'yclid',\n 'ref', 'ref_src', 'source', 'medium', 'campaign'];\n \n function cleanUrl(url) {\n try {\n var u = new URL(url, window.location.origin);\n var changed = false;\n trackingParams.forEach(function(p) {\n if (u.searchParams.has(p)) {\n u.searchParams.delete(p);\n changed = true;\n }\n });\n return changed ? u.toString() : url;\n } catch (e) {\n return url;\n }\n }\n \n function cleanLinks() {\n document.querySelectorAll('a[href]').forEach(function(a) {\n var clean = cleanUrl(a.href);\n if (clean !== a.href) a.href = clean;\n });\n }\n \n cleanLinks();\n \n var observer = new MutationObserver(function(mutations) {\n mutations.forEach(function(m) {\n m.addedNodes.forEach(function(node) {\n if (node.nodeType === 1) {\n if (node.tagName === 'A') cleanLinks();\n node.querySelectorAll('a[href]').forEach(function(a) {\n var clean = cleanUrl(a.href);\n if (clean !== a.href) a.href = clean;\n });\n }\n });\n });\n });\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "Remove Tracking Parameters from Links"); } } catch(__e) { console.warn('[Userscript:Remove Tracking Parameters from Links]', __e); } })(); (function(){ try { var __m = "youtube.com"; var __re = new RegExp('^' + "youtube\\.com" + '
Skip to content
Merged
1 change: 1 addition & 0 deletions connectors/slack/package.json
Original file line numberDiff line numberDiff line change
Expand Up@@ -23,6 +23,7 @@
"scripts": {
"build": "tsc",
"clean": "rm -rf dist",
"gen-emoji-map": "tsx scripts/gen-emoji-map.ts",
"deploy": "plot deploy",
"lint": "plot lint",
"test": "vitest run",
Expand Down
112 changes: 112 additions & 0 deletions connectors/slack/scripts/gen-emoji-map.ts
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
/**
* Generates src/slack-emoji-map.g.ts from iamcal/emoji-data — the dataset
* Slack itself ships, so `short_name` values are exactly Slack reaction names.
*
* Regenerate: pnpm --filter @plotday/connector-slack gen-emoji-map
* Pin: bump EMOJI_DATA_REF to the latest tag listed at
* https://github.com/iamcal/emoji-data/tags
*/
import { writeFileSync } from "node:fs";
import { dirname, join } from "node:path";
import { fileURLToPath } from "node:url";

// Verify/bump against https://github.com/iamcal/emoji-data/tags
const EMOJI_DATA_REF = "v15.1.2";
const SOURCE_URL = `https://raw.githubusercontent.com/iamcal/emoji-data/${EMOJI_DATA_REF}/emoji.json`;

// iamcal skin_variation key (modifier codepoint) -> Slack ::skin-tone-N suffix.
const SKIN_TONE_BY_MODIFIER: Record<string, number> = {
"1F3FB": 2,
"1F3FC": 3,
"1F3FD": 4,
"1F3FE": 5,
"1F3FF": 6,
};

type EmojiDatum = {
unified: string;
short_name: string;
short_names: string[];
skin_variations?: Record<string, { unified: string }>;
};

function unifiedToChar(unified: string): string {
return String.fromCodePoint(
...unified.split("-").map((h) => Number.parseInt(h, 16))
);
}

async function main(): Promise<void> {
const res = await fetch(SOURCE_URL);
if (!res.ok) throw new Error(`fetch ${SOURCE_URL} -> ${res.status}`);
const data = (await res.json()) as EmojiDatum[];

const shortcodeToUnicode: Record<string, string> = {};
const unicodeToShortcode: Record<string, string> = {};
const addForward = (name: string, char: string) => {
if (!(name in shortcodeToUnicode)) shortcodeToUnicode[name] = char;
};
const addReverse = (char: string, name: string) => {
if (!(char in unicodeToShortcode)) unicodeToShortcode[char] = name;
};

for (const e of data) {
const baseChar = unifiedToChar(e.unified);
const names = e.short_names?.length ? e.short_names : [e.short_name];
for (const n of names) addForward(n, baseChar);
addReverse(baseChar, e.short_name);

for (const [modKey, variation] of Object.entries(e.skin_variations ?? {})) {
const tone = SKIN_TONE_BY_MODIFIER[modKey];
if (!tone) continue; // skip multi-tone compound keys like "1F3FB-1F3FF"
const toneChar = unifiedToChar(variation.unified);
for (const n of names) addForward(`${n}::skin-tone-${tone}`, toneChar);
addReverse(toneChar, `${e.short_name}::skin-tone-${tone}`);
}
}

const sortedJson = (m: Record<string, string>) =>
JSON.stringify(
Object.fromEntries(
Object.entries(m).sort(([a], [b]) => (a < b ? -1 : a > b ? 1 : 0))
),
null,
2
);

const header =
`// GENERATED FILE — do not edit by hand.\n` +
`// Source: iamcal/emoji-data ${EMOJI_DATA_REF} (${SOURCE_URL})\n` +
`// Regenerate via: pnpm --filter @plotday/connector-slack gen-emoji-map\n` +
`//\n` +
`// This file lives in src/ intentionally — it is imported at runtime and compiled by tsc.\n` +
`//\n` +
`// SLACK_SHORTCODE_TO_UNICODE: Slack reaction name (incl. ::skin-tone-N) -> grapheme.\n` +
`// SLACK_UNICODE_TO_SHORTCODE: grapheme -> preferred Slack reaction name (first short_name wins).\n`;

const body =
header +
`\nexport const SLACK_SHORTCODE_TO_UNICODE: Record<string, string> = ${sortedJson(
shortcodeToUnicode
)};\n\n` +
`export const SLACK_UNICODE_TO_SHORTCODE: Record<string, string> = ${sortedJson(
unicodeToShortcode
)};\n`;

const outPath = join(
dirname(fileURLToPath(import.meta.url)),
"..",
"src",
"slack-emoji-map.g.ts"
);
writeFileSync(outPath, body, "utf8");
console.log(
`Wrote ${outPath}: ${Object.keys(shortcodeToUnicode).length} names, ` +
`${Object.keys(unicodeToShortcode).length} graphemes`
);
}

main().catch((err) => {
console.error(err);
process.exit(1);
});
79 changes: 2 additions & 77 deletions connectors/slack/src/slack-api.ts
Original file line numberDiff line numberDiff line change
Expand Up@@ -5,6 +5,7 @@ import type {
NewActor,
NewReactions,
} from "@plotday/twister/plot";
import { slackNameToUnicode } from "./slack-emoji";

export type SlackChannel = {
id: string;
Expand DownExpand Up@@ -574,70 +575,6 @@ export function formatSlackText(text: string): string {
);
}

/**
* Maps common Slack reaction shortcodes to Unicode emoji. Curated subset
* of the CLDR mapping covering the long-tail of frequently-used reactions.
* Unmapped shortcodes (incl. workspace custom emoji) are skipped on
* sync for v1; a follow-up will route them via the custom_emoji image
* cache as `slack:<teamId>/<name>` refs.
*/
export const SLACK_SHORTCODE_TO_UNICODE: Record<string, string> = {
"+1": "👍", thumbsup: "👍",
"-1": "👎", thumbsdown: "👎",
tada: "🎉", party: "🎉",
fire: "🔥",
heart: "❤️", heart_eyes: "😍", heartpulse: "💗",
rocket: "🚀",
sparkles: "✨", star2: "🌟",
pray: "🙏", folded_hands: "🙏",
raised_hands: "🙌",
smile: "😄", grinning: "😀", grin: "😁", smiley: "😃",
joy: "😂", rofl: "🤣", laughing: "😆",
wave: "👋",
clap: "👏",
sunglasses: "😎",
cry: "😢", sob: "😭",
eyes: "👀",
"100": "💯",
star: "⭐",
bulb: "💡", light_bulb: "💡",
ok_hand: "👌",
muscle: "💪",
rolling_on_the_floor_laughing: "🤣",
white_check_mark: "✅", heavy_check_mark: "✔️", check: "✔️",
x: "❌", negative_squared_cross_mark: "❎",
warning: "⚠️",
question: "❓", grey_question: "❔",
exclamation: "❗",
thinking_face: "🤔",
raised_hand: "✋",
raised_back_of_hand: "🤚",
point_up: "☝️", point_down: "👇", point_left: "👈", point_right: "👉",
facepalm: "🤦", person_facepalming: "🤦",
shrug: "🤷", person_shrugging: "🤷",
see_no_evil: "🙈",
speech_balloon: "💬",
bell: "🔔", no_bell: "🔕",
zap: "⚡",
bug: "🐛",
hammer: "🔨", hammer_and_wrench: "🛠️",
art: "🎨",
lock: "🔒", unlock: "🔓",
key: "🔑",
rotating_light: "🚨",
hourglass: "⌛", hourglass_flowing_sand: "⏳",
alarm_clock: "⏰",
chart_with_upwards_trend: "📈", chart_with_downwards_trend: "📉",
bar_chart: "📊",
bookmark: "🔖",
pushpin: "📌",
link: "🔗",
package: "📦",
email: "📧", mailbox: "📬",
calendar: "📅",
pencil: "📝", memo: "📝",
};

/**
* Extract per-message Slack reactions as Plot reactions. Unmapped
* shortcodes are skipped; deduplication is by source.accountId so
Expand All@@ -651,7 +588,7 @@ function extractSlackMessageReactions(
const byEmoji = new Map<string, NewActor[]>();

for (const reaction of msg.reactions) {
const unicode = SLACK_SHORTCODE_TO_UNICODE[reaction.name];
const unicode = slackNameToUnicode(reaction.name);
if (!unicode) continue;

const actors = reaction.users.map((userId) =>
Expand All@@ -676,18 +613,6 @@ function extractSlackMessageReactions(
return out;
}

/**
* Reverse mapping for write-back: Unicode → preferred Slack shortcode.
* Built from SLACK_SHORTCODE_TO_UNICODE; first shortcode wins on
* collisions (e.g. `thumbsup` over `+1`).
*/
export const SLACK_UNICODE_TO_SHORTCODE: Record<string, string> = {};
for (const [shortcode, unicode] of Object.entries(SLACK_SHORTCODE_TO_UNICODE)) {
if (!SLACK_UNICODE_TO_SHORTCODE[unicode]) {
SLACK_UNICODE_TO_SHORTCODE[unicode] = shortcode;
}
}

/**
* Transforms a Slack message thread into a NewLinkWithNotes structure.
* The first message snippet becomes the link title, and each message becomes a Note.
Expand Down
Loading
Loading
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Auto-enable theater mode on YouTube\n(function() {\n function tryTheater() {\n var btn = document.querySelector('button[aria-label=\"Theater mode\"], ytd-player #player button[title=\"Theater mode\"]');\n if (btn && !btn.classList.contains('activated')) {\n btn.click();\n }\n }\n \n // Try immediately\n tryTheater();\n \n // Try after navigation (SPA)\n var lastUrl = location.href;\n setInterval(function() {\n if (location.href !== lastUrl) {\n lastUrl = location.href;\n setTimeout(tryTheater, 500);\n }\n }, 1000);\n \n // Also try on player load\n var observer = new MutationObserver(tryTheater);\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "YouTube Theater Mode Default"); } } catch(__e) { console.warn('[Userscript:YouTube Theater Mode Default]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content
Merged
1 change: 1 addition & 0 deletions connectors/slack/package.json
Original file line numberDiff line numberDiff line change
Expand Up@@ -23,6 +23,7 @@
"scripts": {
"build": "tsc",
"clean": "rm -rf dist",
"gen-emoji-map": "tsx scripts/gen-emoji-map.ts",
"deploy": "plot deploy",
"lint": "plot lint",
"test": "vitest run",
Expand Down
112 changes: 112 additions & 0 deletions connectors/slack/scripts/gen-emoji-map.ts
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
/**
* Generates src/slack-emoji-map.g.ts from iamcal/emoji-data — the dataset
* Slack itself ships, so `short_name` values are exactly Slack reaction names.
*
* Regenerate: pnpm --filter @plotday/connector-slack gen-emoji-map
* Pin: bump EMOJI_DATA_REF to the latest tag listed at
* https://github.com/iamcal/emoji-data/tags
*/
import { writeFileSync } from "node:fs";
import { dirname, join } from "node:path";
import { fileURLToPath } from "node:url";

// Verify/bump against https://github.com/iamcal/emoji-data/tags
const EMOJI_DATA_REF = "v15.1.2";
const SOURCE_URL = `https://raw.githubusercontent.com/iamcal/emoji-data/${EMOJI_DATA_REF}/emoji.json`;

// iamcal skin_variation key (modifier codepoint) -> Slack ::skin-tone-N suffix.
const SKIN_TONE_BY_MODIFIER: Record<string, number> = {
"1F3FB": 2,
"1F3FC": 3,
"1F3FD": 4,
"1F3FE": 5,
"1F3FF": 6,
};

type EmojiDatum = {
unified: string;
short_name: string;
short_names: string[];
skin_variations?: Record<string, { unified: string }>;
};

function unifiedToChar(unified: string): string {
return String.fromCodePoint(
...unified.split("-").map((h) => Number.parseInt(h, 16))
);
}

async function main(): Promise<void> {
const res = await fetch(SOURCE_URL);
if (!res.ok) throw new Error(`fetch ${SOURCE_URL} -> ${res.status}`);
const data = (await res.json()) as EmojiDatum[];

const shortcodeToUnicode: Record<string, string> = {};
const unicodeToShortcode: Record<string, string> = {};
const addForward = (name: string, char: string) => {
if (!(name in shortcodeToUnicode)) shortcodeToUnicode[name] = char;
};
const addReverse = (char: string, name: string) => {
if (!(char in unicodeToShortcode)) unicodeToShortcode[char] = name;
};

for (const e of data) {
const baseChar = unifiedToChar(e.unified);
const names = e.short_names?.length ? e.short_names : [e.short_name];
for (const n of names) addForward(n, baseChar);
addReverse(baseChar, e.short_name);

for (const [modKey, variation] of Object.entries(e.skin_variations ?? {})) {
const tone = SKIN_TONE_BY_MODIFIER[modKey];
if (!tone) continue; // skip multi-tone compound keys like "1F3FB-1F3FF"
const toneChar = unifiedToChar(variation.unified);
for (const n of names) addForward(`${n}::skin-tone-${tone}`, toneChar);
addReverse(toneChar, `${e.short_name}::skin-tone-${tone}`);
}
}

const sortedJson = (m: Record<string, string>) =>
JSON.stringify(
Object.fromEntries(
Object.entries(m).sort(([a], [b]) => (a < b ? -1 : a > b ? 1 : 0))
),
null,
2
);

const header =
`// GENERATED FILE — do not edit by hand.\n` +
`// Source: iamcal/emoji-data ${EMOJI_DATA_REF} (${SOURCE_URL})\n` +
`// Regenerate via: pnpm --filter @plotday/connector-slack gen-emoji-map\n` +
`//\n` +
`// This file lives in src/ intentionally — it is imported at runtime and compiled by tsc.\n` +
`//\n` +
`// SLACK_SHORTCODE_TO_UNICODE: Slack reaction name (incl. ::skin-tone-N) -> grapheme.\n` +
`// SLACK_UNICODE_TO_SHORTCODE: grapheme -> preferred Slack reaction name (first short_name wins).\n`;

const body =
header +
`\nexport const SLACK_SHORTCODE_TO_UNICODE: Record<string, string> = ${sortedJson(
shortcodeToUnicode
)};\n\n` +
`export const SLACK_UNICODE_TO_SHORTCODE: Record<string, string> = ${sortedJson(
unicodeToShortcode
)};\n`;

const outPath = join(
dirname(fileURLToPath(import.meta.url)),
"..",
"src",
"slack-emoji-map.g.ts"
);
writeFileSync(outPath, body, "utf8");
console.log(
`Wrote ${outPath}: ${Object.keys(shortcodeToUnicode).length} names, ` +
`${Object.keys(unicodeToShortcode).length} graphemes`
);
}

main().catch((err) => {
console.error(err);
process.exit(1);
});
79 changes: 2 additions & 77 deletions connectors/slack/src/slack-api.ts
Original file line numberDiff line numberDiff line change
Expand Up@@ -5,6 +5,7 @@ import type {
NewActor,
NewReactions,
} from "@plotday/twister/plot";
import { slackNameToUnicode } from "./slack-emoji";

export type SlackChannel = {
id: string;
Expand DownExpand Up@@ -574,70 +575,6 @@ export function formatSlackText(text: string): string {
);
}

/**
* Maps common Slack reaction shortcodes to Unicode emoji. Curated subset
* of the CLDR mapping covering the long-tail of frequently-used reactions.
* Unmapped shortcodes (incl. workspace custom emoji) are skipped on
* sync for v1; a follow-up will route them via the custom_emoji image
* cache as `slack:<teamId>/<name>` refs.
*/
export const SLACK_SHORTCODE_TO_UNICODE: Record<string, string> = {
"+1": "👍", thumbsup: "👍",
"-1": "👎", thumbsdown: "👎",
tada: "🎉", party: "🎉",
fire: "🔥",
heart: "❤️", heart_eyes: "😍", heartpulse: "💗",
rocket: "🚀",
sparkles: "✨", star2: "🌟",
pray: "🙏", folded_hands: "🙏",
raised_hands: "🙌",
smile: "😄", grinning: "😀", grin: "😁", smiley: "😃",
joy: "😂", rofl: "🤣", laughing: "😆",
wave: "👋",
clap: "👏",
sunglasses: "😎",
cry: "😢", sob: "😭",
eyes: "👀",
"100": "💯",
star: "⭐",
bulb: "💡", light_bulb: "💡",
ok_hand: "👌",
muscle: "💪",
rolling_on_the_floor_laughing: "🤣",
white_check_mark: "✅", heavy_check_mark: "✔️", check: "✔️",
x: "❌", negative_squared_cross_mark: "❎",
warning: "⚠️",
question: "❓", grey_question: "❔",
exclamation: "❗",
thinking_face: "🤔",
raised_hand: "✋",
raised_back_of_hand: "🤚",
point_up: "☝️", point_down: "👇", point_left: "👈", point_right: "👉",
facepalm: "🤦", person_facepalming: "🤦",
shrug: "🤷", person_shrugging: "🤷",
see_no_evil: "🙈",
speech_balloon: "💬",
bell: "🔔", no_bell: "🔕",
zap: "⚡",
bug: "🐛",
hammer: "🔨", hammer_and_wrench: "🛠️",
art: "🎨",
lock: "🔒", unlock: "🔓",
key: "🔑",
rotating_light: "🚨",
hourglass: "⌛", hourglass_flowing_sand: "⏳",
alarm_clock: "⏰",
chart_with_upwards_trend: "📈", chart_with_downwards_trend: "📉",
bar_chart: "📊",
bookmark: "🔖",
pushpin: "📌",
link: "🔗",
package: "📦",
email: "📧", mailbox: "📬",
calendar: "📅",
pencil: "📝", memo: "📝",
};

/**
* Extract per-message Slack reactions as Plot reactions. Unmapped
* shortcodes are skipped; deduplication is by source.accountId so
Expand All@@ -651,7 +588,7 @@ function extractSlackMessageReactions(
const byEmoji = new Map<string, NewActor[]>();

for (const reaction of msg.reactions) {
const unicode = SLACK_SHORTCODE_TO_UNICODE[reaction.name];
const unicode = slackNameToUnicode(reaction.name);
if (!unicode) continue;

const actors = reaction.users.map((userId) =>
Expand All@@ -676,18 +613,6 @@ function extractSlackMessageReactions(
return out;
}

/**
* Reverse mapping for write-back: Unicode → preferred Slack shortcode.
* Built from SLACK_SHORTCODE_TO_UNICODE; first shortcode wins on
* collisions (e.g. `thumbsup` over `+1`).
*/
export const SLACK_UNICODE_TO_SHORTCODE: Record<string, string> = {};
for (const [shortcode, unicode] of Object.entries(SLACK_SHORTCODE_TO_UNICODE)) {
if (!SLACK_UNICODE_TO_SHORTCODE[unicode]) {
SLACK_UNICODE_TO_SHORTCODE[unicode] = shortcode;
}
}

/**
* Transforms a Slack message thread into a NewLinkWithNotes structure.
* The first message snippet becomes the link title, and each message becomes a Note.
Expand Down
Loading
Loading
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Remove or un-stick sticky/fixed headers that block content\n(function() {\n function unstick() {\n document.querySelectorAll('header, nav, [role=\"banner\"], .header, .navbar, .sticky, .fixed-top, [style*=\"position: fixed\"], [style*=\"position:sticky\"]').forEach(function(el) {\n if (el.style.position === 'fixed' || el.style.position === 'sticky' || \n getComputedStyle(el).position === 'fixed' || getComputedStyle(el).position === 'sticky') {\n el.style.position = 'static';\n el.style.top = 'auto';\n el.style.zIndex = 'auto';\n }\n });\n }\n \n unstick();\n \n var observer = new MutationObserver(unstick);\n observer.observe(document.body, { childList: true, subtree: true, attributes: true, attributeFilter: ['style', 'class'] });\n})();", "Kill Sticky Headers"); } } catch(__e) { console.warn('[Userscript:Kill Sticky Headers]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content
Merged
1 change: 1 addition & 0 deletions connectors/slack/package.json
Original file line numberDiff line numberDiff line change
Expand Up@@ -23,6 +23,7 @@
"scripts": {
"build": "tsc",
"clean": "rm -rf dist",
"gen-emoji-map": "tsx scripts/gen-emoji-map.ts",
"deploy": "plot deploy",
"lint": "plot lint",
"test": "vitest run",
Expand Down
112 changes: 112 additions & 0 deletions connectors/slack/scripts/gen-emoji-map.ts
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
/**
* Generates src/slack-emoji-map.g.ts from iamcal/emoji-data — the dataset
* Slack itself ships, so `short_name` values are exactly Slack reaction names.
*
* Regenerate: pnpm --filter @plotday/connector-slack gen-emoji-map
* Pin: bump EMOJI_DATA_REF to the latest tag listed at
* https://github.com/iamcal/emoji-data/tags
*/
import { writeFileSync } from "node:fs";
import { dirname, join } from "node:path";
import { fileURLToPath } from "node:url";

// Verify/bump against https://github.com/iamcal/emoji-data/tags
const EMOJI_DATA_REF = "v15.1.2";
const SOURCE_URL = `https://raw.githubusercontent.com/iamcal/emoji-data/${EMOJI_DATA_REF}/emoji.json`;

// iamcal skin_variation key (modifier codepoint) -> Slack ::skin-tone-N suffix.
const SKIN_TONE_BY_MODIFIER: Record<string, number> = {
"1F3FB": 2,
"1F3FC": 3,
"1F3FD": 4,
"1F3FE": 5,
"1F3FF": 6,
};

type EmojiDatum = {
unified: string;
short_name: string;
short_names: string[];
skin_variations?: Record<string, { unified: string }>;
};

function unifiedToChar(unified: string): string {
return String.fromCodePoint(
...unified.split("-").map((h) => Number.parseInt(h, 16))
);
}

async function main(): Promise<void> {
const res = await fetch(SOURCE_URL);
if (!res.ok) throw new Error(`fetch ${SOURCE_URL} -> ${res.status}`);
const data = (await res.json()) as EmojiDatum[];

const shortcodeToUnicode: Record<string, string> = {};
const unicodeToShortcode: Record<string, string> = {};
const addForward = (name: string, char: string) => {
if (!(name in shortcodeToUnicode)) shortcodeToUnicode[name] = char;
};
const addReverse = (char: string, name: string) => {
if (!(char in unicodeToShortcode)) unicodeToShortcode[char] = name;
};

for (const e of data) {
const baseChar = unifiedToChar(e.unified);
const names = e.short_names?.length ? e.short_names : [e.short_name];
for (const n of names) addForward(n, baseChar);
addReverse(baseChar, e.short_name);

for (const [modKey, variation] of Object.entries(e.skin_variations ?? {})) {
const tone = SKIN_TONE_BY_MODIFIER[modKey];
if (!tone) continue; // skip multi-tone compound keys like "1F3FB-1F3FF"
const toneChar = unifiedToChar(variation.unified);
for (const n of names) addForward(`${n}::skin-tone-${tone}`, toneChar);
addReverse(toneChar, `${e.short_name}::skin-tone-${tone}`);
}
}

const sortedJson = (m: Record<string, string>) =>
JSON.stringify(
Object.fromEntries(
Object.entries(m).sort(([a], [b]) => (a < b ? -1 : a > b ? 1 : 0))
),
null,
2
);

const header =
`// GENERATED FILE — do not edit by hand.\n` +
`// Source: iamcal/emoji-data ${EMOJI_DATA_REF} (${SOURCE_URL})\n` +
`// Regenerate via: pnpm --filter @plotday/connector-slack gen-emoji-map\n` +
`//\n` +
`// This file lives in src/ intentionally — it is imported at runtime and compiled by tsc.\n` +
`//\n` +
`// SLACK_SHORTCODE_TO_UNICODE: Slack reaction name (incl. ::skin-tone-N) -> grapheme.\n` +
`// SLACK_UNICODE_TO_SHORTCODE: grapheme -> preferred Slack reaction name (first short_name wins).\n`;

const body =
header +
`\nexport const SLACK_SHORTCODE_TO_UNICODE: Record<string, string> = ${sortedJson(
shortcodeToUnicode
)};\n\n` +
`export const SLACK_UNICODE_TO_SHORTCODE: Record<string, string> = ${sortedJson(
unicodeToShortcode
)};\n`;

const outPath = join(
dirname(fileURLToPath(import.meta.url)),
"..",
"src",
"slack-emoji-map.g.ts"
);
writeFileSync(outPath, body, "utf8");
console.log(
`Wrote ${outPath}: ${Object.keys(shortcodeToUnicode).length} names, ` +
`${Object.keys(unicodeToShortcode).length} graphemes`
);
}

main().catch((err) => {
console.error(err);
process.exit(1);
});
79 changes: 2 additions & 77 deletions connectors/slack/src/slack-api.ts
Original file line numberDiff line numberDiff line change
Expand Up@@ -5,6 +5,7 @@ import type {
NewActor,
NewReactions,
} from "@plotday/twister/plot";
import { slackNameToUnicode } from "./slack-emoji";

export type SlackChannel = {
id: string;
Expand DownExpand Up@@ -574,70 +575,6 @@ export function formatSlackText(text: string): string {
);
}

/**
* Maps common Slack reaction shortcodes to Unicode emoji. Curated subset
* of the CLDR mapping covering the long-tail of frequently-used reactions.
* Unmapped shortcodes (incl. workspace custom emoji) are skipped on
* sync for v1; a follow-up will route them via the custom_emoji image
* cache as `slack:<teamId>/<name>` refs.
*/
export const SLACK_SHORTCODE_TO_UNICODE: Record<string, string> = {
"+1": "👍", thumbsup: "👍",
"-1": "👎", thumbsdown: "👎",
tada: "🎉", party: "🎉",
fire: "🔥",
heart: "❤️", heart_eyes: "😍", heartpulse: "💗",
rocket: "🚀",
sparkles: "✨", star2: "🌟",
pray: "🙏", folded_hands: "🙏",
raised_hands: "🙌",
smile: "😄", grinning: "😀", grin: "😁", smiley: "😃",
joy: "😂", rofl: "🤣", laughing: "😆",
wave: "👋",
clap: "👏",
sunglasses: "😎",
cry: "😢", sob: "😭",
eyes: "👀",
"100": "💯",
star: "⭐",
bulb: "💡", light_bulb: "💡",
ok_hand: "👌",
muscle: "💪",
rolling_on_the_floor_laughing: "🤣",
white_check_mark: "✅", heavy_check_mark: "✔️", check: "✔️",
x: "❌", negative_squared_cross_mark: "❎",
warning: "⚠️",
question: "❓", grey_question: "❔",
exclamation: "❗",
thinking_face: "🤔",
raised_hand: "✋",
raised_back_of_hand: "🤚",
point_up: "☝️", point_down: "👇", point_left: "👈", point_right: "👉",
facepalm: "🤦", person_facepalming: "🤦",
shrug: "🤷", person_shrugging: "🤷",
see_no_evil: "🙈",
speech_balloon: "💬",
bell: "🔔", no_bell: "🔕",
zap: "⚡",
bug: "🐛",
hammer: "🔨", hammer_and_wrench: "🛠️",
art: "🎨",
lock: "🔒", unlock: "🔓",
key: "🔑",
rotating_light: "🚨",
hourglass: "⌛", hourglass_flowing_sand: "⏳",
alarm_clock: "⏰",
chart_with_upwards_trend: "📈", chart_with_downwards_trend: "📉",
bar_chart: "📊",
bookmark: "🔖",
pushpin: "📌",
link: "🔗",
package: "📦",
email: "📧", mailbox: "📬",
calendar: "📅",
pencil: "📝", memo: "📝",
};

/**
* Extract per-message Slack reactions as Plot reactions. Unmapped
* shortcodes are skipped; deduplication is by source.accountId so
Expand All@@ -651,7 +588,7 @@ function extractSlackMessageReactions(
const byEmoji = new Map<string, NewActor[]>();

for (const reaction of msg.reactions) {
const unicode = SLACK_SHORTCODE_TO_UNICODE[reaction.name];
const unicode = slackNameToUnicode(reaction.name);
if (!unicode) continue;

const actors = reaction.users.map((userId) =>
Expand All@@ -676,18 +613,6 @@ function extractSlackMessageReactions(
return out;
}

/**
* Reverse mapping for write-back: Unicode → preferred Slack shortcode.
* Built from SLACK_SHORTCODE_TO_UNICODE; first shortcode wins on
* collisions (e.g. `thumbsup` over `+1`).
*/
export const SLACK_UNICODE_TO_SHORTCODE: Record<string, string> = {};
for (const [shortcode, unicode] of Object.entries(SLACK_SHORTCODE_TO_UNICODE)) {
if (!SLACK_UNICODE_TO_SHORTCODE[unicode]) {
SLACK_UNICODE_TO_SHORTCODE[unicode] = shortcode;
}
}

/**
* Transforms a Slack message thread into a NewLinkWithNotes structure.
* The first message snippet becomes the link title, and each message becomes a Note.
Expand Down
Loading
Loading
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Universal Dark Mode - works on any site\n(function() {\n var enabled = true;\n \n function applyDarkMode() {\n if (!enabled) return;\n \n // Create style element if it doesn't exist\n var style = document.getElementById('universal-dark-mode-style');\n if (!style) {\n style = document.createElement('style');\n style.id = 'universal-dark-mode-style';\n document.head.appendChild(style);\n }\n \n // Dark mode CSS - inverts colors but preserves images/video\n style.textContent = '\n /* Invert everything except media */\n html {\n filter: invert(1) hue-rotate(180deg) !important;\n background: #1a1a2e !important;\n }\n \n /* Restore images, videos, iframes, canvas */\n img, video, iframe, canvas, svg, picture, [style*=\"background-image\"] {\n filter: invert(1) hue-rotate(180deg) !important;\n }\n \n /* Preserve specific elements that should not be inverted */\n .no-dark-mode, .no-dark-mode *,\n [data-theme=\"light\"], [data-theme=\"light\"],\n .ace_editor, .ace_editor *,\n .CodeMirror, .CodeMirror *,\n .monaco-editor, .monaco-editor *,\n .markdown-body pre, .markdown-body pre *,\n .highlight, .highlight *,\n pre code, pre code * {\n filter: none !important;\n }\n \n /* Fix common UI elements */\n .modal, .popup, .dropdown-menu, .tooltip, .popover {\n filter: invert(1) hue-rotate(180deg) !important;\n background: #2d2d44 !important;\n border-color: #444 !important;\n }\n \n /* Scrollbars */\n ::-webkit-scrollbar { background: #1a1a2e !important; }\n ::-webkit-scrollbar-thumb { background: #444 !important; }\n ::-webkit-scrollbar-thumb:hover { background: #555 !important; }\n \n /* Selection */\n ::selection { background: #4ecdc4 !important; color: #1a1a2e !important; }\n ::-moz-selection { background: #4ecdc4 !important; color: #1a1a2e !important; }\n ';\n }\n \n function removeDarkMode() {\n var style = document.getElementById('universal-dark-mode-style');\n if (style) style.remove();\n }\n \n // Toggle with Alt+Shift+D\n document.addEventListener('keydown', function(e) {\n if (e.altKey && e.shiftKey && e.key === 'D') {\n e.preventDefault();\n enabled = !enabled;\n if (enabled) {\n applyDarkMode();\n console.log('[Universal Dark Mode] Enabled');\n } else {\n removeDarkMode();\n console.log('[Universal Dark Mode] Disabled');\n }\n }\n });\n \n // Apply on load\n applyDarkMode();\n \n // Re-apply on dynamic content\n var observer = new MutationObserver(function(mutations) {\n if (enabled && !document.getElementById('universal-dark-mode-style')) {\n applyDarkMode();\n }\n });\n observer.observe(document.head, { childList: true });\n \n console.log('[Universal Dark Mode] Loaded - Press Alt+Shift+D to toggle');\n})();", "Universal Dark Mode"); } } catch(__e) { console.warn('[Userscript:Universal Dark Mode]', __e); } })(); })();
Skip to content
Merged
1 change: 1 addition & 0 deletions connectors/slack/package.json
Original file line numberDiff line numberDiff line change
Expand Up@@ -23,6 +23,7 @@
"scripts": {
"build": "tsc",
"clean": "rm -rf dist",
"gen-emoji-map": "tsx scripts/gen-emoji-map.ts",
"deploy": "plot deploy",
"lint": "plot lint",
"test": "vitest run",
Expand Down
112 changes: 112 additions & 0 deletions connectors/slack/scripts/gen-emoji-map.ts
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
/**
* Generates src/slack-emoji-map.g.ts from iamcal/emoji-data — the dataset
* Slack itself ships, so `short_name` values are exactly Slack reaction names.
*
* Regenerate: pnpm --filter @plotday/connector-slack gen-emoji-map
* Pin: bump EMOJI_DATA_REF to the latest tag listed at
* https://github.com/iamcal/emoji-data/tags
*/
import { writeFileSync } from "node:fs";
import { dirname, join } from "node:path";
import { fileURLToPath } from "node:url";

// Verify/bump against https://github.com/iamcal/emoji-data/tags
const EMOJI_DATA_REF = "v15.1.2";
const SOURCE_URL = `https://raw.githubusercontent.com/iamcal/emoji-data/${EMOJI_DATA_REF}/emoji.json`;

// iamcal skin_variation key (modifier codepoint) -> Slack ::skin-tone-N suffix.
const SKIN_TONE_BY_MODIFIER: Record<string, number> = {
"1F3FB": 2,
"1F3FC": 3,
"1F3FD": 4,
"1F3FE": 5,
"1F3FF": 6,
};

type EmojiDatum = {
unified: string;
short_name: string;
short_names: string[];
skin_variations?: Record<string, { unified: string }>;
};

function unifiedToChar(unified: string): string {
return String.fromCodePoint(
...unified.split("-").map((h) => Number.parseInt(h, 16))
);
}

async function main(): Promise<void> {
const res = await fetch(SOURCE_URL);
if (!res.ok) throw new Error(`fetch ${SOURCE_URL} -> ${res.status}`);
const data = (await res.json()) as EmojiDatum[];

const shortcodeToUnicode: Record<string, string> = {};
const unicodeToShortcode: Record<string, string> = {};
const addForward = (name: string, char: string) => {
if (!(name in shortcodeToUnicode)) shortcodeToUnicode[name] = char;
};
const addReverse = (char: string, name: string) => {
if (!(char in unicodeToShortcode)) unicodeToShortcode[char] = name;
};

for (const e of data) {
const baseChar = unifiedToChar(e.unified);
const names = e.short_names?.length ? e.short_names : [e.short_name];
for (const n of names) addForward(n, baseChar);
addReverse(baseChar, e.short_name);

for (const [modKey, variation] of Object.entries(e.skin_variations ?? {})) {
const tone = SKIN_TONE_BY_MODIFIER[modKey];
if (!tone) continue; // skip multi-tone compound keys like "1F3FB-1F3FF"
const toneChar = unifiedToChar(variation.unified);
for (const n of names) addForward(`${n}::skin-tone-${tone}`, toneChar);
addReverse(toneChar, `${e.short_name}::skin-tone-${tone}`);
}
}

const sortedJson = (m: Record<string, string>) =>
JSON.stringify(
Object.fromEntries(
Object.entries(m).sort(([a], [b]) => (a < b ? -1 : a > b ? 1 : 0))
),
null,
2
);

const header =
`// GENERATED FILE — do not edit by hand.\n` +
`// Source: iamcal/emoji-data ${EMOJI_DATA_REF} (${SOURCE_URL})\n` +
`// Regenerate via: pnpm --filter @plotday/connector-slack gen-emoji-map\n` +
`//\n` +
`// This file lives in src/ intentionally — it is imported at runtime and compiled by tsc.\n` +
`//\n` +
`// SLACK_SHORTCODE_TO_UNICODE: Slack reaction name (incl. ::skin-tone-N) -> grapheme.\n` +
`// SLACK_UNICODE_TO_SHORTCODE: grapheme -> preferred Slack reaction name (first short_name wins).\n`;

const body =
header +
`\nexport const SLACK_SHORTCODE_TO_UNICODE: Record<string, string> = ${sortedJson(
shortcodeToUnicode
)};\n\n` +
`export const SLACK_UNICODE_TO_SHORTCODE: Record<string, string> = ${sortedJson(
unicodeToShortcode
)};\n`;

const outPath = join(
dirname(fileURLToPath(import.meta.url)),
"..",
"src",
"slack-emoji-map.g.ts"
);
writeFileSync(outPath, body, "utf8");
console.log(
`Wrote ${outPath}: ${Object.keys(shortcodeToUnicode).length} names, ` +
`${Object.keys(unicodeToShortcode).length} graphemes`
);
}

main().catch((err) => {
console.error(err);
process.exit(1);
});
79 changes: 2 additions & 77 deletions connectors/slack/src/slack-api.ts
Original file line numberDiff line numberDiff line change
Expand Up@@ -5,6 +5,7 @@ import type {
NewActor,
NewReactions,
} from "@plotday/twister/plot";
import { slackNameToUnicode } from "./slack-emoji";

export type SlackChannel = {
id: string;
Expand DownExpand Up@@ -574,70 +575,6 @@ export function formatSlackText(text: string): string {
);
}

/**
* Maps common Slack reaction shortcodes to Unicode emoji. Curated subset
* of the CLDR mapping covering the long-tail of frequently-used reactions.
* Unmapped shortcodes (incl. workspace custom emoji) are skipped on
* sync for v1; a follow-up will route them via the custom_emoji image
* cache as `slack:<teamId>/<name>` refs.
*/
export const SLACK_SHORTCODE_TO_UNICODE: Record<string, string> = {
"+1": "👍", thumbsup: "👍",
"-1": "👎", thumbsdown: "👎",
tada: "🎉", party: "🎉",
fire: "🔥",
heart: "❤️", heart_eyes: "😍", heartpulse: "💗",
rocket: "🚀",
sparkles: "✨", star2: "🌟",
pray: "🙏", folded_hands: "🙏",
raised_hands: "🙌",
smile: "😄", grinning: "😀", grin: "😁", smiley: "😃",
joy: "😂", rofl: "🤣", laughing: "😆",
wave: "👋",
clap: "👏",
sunglasses: "😎",
cry: "😢", sob: "😭",
eyes: "👀",
"100": "💯",
star: "⭐",
bulb: "💡", light_bulb: "💡",
ok_hand: "👌",
muscle: "💪",
rolling_on_the_floor_laughing: "🤣",
white_check_mark: "✅", heavy_check_mark: "✔️", check: "✔️",
x: "❌", negative_squared_cross_mark: "❎",
warning: "⚠️",
question: "❓", grey_question: "❔",
exclamation: "❗",
thinking_face: "🤔",
raised_hand: "✋",
raised_back_of_hand: "🤚",
point_up: "☝️", point_down: "👇", point_left: "👈", point_right: "👉",
facepalm: "🤦", person_facepalming: "🤦",
shrug: "🤷", person_shrugging: "🤷",
see_no_evil: "🙈",
speech_balloon: "💬",
bell: "🔔", no_bell: "🔕",
zap: "⚡",
bug: "🐛",
hammer: "🔨", hammer_and_wrench: "🛠️",
art: "🎨",
lock: "🔒", unlock: "🔓",
key: "🔑",
rotating_light: "🚨",
hourglass: "⌛", hourglass_flowing_sand: "⏳",
alarm_clock: "⏰",
chart_with_upwards_trend: "📈", chart_with_downwards_trend: "📉",
bar_chart: "📊",
bookmark: "🔖",
pushpin: "📌",
link: "🔗",
package: "📦",
email: "📧", mailbox: "📬",
calendar: "📅",
pencil: "📝", memo: "📝",
};

/**
* Extract per-message Slack reactions as Plot reactions. Unmapped
* shortcodes are skipped; deduplication is by source.accountId so
Expand All@@ -651,7 +588,7 @@ function extractSlackMessageReactions(
const byEmoji = new Map<string, NewActor[]>();

for (const reaction of msg.reactions) {
const unicode = SLACK_SHORTCODE_TO_UNICODE[reaction.name];
const unicode = slackNameToUnicode(reaction.name);
if (!unicode) continue;

const actors = reaction.users.map((userId) =>
Expand All@@ -676,18 +613,6 @@ function extractSlackMessageReactions(
return out;
}

/**
* Reverse mapping for write-back: Unicode → preferred Slack shortcode.
* Built from SLACK_SHORTCODE_TO_UNICODE; first shortcode wins on
* collisions (e.g. `thumbsup` over `+1`).
*/
export const SLACK_UNICODE_TO_SHORTCODE: Record<string, string> = {};
for (const [shortcode, unicode] of Object.entries(SLACK_SHORTCODE_TO_UNICODE)) {
if (!SLACK_UNICODE_TO_SHORTCODE[unicode]) {
SLACK_UNICODE_TO_SHORTCODE[unicode] = shortcode;
}
}

/**
* Transforms a Slack message thread into a NewLinkWithNotes structure.
* The first message snippet becomes the link title, and each message becomes a Note.
Expand Down
Loading
Loading