Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- {{$giveawayEmoji := `๐`}}{{/* set giveaway emoji to be used */}}
- {{/*Actual Code , do not touch unless you know what youre doing*/}}
- {{/*Declaring global variables,templates*/}}
- {{$globalSdict := sdict }}{{$CCID := .CCID}}{{$syntaxError := 0}}
- {{define "map2sdict"}}{{$map:= (.Get "val")}}{{$tempSdict:=sdict}}{{range $key , $val := $map}}{{$tempSdict.Set $key $val}}{{end}}{{(.Set "res" $tempSdict)}}{{end}}
- {{/*checking direct/indirect command invoke*/}}
- {{if not .ExecData }}
- {{if gt ( len .CmdArgs ) 0 }}
- {{if or (gt (len .CmdArgs) 1) (eq (lower (index .CmdArgs 0) ) "list")}}
- {{/*Command - Start*/}}
- {{if eq (lower (index .CmdArgs 0) ) "start"}}
- {{/*Variable declarations & assignments*/}}
- {{$CmdArgs := joinStr " " (slice (split .StrippedMsg " ") 1 )}}
- {{$maxP := -1}}{{$maxW := 1}}{{$chan:= .Channel.ID}}{{$ID:= ""}}{{$dbData := sdict}}
- {{$uniqueID := toInt (currentTime.Sub (newDate 2019 10 10 0 0 0)).Seconds}}
- {{/*Handling flags, parsing data from input*/}}
- {{with reFindAllSubmatches `(?i)((-w) (\d+)(?:\s|$))` $CmdArgs}}
- {{$CmdArgs = reReplace `(?i)(-w \d+\s+)|(-w \d+$)` $CmdArgs ""}}
- {{$maxW = toInt (index (index . 0) 3)}}
- {{end}}
- {{with reFindAllSubmatches `(?i)((-p) (\d+)(?:\s|$))` $CmdArgs}}
- {{$CmdArgs = reReplace `(?i)(-p \d+(\s+))|(-p \d+$)` $CmdArgs ""}}
- {{$maxP = toInt (index (index . 0) 3)}}
- {{end}}
- {{with reFindAllSubmatches `(?i)(-c (?:<#)?(\d+)(?:>?)(?:\s|$))` $CmdArgs}}
- {{$CmdArgs = reReplace `(?i)(-c ((<#)?\d+(>?))\s+)|(-c ((<#)?\d+(>?))$)` $CmdArgs ""}}
- {{$chan = index (index . 0) 2}}
- {{end}}
- {{$temp := split $CmdArgs " "}}
- {{$dur:= lower (index $temp 0)}}
- {{$prize := ""}}
- {{if gt (len $temp) 1}}{{$prize = joinStr " " (slice $temp 1)}}{{end}}
- {{/* String to Duration */}}
- {{$duration := 0}}
- {{$hr := .TimeHour}}{{$min := .TimeMinute}}{{$sec := .TimeSecond}}
- {{with reFindAllSubmatches `(\d+)(d)` $dur }}
- {{$duration = toDuration ( add (mult 24 (toInt (index (index . 0) 1)) $hr) $duration ) }}
- {{end}}
- {{with reFindAllSubmatches `(\d+)(h)` $dur}}
- {{$duration = toDuration ( add (mult (toInt (index (index . 0) 1)) $hr) $duration ) }}
- {{end}}
- {{with reFindAllSubmatches `(\d+)(m)` $dur}}
- {{$duration = toDuration ( add (mult (toInt (index (index . 0 ) 1)) $min) $duration ) }}
- {{end}}
- {{with reFindAllSubmatches `(\d+)(s)` $dur}}
- {{$duration = toDuration ( add (mult (toInt (index (index . 0 ) 1)) $sec) $duration ) }}
- {{end}}
- {{/* if valid duration & prize */}}
- {{if and ($duration) ($prize)}}
- {{/*if max Participants > max Winners*/}}
- {{if or (ge $maxP $maxW) (eq $maxP -1)}}
- {{/*Giveaway Announcement*/}}
- {{with (sendMessageNoEscapeRetID $chan cembed)}}
- {{/*Make giveaway sdict data Structure */}}
- {{$ID = (joinStr "" $chan .) }}
- {{$giveawaySdict := sdict "chan" $chan "count" 0 "listID" "" "maxWinners" $maxW "maxParticipants" $maxP "expiresAt" (currentTime.Add $duration) "prize" $prize "uID" $uniqueID}}
- {{/*Send Actual Announcement Message*/}}
- {{addMessageReactions $chan . $giveawayEmoji}}
- {{$desc := (joinStr `` `>>> **Prize : **` $prize "\n\n") }}
- {{if gt $maxW 0}}{{$desc = joinStr "" $desc "**Max Winners :** " $maxW }}{{end}}
- {{if gt $maxP 0}}{{$desc = joinStr "" $desc "โ โ โ โ โ **Max Participants :** " $maxP}}{{end}}
- {{$desc = joinStr "" $desc "\n\n**React with " $giveawayEmoji " to enter GiveAway **"}}
- {{editMessageNoEscape $chan . (cembed "title" "๐๐**GiveAway Started !!**๐๐" "description" $desc "color" 16763170 "footer" (sdict "text" (joinStr "" "ID: " $uniqueID " | GiveAway Ends " )) "timestamp" $giveawaySdict.expiresAt) }}
- {{/*Update database values ; schedule giveaway end*/}}
- {{with (dbGet 7777 "giveaway_active").Value}}{{$dbData = .}}{{end}}
- {{$globalSdict.Set "val" $dbData}}{{template "map2sdict" $globalSdict}}{{$dbData = $globalSdict.res}}
- {{$dbData.Set $ID $giveawaySdict}}{{dbSet 7777 "giveaway_active" $dbData}}
- {{$dbData =sdict}}{{with (dbGet 7777 "giveaway_active_IDs").Value}}{{$dbData = .}}{{end}}
- {{$globalSdict.Set "val" $dbData}}{{template "map2sdict" $globalSdict}}{{$dbData = $globalSdict.res}}
- {{$dbData.Set (toString $uniqueID) $ID}}{{dbSet 7777 "giveaway_active_IDs" $dbData}}
- {{scheduleUniqueCC (toInt $CCID) $chan $duration.Seconds $uniqueID $ID}}
- {{else}}
- **Invalid Channel !!**
- {{end}}
- {{else}}
- **Error:** Max Winners cannot be more than Max Participants!!
- {{end}}
- {{else}}
- **Error:** Invalid Duration or Prize !!
- {{end}}
- {{/*Command-End*/}}
- {{else if eq (lower (index .CmdArgs 0) ) "end"}}
- {{$uID := index .CmdArgs 1}}
- {{/*if giveaways active*/}}
- {{with (dbGet 7777 "giveaway_active").Value}}
- {{/*if uID is valid*/}}
- {{$ID := index (dbGet 7777 "giveaway_active_IDs").Value $uID}}
- {{with (index . (toString $ID))}}
- {{/*reschedue giveaway to end instantly*/}}
- {{scheduleUniqueCC (toInt $CCID) .chan 1 .uID $ID}}
- {{else}}
- **Error:** Invalid ID ``{{$uID}}``
- {{end}}
- {{else}}
- **Error:** No Active Giveaways.
- {{end}}
- {{/* Command Cancel */}}
- {{else if eq (lower (index .CmdArgs 0) ) "cancel"}}
- {{$uID := index .CmdArgs 1}}{{$ID := 0}}
- {{/* checking if any giveaways are active*/}}
- {{with (dbGet 7777 "giveaway_active").Value}}
- {{$dbID := (dbGet 7777 "giveaway_active_IDs").Value}} {{$ID = index $dbID $uID}}
- {{/*if ID is valid*/}}
- {{with (index . (toString $ID))}}
- {{/* cancelling giveaway end scheduled cc , updating giveaway announcement message */}}
- {{$chan := .chan}}{{$prize := .prize}}
- {{cancelScheduledUniqueCC (toInt $CCID) .uID}}
- {{$msg := index ( split $ID (toString $chan)) 1}}
- {{with (getMessage $chan $msg )}}{{editMessageNoEscape $chan $msg (cembed "title" "๐๐**GiveAway Cancelled !!**๐๐" "description" (joinStr "" ">>> **Prize:** " $prize) "footer" (sdict "text" "Giveaway Cancelled") "color" 12257822 )}}{{end}}Done!
- {{else}}
- **Error:** Invalid ID ``{{$uID}}``
- {{end}}
- {{/* if found , updating giveaway database */}}
- {{if $ID}}
- {{$newdbData := sdict}}{{range $k , $v := .}}{{if ne $k $ID}}{{$newdbData.Set $k $v}}{{end}}{{end}}
- {{dbSet 7777 "giveaway_active" $newdbData}}
- {{$newdbData := sdict}}{{range $k , $v := $dbID}}{{if ne $k $uID}}{{$newdbData.Set $k $v}}{{end}}{{end}}
- {{dbSet 7777 "giveaway_active_IDs" $newdbData}}
- {{end}}
- {{else}}
- **Error:** No Active Giveaways.
- {{end}}
- {{/* Command List */}}
- {{else if eq (lower (index .CmdArgs 0) ) "list"}}
- {{/* checking if giveaways active*/}}
- {{with (dbGet 7777 "giveaway_active").Value}}
- {{$count := 0}}
- {{/* Listing all active giveaway data fields*/}}
- {{range $k , $v := .}}{{$count = add $count 1}}
- {{$count}}) **ID:** ``{{$v.uID}}`` **Prize:** ``{{$v.prize}}``
- **Ends AT:** ``{{formatTime $v.expiresAt}}``
- {{end}}
- {{else}}
- No Active Giveaways.
- {{end}}
- {{else}}
- {{$syntaxError = 1}} {{/*update global variable for incorrect syntax*/}}
- {{end}}
- {{else}}
- {{$syntaxError = 1}} {{/*update global variable for incorrect syntax*/}}
- {{end}}
- {{else}}
- {{$syntaxError = 1}} {{/*update global variable for incorrect syntax*/}}
- {{end}}
- {{else}}
- {{/* Giveaway Ending handling */}}
- {{/* Setting Variables */}}
- {{$ID := .ExecData}}
- {{$dbData := (dbGet 7777 "giveaway_active" ).Value}}
- {{$giveawayData := (index $dbData $ID) }}
- {{$globalSdict.Set "val" $giveawayData}}{{template "map2sdict" $globalSdict}}{{$giveawayData = $globalSdict.res}}
- {{$countWinners := toInt $giveawayData.maxWinners}} {{$count := toInt $giveawayData.count}}
- {{/* if reaction count < max winners ; update no of winners to find */}}
- {{if lt $count $countWinners}}{{$countWinners = $count}}{{end}}
- {{$chan := .Channel.ID}} {{$msg := index ( split $ID (toString $chan)) 1}}
- {{$listID := $giveawayData.listID}}
- {{/* Consider the reactions/user IDs upto max allowed number if count > maxParticipants*/}}
- {{if and (gt $count $giveawayData.maxParticipants) (gt $giveawayData.maxParticipants 0)}}{{$count = $giveawayData.maxParticipants}}{{$listID = joinStr "," (slice (split $listID ",") 0 $count) ""}}{{end}}
- {{/* computing list of winner mentions */}}
- {{$winnerList := ""}}
- {{range seq 0 $countWinners}}
- {{$winner := index (split $listID ",") (randInt 0 $count )}}
- {{$listID = reReplace (joinStr "" $winner ",") $listID ""}}{{$count = add $count -1}}
- {{$winnerList = (joinStr "" $winnerList "<@" $winner "> ")}}
- {{end}}
- {{/* Update existing giveaway announce message*/}}
- {{$desc := joinStr "" ">>> **Prize:** " $giveawayData.prize "\n\n**Winners:** " }}
- {{if $countWinners }}{{$desc = joinStr "" $desc $winnerList}}{{else}}{{$desc = joinStr "" $desc "No Participants :( "}}{{end}}
- {{with (getMessage $chan $msg )}}{{editMessageNoEscape $chan $msg (cembed "title" "๐๐**GiveAway Ended !!**๐๐" "description" $desc "footer" (sdict "text" "Giveaway Ended at ") "timestamp" currentTime "color" 12257822 )}}{{end}}
- {{/* Announce winners */}}
- {{if $countWinners}}
- {{sendMessage nil (joinStr "" "**Prize:** " $giveawayData.prize "\n**Winner(s) :** " $winnerList)}}
- {{else}}
- **Giveaway Ended, No participants :( !!**
- **Prize : {{$giveawayData.prize}}**
- {{end}}
- {{/* update giveaway database */}}
- {{$newdbData := sdict}}
- {{range $k , $v := $dbData}}{{if ne $k $ID}}{{$newdbData.Set $k $v}}{{end}}{{end}}
- {{dbSet 7777 "giveaway_active" $newdbData}}
- {{$newdbData = sdict}}{{range $k , $v := (dbGet 7777 "giveaway_active_IDs").Value}}{{if ne $k (toString $giveawayData.uID)}}{{$newdbData.Set $k $v}}{{end}}{{end}}
- {{dbSet 7777 "giveaway_active_IDs" $newdbData}}
- {{end}}
- {{/*print error message & syntax details */}}
- {{if $syntaxError}}
- {{sendMessage nil (joinStr "" "__**Incorrect Syntax** __ \n**Commands are :** \n```elm\n" (.Cmd) " start <Time> [Prize] \n\noptional_flags \n-p (max participants : Number) \n-w (max winners : Number)\n-c (channel : Mention/ID)\n```\n```elm\n" (.Cmd) " end <ID>```\n```elm\n" (.Cmd) " cancel <ID>```\n```" (.Cmd) " list ``` ")}}
- {{end}}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement