tangled
alpha
login
or
join now
bwc9876.dev
/
bingus-bot
0
fork
atom
The world's most clever kitty cat
0
fork
atom
overview
issues
pulls
pipelines
Load and Dump chain commands
bwc9876.dev
1 day ago
032de680
c158cdd6
verified
This commit was signed with the committer's
known signature
.
bwc9876.dev
SSH Key Fingerprint:
SHA256:DanMEP/RNlSC7pAVbnXO6wzQV00rqyKj053tz4uH5gQ=
+930
-9
8 changed files
expand all
collapse all
unified
split
Cargo.lock
Cargo.toml
src
brain.rs
cmd
dump_chain.rs
load_chain.rs
mod.rs
weights.rs
main.rs
+726
-4
Cargo.lock
···
131
131
"colog",
132
132
"fastrand",
133
133
"log",
134
134
+
"reqwest",
134
135
"rmp-serde",
135
136
"rustls",
136
137
"serde",
···
170
171
]
171
172
172
173
[[package]]
174
174
+
name = "bumpalo"
175
175
+
version = "3.20.2"
176
176
+
source = "registry+https://github.com/rust-lang/crates.io-index"
177
177
+
checksum = "5d20789868f4b01b2f2caec9f5c4e0213b41e3e5702a50157d699ae31ced2fcb"
178
178
+
179
179
+
[[package]]
173
180
name = "bytes"
174
181
version = "1.11.1"
175
182
source = "registry+https://github.com/rust-lang/crates.io-index"
···
200
207
checksum = "9330f8b2ff13f34540b44e946ef35111825727b38d33286ef986142615121801"
201
208
202
209
[[package]]
210
210
+
name = "cfg_aliases"
211
211
+
version = "0.2.1"
212
212
+
source = "registry+https://github.com/rust-lang/crates.io-index"
213
213
+
checksum = "613afe47fcd5fac7ccf1db93babcb082c5994d996f20b8b159f2ad1658eb5724"
214
214
+
215
215
+
[[package]]
203
216
name = "cmake"
204
217
version = "0.1.57"
205
218
source = "registry+https://github.com/rust-lang/crates.io-index"
···
242
255
dependencies = [
243
256
"bytes",
244
257
"memchr",
258
258
+
]
259
259
+
260
260
+
[[package]]
261
261
+
name = "core-foundation"
262
262
+
version = "0.9.4"
263
263
+
source = "registry+https://github.com/rust-lang/crates.io-index"
264
264
+
checksum = "91e195e091a93c46f7102ec7818a2aa394e1e1771c3ab4825963fa03e45afb8f"
265
265
+
dependencies = [
266
266
+
"core-foundation-sys",
267
267
+
"libc",
245
268
]
246
269
247
270
[[package]]
···
270
293
]
271
294
272
295
[[package]]
296
296
+
name = "displaydoc"
297
297
+
version = "0.2.5"
298
298
+
source = "registry+https://github.com/rust-lang/crates.io-index"
299
299
+
checksum = "97369cbbc041bc366949bc74d34658d6cda5621039731c6310521892a3a20ae0"
300
300
+
dependencies = [
301
301
+
"proc-macro2",
302
302
+
"quote",
303
303
+
"syn",
304
304
+
]
305
305
+
306
306
+
[[package]]
273
307
name = "dunce"
274
308
version = "1.0.5"
275
309
source = "registry+https://github.com/rust-lang/crates.io-index"
276
310
checksum = "92773504d58c093f6de2459af4af33faa518c13451eb8f2b5698ed3d36e7c813"
311
311
+
312
312
+
[[package]]
313
313
+
name = "encoding_rs"
314
314
+
version = "0.8.35"
315
315
+
source = "registry+https://github.com/rust-lang/crates.io-index"
316
316
+
checksum = "75030f3c4f45dafd7586dd6780965a8c7e8e285a5ecb86713e63a79c5b2766f3"
317
317
+
dependencies = [
318
318
+
"cfg-if",
319
319
+
]
277
320
278
321
[[package]]
279
322
name = "env_filter"
···
333
376
checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1"
334
377
335
378
[[package]]
379
379
+
name = "form_urlencoded"
380
380
+
version = "1.2.2"
381
381
+
source = "registry+https://github.com/rust-lang/crates.io-index"
382
382
+
checksum = "cb4cb245038516f5f85277875cdaa4f7d2c9a0fa0468de06ed190163b1581fcf"
383
383
+
dependencies = [
384
384
+
"percent-encoding",
385
385
+
]
386
386
+
387
387
+
[[package]]
336
388
name = "fs_extra"
337
389
version = "1.3.0"
338
390
source = "registry+https://github.com/rust-lang/crates.io-index"
···
374
426
"futures-core",
375
427
"futures-task",
376
428
"pin-project-lite",
429
429
+
"slab",
377
430
]
378
431
379
432
[[package]]
···
383
436
checksum = "ff2abc00be7fca6ebc474524697ae276ad847ad0a6b3faa4bcb027e9a4614ad0"
384
437
dependencies = [
385
438
"cfg-if",
439
439
+
"js-sys",
386
440
"libc",
387
441
"wasi",
442
442
+
"wasm-bindgen",
388
443
]
389
444
390
445
[[package]]
···
394
449
checksum = "899def5c37c4fd7b2664648c28120ecec138e4d395b459e5ca34f9cce2dd77fd"
395
450
dependencies = [
396
451
"cfg-if",
452
452
+
"js-sys",
397
453
"libc",
398
454
"r-efi",
399
455
"wasip2",
456
456
+
"wasm-bindgen",
400
457
]
401
458
402
459
[[package]]
···
508
565
source = "registry+https://github.com/rust-lang/crates.io-index"
509
566
checksum = "96547c2556ec9d12fb1578c4eaf448b04993e7fb79cbaad930a656880a6bdfa0"
510
567
dependencies = [
568
568
+
"base64",
511
569
"bytes",
512
570
"futures-channel",
513
571
"futures-util",
514
572
"http",
515
573
"http-body",
516
574
"hyper",
575
575
+
"ipnet",
517
576
"libc",
577
577
+
"percent-encoding",
518
578
"pin-project-lite",
519
579
"socket2",
580
580
+
"system-configuration",
520
581
"tokio",
521
582
"tower-service",
522
583
"tracing",
584
584
+
"windows-registry",
585
585
+
]
586
586
+
587
587
+
[[package]]
588
588
+
name = "icu_collections"
589
589
+
version = "2.1.1"
590
590
+
source = "registry+https://github.com/rust-lang/crates.io-index"
591
591
+
checksum = "4c6b649701667bbe825c3b7e6388cb521c23d88644678e83c0c4d0a621a34b43"
592
592
+
dependencies = [
593
593
+
"displaydoc",
594
594
+
"potential_utf",
595
595
+
"yoke",
596
596
+
"zerofrom",
597
597
+
"zerovec",
598
598
+
]
599
599
+
600
600
+
[[package]]
601
601
+
name = "icu_locale_core"
602
602
+
version = "2.1.1"
603
603
+
source = "registry+https://github.com/rust-lang/crates.io-index"
604
604
+
checksum = "edba7861004dd3714265b4db54a3c390e880ab658fec5f7db895fae2046b5bb6"
605
605
+
dependencies = [
606
606
+
"displaydoc",
607
607
+
"litemap",
608
608
+
"tinystr",
609
609
+
"writeable",
610
610
+
"zerovec",
611
611
+
]
612
612
+
613
613
+
[[package]]
614
614
+
name = "icu_normalizer"
615
615
+
version = "2.1.1"
616
616
+
source = "registry+https://github.com/rust-lang/crates.io-index"
617
617
+
checksum = "5f6c8828b67bf8908d82127b2054ea1b4427ff0230ee9141c54251934ab1b599"
618
618
+
dependencies = [
619
619
+
"icu_collections",
620
620
+
"icu_normalizer_data",
621
621
+
"icu_properties",
622
622
+
"icu_provider",
623
623
+
"smallvec",
624
624
+
"zerovec",
625
625
+
]
626
626
+
627
627
+
[[package]]
628
628
+
name = "icu_normalizer_data"
629
629
+
version = "2.1.1"
630
630
+
source = "registry+https://github.com/rust-lang/crates.io-index"
631
631
+
checksum = "7aedcccd01fc5fe81e6b489c15b247b8b0690feb23304303a9e560f37efc560a"
632
632
+
633
633
+
[[package]]
634
634
+
name = "icu_properties"
635
635
+
version = "2.1.2"
636
636
+
source = "registry+https://github.com/rust-lang/crates.io-index"
637
637
+
checksum = "020bfc02fe870ec3a66d93e677ccca0562506e5872c650f893269e08615d74ec"
638
638
+
dependencies = [
639
639
+
"icu_collections",
640
640
+
"icu_locale_core",
641
641
+
"icu_properties_data",
642
642
+
"icu_provider",
643
643
+
"zerotrie",
644
644
+
"zerovec",
645
645
+
]
646
646
+
647
647
+
[[package]]
648
648
+
name = "icu_properties_data"
649
649
+
version = "2.1.2"
650
650
+
source = "registry+https://github.com/rust-lang/crates.io-index"
651
651
+
checksum = "616c294cf8d725c6afcd8f55abc17c56464ef6211f9ed59cccffe534129c77af"
652
652
+
653
653
+
[[package]]
654
654
+
name = "icu_provider"
655
655
+
version = "2.1.1"
656
656
+
source = "registry+https://github.com/rust-lang/crates.io-index"
657
657
+
checksum = "85962cf0ce02e1e0a629cc34e7ca3e373ce20dda4c4d7294bbd0bf1fdb59e614"
658
658
+
dependencies = [
659
659
+
"displaydoc",
660
660
+
"icu_locale_core",
661
661
+
"writeable",
662
662
+
"yoke",
663
663
+
"zerofrom",
664
664
+
"zerotrie",
665
665
+
"zerovec",
666
666
+
]
667
667
+
668
668
+
[[package]]
669
669
+
name = "idna"
670
670
+
version = "1.1.0"
671
671
+
source = "registry+https://github.com/rust-lang/crates.io-index"
672
672
+
checksum = "3b0875f23caa03898994f6ddc501886a45c7d3d62d04d2d90788d47be1b1e4de"
673
673
+
dependencies = [
674
674
+
"idna_adapter",
675
675
+
"smallvec",
676
676
+
"utf8_iter",
677
677
+
]
678
678
+
679
679
+
[[package]]
680
680
+
name = "idna_adapter"
681
681
+
version = "1.2.1"
682
682
+
source = "registry+https://github.com/rust-lang/crates.io-index"
683
683
+
checksum = "3acae9609540aa318d1bc588455225fb2085b9ed0c4f6bd0d9d5bcd86f1a0344"
684
684
+
dependencies = [
685
685
+
"icu_normalizer",
686
686
+
"icu_properties",
523
687
]
524
688
525
689
[[package]]
···
530
694
dependencies = [
531
695
"equivalent",
532
696
"hashbrown",
697
697
+
]
698
698
+
699
699
+
[[package]]
700
700
+
name = "ipnet"
701
701
+
version = "2.12.0"
702
702
+
source = "registry+https://github.com/rust-lang/crates.io-index"
703
703
+
checksum = "d98f6fed1fde3f8c21bc40a1abb88dd75e67924f9cffc3ef95607bad8017f8e2"
704
704
+
705
705
+
[[package]]
706
706
+
name = "iri-string"
707
707
+
version = "0.7.10"
708
708
+
source = "registry+https://github.com/rust-lang/crates.io-index"
709
709
+
checksum = "c91338f0783edbd6195decb37bae672fd3b165faffb89bf7b9e6942f8b1a731a"
710
710
+
dependencies = [
711
711
+
"memchr",
712
712
+
"serde",
533
713
]
534
714
535
715
[[package]]
···
579
759
"combine",
580
760
"jni-sys",
581
761
"log",
582
582
-
"thiserror",
762
762
+
"thiserror 1.0.69",
583
763
"walkdir",
584
764
"windows-sys 0.45.0",
585
765
]
···
601
781
]
602
782
603
783
[[package]]
784
784
+
name = "js-sys"
785
785
+
version = "0.3.91"
786
786
+
source = "registry+https://github.com/rust-lang/crates.io-index"
787
787
+
checksum = "b49715b7073f385ba4bc528e5747d02e66cb39c6146efb66b781f131f0fb399c"
788
788
+
dependencies = [
789
789
+
"once_cell",
790
790
+
"wasm-bindgen",
791
791
+
]
792
792
+
793
793
+
[[package]]
604
794
name = "libc"
605
795
version = "0.2.183"
606
796
source = "registry+https://github.com/rust-lang/crates.io-index"
607
797
checksum = "b5b646652bf6661599e1da8901b3b9522896f01e736bad5f723fe7a3a27f899d"
608
798
609
799
[[package]]
800
800
+
name = "litemap"
801
801
+
version = "0.8.1"
802
802
+
source = "registry+https://github.com/rust-lang/crates.io-index"
803
803
+
checksum = "6373607a59f0be73a39b6fe456b8192fcc3585f602af20751600e974dd455e77"
804
804
+
805
805
+
[[package]]
610
806
name = "log"
611
807
version = "0.4.29"
612
808
source = "registry+https://github.com/rust-lang/crates.io-index"
613
809
checksum = "5e5032e24019045c762d3c0f28f5b6b8bbf38563a65908389bf7978758920897"
810
810
+
811
811
+
[[package]]
812
812
+
name = "lru-slab"
813
813
+
version = "0.1.2"
814
814
+
source = "registry+https://github.com/rust-lang/crates.io-index"
815
815
+
checksum = "112b39cec0b298b6c1999fee3e31427f74f676e4cb9879ed1a121b43661a4154"
614
816
615
817
[[package]]
616
818
name = "memchr"
617
819
version = "2.8.0"
618
820
source = "registry+https://github.com/rust-lang/crates.io-index"
619
821
checksum = "f8ca58f447f06ed17d5fc4043ce1b10dd205e060fb3ce5b979b8ed8e59ff3f79"
822
822
+
823
823
+
[[package]]
824
824
+
name = "mime"
825
825
+
version = "0.3.17"
826
826
+
source = "registry+https://github.com/rust-lang/crates.io-index"
827
827
+
checksum = "6877bb514081ee2a7ff5ef9de3281f14a4dd4bceac4c09388074a6b5df8a139a"
620
828
621
829
[[package]]
622
830
name = "mio"
···
711
919
]
712
920
713
921
[[package]]
922
922
+
name = "potential_utf"
923
923
+
version = "0.1.4"
924
924
+
source = "registry+https://github.com/rust-lang/crates.io-index"
925
925
+
checksum = "b73949432f5e2a09657003c25bca5e19a0e9c84f8058ca374f49e0ebe605af77"
926
926
+
dependencies = [
927
927
+
"zerovec",
928
928
+
]
929
929
+
930
930
+
[[package]]
714
931
name = "powerfmt"
715
932
version = "0.2.0"
716
933
source = "registry+https://github.com/rust-lang/crates.io-index"
717
934
checksum = "439ee305def115ba05938db6eb1644ff94165c5ab5e9420d1c1bcedbba909391"
718
935
719
936
[[package]]
937
937
+
name = "ppv-lite86"
938
938
+
version = "0.2.21"
939
939
+
source = "registry+https://github.com/rust-lang/crates.io-index"
940
940
+
checksum = "85eae3c4ed2f50dcfe72643da4befc30deadb458a9b590d720cde2f2b1e97da9"
941
941
+
dependencies = [
942
942
+
"zerocopy",
943
943
+
]
944
944
+
945
945
+
[[package]]
720
946
name = "proc-macro2"
721
947
version = "1.0.106"
722
948
source = "registry+https://github.com/rust-lang/crates.io-index"
···
726
952
]
727
953
728
954
[[package]]
955
955
+
name = "quinn"
956
956
+
version = "0.11.9"
957
957
+
source = "registry+https://github.com/rust-lang/crates.io-index"
958
958
+
checksum = "b9e20a958963c291dc322d98411f541009df2ced7b5a4f2bd52337638cfccf20"
959
959
+
dependencies = [
960
960
+
"bytes",
961
961
+
"cfg_aliases",
962
962
+
"pin-project-lite",
963
963
+
"quinn-proto",
964
964
+
"quinn-udp",
965
965
+
"rustc-hash",
966
966
+
"rustls",
967
967
+
"socket2",
968
968
+
"thiserror 2.0.18",
969
969
+
"tokio",
970
970
+
"tracing",
971
971
+
"web-time",
972
972
+
]
973
973
+
974
974
+
[[package]]
975
975
+
name = "quinn-proto"
976
976
+
version = "0.11.14"
977
977
+
source = "registry+https://github.com/rust-lang/crates.io-index"
978
978
+
checksum = "434b42fec591c96ef50e21e886936e66d3cc3f737104fdb9b737c40ffb94c098"
979
979
+
dependencies = [
980
980
+
"aws-lc-rs",
981
981
+
"bytes",
982
982
+
"getrandom 0.3.4",
983
983
+
"lru-slab",
984
984
+
"rand",
985
985
+
"ring",
986
986
+
"rustc-hash",
987
987
+
"rustls",
988
988
+
"rustls-pki-types",
989
989
+
"slab",
990
990
+
"thiserror 2.0.18",
991
991
+
"tinyvec",
992
992
+
"tracing",
993
993
+
"web-time",
994
994
+
]
995
995
+
996
996
+
[[package]]
997
997
+
name = "quinn-udp"
998
998
+
version = "0.5.14"
999
999
+
source = "registry+https://github.com/rust-lang/crates.io-index"
1000
1000
+
checksum = "addec6a0dcad8a8d96a771f815f0eaf55f9d1805756410b39f5fa81332574cbd"
1001
1001
+
dependencies = [
1002
1002
+
"cfg_aliases",
1003
1003
+
"libc",
1004
1004
+
"once_cell",
1005
1005
+
"socket2",
1006
1006
+
"tracing",
1007
1007
+
"windows-sys 0.52.0",
1008
1008
+
]
1009
1009
+
1010
1010
+
[[package]]
729
1011
name = "quote"
730
1012
version = "1.0.45"
731
1013
source = "registry+https://github.com/rust-lang/crates.io-index"
···
741
1023
checksum = "69cdb34c158ceb288df11e18b4bd39de994f6657d83847bdffdbd7f346754b0f"
742
1024
743
1025
[[package]]
1026
1026
+
name = "rand"
1027
1027
+
version = "0.9.2"
1028
1028
+
source = "registry+https://github.com/rust-lang/crates.io-index"
1029
1029
+
checksum = "6db2770f06117d490610c7488547d543617b21bfa07796d7a12f6f1bd53850d1"
1030
1030
+
dependencies = [
1031
1031
+
"rand_chacha",
1032
1032
+
"rand_core",
1033
1033
+
]
1034
1034
+
1035
1035
+
[[package]]
1036
1036
+
name = "rand_chacha"
1037
1037
+
version = "0.9.0"
1038
1038
+
source = "registry+https://github.com/rust-lang/crates.io-index"
1039
1039
+
checksum = "d3022b5f1df60f26e1ffddd6c66e8aa15de382ae63b3a0c1bfc0e4d3e3f325cb"
1040
1040
+
dependencies = [
1041
1041
+
"ppv-lite86",
1042
1042
+
"rand_core",
1043
1043
+
]
1044
1044
+
1045
1045
+
[[package]]
1046
1046
+
name = "rand_core"
1047
1047
+
version = "0.9.5"
1048
1048
+
source = "registry+https://github.com/rust-lang/crates.io-index"
1049
1049
+
checksum = "76afc826de14238e6e8c374ddcc1fa19e374fd8dd986b0d2af0d02377261d83c"
1050
1050
+
dependencies = [
1051
1051
+
"getrandom 0.3.4",
1052
1052
+
]
1053
1053
+
1054
1054
+
[[package]]
744
1055
name = "regex"
745
1056
version = "1.12.3"
746
1057
source = "registry+https://github.com/rust-lang/crates.io-index"
···
770
1081
checksum = "dc897dd8d9e8bd1ed8cdad82b5966c3e0ecae09fb1907d58efaa013543185d0a"
771
1082
772
1083
[[package]]
1084
1084
+
name = "reqwest"
1085
1085
+
version = "0.13.2"
1086
1086
+
source = "registry+https://github.com/rust-lang/crates.io-index"
1087
1087
+
checksum = "ab3f43e3283ab1488b624b44b0e988d0acea0b3214e694730a055cb6b2efa801"
1088
1088
+
dependencies = [
1089
1089
+
"base64",
1090
1090
+
"bytes",
1091
1091
+
"encoding_rs",
1092
1092
+
"futures-core",
1093
1093
+
"h2",
1094
1094
+
"http",
1095
1095
+
"http-body",
1096
1096
+
"http-body-util",
1097
1097
+
"hyper",
1098
1098
+
"hyper-rustls",
1099
1099
+
"hyper-util",
1100
1100
+
"js-sys",
1101
1101
+
"log",
1102
1102
+
"mime",
1103
1103
+
"percent-encoding",
1104
1104
+
"pin-project-lite",
1105
1105
+
"quinn",
1106
1106
+
"rustls",
1107
1107
+
"rustls-pki-types",
1108
1108
+
"rustls-platform-verifier",
1109
1109
+
"sync_wrapper",
1110
1110
+
"tokio",
1111
1111
+
"tokio-rustls",
1112
1112
+
"tower",
1113
1113
+
"tower-http",
1114
1114
+
"tower-service",
1115
1115
+
"url",
1116
1116
+
"wasm-bindgen",
1117
1117
+
"wasm-bindgen-futures",
1118
1118
+
"web-sys",
1119
1119
+
]
1120
1120
+
1121
1121
+
[[package]]
773
1122
name = "ring"
774
1123
version = "0.17.14"
775
1124
source = "registry+https://github.com/rust-lang/crates.io-index"
···
803
1152
]
804
1153
805
1154
[[package]]
1155
1155
+
name = "rustc-hash"
1156
1156
+
version = "2.1.1"
1157
1157
+
source = "registry+https://github.com/rust-lang/crates.io-index"
1158
1158
+
checksum = "357703d41365b4b27c590e3ed91eabb1b663f07c4c084095e60cbed4362dff0d"
1159
1159
+
1160
1160
+
[[package]]
806
1161
name = "rustls"
807
1162
version = "0.23.37"
808
1163
source = "registry+https://github.com/rust-lang/crates.io-index"
···
835
1190
source = "registry+https://github.com/rust-lang/crates.io-index"
836
1191
checksum = "be040f8b0a225e40375822a563fa9524378b9d63112f53e19ffff34df5d33fdd"
837
1192
dependencies = [
1193
1193
+
"web-time",
838
1194
"zeroize",
839
1195
]
840
1196
···
844
1200
source = "registry+https://github.com/rust-lang/crates.io-index"
845
1201
checksum = "1d99feebc72bae7ab76ba994bb5e121b8d83d910ca40b36e0921f53becc41784"
846
1202
dependencies = [
847
847
-
"core-foundation",
1203
1203
+
"core-foundation 0.10.1",
848
1204
"core-foundation-sys",
849
1205
"jni",
850
1206
"log",
···
878
1234
]
879
1235
880
1236
[[package]]
1237
1237
+
name = "rustversion"
1238
1238
+
version = "1.0.22"
1239
1239
+
source = "registry+https://github.com/rust-lang/crates.io-index"
1240
1240
+
checksum = "b39cdef0fa800fc44525c84ccb54a029961a8215f9619753635a9c0d2538d46d"
1241
1241
+
1242
1242
+
[[package]]
881
1243
name = "same-file"
882
1244
version = "1.0.6"
883
1245
source = "registry+https://github.com/rust-lang/crates.io-index"
···
902
1264
checksum = "b7f4bc775c73d9a02cde8bf7b2ec4c9d12743edf609006c7facc23998404cd1d"
903
1265
dependencies = [
904
1266
"bitflags",
905
905
-
"core-foundation",
1267
1267
+
"core-foundation 0.10.1",
906
1268
"core-foundation-sys",
907
1269
"libc",
908
1270
"security-framework-sys",
···
1033
1395
]
1034
1396
1035
1397
[[package]]
1398
1398
+
name = "stable_deref_trait"
1399
1399
+
version = "1.2.1"
1400
1400
+
source = "registry+https://github.com/rust-lang/crates.io-index"
1401
1401
+
checksum = "6ce2be8dc25455e1f91df71bfa12ad37d7af1092ae736f3a6cd0e37bc7810596"
1402
1402
+
1403
1403
+
[[package]]
1036
1404
name = "subtle"
1037
1405
version = "2.6.1"
1038
1406
source = "registry+https://github.com/rust-lang/crates.io-index"
···
1050
1418
]
1051
1419
1052
1420
[[package]]
1421
1421
+
name = "sync_wrapper"
1422
1422
+
version = "1.0.2"
1423
1423
+
source = "registry+https://github.com/rust-lang/crates.io-index"
1424
1424
+
checksum = "0bf256ce5efdfa370213c1dabab5935a12e49f2c58d15e9eac2870d3b4f27263"
1425
1425
+
dependencies = [
1426
1426
+
"futures-core",
1427
1427
+
]
1428
1428
+
1429
1429
+
[[package]]
1430
1430
+
name = "synstructure"
1431
1431
+
version = "0.13.2"
1432
1432
+
source = "registry+https://github.com/rust-lang/crates.io-index"
1433
1433
+
checksum = "728a70f3dbaf5bab7f0c4b1ac8d7ae5ea60a4b5549c8a5914361c99147a709d2"
1434
1434
+
dependencies = [
1435
1435
+
"proc-macro2",
1436
1436
+
"quote",
1437
1437
+
"syn",
1438
1438
+
]
1439
1439
+
1440
1440
+
[[package]]
1441
1441
+
name = "system-configuration"
1442
1442
+
version = "0.7.0"
1443
1443
+
source = "registry+https://github.com/rust-lang/crates.io-index"
1444
1444
+
checksum = "a13f3d0daba03132c0aa9767f98351b3488edc2c100cda2d2ec2b04f3d8d3c8b"
1445
1445
+
dependencies = [
1446
1446
+
"bitflags",
1447
1447
+
"core-foundation 0.9.4",
1448
1448
+
"system-configuration-sys",
1449
1449
+
]
1450
1450
+
1451
1451
+
[[package]]
1452
1452
+
name = "system-configuration-sys"
1453
1453
+
version = "0.6.0"
1454
1454
+
source = "registry+https://github.com/rust-lang/crates.io-index"
1455
1455
+
checksum = "8e1d1b10ced5ca923a1fcb8d03e96b8d3268065d724548c0211415ff6ac6bac4"
1456
1456
+
dependencies = [
1457
1457
+
"core-foundation-sys",
1458
1458
+
"libc",
1459
1459
+
]
1460
1460
+
1461
1461
+
[[package]]
1053
1462
name = "thiserror"
1054
1463
version = "1.0.69"
1055
1464
source = "registry+https://github.com/rust-lang/crates.io-index"
1056
1465
checksum = "b6aaf5339b578ea85b50e080feb250a3e8ae8cfcdff9a461c9ec2904bc923f52"
1057
1466
dependencies = [
1058
1058
-
"thiserror-impl",
1467
1467
+
"thiserror-impl 1.0.69",
1468
1468
+
]
1469
1469
+
1470
1470
+
[[package]]
1471
1471
+
name = "thiserror"
1472
1472
+
version = "2.0.18"
1473
1473
+
source = "registry+https://github.com/rust-lang/crates.io-index"
1474
1474
+
checksum = "4288b5bcbc7920c07a1149a35cf9590a2aa808e0bc1eafaade0b80947865fbc4"
1475
1475
+
dependencies = [
1476
1476
+
"thiserror-impl 2.0.18",
1059
1477
]
1060
1478
1061
1479
[[package]]
···
1070
1488
]
1071
1489
1072
1490
[[package]]
1491
1491
+
name = "thiserror-impl"
1492
1492
+
version = "2.0.18"
1493
1493
+
source = "registry+https://github.com/rust-lang/crates.io-index"
1494
1494
+
checksum = "ebc4ee7f67670e9b64d05fa4253e753e016c6c95ff35b89b7941d6b856dec1d5"
1495
1495
+
dependencies = [
1496
1496
+
"proc-macro2",
1497
1497
+
"quote",
1498
1498
+
"syn",
1499
1499
+
]
1500
1500
+
1501
1501
+
[[package]]
1073
1502
name = "time"
1074
1503
version = "0.3.47"
1075
1504
source = "registry+https://github.com/rust-lang/crates.io-index"
···
1100
1529
]
1101
1530
1102
1531
[[package]]
1532
1532
+
name = "tinystr"
1533
1533
+
version = "0.8.2"
1534
1534
+
source = "registry+https://github.com/rust-lang/crates.io-index"
1535
1535
+
checksum = "42d3e9c45c09de15d06dd8acf5f4e0e399e85927b7f00711024eb7ae10fa4869"
1536
1536
+
dependencies = [
1537
1537
+
"displaydoc",
1538
1538
+
"zerovec",
1539
1539
+
]
1540
1540
+
1541
1541
+
[[package]]
1542
1542
+
name = "tinyvec"
1543
1543
+
version = "1.10.0"
1544
1544
+
source = "registry+https://github.com/rust-lang/crates.io-index"
1545
1545
+
checksum = "bfa5fdc3bce6191a1dbc8c02d5c8bffcf557bafa17c124c5264a458f1b0613fa"
1546
1546
+
dependencies = [
1547
1547
+
"tinyvec_macros",
1548
1548
+
]
1549
1549
+
1550
1550
+
[[package]]
1551
1551
+
name = "tinyvec_macros"
1552
1552
+
version = "0.1.1"
1553
1553
+
source = "registry+https://github.com/rust-lang/crates.io-index"
1554
1554
+
checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20"
1555
1555
+
1556
1556
+
[[package]]
1103
1557
name = "tokio"
1104
1558
version = "1.50.0"
1105
1559
source = "registry+https://github.com/rust-lang/crates.io-index"
···
1171
1625
"tokio-rustls",
1172
1626
"tokio-util",
1173
1627
]
1628
1628
+
1629
1629
+
[[package]]
1630
1630
+
name = "tower"
1631
1631
+
version = "0.5.3"
1632
1632
+
source = "registry+https://github.com/rust-lang/crates.io-index"
1633
1633
+
checksum = "ebe5ef63511595f1344e2d5cfa636d973292adc0eec1f0ad45fae9f0851ab1d4"
1634
1634
+
dependencies = [
1635
1635
+
"futures-core",
1636
1636
+
"futures-util",
1637
1637
+
"pin-project-lite",
1638
1638
+
"sync_wrapper",
1639
1639
+
"tokio",
1640
1640
+
"tower-layer",
1641
1641
+
"tower-service",
1642
1642
+
]
1643
1643
+
1644
1644
+
[[package]]
1645
1645
+
name = "tower-http"
1646
1646
+
version = "0.6.8"
1647
1647
+
source = "registry+https://github.com/rust-lang/crates.io-index"
1648
1648
+
checksum = "d4e6559d53cc268e5031cd8429d05415bc4cb4aefc4aa5d6cc35fbf5b924a1f8"
1649
1649
+
dependencies = [
1650
1650
+
"bitflags",
1651
1651
+
"bytes",
1652
1652
+
"futures-util",
1653
1653
+
"http",
1654
1654
+
"http-body",
1655
1655
+
"iri-string",
1656
1656
+
"pin-project-lite",
1657
1657
+
"tower",
1658
1658
+
"tower-layer",
1659
1659
+
"tower-service",
1660
1660
+
]
1661
1661
+
1662
1662
+
[[package]]
1663
1663
+
name = "tower-layer"
1664
1664
+
version = "0.3.3"
1665
1665
+
source = "registry+https://github.com/rust-lang/crates.io-index"
1666
1666
+
checksum = "121c2a6cda46980bb0fcd1647ffaf6cd3fc79a013de288782836f6df9c48780e"
1174
1667
1175
1668
[[package]]
1176
1669
name = "tower-service"
···
1348
1841
checksum = "8ecb6da28b8a351d773b68d5825ac39017e680750f980f3a1a85cd8dd28a47c1"
1349
1842
1350
1843
[[package]]
1844
1844
+
name = "url"
1845
1845
+
version = "2.5.8"
1846
1846
+
source = "registry+https://github.com/rust-lang/crates.io-index"
1847
1847
+
checksum = "ff67a8a4397373c3ef660812acab3268222035010ab8680ec4215f38ba3d0eed"
1848
1848
+
dependencies = [
1849
1849
+
"form_urlencoded",
1850
1850
+
"idna",
1851
1851
+
"percent-encoding",
1852
1852
+
"serde",
1853
1853
+
]
1854
1854
+
1855
1855
+
[[package]]
1856
1856
+
name = "utf8_iter"
1857
1857
+
version = "1.0.4"
1858
1858
+
source = "registry+https://github.com/rust-lang/crates.io-index"
1859
1859
+
checksum = "b6c140620e7ffbb22c2dee59cafe6084a59b5ffc27a8859a5f0d494b5d52b6be"
1860
1860
+
1861
1861
+
[[package]]
1351
1862
name = "utf8parse"
1352
1863
version = "0.2.2"
1353
1864
source = "registry+https://github.com/rust-lang/crates.io-index"
···
1388
1899
]
1389
1900
1390
1901
[[package]]
1902
1902
+
name = "wasm-bindgen"
1903
1903
+
version = "0.2.114"
1904
1904
+
source = "registry+https://github.com/rust-lang/crates.io-index"
1905
1905
+
checksum = "6532f9a5c1ece3798cb1c2cfdba640b9b3ba884f5db45973a6f442510a87d38e"
1906
1906
+
dependencies = [
1907
1907
+
"cfg-if",
1908
1908
+
"once_cell",
1909
1909
+
"rustversion",
1910
1910
+
"wasm-bindgen-macro",
1911
1911
+
"wasm-bindgen-shared",
1912
1912
+
]
1913
1913
+
1914
1914
+
[[package]]
1915
1915
+
name = "wasm-bindgen-futures"
1916
1916
+
version = "0.4.64"
1917
1917
+
source = "registry+https://github.com/rust-lang/crates.io-index"
1918
1918
+
checksum = "e9c5522b3a28661442748e09d40924dfb9ca614b21c00d3fd135720e48b67db8"
1919
1919
+
dependencies = [
1920
1920
+
"cfg-if",
1921
1921
+
"futures-util",
1922
1922
+
"js-sys",
1923
1923
+
"once_cell",
1924
1924
+
"wasm-bindgen",
1925
1925
+
"web-sys",
1926
1926
+
]
1927
1927
+
1928
1928
+
[[package]]
1929
1929
+
name = "wasm-bindgen-macro"
1930
1930
+
version = "0.2.114"
1931
1931
+
source = "registry+https://github.com/rust-lang/crates.io-index"
1932
1932
+
checksum = "18a2d50fcf105fb33bb15f00e7a77b772945a2ee45dcf454961fd843e74c18e6"
1933
1933
+
dependencies = [
1934
1934
+
"quote",
1935
1935
+
"wasm-bindgen-macro-support",
1936
1936
+
]
1937
1937
+
1938
1938
+
[[package]]
1939
1939
+
name = "wasm-bindgen-macro-support"
1940
1940
+
version = "0.2.114"
1941
1941
+
source = "registry+https://github.com/rust-lang/crates.io-index"
1942
1942
+
checksum = "03ce4caeaac547cdf713d280eda22a730824dd11e6b8c3ca9e42247b25c631e3"
1943
1943
+
dependencies = [
1944
1944
+
"bumpalo",
1945
1945
+
"proc-macro2",
1946
1946
+
"quote",
1947
1947
+
"syn",
1948
1948
+
"wasm-bindgen-shared",
1949
1949
+
]
1950
1950
+
1951
1951
+
[[package]]
1952
1952
+
name = "wasm-bindgen-shared"
1953
1953
+
version = "0.2.114"
1954
1954
+
source = "registry+https://github.com/rust-lang/crates.io-index"
1955
1955
+
checksum = "75a326b8c223ee17883a4251907455a2431acc2791c98c26279376490c378c16"
1956
1956
+
dependencies = [
1957
1957
+
"unicode-ident",
1958
1958
+
]
1959
1959
+
1960
1960
+
[[package]]
1961
1961
+
name = "web-sys"
1962
1962
+
version = "0.3.91"
1963
1963
+
source = "registry+https://github.com/rust-lang/crates.io-index"
1964
1964
+
checksum = "854ba17bb104abfb26ba36da9729addc7ce7f06f5c0f90f3c391f8461cca21f9"
1965
1965
+
dependencies = [
1966
1966
+
"js-sys",
1967
1967
+
"wasm-bindgen",
1968
1968
+
]
1969
1969
+
1970
1970
+
[[package]]
1971
1971
+
name = "web-time"
1972
1972
+
version = "1.1.0"
1973
1973
+
source = "registry+https://github.com/rust-lang/crates.io-index"
1974
1974
+
checksum = "5a6580f308b1fad9207618087a65c04e7a10bc77e02c8e84e9b00dd4b12fa0bb"
1975
1975
+
dependencies = [
1976
1976
+
"js-sys",
1977
1977
+
"wasm-bindgen",
1978
1978
+
]
1979
1979
+
1980
1980
+
[[package]]
1391
1981
name = "webpki-root-certs"
1392
1982
version = "1.0.6"
1393
1983
source = "registry+https://github.com/rust-lang/crates.io-index"
···
1410
2000
version = "0.2.1"
1411
2001
source = "registry+https://github.com/rust-lang/crates.io-index"
1412
2002
checksum = "f0805222e57f7521d6a62e36fa9163bc891acd422f971defe97d64e70d0a4fe5"
2003
2003
+
2004
2004
+
[[package]]
2005
2005
+
name = "windows-registry"
2006
2006
+
version = "0.6.1"
2007
2007
+
source = "registry+https://github.com/rust-lang/crates.io-index"
2008
2008
+
checksum = "02752bf7fbdcce7f2a27a742f798510f3e5ad88dbe84871e5168e2120c3d5720"
2009
2009
+
dependencies = [
2010
2010
+
"windows-link",
2011
2011
+
"windows-result",
2012
2012
+
"windows-strings",
2013
2013
+
]
2014
2014
+
2015
2015
+
[[package]]
2016
2016
+
name = "windows-result"
2017
2017
+
version = "0.4.1"
2018
2018
+
source = "registry+https://github.com/rust-lang/crates.io-index"
2019
2019
+
checksum = "7781fa89eaf60850ac3d2da7af8e5242a5ea78d1a11c49bf2910bb5a73853eb5"
2020
2020
+
dependencies = [
2021
2021
+
"windows-link",
2022
2022
+
]
2023
2023
+
2024
2024
+
[[package]]
2025
2025
+
name = "windows-strings"
2026
2026
+
version = "0.5.1"
2027
2027
+
source = "registry+https://github.com/rust-lang/crates.io-index"
2028
2028
+
checksum = "7837d08f69c77cf6b07689544538e017c1bfcf57e34b4c0ff58e6c2cd3b37091"
2029
2029
+
dependencies = [
2030
2030
+
"windows-link",
2031
2031
+
]
1413
2032
1414
2033
[[package]]
1415
2034
name = "windows-sys"
···
1566
2185
checksum = "d7249219f66ced02969388cf2bb044a09756a083d0fab1e566056b04d9fbcaa5"
1567
2186
1568
2187
[[package]]
2188
2188
+
name = "writeable"
2189
2189
+
version = "0.6.2"
2190
2190
+
source = "registry+https://github.com/rust-lang/crates.io-index"
2191
2191
+
checksum = "9edde0db4769d2dc68579893f2306b26c6ecfbe0ef499b013d731b7b9247e0b9"
2192
2192
+
2193
2193
+
[[package]]
2194
2194
+
name = "yoke"
2195
2195
+
version = "0.8.1"
2196
2196
+
source = "registry+https://github.com/rust-lang/crates.io-index"
2197
2197
+
checksum = "72d6e5c6afb84d73944e5cedb052c4680d5657337201555f9f2a16b7406d4954"
2198
2198
+
dependencies = [
2199
2199
+
"stable_deref_trait",
2200
2200
+
"yoke-derive",
2201
2201
+
"zerofrom",
2202
2202
+
]
2203
2203
+
2204
2204
+
[[package]]
2205
2205
+
name = "yoke-derive"
2206
2206
+
version = "0.8.1"
2207
2207
+
source = "registry+https://github.com/rust-lang/crates.io-index"
2208
2208
+
checksum = "b659052874eb698efe5b9e8cf382204678a0086ebf46982b79d6ca3182927e5d"
2209
2209
+
dependencies = [
2210
2210
+
"proc-macro2",
2211
2211
+
"quote",
2212
2212
+
"syn",
2213
2213
+
"synstructure",
2214
2214
+
]
2215
2215
+
2216
2216
+
[[package]]
2217
2217
+
name = "zerocopy"
2218
2218
+
version = "0.8.42"
2219
2219
+
source = "registry+https://github.com/rust-lang/crates.io-index"
2220
2220
+
checksum = "f2578b716f8a7a858b7f02d5bd870c14bf4ddbbcf3a4c05414ba6503640505e3"
2221
2221
+
dependencies = [
2222
2222
+
"zerocopy-derive",
2223
2223
+
]
2224
2224
+
2225
2225
+
[[package]]
2226
2226
+
name = "zerocopy-derive"
2227
2227
+
version = "0.8.42"
2228
2228
+
source = "registry+https://github.com/rust-lang/crates.io-index"
2229
2229
+
checksum = "7e6cc098ea4d3bd6246687de65af3f920c430e236bee1e3bf2e441463f08a02f"
2230
2230
+
dependencies = [
2231
2231
+
"proc-macro2",
2232
2232
+
"quote",
2233
2233
+
"syn",
2234
2234
+
]
2235
2235
+
2236
2236
+
[[package]]
2237
2237
+
name = "zerofrom"
2238
2238
+
version = "0.1.6"
2239
2239
+
source = "registry+https://github.com/rust-lang/crates.io-index"
2240
2240
+
checksum = "50cc42e0333e05660c3587f3bf9d0478688e15d870fab3346451ce7f8c9fbea5"
2241
2241
+
dependencies = [
2242
2242
+
"zerofrom-derive",
2243
2243
+
]
2244
2244
+
2245
2245
+
[[package]]
2246
2246
+
name = "zerofrom-derive"
2247
2247
+
version = "0.1.6"
2248
2248
+
source = "registry+https://github.com/rust-lang/crates.io-index"
2249
2249
+
checksum = "d71e5d6e06ab090c67b5e44993ec16b72dcbaabc526db883a360057678b48502"
2250
2250
+
dependencies = [
2251
2251
+
"proc-macro2",
2252
2252
+
"quote",
2253
2253
+
"syn",
2254
2254
+
"synstructure",
2255
2255
+
]
2256
2256
+
2257
2257
+
[[package]]
1569
2258
name = "zeroize"
1570
2259
version = "1.8.2"
1571
2260
source = "registry+https://github.com/rust-lang/crates.io-index"
1572
2261
checksum = "b97154e67e32c85465826e8bcc1c59429aaaf107c1e4a9e53c8d8ccd5eff88d0"
2262
2262
+
2263
2263
+
[[package]]
2264
2264
+
name = "zerotrie"
2265
2265
+
version = "0.2.3"
2266
2266
+
source = "registry+https://github.com/rust-lang/crates.io-index"
2267
2267
+
checksum = "2a59c17a5562d507e4b54960e8569ebee33bee890c70aa3fe7b97e85a9fd7851"
2268
2268
+
dependencies = [
2269
2269
+
"displaydoc",
2270
2270
+
"yoke",
2271
2271
+
"zerofrom",
2272
2272
+
]
2273
2273
+
2274
2274
+
[[package]]
2275
2275
+
name = "zerovec"
2276
2276
+
version = "0.11.5"
2277
2277
+
source = "registry+https://github.com/rust-lang/crates.io-index"
2278
2278
+
checksum = "6c28719294829477f525be0186d13efa9a3c602f7ec202ca9e353d310fb9a002"
2279
2279
+
dependencies = [
2280
2280
+
"yoke",
2281
2281
+
"zerofrom",
2282
2282
+
"zerovec-derive",
2283
2283
+
]
2284
2284
+
2285
2285
+
[[package]]
2286
2286
+
name = "zerovec-derive"
2287
2287
+
version = "0.11.2"
2288
2288
+
source = "registry+https://github.com/rust-lang/crates.io-index"
2289
2289
+
checksum = "eadce39539ca5cb3985590102671f2567e659fca9666581ad3411d59207951f3"
2290
2290
+
dependencies = [
2291
2291
+
"proc-macro2",
2292
2292
+
"quote",
2293
2293
+
"syn",
2294
2294
+
]
1573
2295
1574
2296
[[package]]
1575
2297
name = "zmij"
+1
Cargo.toml
···
9
9
colog = "1.4.0"
10
10
fastrand = "2.3.0"
11
11
log = "0.4.29"
12
12
+
reqwest = "0.13.2"
12
13
rmp-serde = "1.3.1"
13
14
rustls = "0.23.37"
14
15
serde = { version = "1.0.228", features = ["derive"] }
+43
src/brain.rs
···
212
212
pub fn get_weights(&self, tok: &str) -> Option<&Edges> {
213
213
self.0.get(&Self::normalize_token(tok))
214
214
}
215
215
+
216
216
+
fn legacy_token_format(tok: &Token) -> String {
217
217
+
tok.as_ref()
218
218
+
.map(|s| format!("W-{s}"))
219
219
+
.unwrap_or_else(|| String::from("E--"))
220
220
+
}
221
221
+
222
222
+
pub fn as_legacy_hashmap(&self) -> HashMap<String, HashMap<String, Weight>> {
223
223
+
self.0
224
224
+
.iter()
225
225
+
.map(|(k, v)| {
226
226
+
let map =
227
227
+
v.0.iter()
228
228
+
.map(|(t, w)| (Self::legacy_token_format(t), *w))
229
229
+
.collect();
230
230
+
(Self::legacy_token_format(k), map)
231
231
+
})
232
232
+
.collect()
233
233
+
}
234
234
+
235
235
+
fn read_legacy_token(s: String) -> Token {
236
236
+
match s.as_str() {
237
237
+
"E--" => None,
238
238
+
word => Some(word.strip_prefix("W-").unwrap_or(word).to_string()),
239
239
+
}
240
240
+
}
241
241
+
242
242
+
pub fn from_legacy_hashmap(map: HashMap<String, HashMap<String, Weight>>) -> Self {
243
243
+
Self(
244
244
+
map.into_iter()
245
245
+
.map(|(k, v)| {
246
246
+
let sum = v.values().map(|w| *w as u64).sum::<u64>() as u64;
247
247
+
let edges = Edges(
248
248
+
v.into_iter()
249
249
+
.map(|(t, w)| (Self::read_legacy_token(t), w))
250
250
+
.collect(),
251
251
+
sum,
252
252
+
);
253
253
+
(Self::read_legacy_token(k), edges)
254
254
+
})
255
255
+
.collect(),
256
256
+
)
257
257
+
}
215
258
}
216
259
217
260
#[cfg(test)]
+58
src/cmd/dump_chain.rs
···
1
1
+
use std::sync::Arc;
2
2
+
3
3
+
use brotli::enc::BrotliEncoderParams;
4
4
+
use twilight_interactions::command::{CommandModel, CreateCommand};
5
5
+
use twilight_model::{
6
6
+
application::interaction::{Interaction, application_command::CommandData},
7
7
+
http::attachment::Attachment,
8
8
+
};
9
9
+
10
10
+
use crate::{BotContext, cmd::DEFER_INTER_RESP_EPHEMERAL, prelude::*};
11
11
+
12
12
+
#[derive(CommandModel, CreateCommand)]
13
13
+
#[command(name = "dump_chain", desc = "Dump chain")]
14
14
+
pub struct DumpChainCommand {
15
15
+
/// Generate as Nushell (Legacy) compatible msgpack
16
16
+
compat: Option<bool>,
17
17
+
}
18
18
+
19
19
+
impl DumpChainCommand {
20
20
+
pub async fn handle(inter: Interaction, data: CommandData, ctx: Arc<BotContext>) -> Result {
21
21
+
let Self { compat } =
22
22
+
Self::from_interaction(data.into()).context("Failed to parse command data")?;
23
23
+
24
24
+
let client = ctx.http.interaction(ctx.app_id);
25
25
+
26
26
+
client
27
27
+
.create_response(inter.id, &inter.token, &DEFER_INTER_RESP_EPHEMERAL)
28
28
+
.await
29
29
+
.context("Failed to defer")?;
30
30
+
31
31
+
let mut buf = Vec::<u8>::with_capacity(4096);
32
32
+
let params = BrotliEncoderParams::default();
33
33
+
let mut brotli_writer = brotli::CompressorWriter::with_params(&mut buf, 4096, ¶ms);
34
34
+
35
35
+
if compat.unwrap_or_default() {
36
36
+
let brain = ctx.brain_handle.lock().await;
37
37
+
let map = brain.as_legacy_hashmap();
38
38
+
drop(brain);
39
39
+
rmp_serde::encode::write(&mut brotli_writer, &map)
40
40
+
.context("Failed to legacy encode brain")?;
41
41
+
} else {
42
42
+
let brain = ctx.brain_handle.lock().await;
43
43
+
rmp_serde::encode::write(&mut brotli_writer, &*brain)
44
44
+
.context("Failed to write serialized brain")?;
45
45
+
}
46
46
+
drop(brotli_writer);
47
47
+
48
48
+
let attachment = Attachment::from_bytes(String::from("brain.msgpackz"), buf, 1);
49
49
+
50
50
+
client
51
51
+
.update_response(&inter.token)
52
52
+
.attachments(&[attachment])
53
53
+
.await
54
54
+
.context("Failed to send brain")?;
55
55
+
56
56
+
Ok(())
57
57
+
}
58
58
+
}
+67
src/cmd/load_chain.rs
···
1
1
+
use std::sync::{Arc, atomic::Ordering};
2
2
+
3
3
+
use twilight_interactions::command::{CommandModel, CreateCommand};
4
4
+
use twilight_model::{
5
5
+
application::interaction::{Interaction, application_command::CommandData},
6
6
+
channel::Attachment,
7
7
+
};
8
8
+
9
9
+
use crate::{
10
10
+
BotContext, brain::Brain, cmd::DEFER_INTER_RESP_EPHEMERAL, prelude::*, status::update_status,
11
11
+
};
12
12
+
13
13
+
#[derive(CommandModel, CreateCommand)]
14
14
+
#[command(name = "load_chain", desc = "Load a chain from a .msgpackz file")]
15
15
+
pub struct LoadChainCommand {
16
16
+
/// Brain file to load
17
17
+
file: Attachment,
18
18
+
/// Use a Nushell (Legacy) compatible msgpack
19
19
+
compat: Option<bool>,
20
20
+
}
21
21
+
22
22
+
impl LoadChainCommand {
23
23
+
pub async fn handle(inter: Interaction, data: CommandData, ctx: Arc<BotContext>) -> Result {
24
24
+
let Self { file, compat } =
25
25
+
Self::from_interaction(data.into()).context("Failed to parse command data")?;
26
26
+
27
27
+
let client = ctx.http.interaction(ctx.app_id);
28
28
+
29
29
+
client
30
30
+
.create_response(inter.id, &inter.token, &DEFER_INTER_RESP_EPHEMERAL)
31
31
+
.await
32
32
+
.context("Failed to defer")?;
33
33
+
34
34
+
let mut data = std::io::Cursor::new(
35
35
+
reqwest::get(file.url)
36
36
+
.await
37
37
+
.context("Failed to request attachment")?
38
38
+
.bytes()
39
39
+
.await
40
40
+
.context("Failed to decode as bytes")?,
41
41
+
);
42
42
+
let mut brotli_stream = brotli::Decompressor::new(&mut data, 4096);
43
43
+
44
44
+
let new_brain: Brain = if compat.unwrap_or_default() {
45
45
+
Brain::from_legacy_hashmap(
46
46
+
rmp_serde::from_read(&mut brotli_stream).context("Failed to decode brain file")?,
47
47
+
)
48
48
+
} else {
49
49
+
rmp_serde::from_read(&mut brotli_stream).context("Failed to decode brain file")?
50
50
+
};
51
51
+
52
52
+
{
53
53
+
let mut brain = ctx.brain_handle.lock().await;
54
54
+
brain.merge_from(new_brain);
55
55
+
ctx.pending_save.store(true, Ordering::Relaxed);
56
56
+
update_status(&*brain, &ctx.shard_sender).context("Failed to update status")?;
57
57
+
}
58
58
+
59
59
+
client
60
60
+
.update_response(&inter.token)
61
61
+
.content(Some("Bingus Learned!"))
62
62
+
.await
63
63
+
.context("Failed to send brain")?;
64
64
+
65
65
+
Ok(())
66
66
+
}
67
67
+
}
+32
-2
src/cmd/mod.rs
···
1
1
+
mod dump_chain;
2
2
+
mod load_chain;
1
3
mod weights;
2
4
3
5
use std::sync::Arc;
···
5
7
use log::warn;
6
8
use twilight_interactions::command::CreateCommand;
7
9
use twilight_model::application::interaction::{Interaction, application_command::CommandData};
8
8
-
use twilight_model::http::interaction::{InteractionResponse, InteractionResponseType};
10
10
+
use twilight_model::channel::message::MessageFlags;
11
11
+
use twilight_model::http::interaction::{
12
12
+
InteractionResponse, InteractionResponseData, InteractionResponseType,
13
13
+
};
9
14
15
15
+
use crate::cmd::dump_chain::DumpChainCommand;
16
16
+
use crate::cmd::load_chain::LoadChainCommand;
10
17
use crate::{BotContext, prelude::*};
11
18
12
19
use weights::WeightsCommand;
···
16
23
data: None,
17
24
};
18
25
26
26
+
const DEFER_INTER_RESP_EPHEMERAL: InteractionResponse = InteractionResponse {
27
27
+
kind: InteractionResponseType::DeferredChannelMessageWithSource,
28
28
+
data: Some(InteractionResponseData {
29
29
+
allowed_mentions: None,
30
30
+
attachments: None,
31
31
+
choices: None,
32
32
+
components: None,
33
33
+
content: None,
34
34
+
custom_id: None,
35
35
+
embeds: None,
36
36
+
flags: Some(MessageFlags::EPHEMERAL),
37
37
+
title: None,
38
38
+
tts: None,
39
39
+
poll: None,
40
40
+
}),
41
41
+
};
42
42
+
19
43
pub async fn register_all_commands(ctx: Arc<BotContext>) -> Result {
20
20
-
let commands = [WeightsCommand::create_command().into()];
44
44
+
let commands = [
45
45
+
WeightsCommand::create_command().into(),
46
46
+
DumpChainCommand::create_command().into(),
47
47
+
LoadChainCommand::create_command().into(),
48
48
+
];
21
49
22
50
let client = ctx.http.interaction(ctx.app_id);
23
51
···
36
64
) -> Result {
37
65
match &*data.name {
38
66
"weights" => WeightsCommand::handle(inter, data, ctx).await,
67
67
+
"dump_chain" => DumpChainCommand::handle(inter, data, ctx).await,
68
68
+
"load_chain" => LoadChainCommand::handle(inter, data, ctx).await,
39
69
other => {
40
70
warn!("Unknown command send: {other}");
41
71
Ok(())
+2
-2
src/cmd/weights.rs
···
35
35
36
36
impl WeightsCommand {
37
37
pub async fn handle(inter: Interaction, data: CommandData, ctx: Arc<BotContext>) -> Result {
38
38
-
let WeightsCommand { token } = WeightsCommand::from_interaction(data.into())
39
39
-
.context("Failed to parse command data")?;
38
38
+
let Self { token } =
39
39
+
Self::from_interaction(data.into()).context("Failed to parse command data")?;
40
40
41
41
let client = ctx.http.interaction(ctx.app_id);
42
42
+1
-1
src/main.rs
···
207
207
if let Err(why) = save_brain(ctx.clone()).await {
208
208
error!("Failed to save brain file:\n{why:?}");
209
209
}
210
210
-
ctx.pending_save.store(true, Ordering::Relaxed);
210
210
+
ctx.pending_save.store(false, Ordering::Relaxed);
211
211
});
212
212
}
213
213
},