Skip to content

Commit

Permalink
feat: upgrade file structure (#525)
Browse files Browse the repository at this point in the history
* feat: upgrade file structure

* Update package.json
  • Loading branch information
Ruffpuff1 committed Apr 22, 2022
1 parent 49d7bb5 commit 2de8310
Show file tree
Hide file tree
Showing 86 changed files with 409 additions and 452 deletions.
8 changes: 4 additions & 4 deletions .github/labeler.yml
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,12 @@
- packages/types/**/*

'GraphQL: stardrop':
- graphql/stardrop/*
- graphql/stardrop/**/*
- api/stardrop/*
- api/stardrop/**/*

'Docker Images: ravy.lgbt':
- docker/ravy.lgbt/*
- docker/ravy.lgbt/**/*
- third_party/ravy.lgbt/*
- third_party/ravy.lgbt/**/*

'I18n: en-US':
- apps/foxxie/src/languages/en-US/*
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/ravy-lgbt-deployment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ on:
branches:
- main
paths:
- 'docker/ravy.lgbt/**'
- 'third_party/ravy.lgbt/**'
- '.github/workflows/ravy-lgbt-deployment.yml'
workflow_dispatch:

Expand Down Expand Up @@ -34,7 +34,7 @@ jobs:
uses: docker/build-push-action@ac9327eae2b366085ac7f6a2d02df8aa8ead720a # tag=v2.10.0
with:
push: true
context: ./docker/ravy.lgbt
context: ./third_party/ravy.lgbt
tags: |
ruffpuff/ravy.lgbt:latest
ghcr.io/ruffpuff1/ravy.lgbt:latest
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/stardrop-deployment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ on:
branches:
- main
paths:
- 'graphql/stardrop/src/**'
- 'graphql/stardrop/Dockerfile'
- 'api/stardrop/src/**'
- 'api/stardrop/Dockerfile'
- '.github/workflows/stardrop-deployment.yml'
- 'graphql/stardrop/package.json'
- 'api/stardrop/package.json'
workflow_dispatch:

jobs:
Expand Down Expand Up @@ -36,7 +36,7 @@ jobs:
uses: docker/build-push-action@ac9327eae2b366085ac7f6a2d02df8aa8ead720a # tag=v2.10.0
with:
push: true
context: ./graphql/stardrop
context: ./api/stardrop
tags: |
ruffpuff/stardrop:latest
ghcr.io/ruffpuff1/stardrop:latest
Expand Down
Empty file added api/README.md
Empty file.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion apps/foxxie/src/commands/Misc/reminder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export class UserCommand extends FoxxieCommand {
});
const repeat = await args.pick('timespan', { minimum: minutes(1), maximum: years(1) }).catch(() => null);
const channel = await args.pick('guildTextChannel').catch(() => null);
const content = await args.rest('string') ?? args.t(LanguageKeys.Commands.Misc.ReminderDefault);
const content = (await args.rest('string')) ?? args.t(LanguageKeys.Commands.Misc.ReminderDefault);

let json: ReturnType<MessageEmbed['toJSON']> | null = null;
try {
Expand Down
2 changes: 1 addition & 1 deletion apps/foxxie/src/commands/Social/Leveling/level.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ export class UserCommand extends SocialCommand {
const nextLevel = xpNeeded(level + 1);

const diff = nextLevel - points;
const progressBar = Math.max(Math.round(points / nextLevel * 296), 10);
const progressBar = Math.max(Math.round((points / nextLevel) * 296), 10);
const position = await this.getPosition(member);

return new Canvas(640, 174)
Expand Down
2 changes: 1 addition & 1 deletion apps/foxxie/src/commands/Social/reputation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export class UserCommand extends SocialCommand {
return send(msg, content);
}

const reset = previously.length >= 3 || timeReputation && timeReputation + days(1) < Date.now();
const reset = previously.length >= 3 || (timeReputation && timeReputation + days(1) < Date.now());

if (reset) author.cooldown.reputation.users = [];
if (author.cooldown.reputation.users.includes(user.id)) this.error(LanguageKeys.Commands.Social.ReputationAlreadyExists, { user: user.tag });
Expand Down
12 changes: 6 additions & 6 deletions apps/foxxie/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,12 @@ export function getDurationOptions(lng: string): DurationFormatAssetsTime {
}

export function channelList(value: Collection<string, GuildChannel>, t: TFunction): string {
const textSize = value.reduce((acc, itm) => acc += itm.type === 'GUILD_TEXT' ? 1 : 0, 0);
const stageSize = value.reduce((acc, itm) => acc += itm.type === 'GUILD_STAGE_VOICE' ? 1 : 0, 0);
const storeSize = value.reduce((acc, itm) => acc += itm.type === 'GUILD_STORE' ? 1 : 0, 0);
const newsSize = value.reduce((acc, itm) => acc += itm.type === 'GUILD_NEWS' ? 1 : 0, 0);
const voiceSize = value.reduce((acc, itm) => acc += itm.type === 'GUILD_VOICE' ? 1 : 0, 0);
const pubThreadSize = value.reduce((acc, itm) => acc += itm.type === 'GUILD_PUBLIC_THREAD' ? 1 : 0, 0);
const textSize = value.reduce((acc, itm) => (acc += itm.type === 'GUILD_TEXT' ? 1 : 0), 0);
const stageSize = value.reduce((acc, itm) => (acc += itm.type === 'GUILD_STAGE_VOICE' ? 1 : 0), 0);
const storeSize = value.reduce((acc, itm) => (acc += itm.type === 'GUILD_STORE' ? 1 : 0), 0);
const newsSize = value.reduce((acc, itm) => (acc += itm.type === 'GUILD_NEWS' ? 1 : 0), 0);
const voiceSize = value.reduce((acc, itm) => (acc += itm.type === 'GUILD_VOICE' ? 1 : 0), 0);
const pubThreadSize = value.reduce((acc, itm) => (acc += itm.type === 'GUILD_PUBLIC_THREAD' ? 1 : 0), 0);

return (
[
Expand Down
23 changes: 2 additions & 21 deletions apps/foxxie/src/lib/database/config.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,7 @@
import 'reflect-metadata';
import { createConnection } from 'typeorm';
import { container } from '@sapphire/framework';
import {
GuildEntity,
ClientEntity,
MemberEntity,
NoteEntity,
StarEntity,
UserEntity,
ScamEntity,
CommandEntity
} from './entities';
import { GuildEntity, ClientEntity, MemberEntity, NoteEntity, StarEntity, UserEntity, ScamEntity, CommandEntity } from './entities';
import { BackgroundEntity } from './entities/BackgroundEntity';
import { MongoDB } from './MongoDB';

Expand All @@ -22,17 +13,7 @@ export async function config(): Promise<void> {
port: 3306,
username: process.env.MONGO_USER,
password: process.env.MONGO_PASSWORD,
entities: [
BackgroundEntity,
CommandEntity,
ClientEntity,
GuildEntity,
MemberEntity,
NoteEntity,
ScamEntity,
StarEntity,
UserEntity
],
entities: [BackgroundEntity, CommandEntity, ClientEntity, GuildEntity, MemberEntity, NoteEntity, ScamEntity, StarEntity, UserEntity],
authSource: 'admin',
useNewUrlParser: true,
useUnifiedTopology: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ export class GuildSettingsManager<T extends GuildEntity> extends Collection<stri
const lock = this.locks.acquire(key);
try {
await lock.readLock();
const settings = this.get(key) ?? await this.processFetch(key);
const settings = this.get(key) ?? (await this.processFetch(key));

if (!list) return settings;

Expand Down Expand Up @@ -144,7 +144,7 @@ export class GuildSettingsManager<T extends GuildEntity> extends Collection<stri
const lock = this.locks.acquire(key);

await lock.writeLock();
const found = this.get(key) || await this.unlockOnThrow(this.processFetch(key), lock);
const found = this.get(key) || (await this.unlockOnThrow(this.processFetch(key), lock));

try {
if (typeof changes === 'function') {
Expand Down
6 changes: 3 additions & 3 deletions apps/foxxie/src/lib/database/structures/Serializer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ export abstract class Serializer<T> extends AliasPiece {
// eslint-disable-next-line complexity
protected minOrMax(value: T, length: number, { entry: { minimum, maximum, inclusive, name }, t }: SerializerUpdateContext): SerializerResult<T> {
if (minimum !== null && maximum !== null) {
if (length >= minimum && length <= maximum && inclusive || length > minimum && length < maximum && !inclusive) {
if ((length >= minimum && length <= maximum && inclusive) || (length > minimum && length < maximum && !inclusive)) {
return this.ok(value);
}

Expand All @@ -130,7 +130,7 @@ export abstract class Serializer<T> extends AliasPiece {
}

if (minimum !== null) {
if (length >= minimum && inclusive || length > minimum && !inclusive) {
if ((length >= minimum && inclusive) || (length > minimum && !inclusive)) {
return this.ok(value);
}

Expand All @@ -143,7 +143,7 @@ export abstract class Serializer<T> extends AliasPiece {
}

if (maximum !== null) {
if (length <= maximum && inclusive || length < maximum && !inclusive) {
if ((length <= maximum && inclusive) || (length < maximum && !inclusive)) {
return this.ok(value);
}

Expand Down
4 changes: 2 additions & 2 deletions apps/foxxie/src/lib/database/transformers.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { ValueTransformer } from 'typeorm';

export const kBigIntTransformer: ValueTransformer = {
from: value => value ? Number(value) : value,
to: value => value ? String(value) : value
from: value => (value ? Number(value) : value),
to: value => (value ? String(value) : value)
};
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export class ModerationCommand extends FoxxieCommand {
const modRolePosition = mod?.roles.highest.position;

// A member who isn't a server owner is not allowed to moderate somebody with higher role than them:
if (!mod || !modRolePosition || !isGuildOwner(mod) && targetRolePos >= modRolePosition) {
if (!mod || !modRolePosition || (!isGuildOwner(mod) && targetRolePos >= modRolePosition)) {
throw context.t(LanguageKeys.Listeners.Errors.ModerationRole, { target: `**${context.target.tag}**` });
}
}
Expand Down
2 changes: 1 addition & 1 deletion apps/foxxie/src/lib/structures/workers/WorkerHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ export class WorkerHandler {

private generateId() {
if (this.id === WorkerHandler.maximumId) {
return this.id = 0;
return (this.id = 0);
}

return this.id++;
Expand Down
2 changes: 1 addition & 1 deletion apps/foxxie/src/lib/structures/workers/WorkerManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,6 @@ export class WorkerManager {
}

private getWorker() {
return this.workers.reduce((best, worker) => best.remaining > worker.remaining ? worker : best);
return this.workers.reduce((best, worker) => (best.remaining > worker.remaining ? worker : best));
}
}
16 changes: 8 additions & 8 deletions apps/foxxie/src/lib/util/API/foxxie.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ export async function fetchApiUserButFallbackToMock(userId: string): Promise<Use
github: null
},
whitelisted: false
}
};
}

throw err;
Expand All @@ -110,19 +110,19 @@ interface UserCb<T extends User, R> {
(model: T): Promise<R> | R;
}

export async function fetchUserProps<K>(userId: string, cb: UserCb<User, K>): Promise<K>
export async function fetchUserProps<K1 extends A, K2 extends A>(userId: string, keys: [K1, K2]): Promise<[User[K1], User[K2]]>
export async function fetchUserProps<K extends A>(userId: string, keys: K): Promise<User[K]>
export async function fetchUserProps<K>(userId: string, cb: UserCb<User, K>): Promise<K>;
export async function fetchUserProps<K1 extends A, K2 extends A>(userId: string, keys: [K1, K2]): Promise<[User[K1], User[K2]]>;
export async function fetchUserProps<K extends A>(userId: string, keys: K): Promise<User[K]>;
export async function fetchUserProps<K>(userId: string, keys: A | [A, A] | UserCb<User, K>) {
const user = await fetchApiUserButFallbackToMock(userId);

if (Array.isArray(keys)) {
return keys.map(k => user[k]);
} else if (typeof keys === 'function') {
return keys(user)
} else {
return user[keys]
}
return keys(user);
}
return user[keys];

}

export async function postApiBan(data: RESTPostAPIUsersUserBansJSONBody): Promise<Endpoints[EndpointsEnum.PostUsersUserBans]> {
Expand Down
2 changes: 1 addition & 1 deletion apps/foxxie/src/lib/util/API/spotify.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ export async function getPlaylistTracks(content: string): Promise<null | string[

const mapped = data.tracks.items.map(song => {
const { track } = song;
return `${track.name} - ${track.artists[0].name}`;
return `${track?.name} - ${track?.artists[0].name}`;
});

if (redis) {
Expand Down
2 changes: 1 addition & 1 deletion apps/foxxie/src/lib/util/birthday.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ export function getFormatted({ month, day }: BirthdayData): string {
}

export function yearIsLeap(year: BirthdayData['year']): boolean {
return (year as number) % 4 === 0 && (year as number) % 100 !== 0 || (year as number) % 400 === 0;
return ((year as number) % 4 === 0 && (year as number) % 100 !== 0) || (year as number) % 400 === 0;
}

export function getDuration({ month, day }: BirthdayData): string {
Expand Down
2 changes: 1 addition & 1 deletion apps/foxxie/src/lib/util/decorators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import type { LocaleString } from 'discord-api-types/v10';

export function RequireLevelingEnabled(): MethodDecorator {
return createFunctionPrecondition(
(message: GuildMessage) => message.guild ? acquireSettings(message.guild, GuildSettings.Leveling.Enabled) : true,
(message: GuildMessage) => (message.guild ? acquireSettings(message.guild, GuildSettings.Leveling.Enabled) : true),
(message: GuildMessage) => sendLocalizedMessage(message, LanguageKeys.Preconditions.Leveling)
);
}
Expand Down
2 changes: 1 addition & 1 deletion apps/foxxie/src/lib/util/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ export function getServerDetails(): ServerDetails {
return {
totalmemory,
memoryUsed,
memoryPercent: (parseInt(memoryUsed, 10) / parseInt(totalmemory, 10) * 100).toFixed(1),
memoryPercent: ((parseInt(memoryUsed, 10) / parseInt(totalmemory, 10)) * 100).toFixed(1),
process: hostname(),
cpuCount: cpus().length,
cpuUsage: (loadavg()[0] * 10).toFixed(1),
Expand Down
4 changes: 2 additions & 2 deletions apps/foxxie/src/listeners/Analytics/analyticsSocial.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ export class UserListener extends AnalyticsListener<Events.AnalyticsPostStats> {
const combined = members.concat(users as unknown as MemberEntity);

return {
points: combined.reduce((acc, d) => d.points += acc, 0),
rep: users.reduce((acc, d) => d.reputation += acc, 0),
points: combined.reduce((acc, d) => (d.points += acc), 0),
rep: users.reduce((acc, d) => (d.reputation += acc), 0),
stars: await this.container.db.starboards.find().then(s => s.length)
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import type { TFunction } from '@foxxie/i18n';
})
export class UserListener extends Listener<Events.GuildMessageDeleteLog> {
public async run(...[msg]: EventArgs<Events.GuildMessageDeleteLog>): Promise<void> {
if (msg.partial || !msg.guild || !msg.guild.available || msg.author!.bot || !msg.content && !msg.attachments.size) return;
if (msg.partial || !msg.guild || !msg.guild.available || msg.author!.bot || (!msg.content && !msg.attachments.size)) return;

const [ignoredChannels, t] = await this.container.prisma.guilds(msg.guild.id, settings => [settings[GuildSettings.Channels.IgnoreAll], settings.getLanguage()]);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export class UserListener extends Listener<Events.UserMessage> {
// don't run on edits.
if (msg.editedAt) return;

if (!await this.isEnabled(msg)) return;
if (!(await this.isEnabled(msg))) return;
if (Date.now() - msg.member.joinedTimestamp! < minutes(5)) return;
if (this.isRatelimited(msg.author.id)) return;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ export class UserListener extends Listener<Events.PointsReward> {
const settings = await this.getLevelSettings(msg.guild);
if (!settings.announce) return;

const isSent = this.container.redis ? await this.container.redis.get(this.getKey(msg)) === '1' : false;
const isSent = this.container.redis ? (await this.container.redis.get(this.getKey(msg))) === '1' : false;

if (!isSent) {
const content = this.getLevelContent(settings.t, msg.member, level);
Expand Down
4 changes: 2 additions & 2 deletions apps/foxxie/src/listeners/Guilds/Messages/boostMessage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ export class UserListener extends AutomationListener<Events.SystemMessage> {
await this.sendMessage(msg, channel);
}

protected nextTier = (guild: Guild) => guild.premiumTier === 'NONE' ? 1 : guild.premiumTier === 'TIER_1' ? 2 : guild.premiumTier === 'TIER_2' ? 3 : 3;
protected nextTier = (guild: Guild) => (guild.premiumTier === 'NONE' ? 1 : guild.premiumTier === 'TIER_1' ? 2 : guild.premiumTier === 'TIER_2' ? 3 : 3);

protected tierBoostCount = (guild: Guild) => guild.premiumTier === 'NONE' ? 2 : guild.premiumTier === 'TIER_1' ? 7 : guild.premiumTier === 'TIER_2' ? 14 : 14;
protected tierBoostCount = (guild: Guild) => (guild.premiumTier === 'NONE' ? 2 : guild.premiumTier === 'TIER_1' ? 7 : guild.premiumTier === 'TIER_2' ? 14 : 14);

protected format(message: string, member: GuildMember, t: TFunction) {
const replaced = message.replace(this.boostMatchRegex, match => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export class UserListener extends Listener<Events.UserMessage> {

const previousChannelMessages = [];
if (msg.channel.permissionsFor(msg.guild.me!).has(PermissionFlagsBits.ReadMessageHistory)) {
previousChannelMessages.push(...await this.fetchMessages(msg, t));
previousChannelMessages.push(...(await this.fetchMessages(msg, t)));
}

for (const match of wordResults.results) {
Expand Down
2 changes: 1 addition & 1 deletion apps/foxxie/src/listeners/Guilds/Messages/statsMessage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export class UserListener extends Listener<Events.StatsMessage> {
}

private async countGuild(guildId: string): Promise<void> {
await writeSettings(guildId, (settings: GuildEntity) => settings[GuildSettings.MessageCount] += 1);
await writeSettings(guildId, (settings: GuildEntity) => (settings[GuildSettings.MessageCount] += 1));
}

private async countMember(member: GuildMember, guildId: string): Promise<void> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ export class UserListener extends ModerationListener {
}

private async validLink(msg: GuildMessage, code: string, url: string) {
return await this.allowedLink(msg, code) ? null : url;
return (await this.allowedLink(msg, code)) ? null : url;
}

private async allowedLink(msg: GuildMessage, code: string) {
Expand Down
4 changes: 2 additions & 2 deletions apps/foxxie/src/scheduled-tasks/Cron/updateClockChannel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ export class UserTask extends ScheduledTask {
} catch (error) {
if (!(error instanceof DiscordAPIError)) return;
if (error.code === RESTJSONErrorCodes.UnknownChannel) {
await writeSettings(guild, settings => settings.clockChannel = null);
await writeSettings(guild, settings => (settings.clockChannel = null));
}
}
}
Expand All @@ -95,7 +95,7 @@ export class UserTask extends ScheduledTask {
}

private getSceneEmoji(sign: string, parsedHour: number, parsedMin: number) {
const isAfterSunset = parsedHour > 5 && sign === 'pm' || sign === 'am' && (parsedHour < 5 || parsedHour === 12);
const isAfterSunset = (parsedHour > 5 && sign === 'pm') || (sign === 'am' && (parsedHour < 5 || parsedHour === 12));
const isSunSet = parsedHour === 5 && parsedMin < 30;
const isDusk = parsedHour === 5 && parsedMin >= 30;
const isTop = parsedHour === 12 && sign === 'am';
Expand Down
2 changes: 1 addition & 1 deletion apps/foxxie/src/scheduled-tasks/disboard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export class UserTask extends ScheduledTask {
await channel.send({ content: message || base || null, embeds });
} catch (error) {
if (!(error instanceof DiscordAPIError)) return;

if (error.code === RESTJSONErrorCodes.UnknownChannel) {
await this.container.prisma.guilds(guild.id, {
[GuildSettings.Channels.Disboard]: null
Expand Down

0 comments on commit 2de8310

Please sign in to comment.