refactor: conform to linting rules

This commit is contained in:
Paul Makles
2023-04-14 20:28:18 +01:00
parent a6e27ea151
commit 733358266a
20 changed files with 79 additions and 28 deletions
+1 -1
View File
@@ -17,7 +17,7 @@
"strings": false,
"identifiers": false,
"templates": false,
"skipWords": ["uri"],
"skipWords": ["uri", "webhook", "unreads"],
"minLength": 3
}
],
+1 -1
View File
@@ -1,7 +1,7 @@
import { Accessor, Setter, createSignal } from "solid-js";
import EventEmitter from "eventemitter3";
import { API, DataCreateAccount, Metadata, Role } from "revolt-api";
import { API, DataCreateAccount, Role } from "revolt-api";
import type { DataLogin, RevoltConfig } from "revolt-api";
import { Channel, Emoji, Message, Server, ServerMember, User } from "./classes";
+7
View File
@@ -32,6 +32,10 @@ export class Channel {
this.id = id;
}
/**
* Write to string as a channel mention
* @returns Formatted String
*/
toString() {
return `<#${this.id}>`;
}
@@ -594,6 +598,9 @@ export class Channel {
}
}
/**
* Send the actual acknowledgement request
*/
const performAck = () => {
this.#ackLimit = undefined;
this.#collection.client.api.put(
+1 -1
View File
@@ -85,7 +85,7 @@ export class File {
}
/**
* Whether this file should be spoilered
* Whether this file should have a spoiler
*/
get isSpoiler() {
return this.filename.toLowerCase().startsWith("spoiler_");
+1 -1
View File
@@ -322,7 +322,7 @@ export class Server {
* @returns The newly-created channel
*/
async createChannel(data: DataCreateChannel) {
let channel = await this.#collection.client.api.post(
const channel = await this.#collection.client.api.post(
`/servers/${this.id as ""}/channels`,
data
);
-1
View File
@@ -1,6 +1,5 @@
import type {
DataBanCreate,
DataEditMessage,
DataMemberEdit,
MemberCompositeKey,
} from "revolt-api";
+30
View File
@@ -57,6 +57,11 @@ export abstract class SystemMessage {
export class TextSystemMessage extends SystemMessage {
readonly content: string;
/**
* Construct System Message
* @param client Client
* @param systemMessage System Message
*/
constructor(
client: Client,
systemMessage: API.SystemMessage & { type: "text" }
@@ -72,6 +77,11 @@ export class TextSystemMessage extends SystemMessage {
export class UserSystemMessage extends SystemMessage {
readonly userId: string;
/**
* Construct System Message
* @param client Client
* @param systemMessage System Message
*/
constructor(
client: Client,
systemMessage: API.SystemMessage & {
@@ -102,6 +112,11 @@ export class UserSystemMessage extends SystemMessage {
export class UserModeratedSystemMessage extends UserSystemMessage {
readonly byId: string;
/**
* Construct System Message
* @param client Client
* @param systemMessage System Message
*/
constructor(
client: Client,
systemMessage: API.SystemMessage & {
@@ -127,6 +142,11 @@ export class UserModeratedSystemMessage extends UserSystemMessage {
export class ChannelEditSystemMessage extends SystemMessage {
readonly byId: string;
/**
* Construct System Message
* @param client Client
* @param systemMessage System Message
*/
constructor(
client: Client,
systemMessage: API.SystemMessage & {
@@ -154,6 +174,11 @@ export class ChannelEditSystemMessage extends SystemMessage {
export class ChannelRenamedSystemMessage extends ChannelEditSystemMessage {
readonly name: string;
/**
* Construct System Message
* @param client Client
* @param systemMessage System Message
*/
constructor(
client: Client,
systemMessage: API.SystemMessage & {
@@ -172,6 +197,11 @@ export class ChannelOwnershipChangeSystemMessage extends SystemMessage {
readonly fromId: string;
readonly toId: string;
/**
* Construct System Message
* @param client Client
* @param systemMessage System Message
*/
constructor(
client: Client,
systemMessage: API.SystemMessage & {
+2 -2
View File
@@ -22,8 +22,8 @@ export class User {
}
/**
* Convert to string
* @returns String
* Write to string as a user mention
* @returns Formatted String
*/
toString() {
return `<@${this.id}>`;
+3
View File
@@ -5,6 +5,9 @@ import { HydratedBot } from "../hydration/bot";
import { ClassCollection } from ".";
/**
* Collection of Bots
*/
export class BotCollection extends ClassCollection<Bot, HydratedBot> {
/**
* Fetch bot by ID
+4 -1
View File
@@ -3,6 +3,9 @@ import { HydratedChannel } from "../hydration";
import { ClassCollection } from ".";
/**
* Collection of Channels
*/
export class ChannelCollection extends ClassCollection<
Channel,
HydratedChannel
@@ -12,7 +15,7 @@ export class ChannelCollection extends ClassCollection<
* @param id Id
*/
override delete(id: string): void {
let channel = this.get(id);
const channel = this.get(id);
channel?.server?.channelIds.delete(id);
super.delete(id);
}
@@ -4,6 +4,9 @@ import { HydratedChannelUnread } from "../hydration";
import { ClassCollection } from ".";
/**
* Collection of Channel Unreads
*/
export class ChannelUnreadCollection extends ClassCollection<
ChannelUnread,
HydratedChannelUnread
+5 -1
View File
@@ -168,7 +168,7 @@ export abstract class StoreCollection<T, V> extends Collection<T> {
id: string,
type: keyof Hydrators,
instance: T,
context: any,
context: unknown,
data?: unknown
) {
this.#storage.hydrate(id, type, context, data);
@@ -232,6 +232,10 @@ export abstract class StoreCollection<T, V> extends Collection<T> {
export class ClassCollection<T, V> extends StoreCollection<T, V> {
readonly client: Client;
/**
* Create generic class collection
* @param client Client
*/
constructor(client: Client) {
super();
this.client = client;
+3
View File
@@ -3,6 +3,9 @@ import { HydratedEmoji } from "../hydration";
import { ClassCollection } from ".";
/**
* Collection of Emoji
*/
export class EmojiCollection extends ClassCollection<Emoji, HydratedEmoji> {
/**
* Fetch emoji by ID
+3
View File
@@ -3,6 +3,9 @@ import { HydratedMessage } from "../hydration";
import { ClassCollection } from ".";
/**
* Collection of Messages
*/
export class MessageCollection extends ClassCollection<
Message,
HydratedMessage
+3
View File
@@ -5,6 +5,9 @@ import { HydratedServer } from "../hydration";
import { ClassCollection } from ".";
/**
* Collection of Servers
*/
export class ServerCollection extends ClassCollection<Server, HydratedServer> {
/**
* Fetch server by ID
@@ -3,6 +3,9 @@ import { HydratedServerMember } from "../hydration";
import { ClassCollection } from ".";
/**
* Collection of Server Members
*/
export class ServerMemberCollection extends ClassCollection<
ServerMember,
HydratedServerMember
+3
View File
@@ -3,6 +3,9 @@ import { HydratedUser } from "../hydration";
import { ClassCollection } from ".";
/**
* Collection of Users
*/
export class UserCollection extends ClassCollection<User, HydratedUser> {
/**
* Fetch user by ID
+2 -15
View File
@@ -247,7 +247,7 @@ export async function handleEvent(
// TODO: this should not be necessary in future protocols:
if (event.author && client.options.eagerFetching) {
await client.users.fetch(event.author);
let serverId = client.channels.get(event.channel)?.serverId;
const serverId = client.channels.get(event.channel)?.serverId;
if (serverId)
await client.serverMembers.fetch(serverId, event.author);
}
@@ -772,20 +772,7 @@ export async function handleEvent(
break;
}
case "Auth": {
/*if (typeof client.#session === "string") throw "Unreachable code";
switch (event.event_type) {
case "DeleteSession":
if (event.session_id === client.#session!._id) {
// TODO: logout
}
break;
case "DeleteAllSessions":
if (event.exclude_session_id !== client.#session!._id) {
// TODO: logout
}
break;
}*/
// TODO: implement DeleteSession and DeleteAllSessions
break;
}
}
+3 -3
View File
@@ -25,7 +25,7 @@ export type { HydratedUser } from "./user";
*/
export type MappingFns<Input, Output, Key extends keyof Output> = Record<
Key,
(value: Input, context: any) => Output[Key]
(value: Input, context: unknown) => Output[Key]
>;
/**
@@ -51,7 +51,7 @@ export type Hydrate<Input, Output> = {
function hydrateInternal<Input extends object, Output>(
hydration: Hydrate<Input, Output>,
input: Input,
context: any
context: unknown
): Output {
return (Object.keys(input) as (keyof Input)[]).reduce((acc, key) => {
let targetKey, value;
@@ -100,7 +100,7 @@ type ExtractOutput<T> = T extends Hydrate<any, infer O> ? O : never;
export function hydrate<T extends keyof Hydrators>(
type: T,
input: Partial<ExtractInput<Hydrators[T]>>,
context: any,
context: unknown,
initial?: boolean
) {
return hydrateInternal(
+1 -1
View File
@@ -35,7 +35,7 @@ export class ObjectStorage<T> {
* @param context Context
* @param data Input Data
*/
hydrate(id: string, type: keyof Hydrators, context: any, data?: unknown) {
hydrate(id: string, type: keyof Hydrators, context: unknown, data?: unknown) {
if (data) {
this.set(id, hydrate(type, data as never, context, true) as T);
}