Advertisement
Guest User

Untitled

a guest
Nov 14th, 2019
199
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.75 KB | None | 0 0
  1. {{$giveawayEmoji := `๐ŸŽ‰`}}{{/* set giveaway emoji to be used */}}
  2.  
  3. {{/*Actual Code , do not touch unless you know what youre doing*/}}
  4.  
  5. {{/*Declaring global variables,templates*/}}
  6. {{$globalSdict := sdict }}{{$CCID := .CCID}}{{$syntaxError := 0}}
  7. {{define "map2sdict"}}{{$map:= (.Get "val")}}{{$tempSdict:=sdict}}{{range $key , $val := $map}}{{$tempSdict.Set $key $val}}{{end}}{{(.Set "res" $tempSdict)}}{{end}}
  8.  
  9. {{/*checking direct/indirect command invoke*/}}
  10. {{if not .ExecData }}
  11. {{if gt ( len .CmdArgs ) 0 }}
  12. {{if or (gt (len .CmdArgs) 1) (eq (lower (index .CmdArgs 0) ) "list")}}
  13.  
  14. {{/*Command - Start*/}}
  15. {{if eq (lower (index .CmdArgs 0) ) "start"}}
  16.  
  17. {{/*Variable declarations & assignments*/}}
  18. {{$CmdArgs := joinStr " " (slice (split .StrippedMsg " ") 1 )}}
  19. {{$maxP := -1}}{{$maxW := 1}}{{$chan:= .Channel.ID}}{{$ID:= ""}}{{$dbData := sdict}}
  20. {{$uniqueID := toInt (currentTime.Sub (newDate 2019 10 10 0 0 0)).Seconds}}
  21.  
  22.  
  23. {{/*Handling flags, parsing data from input*/}}
  24. {{with reFindAllSubmatches `(?i)((-w) (\d+)(?:\s|$))` $CmdArgs}}
  25. {{$CmdArgs = reReplace `(?i)(-w \d+\s+)|(-w \d+$)` $CmdArgs ""}}
  26. {{$maxW = toInt (index (index . 0) 3)}}
  27. {{end}}
  28.  
  29. {{with reFindAllSubmatches `(?i)((-p) (\d+)(?:\s|$))` $CmdArgs}}
  30. {{$CmdArgs = reReplace `(?i)(-p \d+(\s+))|(-p \d+$)` $CmdArgs ""}}
  31. {{$maxP = toInt (index (index . 0) 3)}}
  32. {{end}}
  33.  
  34. {{with reFindAllSubmatches `(?i)(-c (?:<#)?(\d+)(?:>?)(?:\s|$))` $CmdArgs}}
  35. {{$CmdArgs = reReplace `(?i)(-c ((<#)?\d+(>?))\s+)|(-c ((<#)?\d+(>?))$)` $CmdArgs ""}}
  36. {{$chan = index (index . 0) 2}}
  37. {{end}}
  38.  
  39. {{$temp := split $CmdArgs " "}}
  40. {{$dur:= lower (index $temp 0)}}
  41. {{$prize := ""}}
  42. {{if gt (len $temp) 1}}{{$prize = joinStr " " (slice $temp 1)}}{{end}}
  43.  
  44. {{/* String to Duration */}}
  45. {{$duration := 0}}
  46. {{$hr := .TimeHour}}{{$min := .TimeMinute}}{{$sec := .TimeSecond}}
  47. {{with reFindAllSubmatches `(\d+)(d)` $dur }}
  48. {{$duration = toDuration ( add (mult 24 (toInt (index (index . 0) 1)) $hr) $duration ) }}
  49. {{end}}
  50. {{with reFindAllSubmatches `(\d+)(h)` $dur}}
  51. {{$duration = toDuration ( add (mult (toInt (index (index . 0) 1)) $hr) $duration ) }}
  52. {{end}}
  53. {{with reFindAllSubmatches `(\d+)(m)` $dur}}
  54. {{$duration = toDuration ( add (mult (toInt (index (index . 0 ) 1)) $min) $duration ) }}
  55. {{end}}
  56. {{with reFindAllSubmatches `(\d+)(s)` $dur}}
  57. {{$duration = toDuration ( add (mult (toInt (index (index . 0 ) 1)) $sec) $duration ) }}
  58. {{end}}
  59.  
  60. {{/* if valid duration & prize */}}
  61. {{if and ($duration) ($prize)}}
  62.  
  63. {{/*if max Participants > max Winners*/}}
  64. {{if or (ge $maxP $maxW) (eq $maxP -1)}}
  65.  
  66. {{/*Giveaway Announcement*/}}
  67. {{with (sendMessageNoEscapeRetID $chan cembed)}}
  68.  
  69. {{/*Make giveaway sdict data Structure */}}
  70. {{$ID = (joinStr "" $chan .) }}
  71. {{$giveawaySdict := sdict "chan" $chan "count" 0 "listID" "" "maxWinners" $maxW "maxParticipants" $maxP "expiresAt" (currentTime.Add $duration) "prize" $prize "uID" $uniqueID}}
  72.  
  73. {{/*Send Actual Announcement Message*/}}
  74. {{addMessageReactions $chan . $giveawayEmoji}}
  75. {{$desc := (joinStr `` `>>> **Prize : **` $prize "\n\n") }}
  76. {{if gt $maxW 0}}{{$desc = joinStr "" $desc "**Max Winners :** " $maxW }}{{end}}
  77. {{if gt $maxP 0}}{{$desc = joinStr "" $desc "โ €โ €โ €โ €โ €**Max Participants :** " $maxP}}{{end}}
  78. {{$desc = joinStr "" $desc "\n\n**React with " $giveawayEmoji " to enter GiveAway **"}}
  79. {{editMessageNoEscape $chan . (cembed "title" "๐ŸŒŸ๐ŸŒŸ**GiveAway Started !!**๐ŸŒŸ๐ŸŒŸ" "description" $desc "color" 16763170 "footer" (sdict "text" (joinStr "" "ID: " $uniqueID " | GiveAway Ends " )) "timestamp" $giveawaySdict.expiresAt) }}
  80.  
  81. {{/*Update database values ; schedule giveaway end*/}}
  82. {{with (dbGet 7777 "giveaway_active").Value}}{{$dbData = .}}{{end}}
  83. {{$globalSdict.Set "val" $dbData}}{{template "map2sdict" $globalSdict}}{{$dbData = $globalSdict.res}}
  84. {{$dbData.Set $ID $giveawaySdict}}{{dbSet 7777 "giveaway_active" $dbData}}
  85. {{$dbData =sdict}}{{with (dbGet 7777 "giveaway_active_IDs").Value}}{{$dbData = .}}{{end}}
  86. {{$globalSdict.Set "val" $dbData}}{{template "map2sdict" $globalSdict}}{{$dbData = $globalSdict.res}}
  87. {{$dbData.Set (toString $uniqueID) $ID}}{{dbSet 7777 "giveaway_active_IDs" $dbData}}
  88. {{scheduleUniqueCC (toInt $CCID) $chan $duration.Seconds $uniqueID $ID}}
  89.  
  90. {{else}}
  91. **Invalid Channel !!**
  92. {{end}}
  93.  
  94. {{else}}
  95. **Error:** Max Winners cannot be more than Max Participants!!
  96. {{end}}
  97.  
  98. {{else}}
  99. **Error:** Invalid Duration or Prize !!
  100. {{end}}
  101.  
  102. {{/*Command-End*/}}
  103. {{else if eq (lower (index .CmdArgs 0) ) "end"}}
  104. {{$uID := index .CmdArgs 1}}
  105. {{/*if giveaways active*/}}
  106. {{with (dbGet 7777 "giveaway_active").Value}}
  107. {{/*if uID is valid*/}}
  108. {{$ID := index (dbGet 7777 "giveaway_active_IDs").Value $uID}}
  109. {{with (index . (toString $ID))}}
  110. {{/*reschedue giveaway to end instantly*/}}
  111. {{scheduleUniqueCC (toInt $CCID) .chan 1 .uID $ID}}
  112.  
  113. {{else}}
  114. **Error:** Invalid ID ``{{$uID}}``
  115. {{end}}
  116.  
  117. {{else}}
  118. **Error:** No Active Giveaways.
  119. {{end}}
  120.  
  121. {{/* Command Cancel */}}
  122. {{else if eq (lower (index .CmdArgs 0) ) "cancel"}}
  123. {{$uID := index .CmdArgs 1}}{{$ID := 0}}
  124.  
  125. {{/* checking if any giveaways are active*/}}
  126. {{with (dbGet 7777 "giveaway_active").Value}}
  127. {{$dbID := (dbGet 7777 "giveaway_active_IDs").Value}} {{$ID = index $dbID $uID}}
  128.  
  129. {{/*if ID is valid*/}}
  130. {{with (index . (toString $ID))}}
  131. {{/* cancelling giveaway end scheduled cc , updating giveaway announcement message */}}
  132. {{$chan := .chan}}{{$prize := .prize}}
  133. {{cancelScheduledUniqueCC (toInt $CCID) .uID}}
  134. {{$msg := index ( split $ID (toString $chan)) 1}}
  135. {{with (getMessage $chan $msg )}}{{editMessageNoEscape $chan $msg (cembed "title" "๐ŸŒŸ๐ŸŒŸ**GiveAway Cancelled !!**๐ŸŒŸ๐ŸŒŸ" "description" (joinStr "" ">>> **Prize:** " $prize) "footer" (sdict "text" "Giveaway Cancelled") "color" 12257822 )}}{{end}}Done!
  136.  
  137. {{else}}
  138. **Error:** Invalid ID ``{{$uID}}``
  139. {{end}}
  140.  
  141. {{/* if found , updating giveaway database */}}
  142. {{if $ID}}
  143. {{$newdbData := sdict}}{{range $k , $v := .}}{{if ne $k $ID}}{{$newdbData.Set $k $v}}{{end}}{{end}}
  144. {{dbSet 7777 "giveaway_active" $newdbData}}
  145. {{$newdbData := sdict}}{{range $k , $v := $dbID}}{{if ne $k $uID}}{{$newdbData.Set $k $v}}{{end}}{{end}}
  146. {{dbSet 7777 "giveaway_active_IDs" $newdbData}}
  147. {{end}}
  148.  
  149. {{else}}
  150. **Error:** No Active Giveaways.
  151. {{end}}
  152.  
  153. {{/* Command List */}}
  154. {{else if eq (lower (index .CmdArgs 0) ) "list"}}
  155.  
  156. {{/* checking if giveaways active*/}}
  157. {{with (dbGet 7777 "giveaway_active").Value}}
  158. {{$count := 0}}
  159.  
  160. {{/* Listing all active giveaway data fields*/}}
  161. {{range $k , $v := .}}{{$count = add $count 1}}
  162. {{$count}}) **ID:** ``{{$v.uID}}`` **Prize:** ``{{$v.prize}}``
  163. **Ends AT:** ``{{formatTime $v.expiresAt}}``
  164. {{end}}
  165.  
  166. {{else}}
  167. No Active Giveaways.
  168. {{end}}
  169.  
  170. {{else}}
  171. {{$syntaxError = 1}} {{/*update global variable for incorrect syntax*/}}
  172. {{end}}
  173. {{else}}
  174. {{$syntaxError = 1}} {{/*update global variable for incorrect syntax*/}}
  175. {{end}}
  176. {{else}}
  177. {{$syntaxError = 1}} {{/*update global variable for incorrect syntax*/}}
  178. {{end}}
  179. {{else}}
  180.  
  181. {{/* Giveaway Ending handling */}}
  182. {{/* Setting Variables */}}
  183. {{$ID := .ExecData}}
  184. {{$dbData := (dbGet 7777 "giveaway_active" ).Value}}
  185. {{$giveawayData := (index $dbData $ID) }}
  186. {{$globalSdict.Set "val" $giveawayData}}{{template "map2sdict" $globalSdict}}{{$giveawayData = $globalSdict.res}}
  187. {{$countWinners := toInt $giveawayData.maxWinners}} {{$count := toInt $giveawayData.count}}
  188.  
  189. {{/* if reaction count < max winners ; update no of winners to find */}}
  190. {{if lt $count $countWinners}}{{$countWinners = $count}}{{end}}
  191. {{$chan := .Channel.ID}} {{$msg := index ( split $ID (toString $chan)) 1}}
  192. {{$listID := $giveawayData.listID}}
  193.  
  194. {{/* Consider the reactions/user IDs upto max allowed number if count > maxParticipants*/}}
  195. {{if and (gt $count $giveawayData.maxParticipants) (gt $giveawayData.maxParticipants 0)}}{{$count = $giveawayData.maxParticipants}}{{$listID = joinStr "," (slice (split $listID ",") 0 $count) ""}}{{end}}
  196.  
  197. {{/* computing list of winner mentions */}}
  198. {{$winnerList := ""}}
  199. {{range seq 0 $countWinners}}
  200. {{$winner := index (split $listID ",") (randInt 0 $count )}}
  201. {{$listID = reReplace (joinStr "" $winner ",") $listID ""}}{{$count = add $count -1}}
  202. {{$winnerList = (joinStr "" $winnerList "<@" $winner "> ")}}
  203. {{end}}
  204.  
  205. {{/* Update existing giveaway announce message*/}}
  206. {{$desc := joinStr "" ">>> **Prize:** " $giveawayData.prize "\n\n**Winners:** " }}
  207. {{if $countWinners }}{{$desc = joinStr "" $desc $winnerList}}{{else}}{{$desc = joinStr "" $desc "No Participants :( "}}{{end}}
  208. {{with (getMessage $chan $msg )}}{{editMessageNoEscape $chan $msg (cembed "title" "๐ŸŒŸ๐ŸŒŸ**GiveAway Ended !!**๐ŸŒŸ๐ŸŒŸ" "description" $desc "footer" (sdict "text" "Giveaway Ended at ") "timestamp" currentTime "color" 12257822 )}}{{end}}
  209.  
  210. {{/* Announce winners */}}
  211. {{if $countWinners}}
  212. {{sendMessage nil (joinStr "" "**Prize:** " $giveawayData.prize "\n**Winner(s) :** " $winnerList)}}
  213. {{else}}
  214. **Giveaway Ended, No participants :( !!**
  215. **Prize : {{$giveawayData.prize}}**
  216. {{end}}
  217.  
  218. {{/* update giveaway database */}}
  219. {{$newdbData := sdict}}
  220. {{range $k , $v := $dbData}}{{if ne $k $ID}}{{$newdbData.Set $k $v}}{{end}}{{end}}
  221. {{dbSet 7777 "giveaway_active" $newdbData}}
  222. {{$newdbData = sdict}}{{range $k , $v := (dbGet 7777 "giveaway_active_IDs").Value}}{{if ne $k (toString $giveawayData.uID)}}{{$newdbData.Set $k $v}}{{end}}{{end}}
  223. {{dbSet 7777 "giveaway_active_IDs" $newdbData}}
  224. {{end}}
  225.  
  226. {{/*print error message & syntax details */}}
  227. {{if $syntaxError}}
  228. {{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 ``` ")}}
  229. {{end}}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement