Added Default Dynamic Command Handlers & api calls
!countdown <duration> !title <newTitle> !game || !category !uptime
This commit is contained in:
@@ -14,21 +14,45 @@ const (
|
||||
MatchContains = "contains"
|
||||
)
|
||||
|
||||
func ReplacePlaceholders(reply, user, channel, bot string) string {
|
||||
now := time.Now()
|
||||
replacements := map[string]string{
|
||||
"$user": user,
|
||||
"$channel": channel,
|
||||
"$bot": bot,
|
||||
"$date": now.Format("02-01-2006"),
|
||||
"$time": now.Format("15:04:05"),
|
||||
}
|
||||
|
||||
for placeholder, value := range replacements {
|
||||
reply = strings.ReplaceAll(reply, placeholder, value)
|
||||
}
|
||||
return reply
|
||||
}
|
||||
|
||||
func messageMatchesCommand(message, botUserName string, cmd commands.CustomCommand) bool {
|
||||
msgLower := strings.ToLower(message)
|
||||
triggerLower := strings.ToLower(cmd.Trigger)
|
||||
triggerLower := ""
|
||||
botMention := "@" + strings.ToLower(botUserName)
|
||||
|
||||
for _, trigger := range cmd.Triggers{
|
||||
triggerLower :=strings.ToLower(trigger)
|
||||
switch cmd.Match {
|
||||
case MatchPrefix:
|
||||
return strings.HasPrefix(msgLower, triggerLower)
|
||||
case MatchMention:
|
||||
return strings.Contains(msgLower, botMention) && strings.Contains(msgLower, triggerLower)
|
||||
case MatchContains:
|
||||
return strings.Contains(msgLower, triggerLower)
|
||||
default:
|
||||
return false
|
||||
case MatchPrefix:
|
||||
if strings.HasPrefix(msgLower, triggerLower) {
|
||||
return true
|
||||
}
|
||||
case MatchMention:
|
||||
if strings.Contains(msgLower, botMention) {
|
||||
return true
|
||||
}
|
||||
case MatchContains:
|
||||
if strings.Contains(msgLower, triggerLower) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func userHasPermisson(user twitch.User, required commands.PermissionLevel) bool {
|
||||
@@ -55,8 +79,22 @@ func HandleMessage(client *twitch.Client, apiClient interface{}, message twitch.
|
||||
msg := message.Message
|
||||
channel := message.Channel
|
||||
|
||||
// uptime title game handlers etc. . .
|
||||
// Dispatch Countdown command
|
||||
if strings.HasPrefix(msg, "!countdown") {
|
||||
HandleCountdownCommand(client, message, user, channel, msg)
|
||||
return
|
||||
}
|
||||
|
||||
// Dispatch title/category commands
|
||||
if strings.HasPrefix(msg, "!title") || strings.HasPrefix(msg, "!category") || strings.HasPrefix(msg, "!game") {
|
||||
HandleTitleCategoryCommand(client, apiClient, message, user, channel, msg)
|
||||
return
|
||||
}
|
||||
|
||||
// Dispatch custom/default commands
|
||||
HandleCustomCommands(client, message, user, channel, botUsername)
|
||||
}
|
||||
// check perms
|
||||
for _, cmd := range commands.GetAllCommands() {
|
||||
if messageMatchesCommand(msg, botName, cmd) {
|
||||
if userHasPermission(user, cmd.Permission) {
|
||||
|
Reference in New Issue
Block a user