From 0b7fc2e7d22073fae38d549d547874ce2510c1bd Mon Sep 17 00:00:00 2001 From: lts20050703 <87189679+lts20050703@users.noreply.github.com> Date: Sat, 27 Nov 2021 22:21:57 +0700 Subject: [PATCH 1/6] UNIT TEST editBotStatus --- tests/misc/editBotStatus.ts | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 tests/misc/editBotStatus.ts diff --git a/tests/misc/editBotStatus.ts b/tests/misc/editBotStatus.ts new file mode 100644 index 000000000..1b7236951 --- /dev/null +++ b/tests/misc/editBotStatus.ts @@ -0,0 +1,12 @@ +import { assertExists } from "../deps.ts"; +import { bot } from "../mod.ts"; +import { ActivityTypes } from "../../src/types/activity/activityTypes.ts"; +Deno.test("editBotStatus", function () { + bot.helpers.editBotStatus({ + status: "dnd", + activities: [{ name: "lts20050703", type: ActivityTypes.Game, createdAt: Date.now() }], + }); + bot.events.presenceUpdate = function (_bot, presense, _oldPresense) { + assertExists(presense); + }; +}); From 85057395cd7eeb619058d964db33b46a3a9b0a0d Mon Sep 17 00:00:00 2001 From: lts20050703 <87189679+lts20050703@users.noreply.github.com> Date: Sun, 28 Nov 2021 00:58:03 +0000 Subject: [PATCH 2/6] Update mod.ts --- tests/mod.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/mod.ts b/tests/mod.ts index 1a699dc35..51d9751c6 100644 --- a/tests/mod.ts +++ b/tests/mod.ts @@ -602,6 +602,7 @@ import "./misc/getVoiceRegions.ts"; import "./misc/snowflake.ts"; import "./misc/typing.ts"; import "./misc/validateDiscovery.ts"; +import "./misc/editBotStatus.ts" //role import "./role/addRole.ts"; From 1259bda5e0c514e709c062b7aa346bcd6ee68163 Mon Sep 17 00:00:00 2001 From: Skillz4Killz <23035000+Skillz4Killz@users.noreply.github.com> Date: Mon, 29 Nov 2021 14:19:12 +0000 Subject: [PATCH 3/6] fix: edit bot nickname name --- tests/members/editBotNickname.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/members/editBotNickname.ts b/tests/members/editBotNickname.ts index dded03378..7efd93edd 100644 --- a/tests/members/editBotNickname.ts +++ b/tests/members/editBotNickname.ts @@ -1,7 +1,7 @@ import { assertEquals } from "../deps.ts"; import { bot, guild } from "../mod.ts"; -Deno.test("editBotNickname", async function () { +Deno.test("[misc] edit a bot's nickname", async function () { const nick = "lts20050703"; const nickname = await bot.helpers.editBotNickname(guild.id, { nick }); assertEquals(nickname, nick); From 5907e4b4bca9b0007b0aeb6c5e2e1a22986b2925 Mon Sep 17 00:00:00 2001 From: Skillz4Killz <23035000+Skillz4Killz@users.noreply.github.com> Date: Mon, 29 Nov 2021 14:19:36 +0000 Subject: [PATCH 4/6] fix: add presence intent --- tests/mod.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/mod.ts b/tests/mod.ts index 51d9751c6..d4caa6778 100644 --- a/tests/mod.ts +++ b/tests/mod.ts @@ -59,6 +59,7 @@ export const bot = createBot({ "GuildMembers", "GuildScheduledEvents", "GuildVoiceStates", + "GuildPresences" ], cache: { isAsync: false, From 2440dc7872df6fcbe62f27e17efd3d76ad1754c1 Mon Sep 17 00:00:00 2001 From: Skillz4Killz <23035000+Skillz4Killz@users.noreply.github.com> Date: Mon, 29 Nov 2021 14:19:56 +0000 Subject: [PATCH 5/6] idk add logs it wont work --- tests/misc/editBotStatus.ts | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/tests/misc/editBotStatus.ts b/tests/misc/editBotStatus.ts index 1b7236951..c066fc033 100644 --- a/tests/misc/editBotStatus.ts +++ b/tests/misc/editBotStatus.ts @@ -1,12 +1,24 @@ import { assertExists } from "../deps.ts"; import { bot } from "../mod.ts"; import { ActivityTypes } from "../../src/types/activity/activityTypes.ts"; -Deno.test("editBotStatus", function () { +import { delayUntil } from "../utils.ts"; + +Deno.test("[misc] edit the bot's status", async function () { + bot.events.presenceUpdate = function (_bot, presense, _oldPresense) { + console.log('in pu') + console.log('in pu') + assertExists(presense); + }; + + bot.events.botUpdate = function (bot, user) { + console.log('in bu') + console.log('in bu') + } + bot.helpers.editBotStatus({ status: "dnd", activities: [{ name: "lts20050703", type: ActivityTypes.Game, createdAt: Date.now() }], }); - bot.events.presenceUpdate = function (_bot, presense, _oldPresense) { - assertExists(presense); - }; + + await delayUntil(10000, () => false) }); From fb18dfe5d10f5601d1ec30d9fb941784c163084f Mon Sep 17 00:00:00 2001 From: Skillz4Killz <23035000+Skillz4Killz@users.noreply.github.com> Date: Mon, 29 Nov 2021 14:20:09 +0000 Subject: [PATCH 6/6] fix: camelize response to discord --- src/helpers/misc/editBotStatus.ts | 41 ++++++++++++++++++++++++++++++- 1 file changed, 40 insertions(+), 1 deletion(-) diff --git a/src/helpers/misc/editBotStatus.ts b/src/helpers/misc/editBotStatus.ts index c45edfc38..cd2bcb9f5 100644 --- a/src/helpers/misc/editBotStatus.ts +++ b/src/helpers/misc/editBotStatus.ts @@ -11,7 +11,46 @@ export function editBotStatus(bot: Bot, data: Omit ({ + name: activity.name, + type: activity.type, + url: activity.url, + created_at: activity.createdAt, + timestamps: activity.timestamps + ? { + start: activity.timestamps.start, + end: activity.timestamps.end, + } + : undefined, + applicationId: activity.applicationId?.toString(), + details: activity.details, + state: activity.state, + emoji: activity.emoji + ? { + name: activity.emoji.name, + id: activity.emoji.id?.toString(), + animated: activity.emoji.animated, + } + : undefined, + party: activity.party + ? { + id: activity.party.id?.toString(), + size: activity.party.size, + } + : undefined, + assets: activity.assets + ? { + large_image: activity.assets.largeImage, + large_text: activity.assets.largeText, + small_image: activity.assets.smallImage, + small_text: activity.assets.smallText, + } + : undefined, + secrets: activity.secrets, + instance: activity.instance, + flags: activity.flags, + buttons: activity.buttons, + })), status: data.status, }, });