Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat: show control panel on 'now playing' embed #924

Merged
merged 1 commit into from
Feb 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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