8000 いろんな役職パネルに対応 by ikafly144 · Pull Request #132 · sabafly/gobot · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

いろんな役職パネルに対応 #132

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

Merged
merged 1 commit into from
Aug 29, 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
13 changes: 2 additions & 11 deletions bot/commands/message_other.go 8000
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"github.com/sabafly/disgo/events"
"github.com/sabafly/gobot/bot/client"
botlib "github.com/sabafly/sabafly-lib/v2/bot"
"github.com/sabafly/sabafly-lib/v2/emoji"
"github.com/sabafly/sabafly-lib/v2/handler"
"github.com/sabafly/sabafly-lib/v2/translate"
)
Expand Down Expand Up @@ -59,22 +58,14 @@ func messageOtherHandler(b *botlib.Bot[*client.Client]) handler.CommandHandler {

func rolePanelConvertCheck(message discord.Message) bool {
switch message.Author.ID {
case 895912135039803402, 1138119538190340146, 1137367652482957313, 971523089550671953:
case 895912135039803402, 1138119538190340146, 1137367652482957313, 971523089550671953 /*役職パネルv3*/, 917780792032251904 /*役職ボット*/, 669817785932578826 /*陽菜*/, 716496407212589087 /*RT*/, 718760319207473152 /*SevenBot*/, 832614051514417202 /*Glow-bot*/ :
if len(message.Embeds) < 1 {
return false
}
lines := strings.Split(message.Embeds[0].Description, "\r")
valid_lines := 0
for _, v := range lines {
if !emoji.MatchString(v) {
continue
}
emojis := emoji.FindAllString(v)
role_strings, ok := strings.CutPrefix(v, emojis[0])
if !ok {
continue
}
if !role_regexp.MatchString(role_strings) {
if !role_regexp.MatchString(v) {
continue
}
valid_lines++
Expand Down
44 changes: 14 additions & 30 deletions bot/commands/role.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,24 +134,7 @@ func rolePanelV2PanelAutoCompleteHandler(b *botlib.Bot[*client.Client]) handler.
func rolePanelV2Create(b *botlib.Bot[*client.Client]) handler.CommandHandler {
return func(event *events.ApplicationCommandInteractionCreate) error {
modal := discord.NewModalCreateBuilder()
role := event.SlashCommandInteractionData().Role("role")
self, valid := event.Client().Caches().SelfMember(*event.GuildID())
if !valid {
return botlib.ReturnErrMessage(event, "error_bot_member_not_found", botlib.WithEphemeral(true))
}
role_map := map[snowflake.ID]discord.Role{}
for _, id := range self.RoleIDs {
role, ok := event.Client().Caches().Role(*event.GuildID(), id)
if !ok {
continue
}
role_map[id] = role
}
hi, _ := botlib.GetHighestRolePosition(role_map)
if role.Managed || role.Position >= hi {
return botlib.ReturnErrMessage(event, "error_invalid_command_argument")
}
modal.SetCustomID(fmt.Sprintf("handler:rp-v2:create-modal:%s", role.ID.String()))
modal.SetCustomID("handler:rp-v2:create-modal")
modal.SetTitle(translate.Message(event.Locale(), "rp_v2_create_modal_title"))
modal.AddActionRow(discord.TextInputComponent{
CustomID: "name",
Expand Down Expand Up @@ -1369,23 +1352,23 @@ func rolePanelV2ConvertComponentHandler(b *botlib.Bot[*client.Client]) handler.C
lines := strings.Split(message.Embeds[0].Description, "\n")
b.Logger.Debugf("lines %d", len(lines))
roles := []db.RolePanelV2Role{}
role_count := 0
for _, v := range lines {
if !emoji.MatchString(v) {
b.Logger.Debug("failed emoji match")
if !role_regexp.MatchString(v) {
b.Logger.Debug("failed role regexp")
continue
}
emojis := emoji.FindAllString(v)
component_emoji := botlib.ParseComponentEmoji(emojis[0])
role_strings, ok := strings.CutPrefix(v, emojis[0])
if !ok {
b.Logger.Debug("failed cut prefix")
continue
var emojis []string
if !emoji.MatchString(v) {
emojis = append(emojis, botlib.Number2Emoji(role_count+1))
} else {
emojis = emoji.FindAllString(v)
}
if !role_regexp.MatchString(role_strings) {
b.Logger.Debug("failed role regexp")
continue
component_emoji := botlib.ParseComponentEmoji(emojis[0])
if _, ok := event.Client().Caches().Emoji(*event.GuildID(), component_emoji.ID); !ok && component_emoji.ID != 0 {
component_emoji = botlib.ParseComponentEmoji(botlib.Number2Emoji(role_count + 1))
}
role_id, err := snowflake.Parse(role_id_regexp.FindString(role_regexp.FindString(role_strings)))
role_id, err := snowflake.Parse(role_id_regexp.FindString(role_regexp.FindString(v)))
if err != nil {
b.Logger.Debug("failed parse role id")
continue
Expand All @@ -1399,6 +1382,7 @@ func rolePanelV2ConvertComponentHandler(b *botlib.Bot[*client.Client]) handler.C
}
role = *role_ptr
}
role_count++
roles = append(roles, db.RolePanelV2Role{
RoleID: role.ID,
RoleName: role.Name,
Expand Down
0