Skip to main content

Counting System

This command runs the counting game.

Trigger

Type: Regex
Trigger: \A

Restrictions

Set this command to only run in your counting channel in the channel restrictions.

Usage

  • Type a number in the counting chat to begin the game!
    • You can't count twice in a row.
  • Run resetcount to reset the count (staff only).

Configuration

  • $emoji
    Emoji to be added to the latest correct count.

  • $wrong
    Response when users get the count wrong.

  • $twice
    Response when users attempt to count twice in a row.

  • $1000_ntf
    Milestone notification for every 1000 numbers counted.

  • $100_ntf
    Milestone notification for every 100 numbers counted.

  • $change_msg
    Informational message to be sent when the latest correct count was changed.

  • $warn_on_del
    Whether to warn when a member deletes their latest correct count.

  • $warn_msg
    Warning message for the above option.

  • 📌 $staff_roles
    List of role IDs to ignore when trying to warn members. Also, only users with one of these roles can run the resetcount command.

Code

{{/*
A counting game.
See <https://yagpdb-cc.github.io/fun/counting> for more information.

Author: SpecialEliteSNP <https://github.com/SpecialEliteSNP>
*/}}

{{/* Configurable values */}}
{{ $emoji := "☑" }}

{{ $wrong := "not the right number bud 😅" }}
{{ $twice := "we do counting together 😠" }}
{{ $1000_ntf := "Holy moly, have we really reached" }}
{{ $100_ntf := "We have reached" }}

{{ $change_msg := "we're currently at:" }}
{{ $warn_on_del := true }}
{{ $warn_msg := "Don't change your latest correct count!" }}
{{ $staff_roles := cslice 763447831829938176 764103587223044116 778952687986802698 764054381535821825 775003755842109440 }}
{{/* End of configurable values */}}

{{/* CODE - Don't edit this part */}}
{{ $c := sdict }}{{ with (dbGet 20 "counting").Value }}{{ $c = sdict . }}{{ end }}
{{ $r := 0 }}{{ with (dbGet .User.ID "resetcount").Value }}{{ $r = . }}{{ end }}
{{ $s := false }}{{ range .Member.Roles }}{{ if in $staff_roles . }}{{ $s = true }}{{ end }}{{ end }}
{{ if not $c }}
{{try}}{{ addReactions "☑" }}{{catch}}{{end}}
{{ dbSet 20 "counting" (sdict "l" (sdict "c" 1 "m" 0 "u" 0 "w" 0)) }}
{{ print .User.Mention ", <#" .Channel.ID "> is all set up as your counting channel!" }}
{{ else if and $s (eq (print .ServerPrefix "resetcount") .Message.Content) }}
{{ deleteTrigger 1 }}
{{ if $s }}
{{ if not $r }}
{{ $m := sendMessageRetID nil (cembed
"color" 16734296
"description" (print "‼ " .User.Mention ", are you sure you want to reset the count to **1**?\n\nIf you're sure, type `-resetcount` again.")
"footer" (sdict "text" "This message will self destruct in 30 seconds")) }}
{{ deleteMessage nil $m 30 }}
{{ dbSetExpire .User.ID "resetcount" (sdict "s" 1 "m" $m) 30 }}
{{ else }}
{{ deleteMessage nil $r.m 0 }}
{{ dbDel .User.ID "resetcount" }}
{{ range $k, $v := $c }}
{{ if eq $k "l" }}{{ $c.Set $k (sdict "c" 1 "m" 0 "u" 0 "w" 0) }}{{ end }}
{{ end }}
{{ dbSet 20 "counting" $c }}
{{ print .User.Mention ", reset the count in <#" .Channel.ID ">!" }}
{{ deleteResponse 10 }}
{{ end }}
{{ else }}
{{ print .User.Mention ", you don't have the permissions to reset the count!" }}
{{ deleteResponse 5 }}
{{ end }}
{{ else if eq .User.ID $c.l.u }}
{{ deleteTrigger 1 }}
{{ print .User.Mention ", " $twice }}
{{ deleteResponse 5 }}
{{ else if or (not (reFind `\A\d+\z` .Message.Content)) (ne $c.l.c (toInt .Message.Content)) }}
{{ deleteTrigger 1 }}
{{ $m := getMessage nil $c.l.m }}
{{ if eq $c.l.m 0 }}
{{ print .User.Mention ", the count starts at 1 😉" }}
{{ else if not $m }}
{{ print .User.Mention ", " $change_msg " `" $c.l.c "`" }}
{{ $s := false }}{{ range (getMember $c.l.u).Roles }}{{ if in $staff_roles . }}{{ $s = true }}{{ end }}{{ end }}
{{ if and $warn_on_del (not $c.l.w) (not $s) }}{{ $h := execAdmin "warn" $c.l.u $warn_msg }}{{ $c.Set "l" (sdict "c" $c.l.c "m" $c.l.m "u" $c.l.u "w" 1) }}{{ dbSet 20 "counting" $c}}{{ end }}
{{ else if ne (sub $c.l.c 1) (toInt $m.Content) }}
{{ print .User.Mention ", " $change_msg " `" $c.l.c "`" }}
{{ $s := false }}{{ range (getMember $c.l.u).Roles }}{{ if in $staff_roles . }}{{ $s = true }}{{ end }}{{ end }}
{{ if and $warn_on_del (not $c.l.w) (not $s) }}{{ $h := execAdmin "warn" $c.l.u $warn_msg }}{{ $c.Set "l" (sdict "c" $c.l.c "m" $c.l.m "u" $c.l.u "w" 1) }}{{ dbSet 20 "counting" $c}}{{ end }}
{{ else }}
{{ print .User.Mention ", " $wrong }}
{{ end }}
{{ deleteResponse 10 }}
{{ else }}
{{ if eq (index .Message.Content 0) 48 }}
{{ deleteTrigger 1 }}
{{ print .User.Mention ", leading zeros are not allowed!"}}
{{ deleteResponse 10 }}
{{ else }}
{{ deleteAllMessageReactions nil $c.l.m }}
{{try}}{{ addReactions $emoji }}{{catch}}{{end}}
{{ $c.Set (str .User.ID) (add ($c.Get (str .User.ID)) 1) }}
{{ $c.Set "l" (sdict "c" (add $c.l.c 1) "m" .Message.ID "u" .User.ID "w" 0) }}
{{ dbSet 20 "counting" $c }}
{{ if eq (toInt (mod $c.l.c 1000)) 0 }}
{{ print $1000_ntf " " $c.l.c "?! 😲" }}
{{ else if eq (toInt (mod $c.l.c 100)) 0 }}
{{ print $100_ntf " " $c.l.c "! 🎉" }}
{{ end }}
{{ end }}
{{ end }}

Author

This custom command was written by @SpecialEliteSNP.