• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

hicommonwealth / commonwealth / 14522275429

17 Apr 2025 06:24PM UTC coverage: 46.108% (-0.2%) from 46.287%
14522275429

push

github

web-flow
Merge pull request #11888 from hicommonwealth/tim/discord-leave-guild-on-disconnect

Discord updates 2

1622 of 3879 branches covered (41.81%)

Branch coverage included in aggregate %.

2 of 30 new or added lines in 2 files covered. (6.67%)

2980 of 6102 relevant lines covered (48.84%)

39.37 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

8.0
/libs/model/src/aggregates/discordBot/removeDiscordBotConfig.command.ts
1
import { InvalidState, logger, type Command } from '@hicommonwealth/core';
2
import * as schemas from '@hicommonwealth/schemas';
3
import { models } from '../../database';
4
import { authRoles } from '../../middleware';
5
import { getDiscordClient } from '../../utils';
6

7
const log = logger(import.meta);
32✔
8

9
export const Errors = {
32✔
10
  ConfigNotFound: 'Config not found.',
11
};
12

13
export function RemoveDiscordBotConfig(): Command<
14
  typeof schemas.RemoveDiscordBotConfig
15
> {
16
  return {
×
17
    ...schemas.RemoveDiscordBotConfig,
18
    auth: [authRoles('admin')],
19
    body: async ({ payload }) => {
20
      const config = await models.DiscordBotConfig.findOne({
×
21
        where: {
22
          community_id: payload.community_id,
23
        },
24
      });
25
      if (!config) throw new InvalidState(Errors.ConfigNotFound);
×
26

NEW
27
      if (config.guild_id && config.guild_id !== '') {
×
NEW
28
        const client = await getDiscordClient();
×
NEW
29
        const guild = client.guilds.cache.get(config.guild_id);
×
NEW
30
        if (guild) {
×
NEW
31
          await guild.leave();
×
NEW
32
          log.trace(`Left Discord server: ${config.guild_id}`);
×
33
        } else {
NEW
34
          log.trace(`Could not find a server with ID: ${config.guild_id}`);
×
35
        }
36
      }
37

38
      await models.sequelize.transaction(async (transaction) => {
×
39
        await models.Community.update(
×
40
          {
41
            discord_config_id: null,
42
            discord_bot_webhooks_enabled: false,
43
          },
44
          {
45
            where: {
46
              id: payload.community_id,
47
            },
48
            transaction,
49
          },
50
        );
51
        await models.DiscordBotConfig.destroy({
×
52
          where: {
53
            community_id: payload.community_id,
54
          },
55
          transaction,
56
        });
57
        await models.Topic.update(
×
58
          { channel_id: null },
59
          {
60
            where: {
61
              community_id: payload.community_id,
62
            },
63
            transaction,
64
          },
65
        );
66
      });
67

68
      return { message: 'Successfully disconnected Discord' };
×
69
    },
70
  };
71
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc