Le vocal : ctx.voice

Mode code

Opale rejoint un salon vocal et joue un son ou une radio en direct depuis un site déclaré : mp3, ogg, webm, wav, flux icecast…

JavaScript
module.uses('icecast.radiofrance.fr');

module.command('radio', async (ctx) => {
  if (ctx.subcommand === 'stop') {
    await ctx.voice.leave();
    return ctx.reply('Radio coupée.');
  }
  const etat = await ctx.members.voiceState(ctx.member).catch(() => null);
  const salon = etat?.channel_id ?? ctx.config.vocal;
  if (!salon) return ctx.reply('Rejoins d’abord un salon vocal.');
  await ctx.voice.play('https://icecast.radiofrance.fr/fip-midfi.mp3', { channel: salon, title: 'FIP' });
  await ctx.reply('📻 FIP en direct !', { public: true });
});

Fonctions

FonctionEffet
ctx.voice.join(salon, { deaf })Rejoint un salon vocal (sourd par défaut).
ctx.voice.play(url, { channel, volume, title })Joue un son. Rejoint channel si donné, sinon reste où il est, sinon rejoint le vocal du membre. Remplace la piste en cours. Volume de 0.05 à 2 (1 par défaut).
ctx.voice.pause() / resume() / stop()Contrôle la lecture.
ctx.voice.leave()Quitte le vocal.
ctx.voice.status()connected, channelId, playing, paused, title, url, elapsedMs, ownedByThisModule
ctx.voice.soundboard(salon, son)Joue un son de la soundboard du serveur.

Enchaîner des pistes

JavaScript
module.on('audioEnd', async (ctx) => {
  const file = (await ctx.storage.get('file')) ?? [];
  const suivant = file.shift();
  await ctx.storage.set('file', file);
  if (suivant) await ctx.voice.play(suivant.url, { title: suivant.titre });
  else await ctx.voice.leave();
});

module.on('audioError', async (ctx) => {
  await ctx.log('Lecture impossible : ' + ctx.event.error);
});

Règles

  • Un seul module à la fois dans le vocal d’un serveur : « Le vocal est déjà utilisé par le module … ».
  • 3 heures au maximum par piste ; 8 sons joués en même temps sur tout Opale.
  • Opale doit pouvoir « Se connecter » et « Parler » dans le salon.
  • Dans voiceJoin et voiceLeave, ctx.voice.channelId et ctx.voice.channelName donnent le salon concerné.
Le vocal : ctx.voice · Documentation Opale