Skip to content

Commit 55f7a08

Browse files
committed
feat: refresh_server_info bot control cmd
1 parent 3fae2cf commit 55f7a08

3 files changed

Lines changed: 33 additions & 4 deletions

File tree

backend/src/plugins/BotControl/BotControlPlugin.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import { RestPerformanceCmd } from "./commands/RestPerformanceCmd.js";
2323
import { ServersCmd } from "./commands/ServersCmd.js";
2424
import { BotControlPluginType, zBotControlConfig } from "./types.js";
2525
import { DebugCountersCmd } from "./commands/DebugCountersCmd.js";
26+
import { RefreshServerInfoCmd } from "./commands/RefreshServerInfoCmd.js";
2627

2728
export const BotControlPlugin = globalPlugin<BotControlPluginType>()({
2829
name: "bot_control",
@@ -47,6 +48,7 @@ export const BotControlPlugin = globalPlugin<BotControlPluginType>()({
4748
AddServerFromInviteCmd,
4849
ChannelToServerCmd,
4950
DebugCountersCmd,
51+
RefreshServerInfoCmd,
5052
],
5153

5254
async afterLoad(pluginData) {
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import { commandTypeHelpers as ct } from "../../../commandTypes.js";
2+
import { isStaffPreFilter } from "../../../pluginUtils.js";
3+
import { updateGuildInfo } from "../../GuildInfoSaver/GuildInfoSaverPlugin.js";
4+
import { botControlCmd } from "../types.js";
5+
6+
export const RefreshServerInfoCmd = botControlCmd({
7+
trigger: ["refresh_server_info", "refresh_guild_info"],
8+
permission: null,
9+
config: {
10+
preFilters: [isStaffPreFilter],
11+
},
12+
13+
signature: {
14+
guildId: ct.anyId(),
15+
},
16+
17+
async run({ pluginData, message: msg, args }) {
18+
const latestGuildData = await pluginData.client.guilds.fetch(args.guildId).catch(() => null);
19+
if (!latestGuildData) {
20+
void msg.channel.send("Could not fetch guild information");
21+
return;
22+
}
23+
24+
await updateGuildInfo(latestGuildData, true);
25+
void msg.channel.send("Guild information updated");
26+
},
27+
});

backend/src/plugins/GuildInfoSaver/GuildInfoSaverPlugin.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,17 +29,17 @@ export const GuildInfoSaverPlugin = guildPlugin<GuildInfoSaverPluginType>()({
2929
},
3030
});
3131

32-
async function updateGuildInfo(guild: Guild) {
32+
export async function updateGuildInfo(guild: Guild, forceOwnerUpdate = false) {
3333
if (!guild.name) {
3434
return;
3535
}
3636

3737
const allowedGuilds = new AllowedGuilds();
3838
const existingData = (await allowedGuilds.find(guild.id))!;
39-
allowedGuilds.updateInfo(guild.id, guild.name, guild.iconURL(), guild.ownerId);
39+
await allowedGuilds.updateInfo(guild.id, guild.name, guild.iconURL(), guild.ownerId);
4040

41-
if (existingData.owner_id !== guild.ownerId || existingData.created_at === existingData.updated_at) {
41+
if (existingData.owner_id !== guild.ownerId || existingData.created_at === existingData.updated_at || forceOwnerUpdate) {
4242
const apiPermissions = new ApiPermissionAssignments();
43-
apiPermissions.applyOwnerChange(guild.id, guild.ownerId);
43+
await apiPermissions.applyOwnerChange(guild.id, guild.ownerId);
4444
}
4545
}

0 commit comments

Comments
 (0)