Skip to content

Commit

Permalink
Add badges to redis
Browse files Browse the repository at this point in the history
  • Loading branch information
gc committed Jul 13, 2024
1 parent 240b07b commit 72f5998
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 6 deletions.
10 changes: 8 additions & 2 deletions dist/TSRedis.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ declare const messageSchema: z.ZodUnion<[z.ZodObject<{
channel: z.ZodEnum<["main"]>;
}, "strip", z.ZodTypeAny, {
type: "text";
text: string;
channel: "main";
text: string;
}, {
type: "text";
text: string;
channel: "main";
text: string;
}>, z.ZodObject<{
type: z.ZodLiteral<"ping">;
channel: z.ZodEnum<["main"]>;
Expand All @@ -28,12 +28,18 @@ type Channel = z.infer<typeof channels>;
declare const userSchema: z.ZodObject<{
username: z.ZodNullable<z.ZodString>;
perk_tier: z.ZodNullable<z.ZodNumber>;
osb_badges: z.ZodNullable<z.ZodString>;
bso_badges: z.ZodNullable<z.ZodString>;
}, "strip", z.ZodTypeAny, {
username: string | null;
perk_tier: number | null;
osb_badges: string | null;
bso_badges: string | null;
}, {
username: string | null;
perk_tier: number | null;
osb_badges: string | null;
bso_badges: string | null;
}>;
type RedisUser = z.infer<typeof userSchema>;
export declare class TSRedis {
Expand Down
16 changes: 14 additions & 2 deletions dist/TSRedis.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 16 additions & 2 deletions src/TSRedis.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
import { escapeMarkdown } from 'discord.js';
import Redis, { type RedisOptions } from 'ioredis';
import MockRedis from 'ioredis-mock';
import { z } from 'zod';

import { stripEmojis } from './util/misc';

function cleanUsername(username: string) {
return escapeMarkdown(stripEmojis(username)).substring(0, 32);
}

const channels = z.enum(['main']);

const patronUpdateMessageSchema = z.object({
Expand All @@ -22,7 +29,9 @@ type Channel = z.infer<typeof channels>;

const userSchema = z.object({
username: z.string().nullable(),
perk_tier: z.number().nullable()
perk_tier: z.number().nullable(),
osb_badges: z.string().nullable(),
bso_badges: z.string().nullable()
});

type RedisUser = z.infer<typeof userSchema>;
Expand Down Expand Up @@ -74,6 +83,9 @@ export class TSRedis {
}

async setUser(userID: string, changes: Partial<RedisUser>) {
if (changes.username) {
changes.username = cleanUsername(changes.username);
}
return this.redis.hset(this.getUserHash(userID), changes);
}

Expand All @@ -82,7 +94,9 @@ export class TSRedis {

return {
username: user.username ?? null,
perk_tier: user.perk_tier ? Number.parseInt(user.perk_tier) : null
perk_tier: user.perk_tier ? Number.parseInt(user.perk_tier) : null,
osb_badges: user.osb_badges ?? null,
bso_badges: user.bso_badges ?? null
};
}
}

0 comments on commit 72f5998

Please sign in to comment.