Skip to content

Commit

Permalink
Merge pull request #1079 from pimothyxd/feat/kick-emote-menu-autocomp…
Browse files Browse the repository at this point in the history
…lete

feat(kick): add emote menu and autocomplete
  • Loading branch information
Excellify authored Sep 30, 2024
2 parents 6a7336b + 8daf329 commit 707fed6
Show file tree
Hide file tree
Showing 12 changed files with 1,000 additions and 53 deletions.
26 changes: 26 additions & 0 deletions src/common/Input.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
export function getSearchRange(text: string, position: number): [number, number] {
let start = 0;
let end = 0;

for (let i = position; ; i--) {
if (i < 1 || (text.charAt(i - 1) === " " && i !== position)) {
start = i;
break;
}
}

for (let i = position + 1; ; i++) {
if (i > text.length || text.charAt(i - 1) === " ") {
end = i - 1;
break;
}
}

return [start, end];
}

export interface TabToken {
token: string;
priority: number;
item?: SevenTV.ActiveEmote;
}
4 changes: 2 additions & 2 deletions src/common/Tokenize.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { AnyToken, ChatUser, EmoteToken, LinkToken, TextToken, VoidToken } from "@/common/chat/ChatMessage";
import { convertKickEmote } from "./Transform";
import { convertExternalKickEmote } from "./Transform";
import { parse as tldParse } from "tldts";

const URL_PROTOCOL_REGEXP = /^https?:\/\//i;
Expand All @@ -20,7 +20,7 @@ export function tokenize(opt: TokenizeOptions) {
return {
name: name,
id: id,
data: convertKickEmote(id, name),
data: convertExternalKickEmote(id, name),
provider: "PLATFORM",
} as SevenTV.ActiveEmote;
}
Expand Down
64 changes: 63 additions & 1 deletion src/common/Transform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,39 @@ export function convertPlatformEmoteSet(data: Twitch.TwitchEmoteSet): SevenTV.Em
};
}

export function convertKickEmoteSet(data: Kick.KickEmoteSet): SevenTV.EmoteSet {
const isGlobalSet = !("user" in data);

return {
id: "PLATFORM#" + data.id,
name: isGlobalSet ? data.name : data.user.username,
immutable: true,
privileged: true,
tags: [],
flags: 0,
provider: "PLATFORM",
scope: isGlobalSet ? "GLOBAL" : "CHANNEL",
owner: !isGlobalSet
? {
id: data.user_id.toString(),
username: data.user.username,
display_name: data.user.username,
avatar_url: data.user.profile_pic,
}
: undefined,
emotes: data.emotes.map((e) => {
const d = convertKickEmote(e, !isGlobalSet ? data.user : undefined);
return {
id: e.id.toString(),
name: e.name,
flags: 0,
provider: "PLATFORM",
data: d,
};
}),
};
}

export function convertTwitchEmote(
data: Partial<Twitch.TwitchEmote>,
owner?: Twitch.TwitchEmoteSet["owner"],
Expand Down Expand Up @@ -80,6 +113,35 @@ export function convertTwitchEmote(
return emote;
}

export function convertKickEmote(data: Kick.KickEmote, owner?: Kick.KickUserEmoteSet["user"]): SevenTV.Emote {
return {
id: data.id?.toString(),
name: data.name,
flags: undefined,
tags: [],
state: [],
lifecycle: 3,
listed: true,
owner: owner
? {
id: owner.id,
username: owner.username,
display_name: owner.username,
avatar_url: owner.profile_pic,
}
: null,
host: {
url: "//files.kick.com/emotes/" + data.id,
files: [
{
name: "fullsize",
format: "PNG",
},
],
},
};
}

export function convertCheerEmote(data: Twitch.ChatMessage.EmotePart["content"]): SevenTV.Emote {
return {
id: data.emoteID ?? "",
Expand Down Expand Up @@ -348,7 +410,7 @@ export function semanticVersionToNumber(ver: string): number {
return result;
}

export function convertKickEmote(id: string, name: string): SevenTV.Emote {
export function convertExternalKickEmote(id: string, name: string): SevenTV.Emote {
return {
id: id,
name: name,
Expand Down
Loading

0 comments on commit 707fed6

Please sign in to comment.