-
Notifications
You must be signed in to change notification settings - Fork 66
/
yagpdb_update.yag
37 lines (34 loc) · 2.3 KB
/
yagpdb_update.yag
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
{{/*
Trigger: 10 Minutes
Trigger Type: Interval
Note: If if the command runs for the first time it will output a preview / example on how it will look.
That means if it ran once it will work afterwards.
Copyright (c): Black Wolf, 2021
License: MIT
Repository: https://github.com/BlackWolfWoof/yagpdb-cc/
*/}}
{{$channel := .Channel.ID}}{{/*The channel it should be sending the message in, .Channel.ID = current channel*/}}
{{$version := index (reFindAllSubmatches `YAGPDB Status, version (.+)` (exec "yagstatus").Title) 0 1}}
{{$yagversion := sdict}}{{with dbGet $.BotUser.ID "yagversion"}}{{$yagversion = .Value}}{{end}}
{{$firsttime := ""}}
{{if not $yagversion.version}}
{{$yagversion = sdict "version" "No old versions recorded" "last_update" (toDuration "5329h"|(newDate 2015 1 1 0 0 0).Add|currentTime.Sub|(newDate 2015 1 1 0 0 0).Add)}}{{$firsttime = " - ❗Example❗ "}}
{{end}}
{{if not (eq $yagversion.version $version)}}
{{$time1 := $yagversion.last_update}}
{{$days := fdiv (currentTime.Sub $yagversion.last_update).Hours 24}}{{$human := currentTime.Sub $yagversion.last_update|humanizeDurationSeconds}}
{{if currentTime.Before $yagversion.last_update}}
{{$days = fdiv ($yagversion.last_update.Sub currentTime).Hours 24}}{{$human = $yagversion.last_update.Sub currentTime|humanizeDurationSeconds}}
{{end}}
{{$y := fdiv $days 365.25|roundFloor|toFloat}}
{{$mo := sub (fdiv $days 30.417) (mult $y 12)|roundFloor|toFloat}}
{{$d := toFloat (add (mult $y 365.25) (mult $mo 30.417)|sub $days)}}
{{sendMessage $channel (cembed
"fields" (cslice
(sdict "name" "**• Version:** <:editmessage:710443113902243851>" "value" (print "Old: \u2004\u200A`" $yagversion.version "`\nNew: `" $version "`") "inline" true)
(sdict "name" "**• Time:** <:stopwatch1:650328464825516062>" "value" (print "Time that passed since the last update:\n**" (currentTime.Sub $yagversion.last_update|humanizeDurationHours) "\n🗓️<t:" $time1.Unix ":d> ⏱️<t:" $time1.Unix ":T>\u200A⌛\u200A" (toInt $y) "Y " (toInt $mo) "M " (toInt $d) "D**") "inline" true))
"author" (sdict "icon_url" "https://cdn.discordapp.com/emojis/708214342067421215.png" "name" (print "YAGPDB updated" $firsttime))
"color" 0x738BD7
"timestamp" currentTime)}}
{{dbSet $.BotUser.ID "yagversion" (sdict "version" $version "last_update" currentTime)}}
{{end}}