Please don’t rely on this Gitea instance being around forever.
If any of your build scripts use my (kageru’s) projects hosted here, check my Github or IEW on Github for encoding projects. If you can’t find what you’re looking for there, tell me to migrate it.
Also extracted the command permission logic to a separate function
because it was getting ridiculous. It might be a by slower now, but I
really don’t care. Readabiliy should be much better, except now it’s
even more obvious how bad the entire idea behind that logic was/is.
Shikata ga nai, I guess.
Now supports embeds as an optional parameter. Already 80% less copy
paste code for the redirects. Can’t get it of it 100% because reasons.
Slight adjustments to logging so I can finally see embeds the bot is
sending.
s.ChannelMessageSend(dm.ID,"Deine Nachricht wurde gelöscht, weil sie ein verbotenes Wort enthielt. Falls du sie editieren und erneut abschicken willst, hier die Nachricht:")
// This is a restriction imposed by my own wrapper,
// but working around it is not actually necessary for performance and makes the code uglier in other places.
for_,newRole:=rangeconfig.RoleCommands{
// check if the user has a twitch sub or any of the patreon roles
isAllowed:=false
for_,curRole:=rangeMember.Roles{
ifrequired.Contains(curRole){
isAllowed=true
}
}
if!isAllowed{
s.ChannelMessageSend(dm.ID,"Du kannst dir keine Rolle zuweisen, da weder Patreon noch Twitch mit deinem Account verlinkt ist oder du Selphy auf keiner dieser Plattformen unterstützt. Bei Problemen wende dich bitte an die `!mods`.")
log.Printf("Denied role %s to %s. User is neither patron nor sub.",roleName(s.State,newRole),userToString(m.Author))
return
}
for_,curRole:=rangeMember.Roles{
// If the user already has one of the available roles, tell them and exit
ifnewRole==curRole{
ifcurRole==role{
// User is trying to get the role they already have
s.ChannelMessageSend(dm.ID,"Baka, die Rolle hast du doch schon.")
log.Printf("Denied Role %s to %s. User already has %s",roleName(s.State,curRole),userToString(m.Author),roleName(s.State,curRole))
}else{
s.ChannelMessageSend(dm.ID,"Baka, du kannst nur eine der Rollen haben.")
log.Printf("Denied Role %s to %s. User already has %s",roleName(s.State,curRole),userToString(m.Author),roleName(s.State,curRole))
log.Printf("Giving Role %s to %s",roleName(s.State,role),userToString(m.Author))
}
}
}
funcgetHelpEmbed()*discordgo.MessageEmbed{
commandList:="Im Folgenden findest du eine automatisch generierte Liste aller Commands. Um herauszufinden, was sie tun, probiere sie aus oder lies den Source Code (siehe unten).\n```- !complain\n- !scomplain\n"
Value:fmt.Sprintf("Bei Fragen zum Bot, Vorschlägen, Bugs etc. wende dich bitte an <@%s> oder öffne eine Issue auf https://git.kageru.moe/kageru/discord-selphybot.",config.Admins[0]),
commandList:="Im Folgenden findest du eine automatisch generierte Liste aller Commands. Um herauszufinden, was sie tun, probiere sie aus oder lies den Source Code (siehe unten).\n```- !complain\n- !scomplain\n"
Value:fmt.Sprintf("Bei Fragen zum Bot, Vorschlägen, Bugs etc. wende dich bitte an <@%s> oder öffne eine Issue auf https://git.kageru.moe/kageru/discord-selphybot.",config.Admins[0]),
log.Println(fmt.Sprintf("Error creating DM with %s",userToString(member.User),err))
}else{
embed:=getWelcomeEmbed()
_,err=s.ChannelMessageSendEmbed(dm.ID,embed)
iferr!=nil{
log.Println(fmt.Sprintf("Error sending DM to %s",userToString(member.User),err))
}
}
iferr!=nil{
// if any of the preceding operations produced an error
log.Printf("Sending welcome @mention at %s",userToString(member.User))
s.ChannelMessageSend(config.GeneralChannel,fmt.Sprintf("Wilkommen <@%s>. Bitte aktiviere vorübergehend DMs für diesen Server und sende eine Nachricht mit !welcome an mich.",member.User.ID))
s.ChannelMessageSend(config.GeneralChannel,fmt.Sprintf("Wilkommen <@%s>. Bitte aktiviere vorübergehend DMs für diesen Server und sende eine Nachricht mit !welcome an mich. https://cdn.discordapp.com/attachments/333450842151714816/591581555219234826/Selphy-queen.png",member.User.ID))
registerCommand(Command{Trigger:"(\\s|\n|^)[nN][hH]([ ?.,\n]|$)",Output:"<@%s> „nh“ ist kein Wort, du Oboe!",DeleteInput:true,OutputIsReply:true,Type:CommandTypeRegex})
registerCommand(Command{Trigger:"einzigste",Output:"<@%s> Es heißt „einzige“, du Tuba.",DeleteInput:true,OutputIsReply:true,Type:CommandTypeContains})
registerCommand(Command{Trigger:"(\\s|\n|^)[nN][hH]([ ?.,\n]|$)",Output:"<@%s> „nh“ ist kein Wort, du Oboe!",DeleteInput:true,OutputIsReply:true,Type:CommandTypeRegex})
registerCommand(Command{Trigger:"einzigste",Output:"<@%s> Es heißt „einzige“, du Tuba.",DeleteInput:true,OutputIsReply:true,Type:CommandTypeContains})
registerCommand(Command{Trigger:"praise the sun",Output:"If only I could be so grossly incandescent \\\\[T]/",Type:CommandTypeContains,IgnoreCase:true,Cooldown:85600})
registerCommand(Command{Trigger:"praise the sun",Output:"If only I could be so grossly incandescent \\\\[T]/",Type:CommandTypeContains,IgnoreCase:true,Cooldown:85600})
registerCommand(Command{Trigger:"!mods",Output:"Bei Fragen, Problemen und Beschwerden wende dich bitte an die Moderatoren oder schick mir eine Nachricht beginnend mit !complain, um dich anonym zu beschweren.\nAktuell anwesende Mods werden dir rechts mit dem Rang „Maid“ angezeigt.",Type:CommandTypeFullMatch})
registerCommand(Command{Trigger:"!mods",Output:"Bei Fragen, Problemen und Beschwerden wende dich bitte an die Moderatoren oder schick mir eine Nachricht beginnend mit !complain, um dich anonym zu beschweren.\nAktuell anwesende Mods werden dir rechts mit dem Rang „Maid“ angezeigt.",Type:CommandTypeFullMatch})
// This needs to be the last command because getHelpEmbed is evaluated here once, not on every function call. Putting it too early will result in missing commands in the output.
// This needs to be the last command because getHelpEmbed is evaluated here once, not on every function call. Putting it too early will result in missing commands in the output.