├── .gitignore ├── README.md ├── egg.nim ├── eternity └── run /.gitignore: -------------------------------------------------------------------------------- 1 | eggs.txt 2 | .env 3 | .idea -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Egg 2 | This bot reacts to any message containing `egg`, and will count the total eggs ever mentioned. 3 | 4 | ## Building 5 | 6 | - `nim` >= 1.4.4 7 | - `nimble install dimscord@#head` 8 | - `./run` 9 | -------------------------------------------------------------------------------- /egg.nim: -------------------------------------------------------------------------------- 1 | import dimscord, asyncdispatch, times, options, os, parseutils, strutils 2 | 3 | let discord = newDiscordClient(getEnv("EGG_BOT_TOKEN")) 4 | var eggs = 0 5 | 6 | if fileExists("eggs.txt"): 7 | discard readFile("eggs.txt").parseInt(eggs) 8 | 9 | proc onReady(s: Shard, r: Ready) {.event(discord).} = 10 | echo "Ready as " & $r.user 11 | await s.updateStatus(activity = ActivityStatus( 12 | name: $eggs & " 🥚", 13 | kind: atPlaying 14 | ).some, status = "online") 15 | 16 | proc messageCreate(s: Shard, m: Message) {.event(discord).} = 17 | if not m.author.bot and m.content.toLowerAscii.contains("egg"): 18 | eggs.inc 19 | 20 | try: 21 | await discord.api.addMessageReaction(m.channelId, m.id, "🥚") 22 | await s.updateStatus(activity = ActivityStatus( 23 | name: $eggs & " 🥚", 24 | kind: atPlaying 25 | ).some, status = "online") 26 | writeFile("eggs.txt", $eggs) 27 | except: 28 | discard #I don't care 29 | 30 | waitFor discord.startSession() 31 | -------------------------------------------------------------------------------- /eternity: -------------------------------------------------------------------------------- 1 | while : 2 | do 3 | nim r -d:ssl egg.nim 4 | done 5 | -------------------------------------------------------------------------------- /run: -------------------------------------------------------------------------------- 1 | nim r -d:ssl egg.nim --------------------------------------------------------------------------------