Skip to content

Commit

Permalink
in-memory history for stars and forks
Browse files Browse the repository at this point in the history
  • Loading branch information
danieldietzler committed Oct 7, 2023
1 parent 5660729 commit 71f85dd
Showing 1 changed file with 29 additions and 2 deletions.
31 changes: 29 additions & 2 deletions src/commands/slashes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ const helpTexts: Record<string, string> = {
"For ideas or features you'd like Immich to have, feel free to [open a feature request in the Github discussions](https://github.com/immich-app/immich/discussions/new?category=feature-request). However, please make sure to search for similar requests first to avoid duplicates. ",
};

const _star_history: Record<string, number | undefined> = {};
const _fork_history: Record<string, number | undefined> = {};

@Discord()
export class Commands {
@Slash({ description: 'Links to Immich pages' })
Expand Down Expand Up @@ -69,19 +72,43 @@ export class Commands {

@Slash({ description: 'Immich stars' })
async stars(interaction: CommandInteraction) {
const lastStarsCount = _star_history[interaction.channelId];

try {
const response = await (await fetch('https://api.github.com/repos/immich-app/immich')).json();
interaction.reply(`Stars ⭐: ${response['stargazers_count']}`);
const starsCount = response['stargazers_count'] as number;
const delta = lastStarsCount && starsCount - lastStarsCount;
const formattedDelta = delta && Intl.NumberFormat(undefined, { signDisplay: 'always' }).format(delta);

interaction.reply(
`Stars ⭐: ${response['stargazers_count']}${
formattedDelta && ` (${formattedDelta} stars since the last call in this channel)`
}`,
);

_star_history[interaction.channelId] = starsCount;
} catch (error) {
interaction.reply("Couldn't fetch stars count from github api");
}
}

@Slash({ description: 'Immich forks' })
async forks(interaction: CommandInteraction) {
const lastForksCount = _fork_history[interaction.channelId];

try {
const response = await (await fetch('https://api.github.com/repos/immich-app/immich')).json();
interaction.reply(`Forks: ${response['forks_count']}`);
const forksCount = response['forks_count'] as number;
const delta = lastForksCount && forksCount - lastForksCount;
const formattedDelta = delta && Intl.NumberFormat(undefined, { signDisplay: 'always' }).format(delta);

interaction.reply(
`Forks: ${response['forks_count']}${
formattedDelta && ` (${formattedDelta} forks since the last call in this channel)`
}`,
);

_fork_history[interaction.channelId] = forksCount;
} catch (error) {
interaction.reply("Couldn't fetch forks count from github api");
}
Expand Down

0 comments on commit 71f85dd

Please sign in to comment.