Skip to content

Commit 246a074

Browse files
committed
feat: editMessage, refactor message handling and related methods
1 parent 008197c commit 246a074

File tree

19 files changed

+102
-77
lines changed

19 files changed

+102
-77
lines changed

.eslintrc.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,11 @@ module.exports = {
1919
plugins: ['simple-import-sort', 'sort-keys-fix'],
2020
root: true,
2121
rules: {
22-
'@typescript-eslint/no-var-requires': "off",
2322
'@typescript-eslint/explicit-member-accessibility': 'warn',
2423
'@typescript-eslint/naming-convention': [
2524
'warn',
2625
{
27-
format: ['camelCase', 'UPPER_CASE'],
26+
format: ['camelCase', 'UPPER_CASE', 'PascalCase'],
2827
leadingUnderscore: 'allow',
2928
selector: 'default',
3029
trailingUnderscore: 'allow',
@@ -51,6 +50,7 @@ module.exports = {
5150
'@typescript-eslint/no-empty-function': 'off',
5251
'@typescript-eslint/no-empty-interface': 'warn',
5352
'@typescript-eslint/no-non-null-assertion': 'off',
53+
'@typescript-eslint/no-var-requires': 'off',
5454
'accessor-pairs': 'warn',
5555
'array-bracket-spacing': 'warn',
5656
'array-callback-return': 'warn',
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
#!/bin/sh
22
. "$(dirname "$0")/_/husky.sh"
33

4-
npm run build && npm run lint
4+
npm run build

.husky/lint-staged

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!/bin/sh
2+
. "$(dirname "$0")/_/husky.sh"
3+
4+
npx lint-staged

package.json

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
"version": "0.0.0",
44
"description": "Main overarching package utilizing lerna to manage all the @guildedjs packages",
55
"private": true,
6+
"author": "Zaid \"Nico\"",
7+
"license": "MIT",
68
"scripts": {
79
"build": "npx lerna run build",
810
"bootstrap": "npx lerna bootstrap",
@@ -15,12 +17,6 @@
1517
"changelog": "npx conventional-changelog -p angular -i CHANGELOG.md -s",
1618
"reset": "cd scripts && node refresh.js"
1719
},
18-
"repository": {
19-
"type": "git",
20-
"url": "git+https://github.com/zaida04/guilded.js.git"
21-
},
22-
"author": "Zaid \"Nico\"",
23-
"license": "MIT",
2420
"devDependencies": {
2521
"@babel/core": "^7.12.17",
2622
"@babel/generator": "^7.13.0",
@@ -52,6 +48,10 @@
5248
"typedoc-plugin-remove-references": "0.0.5",
5349
"typescript": "^4.0.5"
5450
},
51+
"repository": {
52+
"type": "git",
53+
"url": "git+https://github.com/zaida04/guilded.js.git"
54+
},
5555
"bugs": {
5656
"url": "https://github.com/zaida04/guilded.js/issues"
5757
},

packages/common/lib/MessageUtil.ts

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/* eslint-disable @typescript-eslint/no-non-null-assertion */
22
/* eslint-disable max-depth */
33
import Embed from '@guildedjs/embeds';
4-
import { APIContent } from '@guildedjs/guilded-api-typings';
4+
import type { APIContent } from '@guildedjs/guilded-api-typings';
55

66
import { CONSTANTS } from './Consts';
77
import { generateUUID } from './UUID';
@@ -10,7 +10,10 @@ import { generateUUID } from './UUID';
1010
* Convert a string or other content to a message suitable to be sent to guilded
1111
* @internal
1212
*/
13-
export function convertToMessageFormat(i: string | Embed, e?: Embed): [string, Record<string, any>] {
13+
export function convertToMessageFormat(
14+
i: string | Embed,
15+
e?: Embed,
16+
): [string, { messageId: string; content: APIContent }] {
1417
let STR_INPUT = '';
1518
let embed;
1619

@@ -19,12 +22,14 @@ export function convertToMessageFormat(i: string | Embed, e?: Embed): [string, R
1922
if (e) embed = e;
2023

2124
const messageID = generateUUID();
22-
const message: { content?: Record<string, any>; messageId: string } = { messageId: messageID };
23-
message.content = parseToMessage(STR_INPUT, embed);
25+
const message = {
26+
content: parseToMessage(STR_INPUT, embed),
27+
messageId: messageID,
28+
};
2429
return [messageID, message];
2530
}
2631

27-
function parseToMessage(input: string | Embed, embed?: Embed) {
32+
export function parseToMessage(input: string | Embed, embed?: Embed): APIContent {
2833
return {
2934
document: {
3035
data: {},
@@ -242,7 +247,7 @@ export interface MessageDataNode {
242247
*/
243248
export interface parsedTextResponse {
244249
type: string;
245-
content: any;
250+
content: string;
246251
mention?: unknown;
247252
reaction?: unknown;
248253
channel?: unknown;

packages/guilded-api-typings/lib/common/structures/Team.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,21 +13,21 @@ export interface APITeam {
1313
bannerImages: unknown;
1414
baseGroup: APIGroup;
1515
bio: string | null;
16-
bots: any[];
16+
bots: unknown[];
1717
canInviteMembers?: boolean;
1818
canManageTournaments?: boolean;
1919
canUpdateTeam?: boolean;
2020
characteristics: string | null;
2121
createdAt: string;
2222
customizationInfo: unknown;
23-
deafenedMembers?: any[];
23+
deafenedMembers?: unknown[];
2424
description: string;
2525
discordGuildId: string | null;
2626
discordServerName: string | null;
27-
flair: any[];
27+
flair: unknown[];
2828
followerCount: number;
2929
followingGroups: string[] | null;
30-
games: any[];
30+
games: unknown[];
3131
homeBannerImageLg: string | null;
3232
homeBannerImageMd: string | null;
3333
homeBannerImageSm: string | null;
@@ -45,7 +45,7 @@ export interface APITeam {
4545
lfmStatusByGameId: unknown;
4646
measurements: APIMeasurements;
4747
members: APIMember[];
48-
mutedMembers: any[];
48+
mutedMembers: string[];
4949
memberCount?: string;
5050
membershipRole: string;
5151
name: string;
@@ -75,7 +75,7 @@ export interface APIPartialTeam {
7575
id: string;
7676
name: string;
7777
subdomain: string;
78-
activity: any[];
78+
activity: unknown[];
7979
games: string[] | null[];
8080
profilePicture: string;
8181
teamDashImage: string;
@@ -141,7 +141,7 @@ export interface APIMeasurements {
141141
numFollowers: number;
142142
numRecentMatches: number;
143143
numRecentMatchWins: number;
144-
matchmakingGameRanks: any[];
144+
matchmakingGameRanks: unknown[];
145145
numFollowersAndMembers: number;
146146
numMembersAddedInLastDay: number;
147147
numMembersAddedInLastWeek: number;

packages/guilded-api-typings/lib/common/structures/User.ts

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -84,13 +84,19 @@ export interface APIUser {
8484

8585
export interface APIClientUser extends APIUser {
8686
useMinimalNav: boolean;
87-
blockedUsers: any[];
88-
socialLinks: any[];
87+
blockedUsers: unknown[];
88+
socialLinks: APIUserSocialLinks[];
8989
userPresenceStatus: number;
90-
badges: any[];
90+
badges: string[];
9191
canRedeemGold: boolean;
9292
isUnrecoverable: boolean;
9393
devices: APIDevice[];
94-
userChannelNotificationSettings: any[];
94+
userChannelNotificationSettings: unknown[];
9595
upsell: null;
9696
}
97+
98+
export interface APIUserSocialLinks {
99+
type: string;
100+
handle: string;
101+
additionalInfo: unknown;
102+
}

packages/guilded-api-typings/lib/rest/Channel.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,6 @@ export interface APIPostChannelAnnouncementsBody {
183183
export interface APIGetTeamChannels {
184184
channels: APITeamChannel[];
185185
badgedChannelContentByChannelId: unknown;
186-
temporalChannels: any[];
186+
temporalChannels: unknown[];
187187
categories: APITeamChannel[];
188188
}

packages/guilded-api-typings/lib/rest/User.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,5 +67,5 @@ export interface APIPostLoginResponse {
6767
export interface APIGetUserDMChannels {
6868
channels: APIDMChannel[];
6969
unreadInfoByChannelId: unknown;
70-
users: any[];
70+
users: APIUser[];
7171
}

packages/guilded.js/__tests__/modules/message.js

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,30 @@
11
module.exports = async (client, passed, failed, testText, errorText) => {
22
let message;
3+
const content = 'TESTING MESSAGE';
4+
35
try {
46
console.log('...sending message');
5-
message = await client.channels.sendMessage(process.env.CHANNEL_ID, 'TESTING MESSAGE');
7+
message = await client.channels.sendMessage(process.env.CHANNEL_ID, content);
68
testText(`Successfully sent message with ID: ${message}!`);
79
} catch (e) {
810
errorText(`Message sending failed! ${e}`);
911
throw e;
1012
}
1113

14+
try {
15+
console.log('...editing message');
16+
const newMessage = await client.channels.editMessage(
17+
process.env.CHANNEL_ID,
18+
message,
19+
'THIS IS AN EDITED TEST MESSAGE',
20+
);
21+
if (content === newMessage.content) throw new Error('Content is unchanged!');
22+
testText(`Successfully edited message ${message} with new content ${newMessage.content}`);
23+
} catch (e) {
24+
errorText(`Message editing failed! ${e}`);
25+
throw e;
26+
}
27+
1228
try {
1329
console.log('...deleting message');
1430
await client.channels.deleteMessage(process.env.CHANNEL_ID, message);

0 commit comments

Comments
 (0)