Adds icons to group list and adds new playdate
This commit is contained in:
parent
2f826fbf36
commit
8ac59567b9
4 changed files with 55 additions and 6 deletions
1
public/icons/people-group-solid.svg
Normal file
1
public/icons/people-group-solid.svg
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 640 512"><!--!Font Awesome Free 6.7.2 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free Copyright 2025 Fonticons, Inc.--><path fill="#FFD43B" d="M72 88a56 56 0 1 1 112 0A56 56 0 1 1 72 88zM64 245.7C54 256.9 48 271.8 48 288s6 31.1 16 42.3l0-84.7zm144.4-49.3C178.7 222.7 160 261.2 160 304c0 34.3 12 65.8 32 90.5l0 21.5c0 17.7-14.3 32-32 32l-64 0c-17.7 0-32-14.3-32-32l0-26.8C26.2 371.2 0 332.7 0 288c0-61.9 50.1-112 112-112l32 0c24 0 46.2 7.5 64.4 20.3zM448 416l0-21.5c20-24.7 32-56.2 32-90.5c0-42.8-18.7-81.3-48.4-107.7C449.8 183.5 472 176 496 176l32 0c61.9 0 112 50.1 112 112c0 44.7-26.2 83.2-64 101.2l0 26.8c0 17.7-14.3 32-32 32l-64 0c-17.7 0-32-14.3-32-32zm8-328a56 56 0 1 1 112 0A56 56 0 1 1 456 88zM576 245.7l0 84.7c10-11.3 16-26.1 16-42.3s-6-31.1-16-42.3zM320 32a64 64 0 1 1 0 128 64 64 0 1 1 0-128zM240 304c0 16.2 6 31 16 42.3l0-84.7c-10 11.3-16 26.1-16 42.3zm144-42.3l0 84.7c10-11.3 16-26.1 16-42.3s-6-31.1-16-42.3zM448 304c0 44.7-26.2 83.2-64 101.2l0 42.8c0 17.7-14.3 32-32 32l-64 0c-17.7 0-32-14.3-32-32l0-42.8c-37.8-18-64-56.5-64-101.2c0-61.9 50.1-112 112-112l32 0c61.9 0 112 50.1 112 112z"/></svg>
|
||||||
|
After Width: | Height: | Size: 1.2 KiB |
|
|
@ -3,7 +3,13 @@ import {
|
||||||
Interaction,
|
Interaction,
|
||||||
CommandInteraction,
|
CommandInteraction,
|
||||||
ChatInputCommandInteraction,
|
ChatInputCommandInteraction,
|
||||||
MessageFlags, GuildMemberRoleManager, InteractionReplyOptions, GuildMember, EmbedBuilder, AutocompleteInteraction
|
MessageFlags,
|
||||||
|
GuildMemberRoleManager,
|
||||||
|
InteractionReplyOptions,
|
||||||
|
GuildMember,
|
||||||
|
EmbedBuilder,
|
||||||
|
AutocompleteInteraction,
|
||||||
|
formatEmoji, roleMention, time
|
||||||
} from "discord.js";
|
} from "discord.js";
|
||||||
import {AutocompleteCommand, ChatInteractionCommand, Command} from "./Command";
|
import {AutocompleteCommand, ChatInteractionCommand, Command} from "./Command";
|
||||||
import {GroupModel} from "../../Models/GroupModel";
|
import {GroupModel} from "../../Models/GroupModel";
|
||||||
|
|
@ -17,6 +23,9 @@ import {GroupConfigurationRenderer} from "../../Groups/GroupConfigurationRendere
|
||||||
import {GroupConfigurationHandler} from "../../Groups/GroupConfigurationHandler";
|
import {GroupConfigurationHandler} from "../../Groups/GroupConfigurationHandler";
|
||||||
import {GroupConfigurationTransformers} from "../../Groups/GroupConfigurationTransformers";
|
import {GroupConfigurationTransformers} from "../../Groups/GroupConfigurationTransformers";
|
||||||
import {GroupConfigurationRepository} from "../../Repositories/GroupConfigurationRepository";
|
import {GroupConfigurationRepository} from "../../Repositories/GroupConfigurationRepository";
|
||||||
|
import {IconCache} from "../../Icons/IconCache";
|
||||||
|
import {PlaydateRepository} from "../../Repositories/PlaydateRepository";
|
||||||
|
import playdate from "../../Database/tables/Playdate";
|
||||||
|
|
||||||
export class GroupCommand implements Command, ChatInteractionCommand, AutocompleteCommand {
|
export class GroupCommand implements Command, ChatInteractionCommand, AutocompleteCommand {
|
||||||
private static GOODBYE_MESSAGES: string[] = [
|
private static GOODBYE_MESSAGES: string[] = [
|
||||||
|
|
@ -109,15 +118,29 @@ export class GroupCommand implements Command, ChatInteractionCommand, Autocomple
|
||||||
const repo = Container.get<GroupRepository>(GroupRepository.name);
|
const repo = Container.get<GroupRepository>(GroupRepository.name);
|
||||||
const groups = repo.findGroupsByMember(<GuildMember>interaction.member);
|
const groups = repo.findGroupsByMember(<GuildMember>interaction.member);
|
||||||
|
|
||||||
|
const playdateRepo = Container.get<PlaydateRepository>(PlaydateRepository.name);
|
||||||
|
|
||||||
|
const iconCache = Container.get<IconCache>(IconCache.name);
|
||||||
|
|
||||||
const embed = new EmbedBuilder()
|
const embed = new EmbedBuilder()
|
||||||
.setTitle("Your groups on this server:")
|
.setTitle("Your groups on this server:")
|
||||||
.setFields(
|
.setFields(
|
||||||
groups.map(group => {
|
groups.map(group => {
|
||||||
|
const nextPlaydate = playdateRepo.getNextPlaydateForGroup(group);
|
||||||
|
|
||||||
|
const values = [
|
||||||
|
`${iconCache.getEmoji("people_group_solid")} ${roleMention(group.role.roleid)}`
|
||||||
|
];
|
||||||
|
|
||||||
|
if (nextPlaydate) {
|
||||||
|
values.push(
|
||||||
|
`${iconCache.getEmoji("calendar_days_solid")} ${time(nextPlaydate.from_time, "F")}`
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
name: group.name,
|
name: group.name,
|
||||||
value: `
|
value: values.join("\n")
|
||||||
Role: <@&${group.role.roleid}>
|
|
||||||
`
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
import {Routes} from "discord.js";
|
import {formatEmoji, Routes, Snowflake} from "discord.js";
|
||||||
import {DiscordClient} from "../Discord/DiscordClient";
|
import {DiscordClient} from "../Discord/DiscordClient";
|
||||||
|
|
||||||
export class IconCache {
|
export class IconCache {
|
||||||
|
|
@ -10,7 +10,7 @@ export class IconCache {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public get(iconName: string): string | null {
|
public get(iconName: string): Snowflake | null {
|
||||||
if (!this.existingIcons?.has(iconName)) {
|
if (!this.existingIcons?.has(iconName)) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
@ -18,6 +18,15 @@ export class IconCache {
|
||||||
return this.existingIcons?.get(iconName) ?? null;
|
return this.existingIcons?.get(iconName) ?? null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public getEmoji(iconName: string): string {
|
||||||
|
const id = this.get(iconName);
|
||||||
|
|
||||||
|
return formatEmoji({
|
||||||
|
id: id,
|
||||||
|
name: iconName
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
public async set(iconName: string, pngBuffer: Buffer) {
|
public async set(iconName: string, pngBuffer: Buffer) {
|
||||||
const pngBase64 = pngBuffer.toString("base64");
|
const pngBase64 = pngBuffer.toString("base64");
|
||||||
const iconDataUrl = `data:image/png;base64,${pngBase64}`;
|
const iconDataUrl = `data:image/png;base64,${pngBase64}`;
|
||||||
|
|
|
||||||
|
|
@ -58,6 +58,22 @@ export class PlaydateRepository extends Repository<PlaydateModel, DBPlaydate> {
|
||||||
return finds.map((playdate) => this.convertToModelType(playdate, group));
|
return finds.map((playdate) => this.convertToModelType(playdate, group));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
getNextPlaydateForGroup(group: GroupModel): PlaydateModel | null {
|
||||||
|
let sql = `SELECT * FROM ${this.schema.name} WHERE groupid = ? AND time_from > ? ORDER BY time_from ASC LIMIT 1`;
|
||||||
|
|
||||||
|
const find = this.database.fetch<number, DBPlaydate>(
|
||||||
|
sql,
|
||||||
|
group.id,
|
||||||
|
Date.now()
|
||||||
|
)
|
||||||
|
|
||||||
|
if (!find) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return this.convertToModelType(find, group)
|
||||||
|
}
|
||||||
|
|
||||||
protected convertToModelType(intermediateModel: DBPlaydate | undefined, fixedGroup: Nullable<GroupModel> = null): PlaydateModel {
|
protected convertToModelType(intermediateModel: DBPlaydate | undefined, fixedGroup: Nullable<GroupModel> = null): PlaydateModel {
|
||||||
if (!intermediateModel) {
|
if (!intermediateModel) {
|
||||||
throw new Error("Unable to convert the playdate model");
|
throw new Error("Unable to convert the playdate model");
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue