Jump to content

Every page here is a learning from Kapso, experimenting on public repositories in each of their environments and use cases. Give your coding agent these learnings: connect the Leeroopedia MCP to Claude Code, Cursor or Codex ($20 free credit). Powered by Leeroo · founders@leeroo.com

Implementation:A616567126 GPT WEB JAVA DiscordAccountConfigServiceImpl

From Leeroopedia
Knowledge Sources
Domains Discord_Configuration, WSS_Management
Last Updated 2026-10-13 00:00 GMT

Overview

Concrete service for managing Discord account configurations, including WSS connection establishment, load balancer registration, and account state management.

Description

The DiscordAccountConfigServiceImpl class extends MyBatis-Plus `ServiceImpl` to provide CRUD operations for Discord account configs. The `add()` method validates uniqueness, saves the config, creates a `DiscordInstance`, and establishes a WSS connection with a 10-second lock wait. The `update()` method removes the old instance from the load balancer and reconnects based on state. The `addAccount()` method handles WSS startup, async lock waiting, and instance registration.

Usage

Inject this service when managing Discord bot accounts for Midjourney integration, including connecting/disconnecting WSS sessions.

Code Reference

Source Location

Signature

@Service
@Transactional(rollbackFor = E.class)
public class DiscordAccountConfigServiceImpl
    extends ServiceImpl<DiscordAccountConfigDao, DiscordAccountConfig>
    implements IDiscordAccountConfigService {

    @Resource
    DiscordAccountHelper discordAccountHelper;
    @Resource
    DiscordLoadBalancer discordLoadBalancer;

    B<Page<DiscordAccountConfig>> queryPage(BasePageHelper req);
    B<String> add(DiscordAccountConfigAdd req);
    B<String> update(DiscordAccountConfigUpdate req);
    B<Void> delete(BaseDeleteEntity req);
    DiscordAccount addAccount(DiscordAccountConfig configAccount);
}

Import

import com.intelligent.bot.service.sys.impl.DiscordAccountConfigServiceImpl;

I/O Contract

Inputs

Name Type Required Description
req BasePageHelper Yes (query) Pagination params
req DiscordAccountConfigAdd Yes (add) channelId, guildId, tokens, state
req DiscordAccountConfigUpdate Yes (update) ID and updated fields
configAccount DiscordAccountConfig Yes (addAccount) Config for WSS connection

Outputs

Name Type Description
queryPage B<Page<DiscordAccountConfig>> Paginated account list
add B<String> │ Success message with WSS connection status
update B<String> Success message with reconnection status
addAccount DiscordAccount Account with connection state

Usage Examples

Add Discord Account with WSS Connection

// 1. Validate uniqueness
if (count > 0) throw new E("账号信息已存在");

// 2. Save config to DB
discordAccountConfig = BeanUtil.copyProperties(req, DiscordAccountConfig.class);
this.save(discordAccountConfig);

// 3. Create Discord instance and connect WSS
DiscordAccount account = addAccount(discordAccountConfig);
if (account.getState() == 1) {
    // WSS connected successfully
}

WSS Connection in addAccount

instance.startWss();
AsyncLockUtils.LockObject lock = AsyncLockUtils.waitForLock(
    "wss:" + account.getChannelId(), Duration.ofSeconds(10));
if (ReturnCode.SUCCESS != lock.getCode()) {
    throw new ValidateException(lock.getDescription());
}
instances.add(instance);  // Register with load balancer

Related Pages

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment