Skip to content

Commit 03a395d

Browse files
Merge branch 'develop' into fetchcall-to-store-token-in-rds-backend
2 parents ab392eb + 6848e0a commit 03a395d

File tree

4 files changed

+38
-0
lines changed

4 files changed

+38
-0
lines changed

.github/workflows/register-commands-production.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ jobs:
2727
secrets: |
2828
DISCORD_PUBLIC_KEY
2929
DISCORD_TOKEN
30+
DISCORD_GUILD_ID
3031
CURRENT_ENVIRONMENT
3132
BOT_PRIVATE_KEY
3233
env:
@@ -35,3 +36,4 @@ jobs:
3536
DISCORD_PUBLIC_KEY: ${{secrets.DISCORD_PUBLIC_KEY}}
3637
DISCORD_TOKEN: ${{secrets.DISCORD_TOKEN}}
3738
BOT_PRIVATE_KEY: ${{secrets.BOT_PRIVATE_KEY}}
39+
DISCORD_GUILD_ID: ${{secrets.DISCORD_GUILD_ID}}

.github/workflows/register-commands-staging.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ jobs:
2727
secrets: |
2828
DISCORD_PUBLIC_KEY
2929
DISCORD_TOKEN
30+
DISCORD_GUILD_ID
3031
CURRENT_ENVIRONMENT
3132
BOT_PRIVATE_KEY
3233
env:
@@ -35,3 +36,4 @@ jobs:
3536
DISCORD_PUBLIC_KEY: ${{secrets.DISCORD_PUBLIC_KEY}}
3637
DISCORD_TOKEN: ${{secrets.DISCORD_TOKEN}}
3738
BOT_PRIVATE_KEY: ${{secrets.BOT_PRIVATE_KEY}}
39+
DISCORD_GUILD_ID: ${{secrets.DISCORD_GUILD_ID}}

src/constants/responses.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,6 @@ export const STATUS_CHECK = {
1515
};
1616

1717
export const COMMAND_NOT_FOUND = "Command Not Found";
18+
19+
export const INTERNAL_SERVER_ERROR =
20+
"Oops! We have encountered an internal Server Error";

src/utils/updateNickname.ts

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import { INTERNAL_SERVER_ERROR } from "../constants/responses";
2+
import { DISCORD_BASE_URL } from "../constants/urls";
3+
import { env } from "../typeDefinitions/default.types";
4+
5+
export async function updateNickName(
6+
discordId: string,
7+
nickname: string,
8+
env: env
9+
) {
10+
const changeNickNameURL = `${DISCORD_BASE_URL}/guilds/${env.DISCORD_GUILD_ID}/members/${discordId}`;
11+
const data = { nick: nickname };
12+
try {
13+
const nameChangeResponse = await fetch(changeNickNameURL, {
14+
method: "PATCH",
15+
headers: {
16+
"Content-Type": "application/json",
17+
Authorization: `Bot ${env.DISCORD_TOKEN}`,
18+
},
19+
body: JSON.stringify(data),
20+
});
21+
if (nameChangeResponse.ok) {
22+
return await nameChangeResponse.json();
23+
} else {
24+
console.log(nameChangeResponse.json());
25+
return INTERNAL_SERVER_ERROR;
26+
}
27+
} catch (error) {
28+
console.log(error);
29+
return INTERNAL_SERVER_ERROR;
30+
}
31+
}

0 commit comments

Comments
 (0)