Skip to content

Commit

Permalink
Feat: show control panel on 'now playing' embed (#924)
Browse files Browse the repository at this point in the history
Feat: show control panel on now playing embed
  • Loading branch information
mtripg6666tdr authored Feb 4, 2023
1 parent 939130a commit bdcca41
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 1 deletion.
7 changes: 7 additions & 0 deletions src/Component/CommandMessage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,18 @@
* If not, see <https://www.gnu.org/licenses/>.
*/

import type { Message, TextChannel } from "eris";

import { CommandMessage as LibCommandMessage } from "@mtripg6666tdr/eris-command-resolver";

import { Util } from "../Util";

export class CommandMessage extends LibCommandMessage {
// expose protected method
public static override createFromMessageWithParsed(message: Message<TextChannel>, command: string, options: string[], rawOptions: string): CommandMessage{
return super.createFromMessageWithParsed(message, command, options, rawOptions);
}

protected static override parseCommand(content:string, prefixLength:number){
const resolved = super.parseCommand(content, prefixLength, Util.string.NormalizeText);
// 超省略形を捕捉
Expand Down
38 changes: 37 additions & 1 deletion src/Component/PlayManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,43 @@ export class PlayManager extends ServerManagerBase {
embed.addField(":warning:注意", FallBackNotice);
}
this.emit("playStartUIPrepared", embed);
mes.edit({content: "", embeds: [embed.toEris()]}).catch(e => Util.logger.log(e, "error"));
mes.edit({
content: "",
embeds: [embed.toEris()],
components: [
new Helper.MessageActionRowBuilder()
.addComponents(
new Helper.MessageButtonBuilder()
.setCustomId("control_rewind")
.setEmoji("⏮️")
.setStyle("SECONDARY"),
new Helper.MessageButtonBuilder()
.setCustomId("control_playpause")
.setEmoji("⏯️")
.setLabel("再生/一時停止")
.setStyle("PRIMARY"),
new Helper.MessageButtonBuilder()
.setCustomId("control_skip")
.setEmoji("⏭️")
.setStyle("SECONDARY"),
new Helper.MessageButtonBuilder()
.setCustomId("control_onceloop")
.setEmoji("🔂")
.setLabel("ワンスループ")
.setStyle("SECONDARY"),
)
.toEris()
]
}).catch(e => Util.logger.log(e, "error"));
const removeControls = () => {
this.off("playCompleted", removeControls);
this.off("error", removeControls);
mes.edit({
components: []
}).catch(er => this.Log(er, "error"));
};
this.once("playCompleted", removeControls);
this.once("error", removeControls);
}
}
catch(e){
Expand Down
20 changes: 20 additions & 0 deletions src/bot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,26 @@ export class MusicBot extends MusicBotBase {
components: [],
}).catch(er => this.Log(er, "error"));
}
}else if(interaction.data.custom_id.startsWith("control_")){
let command:string = null;
switch(interaction.data.custom_id){
case "control_rewind":
command = "rewind";
break;
case "control_playpause":
command = server.player.isPaused ? "play" : "pause";
break;
case "control_skip":
command = "skip";
break;
case "control_onceloop":
command = "onceloop";
break;
default:
return;
}
const commandMessage = CommandMessage.createFromMessageWithParsed(interaction.message as discord.Message<discord.TextChannel>, "command", [], "");
CommandManager.instance.resolve(command)?.run(commandMessage, this.createCommandRunnerArgs(commandMessage.guild.id, commandMessage.options, commandMessage.rawOptions));
}else{
const updateEffectPanel = () => {
const mes = interaction.message;
Expand Down

0 comments on commit bdcca41

Please sign in to comment.