mirror of
https://gitlab.com/Kwoth/nadekobot.git
synced 2025-09-10 17:28:27 -04:00
Compare commits
481 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
6d6a3a811f | ||
|
fb4aac9f0d | ||
|
a98981de86 | ||
|
8112337aaf | ||
|
73f7394e31 | ||
|
987d88287a | ||
|
9dc783b36f | ||
|
13741b8317 | ||
|
313ca2674e | ||
|
98956481e9 | ||
|
51e887fe04 | ||
|
8ceab64b96 | ||
|
92b8511cf1 | ||
|
a6a052571e | ||
|
699a5e0c8c | ||
|
76fedc5ff1 | ||
|
992aa781fa | ||
|
e52bf798cf | ||
|
710f4f2ed8 | ||
|
dcc27a4a99 | ||
|
032b6bfd57 | ||
|
737bbb8ec1 | ||
|
e71708f5e8 | ||
|
9841d72622 | ||
|
391a3f0513 | ||
|
aa3409a9cf | ||
|
9a80383327 | ||
|
7e61f7fb46 | ||
|
d526a2fac6 | ||
|
80efb954f1 | ||
|
67c156e40f | ||
|
26f76ef7b9 | ||
|
90cee1bfa9 | ||
|
26171a0ff7 | ||
|
59447d7aa8 | ||
|
a4053d0666 | ||
|
fcd016aed3 | ||
|
719f62a0ac | ||
|
9b9fa2f357 | ||
|
823f4731c3 | ||
|
5feff8f4b2 | ||
|
95d20609a8 | ||
|
b416b9f963 | ||
|
a7c48b13a0 | ||
|
003b71ba00 | ||
|
89593dcc2c | ||
|
fa9352d1f8 | ||
|
4a2f7ffc76 | ||
|
fb1555c075 | ||
|
7a0b409d88 | ||
|
c869f2e335 | ||
|
01da7e813e | ||
|
76b7e09905 | ||
|
8dca948224 | ||
|
ffcbfe6467 | ||
|
d5c70def93 | ||
|
34dccab16b | ||
|
2fab61c4f8 | ||
|
9f96edbb46 | ||
|
3c23b58088 | ||
|
e10530bc0e | ||
|
f24692e79b | ||
|
8a6edc17e4 | ||
|
9ce2837f5a | ||
|
e49e3eec69 | ||
|
3992ae392b | ||
|
8f0c5fab47 | ||
|
780a260b88 | ||
|
25692b9585 | ||
|
ed3ce52865 | ||
|
f5f0f1e250 | ||
|
9d9e61fdfb | ||
|
e68e948a80 | ||
|
cb98f4aa15 | ||
|
bfec0cbcbf | ||
|
3e1268f3bb | ||
|
c28f458972 | ||
|
27ac948463 | ||
|
3f9a3c4c18 | ||
|
9a5545a951 | ||
|
584193db18 | ||
|
1a132fd234 | ||
|
fd6a51ac82 | ||
|
eb1fabb2b7 | ||
|
d079e684bd | ||
|
bf817a1436 | ||
|
78f1624aaf | ||
|
793a49fc64 | ||
|
8b6be656b3 | ||
|
89a88304dc | ||
|
a7fe9ae08f | ||
|
0469705037 | ||
|
dc568fe0e2 | ||
|
eb01bb6c08 | ||
|
71a3539d0e | ||
|
c896a0cdb8 | ||
|
8effe817ad | ||
|
eedf6998b6 | ||
|
e6b7c31a72 | ||
|
2f77fd57b0 | ||
|
fda3d92134 | ||
|
fe6f28143b | ||
|
df3909fc55 | ||
|
9ffa701742 | ||
|
a4f7df8aee | ||
|
15e6cff14a | ||
|
e63ac07a52 | ||
|
a294e3bf8f | ||
|
a5b2fac69c | ||
|
a8e06a5ae4 | ||
|
761bdd8610 | ||
|
b5904889b0 | ||
|
5b4517cf5c | ||
|
72158c0a2c | ||
|
1ca6f6dc5c | ||
|
005fd7b8c6 | ||
|
3fc53b0609 | ||
|
62ec2241e4 | ||
|
75f8254a8e | ||
|
f23ffe0c67 | ||
|
d1a818542c | ||
|
15f67e3a51 | ||
|
412f346ac8 | ||
|
8107a80c4c | ||
|
f1c7d7437a | ||
|
9a013db25f | ||
|
6f75161c80 | ||
|
3f56e5b651 | ||
|
4875abbe86 | ||
|
83863f3a6c | ||
|
f07abad1ec | ||
|
b6909a4120 | ||
|
aaf7f04216 | ||
|
628871b0da | ||
|
a50ad09c8d | ||
|
1358ff50a4 | ||
|
ee9fede3b1 | ||
|
1d7e9e8471 | ||
|
d2fe7f8d11 | ||
|
75958efe17 | ||
|
7746d2aca1 | ||
|
e631df3326 | ||
|
ba44fdb55f | ||
|
59a1e56dad | ||
|
cd6fe46c2b | ||
|
fb4f470b44 | ||
|
b69e25edf4 | ||
|
9eae27bc15 | ||
|
bed36f8784 | ||
|
623f5ccd5e | ||
|
6da8201c2d | ||
|
d1c24d4721 | ||
|
7e5055268a | ||
|
e84e33b94f | ||
|
f21c96bdf4 | ||
|
430daf9b19 | ||
|
7c8756096d | ||
|
7d9e456fe5 | ||
|
948db31384 | ||
|
df1a775fec | ||
|
6c169e057b | ||
|
b164da38e3 | ||
|
dc229ea2b3 | ||
|
b853495d65 | ||
|
0ff02cede9 | ||
|
f7e0e635e6 | ||
|
a065189023 | ||
|
1affeb0683 | ||
|
6b3c9f01ca | ||
|
e9eb6ff2ad | ||
|
0170536d1c | ||
|
c65e769128 | ||
|
998779203a | ||
|
e0e4d697c3 | ||
|
e9c7293014 | ||
|
cf876a4148 | ||
|
6b9a858f28 | ||
|
38e3badb87 | ||
|
13d2fbd560 | ||
|
8d3f2f186a | ||
|
9572b9dc43 | ||
|
ca32086089 | ||
|
57f839dbcd | ||
|
71d6eeb9dd | ||
|
8c51cf8537 | ||
|
b683026cf3 | ||
|
bca2bc5af1 | ||
|
b385a83bdd | ||
|
3bf0286c81 | ||
|
98272f66e7 | ||
|
cf3788c6ea | ||
|
4b3fc53cb6 | ||
|
4e17dca856 | ||
|
82d89148f3 | ||
|
cc4c09b4d7 | ||
|
616f01f8b2 | ||
|
56f89a02bc | ||
|
48ce988d20 | ||
|
119b1cdec2 | ||
|
43fa5a22f5 | ||
|
3c715a29ca | ||
|
31e1cbb19f | ||
|
8e464e9f09 | ||
|
a190a3d933 | ||
|
bedba98130 | ||
|
d69f8435f6 | ||
|
8440b34338 | ||
|
a2715740c1 | ||
|
36b7fd2352 | ||
|
6563cb507a | ||
|
cc6128997e | ||
|
e942da4470 | ||
|
ab2bcdf00d | ||
|
d7c1dad4f0 | ||
|
8bd6b887b8 | ||
|
d326e19196 | ||
|
fa822853df | ||
|
22bff7838a | ||
|
25fce1bd75 | ||
|
a73482e838 | ||
|
bb395f18a2 | ||
|
e20212a6cb | ||
|
0f8291c589 | ||
|
a7b3a238f5 | ||
|
bb800f4e38 | ||
|
b10eded334 | ||
|
3e15e50667 | ||
|
516bc1e484 | ||
|
6a042c3faa | ||
|
967784c860 | ||
|
ccf92ca702 | ||
|
c20b851dc7 | ||
|
39fc21d41c | ||
|
c8c0b27d6a | ||
|
9a21ba3d53 | ||
|
0042c22ceb | ||
|
a0ba9be34e | ||
|
91da78a2ee | ||
|
8eca8e1dfb | ||
|
b12e97a0a7 | ||
|
99c60459f8 | ||
|
3db194c186 | ||
|
0b720a0439 | ||
|
d9011106ac | ||
|
17ca609fe9 | ||
|
0f1ba400db | ||
|
2b8daa2177 | ||
|
f3ed14de5b | ||
|
251d5a4df4 | ||
|
f761714f15 | ||
|
93b0e38264 | ||
|
5f7b030a66 | ||
|
0b122e8d3f | ||
|
34955f88f6 | ||
|
b34fd6da4e | ||
|
9a35716331 | ||
|
156069db0e | ||
|
ea8e444b10 | ||
|
ff779ad494 | ||
|
c9287dc166 | ||
|
7885106266 | ||
|
946b095d4b | ||
|
5bb8f3f7c8 | ||
|
f41b1fb93c | ||
|
8efdd3dffe | ||
|
fb9a7964df | ||
|
1396d9d55a | ||
|
e7ddcebeab | ||
|
9d3a386f32 | ||
|
83c9c372e4 | ||
|
4bb4209c92 | ||
|
744018802f | ||
|
470bb9657f | ||
|
2fb4bb2ea4 | ||
|
43dd37c4f1 | ||
|
5fac500dcf | ||
|
fd25f5bf45 | ||
|
9d3e80eb32 | ||
|
42cbb7f626 | ||
|
4d175477f5 | ||
|
643987c41f | ||
|
03396642a4 | ||
|
3fd5f0c97a | ||
|
5d78f29329 | ||
|
2a98aceae6 | ||
|
5c933b676d | ||
|
2e4de7723e | ||
|
a8e00a19ba | ||
|
8acf6b1194 | ||
|
11d9db99ff | ||
|
c66e0fb6b7 | ||
|
1517a35ef7 | ||
|
c5179979d7 | ||
|
6b14c04e37 | ||
|
4ec3eb7855 | ||
|
4752c4b7cd | ||
|
dfec2f589e | ||
|
f616364d8a | ||
|
4294f8efd5 | ||
|
69eb5f2c56 | ||
|
8d26d16fff | ||
|
bdde065209 | ||
|
e2477638b5 | ||
|
f398cddaf0 | ||
|
dc846965ae | ||
|
dbbdc66dca | ||
|
df85b3b250 | ||
|
f1d9db699f | ||
|
210da263ad | ||
|
1716c69132 | ||
|
14bfcb54dc | ||
|
9f445c0866 | ||
|
3343fd2f6e | ||
|
9103dd9fdb | ||
|
1a8c9a6cba | ||
|
9d2f251923 | ||
|
3744dd287c | ||
|
f65ba100af | ||
|
cc52605c90 | ||
|
3d3dc532dc | ||
|
6c58a6a72d | ||
|
cefd81d810 | ||
|
34c96c697a | ||
|
1cc5e0e1d8 | ||
|
deaedce6c7 | ||
|
91e4d9dffc | ||
|
a826f4245f | ||
|
780eec62b3 | ||
|
dbeb83561a | ||
|
6c11d11645 | ||
|
e9923a7691 | ||
|
5fbe93d898 | ||
|
65995bdca4 | ||
|
f7c333b671 | ||
|
f9d18aa086 | ||
|
571e1c801f | ||
|
f922543d33 | ||
|
6bec67006c | ||
|
050eaa48eb | ||
|
248ce8b3d2 | ||
|
04a488cdf2 | ||
|
6bc2fc88f9 | ||
|
69b6ed6a49 | ||
|
e30b126726 | ||
|
a5e2321c5b | ||
|
322e9a329d | ||
|
7ca6ab8562 | ||
|
8a27dcc481 | ||
|
bed61c521f | ||
|
46ea1698eb | ||
|
c47417024d | ||
|
eedc2d05ff | ||
|
d24dba7ed0 | ||
|
9bdf58ec27 | ||
|
5de9c5d067 | ||
|
64b2a46c95 | ||
|
f42deda3e2 | ||
|
a464e7c643 | ||
|
1f36fa75c4 | ||
|
ad6d732687 | ||
|
1f51c54449 | ||
|
7b5145f116 | ||
|
18b10b8c6f | ||
|
f05435f864 | ||
|
7cbedc82bf | ||
|
3be208f1b3 | ||
|
2606bda8df | ||
|
ab1272b491 | ||
|
43047c0ab0 | ||
|
34471abd64 | ||
|
fa259384f1 | ||
|
cb865d5012 | ||
|
1db97decd1 | ||
|
b02768a08e | ||
|
e55d60f1aa | ||
|
b009438e0e | ||
|
4b5d27d963 | ||
|
91ee0d121c | ||
|
a8767f1136 | ||
|
44478e0f47 | ||
|
c73c2da6a4 | ||
|
5ed005211e | ||
|
d80cbb4647 | ||
|
9a96ef76ba | ||
|
5b5bc278ff | ||
|
5cb95cf94d | ||
|
f132aa2624 | ||
|
3b6b3bcf07 | ||
|
78d97db224 | ||
|
35ddd150ba | ||
|
39ae070c9d | ||
|
24a9a02cc3 | ||
|
0f68abcac9 | ||
|
908c61633d | ||
|
054fc30672 | ||
|
11ffdd84a3 | ||
|
5d2d74b92a | ||
|
18400dc53a | ||
|
29d94640af | ||
|
f6a53b96c7 | ||
|
1aa95a5dd0 | ||
|
fcfeb152c9 | ||
|
0b64df95ef | ||
|
7512f4a1e0 | ||
|
789c453863 | ||
|
615e1dd044 | ||
|
7cb15f5278 | ||
|
3a516ab32a | ||
|
6159d84988 | ||
|
cbe617bc59 | ||
|
e4b98a0c07 | ||
|
e23233ee06 | ||
|
8b1efa9b4f | ||
|
8e1ec2ed9e | ||
|
0e555a4ed7 | ||
|
a6a1d8cb6f | ||
|
6595c3a43d | ||
|
77bb5724d8 | ||
|
48ea595136 | ||
|
1068457584 | ||
|
eca7973266 | ||
|
46ba2df0b8 | ||
|
a8f9a6e439 | ||
|
cca5b5d41b | ||
|
95bde7021a | ||
|
9bf9e06dbf | ||
|
c1bfb19a1d | ||
|
ad0a9ceb9d | ||
|
75f0574cc8 | ||
|
c3fda25a93 | ||
|
7991659f74 | ||
|
77195843d0 | ||
|
bed3347cd9 | ||
|
0c74a9874e | ||
|
b079492d38 | ||
|
28720ebcea | ||
|
3d456e5c14 | ||
|
83017e25ab | ||
|
72b3565e2e | ||
|
59cea6ee38 | ||
|
cbcfa77a34 | ||
|
cfb202cc95 | ||
|
b7d1fd1b47 | ||
|
4cf3bdb53a | ||
|
aab5bc9744 | ||
|
1f14c9066e | ||
|
9ade3c9537 | ||
|
1dc393d2b1 | ||
|
798b66db9b | ||
|
57e65e5515 | ||
|
86e728b753 | ||
|
fd032d3e91 | ||
|
eab16865cd | ||
|
fc4cbf5276 | ||
|
a34a86bbfa | ||
|
a016b3546f | ||
|
e09435da37 | ||
|
416f3d604c | ||
|
d9f371f994 | ||
|
c1c22d0477 | ||
|
339f13d31a | ||
|
4190f07d9c | ||
|
a9bdf36c53 | ||
|
1913cd4309 | ||
|
624439f684 | ||
|
3e14dc22cb | ||
|
f4178aeacd | ||
|
aaf3c9cfe9 | ||
|
f6ee012b15 | ||
|
363ef42923 | ||
|
cc522ef872 | ||
|
0e192ee7f0 | ||
|
ddd0592b30 | ||
|
c4efe2965b | ||
|
a90b5a62f3 | ||
|
50a4497532 | ||
|
c3d6183d73 | ||
|
864a8fd7b6 | ||
|
e7db631151 | ||
|
c7b312196e | ||
|
8cd7a50720 |
@@ -1,6 +1,13 @@
|
||||
# Ignore all files
|
||||
*
|
||||
|
||||
# Don't ignore nugetconfig
|
||||
!./NuGet.Config
|
||||
# Don't ignore src projects
|
||||
!src/Nadeko.Econ/**
|
||||
!src/Nadeko.Common/**
|
||||
# Use Nadeko.Medusa project
|
||||
!src/Nadeko.Medusa/**
|
||||
# Use NadekoBot project
|
||||
!src/NadekoBot/**
|
||||
# Use NadekoBot.Coordinator project
|
||||
|
8
.gitignore
vendored
8
.gitignore
vendored
@@ -1,5 +1,13 @@
|
||||
#Manually added files
|
||||
|
||||
src/NadekoBot/data/last_known_version.txt
|
||||
|
||||
# medusa stuff
|
||||
!src/NadekoBot/data/medusae/medusa.yml
|
||||
src/NadekoBot/data/medusae/**
|
||||
|
||||
# other
|
||||
|
||||
command_errors*.txt
|
||||
output/
|
||||
src/NadekoBot/output
|
||||
|
175
.gitlab-ci.yml
175
.gitlab-ci.yml
@@ -7,6 +7,7 @@ stages:
|
||||
- release
|
||||
- publish-windows
|
||||
- upload-windows-updater-release
|
||||
- publish-medusa-package
|
||||
|
||||
variables:
|
||||
project: "NadekoBot"
|
||||
@@ -18,41 +19,41 @@ variables:
|
||||
PACKAGE_REGISTRY_URL: "${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/packages/generic/NadekoBot-build/${CI_COMMIT_TAG}"
|
||||
INSTALLER_OUTPUT_DIR: "nadeko-installers/${CI_COMMIT_TAG}"
|
||||
INSTALLER_FILE_NAME: "nadeko-setup-${CI_COMMIT_TAG}.exe"
|
||||
|
||||
|
||||
build:
|
||||
stage: build
|
||||
script:
|
||||
- "dotnet publish -c Release -r linux-x64 -o $LINUX_X64_OUTPUT_DIR src/NadekoBot/NadekoBot.csproj"
|
||||
- "dotnet publish -c Release -r win7-x64 -o $WIN_X64_OUTPUT_DIR src/NadekoBot/NadekoBot.csproj"
|
||||
- "dotnet publish -c Release -r linux-x64 --self-contained -o $LINUX_X64_OUTPUT_DIR src/NadekoBot/NadekoBot.csproj"
|
||||
- "dotnet publish -c Release -r win7-x64 --self-contained -o $WIN_X64_OUTPUT_DIR src/NadekoBot/NadekoBot.csproj"
|
||||
artifacts:
|
||||
paths:
|
||||
- "$LINUX_X64_OUTPUT_DIR/"
|
||||
- "$WIN_X64_OUTPUT_DIR/"
|
||||
|
||||
upload-builds:
|
||||
stage: upload-builds
|
||||
image: alpine:latest
|
||||
rules:
|
||||
- if: $CI_COMMIT_TAG
|
||||
script:
|
||||
- apk add --no-cache curl tar zip
|
||||
- "tar cvf $LINUX_X64_RELEASE $LINUX_X64_OUTPUT_DIR/*"
|
||||
- "zip -r $WIN_X64_RELEASE $WIN_X64_OUTPUT_DIR/*"
|
||||
- |
|
||||
curl --header "JOB-TOKEN: ${CI_JOB_TOKEN}" --upload-file $LINUX_X64_RELEASE $PACKAGE_REGISTRY_URL/$LINUX_X64_RELEASE
|
||||
- |
|
||||
curl --header "JOB-TOKEN: ${CI_JOB_TOKEN}" --upload-file $WIN_X64_RELEASE $PACKAGE_REGISTRY_URL/$WIN_X64_RELEASE
|
||||
stage: upload-builds
|
||||
image: alpine:latest
|
||||
rules:
|
||||
- if: $CI_COMMIT_TAG
|
||||
script:
|
||||
- apk add --no-cache curl tar zip
|
||||
- "tar cvf $LINUX_X64_RELEASE $LINUX_X64_OUTPUT_DIR/*"
|
||||
- "zip -r $WIN_X64_RELEASE $WIN_X64_OUTPUT_DIR/*"
|
||||
- |
|
||||
curl --header "JOB-TOKEN: ${CI_JOB_TOKEN}" --upload-file $LINUX_X64_RELEASE $PACKAGE_REGISTRY_URL/$LINUX_X64_RELEASE
|
||||
- |
|
||||
curl --header "JOB-TOKEN: ${CI_JOB_TOKEN}" --upload-file $WIN_X64_RELEASE $PACKAGE_REGISTRY_URL/$WIN_X64_RELEASE
|
||||
|
||||
release:
|
||||
stage: release
|
||||
image: registry.gitlab.com/gitlab-org/release-cli:latest
|
||||
rules:
|
||||
- if: $CI_COMMIT_TAG
|
||||
script:
|
||||
- |
|
||||
release-cli create --name "NadekoBot v$CI_COMMIT_TAG" --description "## [Changelog](https://gitlab.com/Kwoth/nadekobot/-/blob/v4/CHANGELOG.md#$(echo "$CI_COMMIT_TAG" | sed "s/\.//g")-$(date +%d%m%Y))" --tag-name $CI_COMMIT_TAG \
|
||||
--assets-link "{\"name\":\"${LINUX_X64_RELEASE}\",\"url\":\"${PACKAGE_REGISTRY_URL}/${LINUX_X64_RELEASE}\"}" \
|
||||
--assets-link "{\"name\":\"${WIN_X64_RELEASE}\",\"url\":\"${PACKAGE_REGISTRY_URL}/${WIN_X64_RELEASE}\"}"
|
||||
stage: release
|
||||
image: registry.gitlab.com/gitlab-org/release-cli:latest
|
||||
rules:
|
||||
- if: $CI_COMMIT_TAG
|
||||
script:
|
||||
- |
|
||||
release-cli create --name "NadekoBot v$CI_COMMIT_TAG" --description "## [Changelog](https://gitlab.com/Kwoth/nadekobot/-/blob/v4/CHANGELOG.md#$(echo "$CI_COMMIT_TAG" | sed "s/\.//g")-$(date +%d%m%Y))" --tag-name $CI_COMMIT_TAG \
|
||||
--assets-link "{\"name\":\"${LINUX_X64_RELEASE}\",\"url\":\"${PACKAGE_REGISTRY_URL}/${LINUX_X64_RELEASE}\"}" \
|
||||
--assets-link "{\"name\":\"${WIN_X64_RELEASE}\",\"url\":\"${PACKAGE_REGISTRY_URL}/${WIN_X64_RELEASE}\"}"
|
||||
|
||||
test:
|
||||
stage: test
|
||||
@@ -63,63 +64,75 @@ test:
|
||||
- "dotnet test"
|
||||
|
||||
publish-windows:
|
||||
stage: publish-windows
|
||||
rules:
|
||||
- if: '$CI_COMMIT_TAG'
|
||||
image: scottyhardy/docker-wine
|
||||
before_script:
|
||||
- choco install dotnet-6.0-runtime -y
|
||||
- choco install dotnet-6.0-sdk -y
|
||||
- choco install innosetup -y
|
||||
artifacts:
|
||||
paths:
|
||||
- "$INSTALLER_OUTPUT_DIR/$INSTALLER_FILE_NAME"
|
||||
script:
|
||||
- dotnet clean
|
||||
- dotnet restore
|
||||
- dotnet publish -c Release --runtime win7-x64 /p:Version=$CI_COMMIT_TAG src/NadekoBot
|
||||
- $env:NADEKOBOT_INSTALL_VERSION = $CI_COMMIT_TAG
|
||||
- iscc.exe "/O+" ".\exe_builder.iss"
|
||||
tags:
|
||||
- windows
|
||||
stage: publish-windows
|
||||
rules:
|
||||
- if: "$CI_COMMIT_TAG"
|
||||
image: scottyhardy/docker-wine
|
||||
before_script:
|
||||
- choco install dotnet-6.0-runtime --version=6.0.4 -y
|
||||
- choco install dotnet-6.0-sdk --version=6.0.202 -y
|
||||
- choco install innosetup -y
|
||||
artifacts:
|
||||
paths:
|
||||
- "$INSTALLER_OUTPUT_DIR/$INSTALLER_FILE_NAME"
|
||||
script:
|
||||
- dotnet clean
|
||||
- dotnet restore -f --no-cache -v n
|
||||
- dotnet publish -c Release --runtime win7-x64 /p:Version=$CI_COMMIT_TAG src/NadekoBot
|
||||
- $env:NADEKOBOT_INSTALL_VERSION = $CI_COMMIT_TAG
|
||||
- iscc.exe "/O+" ".\exe_builder.iss"
|
||||
tags:
|
||||
- windows
|
||||
|
||||
upload-windows-updater-release:
|
||||
stage: upload-windows-updater-release
|
||||
rules:
|
||||
- if: '$CI_COMMIT_TAG'
|
||||
image:
|
||||
name: amazon/aws-cli
|
||||
entrypoint: [""]
|
||||
script:
|
||||
- sed -i "s/_INSTALLER_FILE_NAME_/$INSTALLER_FILE_NAME/g" releases-v3.json
|
||||
- sed -i "s/_VERSION_/$CI_COMMIT_TAG/g" releases-v3.json
|
||||
- aws --version
|
||||
- aws --endpoint-url $AWS_SERVICE_URL s3api put-object --bucket "$AWS_BUCKET_NAME" --key "dl/bot/$INSTALLER_FILE_NAME" --acl public-read --body "$INSTALLER_OUTPUT_DIR/$INSTALLER_FILE_NAME"
|
||||
- aws --endpoint-url $AWS_SERVICE_URL s3api put-object --bucket "$AWS_BUCKET_NAME" --key "dl/bot/releases-v3.json" --acl public-read --body "releases-v3.json"
|
||||
stage: upload-windows-updater-release
|
||||
rules:
|
||||
- if: "$CI_COMMIT_TAG"
|
||||
image:
|
||||
name: amazon/aws-cli
|
||||
entrypoint: [""]
|
||||
script:
|
||||
- sed -i "s/_INSTALLER_FILE_NAME_/$INSTALLER_FILE_NAME/g" releases-v3.json
|
||||
- sed -i "s/_VERSION_/$CI_COMMIT_TAG/g" releases-v3.json
|
||||
- aws --version
|
||||
- aws --endpoint-url $AWS_SERVICE_URL s3api put-object --bucket "$AWS_BUCKET_NAME" --key "dl/bot/$INSTALLER_FILE_NAME" --acl public-read --body "$INSTALLER_OUTPUT_DIR/$INSTALLER_FILE_NAME"
|
||||
- aws --endpoint-url $AWS_SERVICE_URL s3api put-object --bucket "$AWS_BUCKET_NAME" --key "dl/bot/releases-v3.json" --acl public-read --body "releases-v3.json"
|
||||
|
||||
# docker-build:
|
||||
# # Use the official docker image.
|
||||
# image: docker:latest
|
||||
# stage: build
|
||||
# services:
|
||||
# - docker:dind
|
||||
# before_script:
|
||||
# - docker login -u "$CI_REGISTRY_USER" -p "$CI_REGISTRY_PASSWORD" $CI_REGISTRY
|
||||
# # Default branch leaves tag empty (= latest tag)
|
||||
# # All other branches are tagged with the escaped branch name (commit ref slug)
|
||||
# script:
|
||||
# - |
|
||||
# if [[ "$CI_COMMIT_BRANCH" == "$CI_DEFAULT_BRANCH" ]]; then
|
||||
# tag=""
|
||||
# echo "Running on default branch '$CI_DEFAULT_BRANCH': tag = 'latest'"
|
||||
# else
|
||||
# tag=":$CI_COMMIT_REF_SLUG"
|
||||
# echo "Running on branch '$CI_COMMIT_BRANCH': tag = $tag"
|
||||
# fi
|
||||
# - docker build --pull -t "$CI_REGISTRY_IMAGE${tag}" .
|
||||
# - docker push "$CI_REGISTRY_IMAGE${tag}"
|
||||
# # Run this job in a branch where a Dockerfile exists
|
||||
# rules:
|
||||
# - if: $CI_COMMIT_BRANCH
|
||||
# exists:
|
||||
# - Dockerfile
|
||||
publish-medusa-package:
|
||||
stage: publish-medusa-package
|
||||
rules:
|
||||
- if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH || $CI_COMMIT_TAG
|
||||
script:
|
||||
- LAST_TAG=$(git describe --tags --abbrev=0)
|
||||
- if [ $CI_COMMIT_TAG ];then MEDUSA_VERSION="$CI_COMMIT_TAG"; else MEDUSA_VERSION="$LAST_TAG-$CI_COMMIT_SHORT_SHA"; fi
|
||||
- cd src/Nadeko.Medusa/
|
||||
- dotnet pack -c Release /p:Version=$MEDUSA_VERSION -o bin/Release/packed
|
||||
- dotnet nuget push bin/Release/packed/ --source https://www.myget.org/F/nadeko/api/v2/package --api-key "$MYGET_API_KEY"
|
||||
|
||||
docker-build:
|
||||
# Use the official docker image.
|
||||
image: docker:latest
|
||||
stage: build
|
||||
allow_failure: true
|
||||
services:
|
||||
- docker:dind
|
||||
before_script:
|
||||
- docker login -u "$CI_REGISTRY_USER" -p "$CI_REGISTRY_PASSWORD" $CI_REGISTRY
|
||||
# Default branch leaves tag empty (= latest tag)
|
||||
# All other branches are tagged with the escaped branch name (commit ref slug)
|
||||
script:
|
||||
- |
|
||||
if [[ "$CI_COMMIT_BRANCH" == "$CI_DEFAULT_BRANCH" ]]; then
|
||||
tag=""
|
||||
echo "Running on default branch '$CI_DEFAULT_BRANCH': tag = 'latest'"
|
||||
else
|
||||
tag=":$CI_COMMIT_SHA"
|
||||
echo "Running on branch '$CI_COMMIT_BRANCH': tag = $tag"
|
||||
fi
|
||||
- docker build --pull -t "$CI_REGISTRY_IMAGE${tag}" .
|
||||
- docker push "$CI_REGISTRY_IMAGE${tag}"
|
||||
# Run this job in a branch where a Dockerfile exists
|
||||
rules:
|
||||
- if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH || $CI_COMMIT_TAG
|
||||
exists:
|
||||
- Dockerfile
|
||||
|
712
CHANGELOG.md
712
CHANGELOG.md
@@ -1,14 +1,667 @@
|
||||
# Changelog
|
||||
|
||||
Experimental changelog. Mostly based on [keepachangelog](https://keepachangelog.com/en/1.0.0/) except date format. a-c-f-r-o
|
||||
#todo .trans fix
|
||||
|
||||
## Unreleased
|
||||
## [4.3.13] - 20.02.2023
|
||||
|
||||
- More cool stuff coming soon
|
||||
### Fixed
|
||||
|
||||
- Fixed `.log userpresence`
|
||||
- `.q` will now use `yt-dlp` if anything other than `ytProvider: Ytdl` is set in `data/searches.yml`
|
||||
- Fixed Title links on some embeds
|
||||
|
||||
## [4.3.12] - 12.02.2023
|
||||
|
||||
### Fixed
|
||||
|
||||
- Fixed `.betstats` not working on european locales
|
||||
- Timed `.ban` will work on users who are not in the server
|
||||
- Fixed some bugs in the medusa system
|
||||
|
||||
## [4.3.11] - 21.01.2023
|
||||
|
||||
### Added
|
||||
|
||||
- Added `.doas` Bot owner only command
|
||||
- Added `.stickeradd` command
|
||||
|
||||
### Changed
|
||||
|
||||
- `.waifuinfo` optimized
|
||||
- You can now specify an optional custom message in `.feed` and `.yun` which will be posted along with an update
|
||||
- Greet/bye messages will now get disabled if they're set to a deleted/unknown channel
|
||||
- Updated response strings
|
||||
- `.translate` now supports many more languages
|
||||
- `.translangs` prettier output
|
||||
|
||||
### Fixed
|
||||
|
||||
- Added logging for thread events
|
||||
- Fixed a bug for `.quotedeleteauthor` causing the executing user to delete own messages
|
||||
- Fixed TimeOut punishment not alklowing duration
|
||||
- Fixed a nullref in streamrole service
|
||||
- Fixed some potential causes for ratelimit due to default message retry settings
|
||||
- Fixed a patron rewards bug caused by monthly donation checking not accounting for year increase
|
||||
- Fixed a patron rewards bug for users who connected the same discord account with multiple patreon accounts
|
||||
- `.deletecurrency` will now also reset banked currency
|
||||
- Fixed DMHelpText reply
|
||||
- `.h` command show now properly show both channel and server user permission requirements
|
||||
- Many fixes and improvements to medusa system
|
||||
- Fixed trivia --nohint
|
||||
- `.joinrace` will no longer fail if the user isn't in the database yet
|
||||
|
||||
## [4.3.10] - 10.11.2022
|
||||
|
||||
### Added
|
||||
|
||||
- `.filterlist` / `.fl` command which lists link and invite filtering channels and status
|
||||
- Added support for `%target%` placeholder in `.alias` command
|
||||
- Added .forwardtochannel which will forward messages to the current channel. It has lower priority than fwtoall
|
||||
- Added .exprtoggleglobal / .extg which can be used to toggle usage of global expressions on the server
|
||||
|
||||
### Changed
|
||||
|
||||
- .meload and .meunload are now case sensitive. Previously loaded medusae may need to be reloaded or data/medusae/medusa.yml may need to be edited manually
|
||||
- Several club related command have their error messages improved
|
||||
- Updated help text for .antispam and .antiraid
|
||||
- You can now specify time and date (time is optional) in `.remind` command instead of relative time, in the format `HH:mm dd.MM.YYYY`
|
||||
- OwnerId will be automatically added to `creds.yml` at bot startup if it's missing
|
||||
|
||||
### Fixed
|
||||
|
||||
- Fixed `.cmdcd` console error
|
||||
- Fixed an error when currency is add per xp
|
||||
- Fixed an issue preventing execution of expressions starting with @Bot when cleverbot is enabled on the server
|
||||
- Fixed `.feedadd`
|
||||
- Fixed `.prune @target` not working
|
||||
- Medusa modules (sneks) should now inherit medusa description when listed in .mdls command
|
||||
- Fixed command cooldown calculation
|
||||
|
||||
## [4.3.9] - 12.10.2022
|
||||
|
||||
### Added
|
||||
|
||||
- `.betstats` shows sum of all bets, payouts and the payout rate in %. Updates once an hour
|
||||
|
||||
### Changed
|
||||
|
||||
- `.betstats` looks way better (except on Mac)
|
||||
- `.feedadd` errors clarified and separated in individual error messages for each issue.
|
||||
- `.clubban` and `.clubunban` errors clarified and separated in individual error messages for each issue.
|
||||
- `.clubapply` better error messages
|
||||
|
||||
### Fixed
|
||||
|
||||
- `.timely` 'Remind' button fixed in DMs
|
||||
- `.cmdcd` database bugs fixed
|
||||
- Fixed bugged mysql and postgresql migrations
|
||||
- Fixed issues with lodaing medusae due to strict versioning
|
||||
|
||||
### Removed
|
||||
|
||||
- `.slotstats` Superseded by `.betstats`
|
||||
|
||||
## [4.3.8] - 02.10.2022
|
||||
|
||||
### Added
|
||||
|
||||
- Added `.autopublish` command which will automatically publish messages posted in the channel.
|
||||
- Added `--after <messageid>` option to prune which will make prune only delete messages after the specified message id.
|
||||
|
||||
### Changed
|
||||
|
||||
- `.prune` options `--after` and `--safe` are now proper command options, and will show in .h help
|
||||
- `.cmdcd` code mostly rewritten, slight QoL improvements.
|
||||
- Clarified `.remind` permission requirements in help text
|
||||
- `.cmdcds` looks a little better, and is paginated
|
||||
|
||||
### Fixed
|
||||
|
||||
- Fixed trivia bugs
|
||||
- Fixed `.yun` not working with channels with underscore in the name
|
||||
|
||||
## [4.3.7] - 14.09.2022
|
||||
|
||||
### Added
|
||||
|
||||
- Added `.exprdelserv` (.exds) to completement .exas. Deletes an expression on the current server and is susceptible to .dpo, unlike .exd
|
||||
- Added `.shopreq` which lets you set role requirement for specific shop items
|
||||
- Added `.shopbuy` alias to `.buy`
|
||||
|
||||
### Fixed
|
||||
|
||||
- Fixed `.convertlist` showing currencies twice (this may not apply to existing users and it may require you to manually remove all currencies from units.json)
|
||||
|
||||
### Removed
|
||||
|
||||
- Removed `Viewer` field from stream online notification as it is (almost?) always 0.
|
||||
|
||||
## [4.3.6] - 08.09.2022
|
||||
|
||||
### Added
|
||||
|
||||
- Added `.expraddserver` (.exas) which will server as a server-only alternative to '.exa' in case users want to override default Admin permissions with .dpo
|
||||
- Added .banprune command which sets how many days worth of messages will be pruned when bot (soft)bans a person either through a command or another punishment feature.
|
||||
- Added .qdelauth - Delete all quotes by the specified author on this server. If you target yourself - no permission required
|
||||
- Added `.timeout` command
|
||||
- Added an option to award currency based on received xp
|
||||
|
||||
### Changed
|
||||
|
||||
- Reminders now have embed support, but plaintext field is not supported.
|
||||
- User friendlier errors when parsing a number in a command fails
|
||||
|
||||
### Fixed
|
||||
|
||||
- Awarded xp is now correctly used in level up calculations
|
||||
|
||||
## [4.3.5] - 17.08.2022
|
||||
|
||||
### Added
|
||||
|
||||
- Added a 'Use' button when a user already owns an item
|
||||
- Added a 'Pull Again' button to slots
|
||||
- Added `.roleinfo` command
|
||||
- Added `.emojiremove` command
|
||||
- Added `.threadcreate` and `.threaddelete` commands
|
||||
- Added `.bank seize` / `.bank award` owner only commands
|
||||
|
||||
### Changed
|
||||
|
||||
- Running a .timely command early now shows a pending color
|
||||
- .xp system is once again no longer opt in for servers
|
||||
- It's still opt-in for global and requires users to run .xp at least once in order to start gaining global xp
|
||||
|
||||
### Fixed
|
||||
|
||||
- Fixed users not getting club xp
|
||||
|
||||
## [4.3.4] - 07.08.2022
|
||||
|
||||
### Fixed
|
||||
|
||||
- Fixed users getting XP out of nowhere while voice xp is enabled
|
||||
|
||||
## [4.3.3] - 06.08.2022
|
||||
|
||||
### Added
|
||||
|
||||
- Added `betroll` option to `.bettest` command
|
||||
- Added `.xpshopbuy` and `.xpshopuse` convenience commands
|
||||
- Added an optional preview url to teh xp shop item config model which will be shown instead of the real Url
|
||||
|
||||
### Changed
|
||||
|
||||
- Updated position of Username and Club name on the .xp card
|
||||
- Improved text visibility on the .xp card
|
||||
|
||||
### Fixed
|
||||
|
||||
- Possibly fixed .trivia not stopping bug
|
||||
- Fixed very low payout rate on `.betroll`
|
||||
- Fixed an issue with youtube song resolver which caused invalid data to be cached
|
||||
- Added client id to the cache key as a potential fix for VoiceXp 'bug'. The solution may be to use different redis instances for each bot, or to switch from botCache: from 'redis' to 'memory' in creds.yml
|
||||
- Bot owner should now be able to buy items from the xpshop when patron requirement is set
|
||||
- Fixed youtube-dl caching invalid data. Please use yt-dlp instead
|
||||
|
||||
## [4.3.2] - 28.07.2022
|
||||
|
||||
### Fixed
|
||||
|
||||
- Fixed Reaction Roles not working properly with animated emojis
|
||||
- Fixed `.slot` alignment
|
||||
- Fixed `mysql` and `postgresql` reactionrole migration
|
||||
- Fixed repeat loop with `postgresql` db provider
|
||||
- Fixed `.bank withdraw <expression>` will now correctly use bank amount for calculation
|
||||
- [dev] Fixed medusa Reply*LocalizedAsync not working with placeholders
|
||||
|
||||
## [4.3.1] - 27.07.2022
|
||||
|
||||
### Changed
|
||||
|
||||
- Check for updates will run once per hour as it was supposed to
|
||||
|
||||
## [4.3.0] - 27.07.2022
|
||||
|
||||
### Added
|
||||
|
||||
- Added `.bettest` command which lets you test many gambling commands
|
||||
- Better than .slottest
|
||||
- Counts win/loss streaks too
|
||||
- Doesn't count 1x returns as neither wins nor losses
|
||||
- multipliers < 1 are considered losses, > 1 considered wins
|
||||
- Added `.betdraw` command which lets you guess red/black and/or high/low for a random card
|
||||
- They payouts are very good, but seven always loses
|
||||
- Added `.lula` command. Plays the same as `.wof` but looks much nicer, and is easily customizable from gambling.yml without any changes to the sourcecode needed.
|
||||
- Added `.repeatskip` command which makes the next repeat trigger not post anything
|
||||
- Added `.linkonly` which will make the bot only allow link posts in the channel. Exclusive with `.imageonly`
|
||||
- Added release notifications. Bot owners will now receive new release notifications in dms if they have `checkForUpdates` set to `true` in data/bot.yml
|
||||
- You can also configure it via `.conf bot checkfor
|
||||
- updates <true/false>`
|
||||
- Added `.xpshop` which lets bot owners add xp backgrounds and xp frames for sale by configuring `data/xp.yml`
|
||||
- You can also toggle xpshop feature via `.conf xp shop.is_enabled`
|
||||
|
||||
### Changed
|
||||
|
||||
- `.t` Trivia code cleaned up, added ALL pokemon generations
|
||||
|
||||
- `.xpadd` will now work on roles too. It will add the specified xp to each user (visible to the bot) in the role
|
||||
- Improved / cleaned up / modernized how most gambling commands look
|
||||
- `.roll`
|
||||
- `.rolluo`
|
||||
- `.draw`
|
||||
- `.flip`
|
||||
- `.slot`
|
||||
- `.betroll`
|
||||
- `.betflip`
|
||||
- Try them out!
|
||||
- `.draw`, `.betdraw` and some other card commands (not all) will use the new, rewritten deck system
|
||||
- Error will be printed to the console if there's a problem in `.plant`
|
||||
- [dev] Split Nadeko.Common into a separate project
|
||||
- [dev] It will contain classes/utilities which can be shared across different nadeko related projects
|
||||
- [dev] Split Nadeko.Econ into a separate project
|
||||
- [dev] It should be home for the backend any gambling/currency/economy feature
|
||||
- [dev] It will contain most gambling games and any shared logic
|
||||
- [dev] Compliation should take less time and RAM
|
||||
- [dev] No longer using generator and partial methods for commands
|
||||
|
||||
### Fixed
|
||||
|
||||
- `.slot` will now show correct multipliers if they've been modified
|
||||
- Fix patron errors showing up even with permissions disabling the command
|
||||
- Fixed an issue with voice xp breaking xp gain.
|
||||
|
||||
### Removed
|
||||
|
||||
- Removed `.slottest`, replaced by `.bettest`
|
||||
- Removed `.wof`, replaced by `.lula`
|
||||
- [dev] Removed a lot of unused methods
|
||||
- [dev] Removed several unused response strings
|
||||
|
||||
## [4.2.15] - 12.07.2022
|
||||
|
||||
### Fixed
|
||||
|
||||
- Fixed `.nh*ntai` nsfw command
|
||||
- Xp Freezes may have been fixed
|
||||
- `data/images.yml` should once again support local file paths
|
||||
- Fixed multiword aliases
|
||||
|
||||
## [4.2.14] - 03.07.2022
|
||||
|
||||
### Added
|
||||
|
||||
- Added `.log userwarned` (Logging user warnings)
|
||||
- Claiming `.timely` will now show a button which you can click to set a reminder
|
||||
- Added `%server.icon%` placeholder
|
||||
- Added `warn` punishment action for protection commands (it won't work with `.warnp`)
|
||||
|
||||
### Changed
|
||||
|
||||
- `.log userbanned` will now have a ban reason
|
||||
- When `.die` is used, bot will try to update it's status to `Invisible`
|
||||
|
||||
### Fixed
|
||||
|
||||
- Fixed elipsis character issue with aliases/quotes. You should now be able to set an elipsis to be an alias of `.quoteprint`
|
||||
|
||||
## [4.2.13] - 30.06.2022
|
||||
|
||||
### Fixed
|
||||
|
||||
- Fixed `.cash` bank interaction not being ephemeral anymore
|
||||
|
||||
## [4.2.12] - 30.06.2022
|
||||
|
||||
### Fixed
|
||||
|
||||
- Fixed `.trivia --pokemon` showing incorrect pokemons
|
||||
|
||||
## [4.2.11] - 29.06.2022
|
||||
|
||||
### Fixed
|
||||
|
||||
- Fixed `.draw` command
|
||||
|
||||
## [4.2.10] - 29.06.2022
|
||||
|
||||
- Fixed currency generation working only once
|
||||
|
||||
## [4.2.9] - 25.06.2022
|
||||
|
||||
### Fixed
|
||||
|
||||
- Fixed `creds_example.yml` misssing from output directory
|
||||
|
||||
## [4.2.8] - 24.06.2022
|
||||
|
||||
### Fixed
|
||||
|
||||
- `.timely` should be fixed
|
||||
|
||||
## [4.2.7] - 24.06.2022
|
||||
|
||||
### Changed
|
||||
|
||||
- New cache abstraction added
|
||||
- 2 implemenations: redis and memory
|
||||
- All current bots will stay on redis cache, all new bots will use **in-process memory cache by default**
|
||||
- This change removes bot's hard dependency on redis
|
||||
- Configurable in `creds.yml` (please read the comments)
|
||||
- You **MUST** use 'redis' if your bot runs on more than 1 shard (2000+ servers)
|
||||
- [dev] Using new non-locking ConcurrentDictionary
|
||||
|
||||
### Fixed
|
||||
|
||||
- `.xp` will now show default user avatars too
|
||||
|
||||
### Removed
|
||||
|
||||
- Removed `.imagesreload` as images are now lazily loaded on request and then cached
|
||||
|
||||
## [4.2.6] - 22.06.2022
|
||||
|
||||
### Fixed
|
||||
|
||||
- Patron system should now properly by disabled on selfhosts by default.
|
||||
|
||||
## [4.2.5] - 18.06.2022
|
||||
|
||||
### Fixed
|
||||
|
||||
- Fixed `.crypto`, you will still need coinmarketcapApiKey in `creds.yml` in order to make it run consistently as the key is shared
|
||||
|
||||
## [4.2.3] - 17.06.2022
|
||||
|
||||
### Fixed
|
||||
|
||||
- Fixed `.timely` nullref bug and made it nicer
|
||||
- Fixed `.streamrole` not updating in real time!
|
||||
- Disabling specific Global Expressions should now work with `.sc` (and other permission commands)
|
||||
|
||||
## [4.2.2] - 15.06.2022
|
||||
|
||||
### Fixed
|
||||
|
||||
- Added missing Patron Tiers and fixed Patron pledge update bugs
|
||||
- Prevented creds_example.yml error in docker containers from crashing it
|
||||
|
||||
### Changed
|
||||
|
||||
- Rss feeds will now show error counter before deletion
|
||||
|
||||
## [4.2.1] - 14.06.2022
|
||||
|
||||
### Added
|
||||
|
||||
- Localized strings updated
|
||||
|
||||
### Fixed
|
||||
|
||||
- Fixed `.exexport`, `.savechat`, and `.quoteexport`
|
||||
- Fixed plaintext-only embeds
|
||||
- Fixed greet message footer not showing origin server
|
||||
|
||||
## [4.2.0] - 14.06.2022
|
||||
|
||||
### Added
|
||||
|
||||
- Added `data/searches.yml` file which configures some of the new search functionality
|
||||
The file comments explaining what each property does.
|
||||
Explained briefly here:
|
||||
```yml
|
||||
# what will be used for .google command. Either google (official api) or searx
|
||||
webSearchEngine: Google
|
||||
# what will be used for .img command. Either google (official api) or searx
|
||||
imgSearchEngine: Google
|
||||
# how will yt results be retrieved: ytdataapi or ytdl or ytdlp
|
||||
ytProvider: YtDataApiv3
|
||||
# in case web or img search is set to searx, the following instances will be used:
|
||||
searxInstances: []
|
||||
# in case ytProvider is set to invidious, the following instances will be used
|
||||
invidiousInstances: []
|
||||
```
|
||||
- Added new properties to `creds.yml`. google -> searchId and google -> searchImageId.
|
||||
- These properties are used as `cx` (google api query parameter) in case you've setup your `data/searches.yml` to use the official google api.
|
||||
`searchId` is used for web search
|
||||
`searchimageId` is used for image search
|
||||
```yml
|
||||
google:
|
||||
searchId: ""
|
||||
searchImageId: ""
|
||||
```
|
||||
- Check `creds_example.yml` for comments explaining how to obtain them.
|
||||
|
||||
#### Patronage system added
|
||||
- Added `data/patron.yml` for configuration
|
||||
- Implemented only for patreon so far
|
||||
- Patreon subscription code completely rewritten
|
||||
- Users who pledge on patreon get benefits based on the amount they pledged
|
||||
- Public nadeko only. But selfhosters can adapt it to their own patreon pages by configuring their patreon credentials in `creds.yml` and enabling the system in `data/patron.yml` file.
|
||||
- Most of the patronage system strings are hardcoded atm, so if you wish to use this system on selfhosts, you will have to modify the source
|
||||
- Pledge amounts are split into tiers. This is not configurable atm.
|
||||
- Tier I - 1$ - 4.99$ a month
|
||||
- Tier V - 5$ - 9.99$ a month
|
||||
- Tier X - 10$ - 19.99$ a month
|
||||
- Tier XX - 20$ - 49.99$ a month
|
||||
- Tier L - 50$ - 99.99$ a month
|
||||
- Tier C - 100$+ a month
|
||||
- Rewards and command quotas for each of the tiers are configurable
|
||||
- Limitations to certain features are also configurable. ex:
|
||||
```yml
|
||||
quotas:
|
||||
features:
|
||||
"rero:max_count":
|
||||
x: 50
|
||||
```
|
||||
- ^ this setting would set the maximum number of reaction roles to be 50 for a user who is in Patron Tier X
|
||||
- Read the comments in the .yml file for (much) more info
|
||||
- Quota system allows the owner to set up hourly, daily and monthly quota usage for each tier
|
||||
- Quota system applies to entire server owner by a patron
|
||||
- Patron spends own quota by using the commands on any server
|
||||
- Any user on *any* server owned by a patron spends that patron's quota
|
||||
- When users subscribe to patreon they will receive a welcome message
|
||||
- If you're enabling patron system for a selfhost, you will want to edit it
|
||||
|
||||
Added `.patron` and `.patronmessage` commands
|
||||
- `.patron` checks your patronage status, and quotas. Requires patron system to be enabled.
|
||||
- `.patronmessage` (owner only) sends message to all patrons with the specified tier or higher. Supports embeds
|
||||
|
||||
- Added a fake `.cmdcd` command `cleverbot:response` which can be used to limit how often users can talk to the cleverbot.
|
||||
|
||||
### Changed
|
||||
|
||||
- CurrencyReward now support adding additional flowers to patrons.
|
||||
- `.donate` command completely reworked.
|
||||
- Works only on public bot (OnlyPublicBotAttribute)
|
||||
- Guides user on how to donate to support the project
|
||||
- Added interaction explaining selfhosting
|
||||
|
||||
- `.google` reimplemented. It now has 2 modes configurable in `data/searches.yml` under the `webSearchengine` property
|
||||
- If set to `google`, official custom search api will be used. You will need to set googleapikey and google.searchId in `creds.yml`
|
||||
- if set to `searx` one of the instances specified in the `searxInstances:` property will be randomly chosen for each request
|
||||
- instances must have `format=json` allowed (public ones usually don't allow it)
|
||||
- instances are specified as a fully qualified url, example: `https://my.cool.searx.instance.io`
|
||||
- `.image` reimplemented. Same as `.google` - it uses either `google` official api (in which case it uses `google.searchImageId` from `creds.yml`) or `searx`
|
||||
|
||||
- `.youtube` reimplemented. It will use a `ytProvider:` property from `data/searches.yml` to determine how to retrieve results
|
||||
- `ytdataapi` will use the official google api (requires `GoogleApiKey` specified in `creds.yml`) and YoutubeDataApi enabled in the dev console
|
||||
- `ytdl` will use `youtube-dl` program from the host machine. It must be downloaded and it's location must be added to path env variable.
|
||||
- `ytdlp` will use `yt-dlp` program from the host machine. Same as `youtube-dl` - must be in path env variable.
|
||||
- `invidious` will use one of invidious instances specified in the `invidiousInstances` property. Very good.
|
||||
|
||||
- `.google`, `.youtube` and `.image` moved to the new Search group
|
||||
|
||||
Note: Results of each `.youtube` query will be cached for 1 hour to improve perfomance
|
||||
- Removed 30 second `.ping` ratelimit on public nadeko
|
||||
|
||||
- xp image generation changes
|
||||
- In case you have default settings, your xp image will look slightly different
|
||||
- If you've modified xp_template.json, your xp image might look broken. Your old template will be saved in xp_template.json.old
|
||||
- Xp number outline is now slightly thicker
|
||||
- Xp number will now have Center vertical and horizontal alignment
|
||||
- LastLevelUp no longer supported
|
||||
|
||||
- Some commands will now use timestamp tags for better user experience
|
||||
- `.prune` was slightly slowed down to avoid ratelimits
|
||||
- `.wof` moved from it's own group to the default Gambling group
|
||||
- `.feed` urls which error for more than 100 times will be automatically removed.
|
||||
- `.ve` is now enabled by default
|
||||
|
||||
- [dev] nadeko interaction slightly improved to make it less nonsense (they still don't make sense)
|
||||
- [dev] RewardedUsers table slightly changed to make it more general
|
||||
- [dev] renamed `// todo`s which aren't planned soon to `// FUTURE`
|
||||
- [dev] currency rewards have been reimplemented and moved to a separate service
|
||||
|
||||
### Fixed
|
||||
|
||||
- `.rh` no longer needs quotes for multi word roles
|
||||
- `.deletexp` will now properly delete server xp too
|
||||
- Fixed `.crypto` sparklines
|
||||
- [dev] added support for configs to properly parse enums without case sensitivity (ConfigParsers.InsensitiveEnum)
|
||||
- [dev] Fixed a bug in .gencmdlist
|
||||
- [dev] small fixes to creds provider
|
||||
|
||||
### Removed
|
||||
|
||||
- `.ddg` removed.
|
||||
- [dev] removed some dead code and comments
|
||||
|
||||
## [4.1.6] - 14.05.2022
|
||||
|
||||
### Fixed
|
||||
|
||||
- Fixed windows release and updated packages
|
||||
|
||||
## [4.1.5] - 11.05.2022
|
||||
|
||||
### Changed
|
||||
|
||||
- `.clubdesc <msg>` will now have a nicer response
|
||||
|
||||
### Fixed
|
||||
|
||||
- `.give` DM will once again show an amount
|
||||
- Fixed an issue with filters not working and with custom reactions no longer being able to override commands.
|
||||
- Fixed `.stock` command
|
||||
|
||||
## [4.1.4] - 06.05.2022
|
||||
|
||||
### Fixed
|
||||
|
||||
- Fixed `.yun`
|
||||
|
||||
## [4.1.3] - 06.05.2022
|
||||
|
||||
### Added
|
||||
|
||||
- Added support for embed arrays in commands such as .say, .greet, .bye, etc...
|
||||
- Website to create them is live at eb.nadeko.bot (old one is moved to oldeb.nadeko.bot)
|
||||
- Embed arrays don't have a plainText property (it's renamed to 'content')
|
||||
- Embed arrays use color hex values instead of an integer
|
||||
- Old embed format will still work
|
||||
- There shouldn't be any breaking changes
|
||||
- Added `.stondel` command which, when toggled, will make the bot delete online stream messages on the server when the stream goes offline
|
||||
- Added a simple bank system.
|
||||
- Users can deposit, withdraw and check the balance of their currency in the bank.
|
||||
- Users can't check other user's bank balances.
|
||||
- Added a button on a .$ command which, when clicked, sends you a message with your bank balance that only you can see.
|
||||
- Added `.h <command group>`
|
||||
- Using this command will list all commands in the specified group
|
||||
- Atm only .bank is a proper group (`.h bank`)
|
||||
- Added "Bank Accounts" entry to `.economy`
|
||||
|
||||
### Changed
|
||||
|
||||
- Reaction roles rewritten completely
|
||||
- Supports multiple exclusivity groups per message
|
||||
- Supports level requirements
|
||||
- However they can only be added one by one
|
||||
- Use the following commands for more information
|
||||
- `.h .reroa`
|
||||
- `.h .reroli`
|
||||
- `.h .rerot`
|
||||
- `.h .rerorm`
|
||||
- `.h .rerodela`
|
||||
- Pagination is now using buttons instead of reactions
|
||||
- Bot will now support much higher XP values for global and server levels
|
||||
- [dev] Small change and generation perf improvement for the localized response strings
|
||||
|
||||
|
||||
### Fixed
|
||||
|
||||
- Fixed `.deletexp` command
|
||||
- `.give` command should send DMs again
|
||||
- `.modules` command now has a medusa module description
|
||||
|
||||
## [4.1.2] - 16.04.2022
|
||||
|
||||
### Fixed
|
||||
|
||||
- Fixed an issue with missing `.dll` files in release versions
|
||||
|
||||
## [4.1.0] - 16.04.2022
|
||||
|
||||
### Added
|
||||
|
||||
- NadekoBot now supports mysql, postgresql and sqlite
|
||||
- To change the db nadeko will use, simply change the `db type` in `creds.yml`
|
||||
- There is no migration code right now, which means that if you want to switch to another system you'll either have to manually export/import your database or start fresh
|
||||
- Medusa system
|
||||
- A massive new feature which allows developers to create custom modules/plugins/cogs
|
||||
- They can be load/unloaded/updated at runtime without restarting the bot
|
||||
|
||||
### Changed
|
||||
|
||||
- Minor club rework
|
||||
- Clubs names are now case sensitive (owo and OwO can be 2 different clubs)
|
||||
- Removed discriminators
|
||||
- Current discriminators which are greater than 1 are appended to clubnames to avoid duplicates, you can rename your club with `.clubrename` to remove it
|
||||
- Most of the clubs with #1 discriminator no longer have it (For example MyClub#1 will now just be MyClub)
|
||||
- [dev] A lot of refactoring and slight functionality changes within Nadeko's behavior system and command handler which were required in order to support the medusa system
|
||||
|
||||
### Removed
|
||||
|
||||
- Removed `.clublevelreq` command as it doesn't serve much purpose
|
||||
|
||||
## [4.0.6] - 21.03.2022
|
||||
|
||||
### Fixed
|
||||
|
||||
- Fixed voice presence logging
|
||||
- Fixed .clubaccept, .clubban, .clubkick and .clubunban commands
|
||||
|
||||
## [4.0.5] - 21.03.2022
|
||||
|
||||
### Fixed
|
||||
|
||||
- Fixed several bugs in the currency code
|
||||
- Fixed some potential memory leaks
|
||||
- Fixed some response strings
|
||||
|
||||
## [4.0.4] - 04.03.2022
|
||||
|
||||
### Fixed
|
||||
|
||||
- Fixed the `id` which shows up when you add a new Expression
|
||||
- Fixed some strings which were still referring to "CustomReaction(s)" instead of "Expression(s)"
|
||||
|
||||
## [4.0.3] - 04.03.2022
|
||||
|
||||
### Fixed
|
||||
|
||||
- Console should no longer spam numbers when `.antispam` is enabled
|
||||
|
||||
## [4.0.2] - 03.03.2022
|
||||
|
||||
### Fixed
|
||||
|
||||
- Fixed `.rero` not working due to a bug introduced in 4.0
|
||||
|
||||
## [4.0.1] - 03.03.2022
|
||||
|
||||
### Added
|
||||
|
||||
- Added `usePrivilegedIntents` to creds.yml if you don't have or don't want (?) to use them
|
||||
- Added a human-readable, detailed error message if logging in fails due to missing privileged intents
|
||||
|
||||
@@ -17,20 +670,20 @@ Experimental changelog. Mostly based on [keepachangelog](https://keepachangelog.
|
||||
### Added
|
||||
- Added `.deleteemptyservers` command
|
||||
- Added `.curtr <id>` which lets you see full information about one of your own transactions with the specified id
|
||||
- Added trovo.live support for stream notifications (`.stadd`)
|
||||
- Added trovo.live support for stream notifications (`.stadd`)
|
||||
- Added unclaimed waifu decay functionality
|
||||
- Added 3 new settings to `data/gambling.yml` to control it:
|
||||
- waifu.decay.percent - How much % to subtract from unclaimed waifu
|
||||
- waifu.decay.hourInterval - How often to decay the price
|
||||
- waifu.decay.hourInterval - How often to decay the price
|
||||
- waifu.decay.minPrice - Unclaimed waifus with price lower than the one specified here will not be affected by the decay
|
||||
- Added `currency.transactionsLifetime` to `data/gambling.yml` Any transaction older than the number of days specified will be automatically deleted
|
||||
- Added `.stock` command to check stock prices and charts
|
||||
- Re-added `.qap / .queueautoplay`
|
||||
- Re-added `.qap / .queueautoplay`
|
||||
|
||||
### Changed
|
||||
- CustomReactions module (and customreactions db table) has been renamed to Expressions.
|
||||
- This was done to remove confusion about how it relates to discord Reactions (it doesn't, it was created and named before discord reactions existed)
|
||||
- Expression command now start with ex/expr and end with the name of the action or setting.
|
||||
- This was done to remove confusion about how it relates to discord Reactions (it doesn't, it was created and named before discord reactions existed)
|
||||
- Expression command now start with ex/expr and end with the name of the action or setting.
|
||||
- For example `.exd` (`.dcr`) is expression delete, `.exa` (`.acr`)
|
||||
- Permissions (`.lp`) be automatically updated with "ACTUALEXPRESSIONS", "EXPRESSIONS" instead of "ACTUALCUSTOMREACTIONS" and "CUSTOMREACTIONS"
|
||||
- Permissions for `.ecr` (now `.exe`), `.scr` (now `.exs`), `.dcr` (now `.exd`), `.acr` (now `.exa`), `.lcr` (now `.exl`) will be automatically updated
|
||||
@@ -47,11 +700,12 @@ Experimental changelog. Mostly based on [keepachangelog](https://keepachangelog.
|
||||
- [dev] Added Type, Extra, OtherId fields to the database
|
||||
- [dev] CommandStrings will now use methodname as the key, and **not** the command name (first entry in aliases.yml)
|
||||
- In other words aliases.yml and commands.en-US.yml will use the same keys (once again)
|
||||
- [dev] Reorganized module and submodule folders
|
||||
- [dev] Permissionv2 db table renamed to Permissions
|
||||
- [dev] Reorganized module and submodule folders
|
||||
- [dev] Permissionv2 db table renamed to Permissions
|
||||
- [dev] Moved FilterWordsChannelId to a separate table
|
||||
|
||||
### Fixed
|
||||
- Fixed twitch stream notifications (rewrote it to use the new api)
|
||||
- Fixed an extra whitespace in usage part of command help if the command has no arguments
|
||||
- Possible small fix for `.prune` ratelimiting
|
||||
- `.gvc` should now properly trigger when a user is already in a gvc and changes his activity
|
||||
@@ -62,9 +716,9 @@ Experimental changelog. Mostly based on [keepachangelog](https://keepachangelog.
|
||||
- Fixed embed color when disabling `.antialt`
|
||||
|
||||
### Removed
|
||||
- Removed `.bce` - use `.config` or `.config bot` specifically for bot config
|
||||
- Removed obsolete placeholders: %users% %servers% %userfull% %username% %userdiscrim% %useravatar% %id% %uid% %chname% %cid% %sid% %members% %server_time% %shardid% %time% %mention%
|
||||
- Removed some obsolete commands and strings
|
||||
- Removed `.bce` - use `.config` or `.config bot` specifically for bot config
|
||||
- Removed obsolete placeholders: %users% %servers% %userfull% %username% %userdiscrim% %useravatar% %id% %uid% %chname% %cid% %sid% %members% %server_time% %shardid% %time% %mention%
|
||||
- Removed some obsolete commands and strings
|
||||
- Removed code which migrated 2.x to v3 credentials, settings, etc...
|
||||
|
||||
## [3.0.13] - 14.01.2022
|
||||
@@ -103,7 +757,7 @@ Experimental changelog. Mostly based on [keepachangelog](https://keepachangelog.
|
||||
- Looks much nicer
|
||||
- Bot will now reply to user messages with a translation if `del` is disabled
|
||||
- Bot will make an embed with original and translated text with user avatar and name if `del` is enabled
|
||||
- If the bot is unable to delete messages while having `del` enabled, it will reset back to the no-del behavior for the current session
|
||||
- If the bot is unable to delete messages while having `del` enabled, it will reset back to the no-del behavior for the current session
|
||||
|
||||
### Fixed
|
||||
- `.crypto` now supports top 5000 coins
|
||||
@@ -117,7 +771,7 @@ Experimental changelog. Mostly based on [keepachangelog](https://keepachangelog.
|
||||
### Fixed
|
||||
- `.xprewsreset` now has correct permissions
|
||||
|
||||
### Removed
|
||||
### Removed
|
||||
- Removed slot.numbers from `images.yml` as they're no longer used
|
||||
|
||||
## [3.0.9] - 21.11.2021
|
||||
@@ -127,7 +781,7 @@ Experimental changelog. Mostly based on [keepachangelog](https://keepachangelog.
|
||||
|
||||
### Added
|
||||
- Added `.emojiadd` with 3 overloads
|
||||
- `.ea :customEmoji:` which copies another server's emoji
|
||||
- `.ea :customEmoji:` which copies another server's emoji
|
||||
- `.ea newName :customEmoji:` which copies emoji under a different name
|
||||
- `.ea emojiName <imagelink.png>` which creates a new emoji from the specified image
|
||||
- Patreon Access and Refresh Tokens should now be automatically updated once a month as long as the user has provided the necessary credentials in creds.yml file:
|
||||
@@ -141,7 +795,7 @@ Experimental changelog. Mostly based on [keepachangelog](https://keepachangelog.
|
||||
|
||||
## [3.0.8] - 03.11.2021
|
||||
|
||||
### Added
|
||||
### Added
|
||||
- Created VotesApi project nad re-worked vote rewards handling
|
||||
- Updated votes entries in creds.yml with explanations on how to set up vote links
|
||||
|
||||
@@ -166,10 +820,10 @@ Experimental changelog. Mostly based on [keepachangelog](https://keepachangelog.
|
||||
- They are called negative gifts
|
||||
- They show up at the end of the `.gifts` page and are marked with a broken heart
|
||||
- They have a separate multiplier (`waifu.multi.negative_gift_effect` default 0.5, changeable via `.config gambling` or `data/gambling.yml`)
|
||||
- When gifted, the waifu's price will be reduced by the `price * multiplier`
|
||||
- When gifted, the waifu's price will be reduced by the `price * multiplier`
|
||||
- Negative gifts don't show up in `.waifuinfo` nor is the record of them kept in the database
|
||||
|
||||
### Fixed
|
||||
### Fixed
|
||||
- Fixed `%users%` and `%shard.usercount%` placeholders not showing correct values
|
||||
|
||||
## [3.0.6] - 27.09.2021
|
||||
@@ -210,7 +864,7 @@ Experimental changelog. Mostly based on [keepachangelog](https://keepachangelog.
|
||||
- Possible fix for `.repeat` bug
|
||||
- Slight adjustment for repeater logic
|
||||
- Timer should no longer increase on some repeaters
|
||||
- Repeaters should no longer have periods when they're missing from the list
|
||||
- Repeaters should no longer have periods when they're missing from the list
|
||||
- Fixed several commands which used error color for success confirmation messages
|
||||
|
||||
## [3.0.3] - 15.09.2021
|
||||
@@ -271,7 +925,7 @@ Experimental changelog. Mostly based on [keepachangelog](https://keepachangelog.
|
||||
- Explanations on how to get the keys are added as the comments
|
||||
- Code cleanup
|
||||
- Command attributes cleaned up
|
||||
- Removed dummy Remarks and Usages attributes as hey were unused for a few patches but stayed in the code to avoid big git diffsmigration code has ran and it can be safely removed
|
||||
- Removed dummy Remarks and Usages attributes as hey were unused for a few patches but stayed in the code to avoid big git diffsmigration code has ran and it can be safely removed
|
||||
- There are 2 projects: NadekoBot and NadekoBot.Coordinator
|
||||
- You can directly run NadekoBot as the regular bot with one shard
|
||||
- Run NadekoBot.Coordinator if you want more control over your shards and a grpc api for coordinator with which you can start, restart, kill and see status of shards
|
||||
@@ -292,7 +946,7 @@ Experimental changelog. Mostly based on [keepachangelog](https://keepachangelog.
|
||||
|
||||
## [2.46.2] - 14.07.2021
|
||||
|
||||
### Fixed
|
||||
### Fixed
|
||||
|
||||
- Fixed .save for local songs
|
||||
- Fixed .lq for local songs if the song names are too long
|
||||
@@ -363,7 +1017,7 @@ Experimental changelog. Mostly based on [keepachangelog](https://keepachangelog.
|
||||
|
||||
### Added
|
||||
|
||||
- Added `.crsexport` and `.crsimport`
|
||||
- Added `.crsexport` and `.crsimport`
|
||||
- Allows for quick export/import of server or global custom reactions
|
||||
- Requires admin permissions for server crs, and owner for global crs
|
||||
- Explanation of the fields is in the comment at the top of the `.crsexport` .yml file
|
||||
@@ -396,7 +1050,7 @@ Experimental changelog. Mostly based on [keepachangelog](https://keepachangelog.
|
||||
### Added
|
||||
|
||||
- Re-added `%music.playing%` and `%music.queued%` (#290)
|
||||
- Added `%music.servers%` which shows how many servers have a song queued up to play
|
||||
- Added `%music.servers%` which shows how many servers have a song queued up to play
|
||||
ℹ️ ^ Only available to `.ropl` / `.adpl` feature atm
|
||||
- `.autodc` re-added
|
||||
- `.qrp`, `.vol`, `.smch` `.autodc` will now persist
|
||||
@@ -416,7 +1070,7 @@ Experimental changelog. Mostly based on [keepachangelog](https://keepachangelog.
|
||||
- Removing last song in the queue will no longer reset queue index
|
||||
- Having `.rpl` disabled will now correctly stop after the last song, closes #292
|
||||
|
||||
### Removed
|
||||
### Removed
|
||||
|
||||
- `.sad` removed. It's more or less useless. Use `.qrp` and `.autodc` now for similar effect
|
||||
|
||||
@@ -431,7 +1085,7 @@ Experimental changelog. Mostly based on [keepachangelog](https://keepachangelog.
|
||||
|
||||
- Minor perf improvement for filter checks
|
||||
|
||||
### Fixed
|
||||
### Fixed
|
||||
|
||||
- `.qs` result urls are now valid
|
||||
- Custom reactions with "`-`" as a response should once again disable that custom reaction completely
|
||||
@@ -447,8 +1101,8 @@ Experimental changelog. Mostly based on [keepachangelog](https://keepachangelog.
|
||||
- Much faster starting and skipping once the songs are in the queue
|
||||
- Higher quality audio (no stuttering too!)
|
||||
- Local tracks will now have durations if you have ffprobe installed (comes with ffmpeg)
|
||||
- Bot supports joining a different vc without skipping the song if you use `.j`
|
||||
- ⚠️ **DO NOT DRAG THE BOT** to another vc, as it's not properly supported atm, and you will have to do `.play` after dragging it)
|
||||
- Bot supports joining a different vc without skipping the song if you use `.j`
|
||||
- ⚠️ **DO NOT DRAG THE BOT** to another vc, as it's not properly supported atm, and you will have to do `.play` after dragging it)
|
||||
- `.j` makes the bot join your voice channel
|
||||
- `.p` is now alias of play, pause is `.pause`
|
||||
- `.qs` should work without google api key now for most users as it is using a custom loader
|
||||
@@ -471,4 +1125,4 @@ Experimental changelog. Mostly based on [keepachangelog](https://keepachangelog.
|
||||
### Removed
|
||||
|
||||
- Removed admin requirement on `.scrm` as it didn't make sense
|
||||
- Some Music commands are removed because of the complexity they bring in with little value (if you *really* want them back, you can open an issue and specify your *good* reason)
|
||||
- Some Music commands are removed because of the complexity they bring in with little value (if you *really* want them back, you can open an issue and specify your *good* reason)
|
||||
|
21
Dockerfile
21
Dockerfile
@@ -1,10 +1,14 @@
|
||||
FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build
|
||||
WORKDIR /source
|
||||
|
||||
COPY src/Nadeko.Medusa/*.csproj src/Nadeko.Medusa/
|
||||
COPY src/Nadeko.Econ/*.csproj src/Nadeko.Econ/
|
||||
COPY src/Nadeko.Common/*.csproj src/Nadeko.Common/
|
||||
COPY src/NadekoBot/*.csproj src/NadekoBot/
|
||||
COPY src/NadekoBot.Coordinator/*.csproj src/NadekoBot.Coordinator/
|
||||
COPY src/NadekoBot.Generators/*.csproj src/NadekoBot.Generators/
|
||||
COPY src/ayu/Ayu.Discord.Voice/*.csproj src/ayu/Ayu.Discord.Voice/
|
||||
COPY NuGet.Config ./
|
||||
RUN dotnet restore src/NadekoBot/
|
||||
|
||||
COPY . .
|
||||
@@ -24,19 +28,22 @@ WORKDIR /app
|
||||
RUN set -xe; \
|
||||
useradd -m nadeko; \
|
||||
apt-get update; \
|
||||
apt-get install -y libopus0 libsodium23 libsqlite3-0 curl ffmpeg python3 python3-pip sudo; \
|
||||
update-alternatives --install /usr/bin/python python /usr/bin/python3.7 1; \
|
||||
apt-get install -y --no-install-recommends libopus0 libsodium23 libsqlite3-0 curl ffmpeg python3 python3-pip sudo; \
|
||||
update-alternatives --install /usr/bin/python python /usr/bin/python3.9 1; \
|
||||
echo 'Defaults>nadeko env_keep+="ASPNETCORE_* DOTNET_* NadekoBot_* shard_id total_shards TZ"' > /etc/sudoers.d/nadeko; \
|
||||
pip3 install --upgrade youtube-dl; \
|
||||
apt-get remove -y python3-pip; \
|
||||
chmod +x /usr/local/bin/youtube-dl
|
||||
pip3 install --no-cache-dir --upgrade youtube-dl; \
|
||||
apt-get purge -y python3-pip; \
|
||||
chmod +x /usr/local/bin/youtube-dl; \
|
||||
apt-get autoremove -y; \
|
||||
apt-get autoclean -y
|
||||
|
||||
COPY --from=build /app ./
|
||||
COPY docker-entrypoint.sh /usr/local/sbin
|
||||
|
||||
ENV shard_id=0
|
||||
ENV total_shards=1
|
||||
ENV NadekoBot__creds=/app/data/creds.yml
|
||||
|
||||
VOLUME [ "app/data" ]
|
||||
VOLUME [ "/app/data" ]
|
||||
ENTRYPOINT [ "/usr/local/sbin/docker-entrypoint.sh" ]
|
||||
CMD dotnet NadekoBot.dll "$shard_id" "$total_shards"
|
||||
CMD dotnet NadekoBot.dll "$shard_id" "$total_shards"
|
||||
|
@@ -11,6 +11,8 @@ ProjectSection(SolutionItems) = preProject
|
||||
LICENSE.md = LICENSE.md
|
||||
README.md = README.md
|
||||
.gitlab-ci.yml = .gitlab-ci.yml
|
||||
Dockerfile = Dockerfile
|
||||
NuGet.Config = NuGet.Config
|
||||
EndProjectSection
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "NadekoBot", "src\NadekoBot\NadekoBot.csproj", "{45EC1473-C678-4857-A544-07DFE0D0B478}"
|
||||
@@ -27,6 +29,12 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NadekoBot.Generators", "src
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NadekoBot.VotesApi", "src\NadekoBot.VotesApi\NadekoBot.VotesApi.csproj", "{3BC82CFE-BEE7-451F-986B-17EDD1570C4F}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Nadeko.Medusa", "src\Nadeko.Medusa\Nadeko.Medusa.csproj", "{E685977E-31A4-46F4-A5D7-4E3E39E82E43}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Nadeko.Common", "src\Nadeko.Common\Nadeko.Common.csproj", "{A6022F5F-A764-4D3F-847B-36F0391FF659}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Nadeko.Econ", "src\Nadeko.Econ\Nadeko.Econ.csproj", "{4F4FBF7C-74F0-4AE4-B451-9E60BDCA9C37}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
@@ -70,6 +78,24 @@ Global
|
||||
{3BC82CFE-BEE7-451F-986B-17EDD1570C4F}.GlobalNadeko|Any CPU.Build.0 = Debug|Any CPU
|
||||
{3BC82CFE-BEE7-451F-986B-17EDD1570C4F}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{3BC82CFE-BEE7-451F-986B-17EDD1570C4F}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{E685977E-31A4-46F4-A5D7-4E3E39E82E43}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{E685977E-31A4-46F4-A5D7-4E3E39E82E43}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{E685977E-31A4-46F4-A5D7-4E3E39E82E43}.GlobalNadeko|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{E685977E-31A4-46F4-A5D7-4E3E39E82E43}.GlobalNadeko|Any CPU.Build.0 = Debug|Any CPU
|
||||
{E685977E-31A4-46F4-A5D7-4E3E39E82E43}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{E685977E-31A4-46F4-A5D7-4E3E39E82E43}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{A6022F5F-A764-4D3F-847B-36F0391FF659}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{A6022F5F-A764-4D3F-847B-36F0391FF659}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{A6022F5F-A764-4D3F-847B-36F0391FF659}.GlobalNadeko|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{A6022F5F-A764-4D3F-847B-36F0391FF659}.GlobalNadeko|Any CPU.Build.0 = Debug|Any CPU
|
||||
{A6022F5F-A764-4D3F-847B-36F0391FF659}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{A6022F5F-A764-4D3F-847B-36F0391FF659}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{4F4FBF7C-74F0-4AE4-B451-9E60BDCA9C37}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{4F4FBF7C-74F0-4AE4-B451-9E60BDCA9C37}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{4F4FBF7C-74F0-4AE4-B451-9E60BDCA9C37}.GlobalNadeko|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{4F4FBF7C-74F0-4AE4-B451-9E60BDCA9C37}.GlobalNadeko|Any CPU.Build.0 = Debug|Any CPU
|
||||
{4F4FBF7C-74F0-4AE4-B451-9E60BDCA9C37}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{4F4FBF7C-74F0-4AE4-B451-9E60BDCA9C37}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
@@ -82,6 +108,9 @@ Global
|
||||
{AE9B7F8C-81D7-4401-83A3-643B38258374} = {04929013-5BAB-42B0-B9B2-8F2BB8F16AF2}
|
||||
{3BC3BDF8-1A0B-45EB-AB2B-C0891D4D37B8} = {04929013-5BAB-42B0-B9B2-8F2BB8F16AF2}
|
||||
{3BC82CFE-BEE7-451F-986B-17EDD1570C4F} = {04929013-5BAB-42B0-B9B2-8F2BB8F16AF2}
|
||||
{E685977E-31A4-46F4-A5D7-4E3E39E82E43} = {04929013-5BAB-42B0-B9B2-8F2BB8F16AF2}
|
||||
{A6022F5F-A764-4D3F-847B-36F0391FF659} = {04929013-5BAB-42B0-B9B2-8F2BB8F16AF2}
|
||||
{4F4FBF7C-74F0-4AE4-B451-9E60BDCA9C37} = {04929013-5BAB-42B0-B9B2-8F2BB8F16AF2}
|
||||
EndGlobalSection
|
||||
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||
SolutionGuid = {5F3F555C-855F-4BE8-B526-D062D3E8ACA4}
|
||||
|
6
NuGet.Config
Normal file
6
NuGet.Config
Normal file
@@ -0,0 +1,6 @@
|
||||
<configuration>
|
||||
<packageSources>
|
||||
<add key="nuget.org" value="https://api.nuget.org/v3/index.json" protocolVersion="3" />
|
||||
<add key="nadeko.bot" value="https://www.myget.org/F/nadeko/api/v3/index.json" protocolVersion="3" />
|
||||
</packageSources>
|
||||
</configuration>
|
@@ -1,8 +1,3 @@
|
||||
[](https://discord.gg/nadekobot)
|
||||
[](http://nadekobot.readthedocs.io/en/v4/?badge=v4)
|
||||
[](https://top.gg/bot/116275390695079945)
|
||||
|
||||
|
||||
[](https://nadeko.bot/)
|
||||
|
||||
[](https://invite.nadeko.bot/)
|
||||
|
@@ -13,7 +13,15 @@ do
|
||||
fi
|
||||
done
|
||||
|
||||
# fix folder permissions
|
||||
# creds.yml migration
|
||||
if [ -f /app/creds.yml ]; then
|
||||
echo "Default location for creds.yml is now /app/data/creds.yml."
|
||||
echo "Please move your creds.yml and update your docker-compose.yml accordingly."
|
||||
|
||||
export Nadeko_creds=/app/creds.yml
|
||||
fi
|
||||
|
||||
# ensure nadeko can write on /app/data
|
||||
chown -R nadeko:nadeko "$data"
|
||||
|
||||
# drop to regular user and launch command
|
||||
|
@@ -33,17 +33,17 @@ These are required for a number of features to function properly, and all should
|
||||
For a single owner, it should look like this:
|
||||
|
||||
```yml
|
||||
OwnerIds:
|
||||
- 105635576866156544
|
||||
OwnerIds:
|
||||
- 105635576866156544
|
||||
```
|
||||
|
||||
For multiple owners, it should look like this:
|
||||
|
||||
```yml
|
||||
OwnerIds:
|
||||
- 105635123466156544
|
||||
- 145521851676884992
|
||||
- 341420590009417729
|
||||
OwnerIds:
|
||||
- 105635123466156544
|
||||
- 145521851676884992
|
||||
- 341420590009417729
|
||||
```
|
||||
|
||||
|
||||
|
@@ -1,23 +1,23 @@
|
||||
## Custom Reactions / Expressions
|
||||
## Expressions
|
||||
|
||||
### Important
|
||||
|
||||
- For modifying **global** custom reactions, the ones which will work across all the servers your bot is connected to, you **must** be a Bot Owner.
|
||||
You must also use the commands for adding, deleting and listing these reactions in a direct message with the bot.
|
||||
- For modifying **local** custom reactions, the ones which will only work on the server that they are added on, it is required to have the **Administrator** permission.
|
||||
You must also use the commands for adding, deleting and listing these reactions in the server you want the custom reactions to work on.
|
||||
- For modifying **global** expressions, the ones which will work across all the servers your bot is connected to, you **must** be a Bot Owner.
|
||||
You must also use the commands for adding, deleting and listing these expressions in a direct message with the bot.
|
||||
- For modifying **local** expressions, the ones which will only work on the server that they are added on, it is required to have the **Administrator** permission.
|
||||
You must also use the commands for adding, deleting and listing these expressions in the server you want the expressions to work on.
|
||||
|
||||
### Commands and Their Use
|
||||
|
||||
| Command Name | Description | Example |
|
||||
| :----------: | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | -------------------------------- |
|
||||
| `.acr` | Add a custom reaction with a trigger and a response. Running this command in a server requries the Administrator permission. Running this command in DM is Bot Owner only, and adds a new global custom reaction. | `.acr "hello" Hi there, %user%!` |
|
||||
| `.lcr` | Lists a page of global or server custom reactions (15 reactions per page). Running this command in a DM will list the global custom reactions, while running it in a server will list that server's custom reactions. | `.lcr 1` |
|
||||
| `.dcr` | Deletes a custom reaction based on the provided index. Running this command in a server requires the Administrator permission. Running this command in DM is Bot Owner only, and will delete a global custom reaction. | `.dcr 5` |
|
||||
| `.exa` | Add an expression with a trigger and a response. Running this command in a server requries the Administrator permission. Running this command in DM is Bot Owner only, and adds a new global expression. | `.exadd "hello" Hi there, %user%!` |
|
||||
| `exl` | Lists a page of global or server expression(15 expressions per page). Running this command in a DM will list the global expression, while running it in a server will list that server's expression. | `.exl 1` |
|
||||
| `.exd` | Deletes an expression based on the provided index. Running this command in a server requires the Administrator permission. Running this command in DM is Bot Owner only, and will delete a global expression. | `.exd 5` |
|
||||
|
||||
#### Now that we know the commands let's take a look at an example of adding a command with `.acr`,
|
||||
#### Now that we know the commands let's take a look at an example of adding a command with `.exa`,
|
||||
|
||||
`.acr "Nice Weather" It sure is, %user%!`
|
||||
`.exadd "Nice Weather" It sure is, %user%!`
|
||||
|
||||
This command can be split into two different arguments:
|
||||
|
||||
@@ -28,16 +28,16 @@ An important thing to note about the triger is that, to be more than one word, w
|
||||
|
||||
There's no special requirement for the formatting of the response, so we could just write it in exactly the same way we want it to respond, albeit with a placeholder - which will be explained in this next section.
|
||||
|
||||
Now, if that command was ran in a server, anyone on that server can make the bot mention them, saying `It sure is, @Username` anytime they say "Nice Weather". If the command is ran in a direct message with the bot, then the custom reaction can be used on every server the bot is connected to.
|
||||
Now, if that command was ran in a server, anyone on that server can make the bot mention them, saying `It sure is, @Username` anytime they say "Nice Weather". If the command is ran in a direct message with the bot, then the expression can be used on every server the bot is connected to.
|
||||
|
||||
### Block global Custom Reactions
|
||||
### Block global Expressions
|
||||
|
||||
If you want to disable a global custom reaction which you do not like, and you do not want to remove it, or you are not the bot owner, you can do so by adding a new Custom Reaction with the same trigger on your server, and set the response to `-`.
|
||||
If you want to disable a global expression which you do not like, and you do not want to remove it, or you are not the bot owner, you can do so by adding a new expression with the same trigger on your server, and set the response to `-`.
|
||||
|
||||
For example:
|
||||
`.acr /o/ -`
|
||||
`.exa /o/ -`
|
||||
|
||||
Now if you try to trigger `/o/`, it won't print anything even if there is a global custom reaction with the same name.
|
||||
Now if you try to trigger `/o/`, it won't print anything even if there is a global expression with the same name.
|
||||
|
||||
### Placeholders!
|
||||
|
||||
|
@@ -10,7 +10,7 @@ Donating to us also gives you the following benefits:
|
||||
- A hoisted **Donators role** in our [Discord server][discord-server]
|
||||
- Access to exclusive **#noticed** text and voice channels
|
||||
- **1000 flowers** on the public bot per dollar donated (after fees)
|
||||
- **Custom Reactions** on the public bot for [Patreon pledges][patreon] of $5 or higher
|
||||
- **Expressions** on the public bot for [Patreon pledges][patreon] of $5 or higher
|
||||
|
||||
## Patreon
|
||||
|
||||
|
@@ -1,18 +1,25 @@
|
||||
# Setting up NadekoBot with Docker
|
||||
|
||||
# DO NOT USE YET - WORK IN PROGRESS
|
||||
# WORK IN PROGRESS
|
||||
|
||||
### Docker Compose
|
||||
### Installation
|
||||
|
||||
1. Create a `/srv/nadeko` folder
|
||||
- `mkdir -p /srv/nadeko`
|
||||
2. Create a `docker-compose.yml`
|
||||
- nano `docker-compose.yml`
|
||||
- copy the following contents into it:
|
||||
##### docker-compose.yml
|
||||
```yml
|
||||
version: "3.7"
|
||||
services:
|
||||
nadeko:
|
||||
image: registry.gitlab.com/veovis/nadekobot:v3-docker
|
||||
image: registry.gitlab.com/kwoth/nadekobot:latest
|
||||
depends_on:
|
||||
- redis
|
||||
environment:
|
||||
TZ: Europe/Paris
|
||||
#NadekoBot_RedisOptions: redis,name=nadeko
|
||||
NadekoBot_RedisOptions: redis,name=nadeko
|
||||
#NadekoBot_ShardRunCommand: dotnet
|
||||
#NadekoBot_ShardRunArguments: /app/NadekoBot.dll {0} {1}
|
||||
volumes:
|
||||
@@ -27,6 +34,12 @@ services:
|
||||
volumes:
|
||||
- /srv/nadeko/redis-data:/data
|
||||
```
|
||||
3. Save your file and run docker compose
|
||||
- `docker-compose up`
|
||||
4. Edit creds in `/srv/nadeko/conf/creds.yml`
|
||||
5. Run it again with
|
||||
- `docker-compose up`
|
||||
|
||||
### Updating
|
||||
- `cd /srv/nadeko`
|
||||
- `docker-compose pull`
|
||||
|
@@ -1,4 +1,4 @@
|
||||
# Setting up NadekoBot on Linux
|
||||
w# Setting up NadekoBot on Linux
|
||||
|
||||
| Table of Contents |
|
||||
| :-------------------------------------------------- |
|
||||
@@ -15,25 +15,38 @@
|
||||
|
||||
It is recommended that you use **Ubuntu 20.04**, as there have been nearly no problems with it. Also, **32-bit systems are incompatible**.
|
||||
|
||||
|
||||
### Ubuntu 22.04 is ruled as incompatible so double check which ubuntu version you are using.
|
||||
|
||||
##### Compatible operating systems:
|
||||
|
||||
- Ubuntu: 16.04, 18.04, 20.04, 21.04, 21.10
|
||||
- Mint: 19, 20
|
||||
- Debian: 9, 10
|
||||
- Debian: 10, 11
|
||||
- CentOS: 7
|
||||
- openSUSE
|
||||
- Fedora: 33, 34, 35
|
||||
|
||||
## Linux From Source
|
||||
|
||||
Open Terminal (if you're on an installation with a window manager) and navigate to the location where you want to install the bot (for example `cd ~`)
|
||||
##### Migration from v3 -> v4
|
||||
|
||||
Follow the following few steps only if you're migrating from v3. If not, skip to installation instructions.
|
||||
|
||||
Use the new installer script: `cd ~ && wget -N https://gitlab.com/Kwoth/nadeko-bash-installer/-/raw/v4/linuxAIO.sh && bash linuxAIO.sh`
|
||||
> - Install prerequisites (type `1` and press `enter`)
|
||||
> - Download (type `2` and press `enter`)
|
||||
> - Run (type `3` and press `enter`)
|
||||
> - Done
|
||||
|
||||
##### Installation Instructions
|
||||
|
||||
1. Download and run the **new** installer script `cd ~ && wget -N https://gitlab.com/Kwoth/nadeko-bash-installer/-/raw/master/linuxAIO.sh && bash linuxAIO.sh`
|
||||
Open Terminal (if you're on an installation with a window manager) and navigate to the location where you want to install the bot (for example `cd ~`)
|
||||
|
||||
1. Download and run the **new** installer script `cd ~ && wget -N https://gitlab.com/Kwoth/nadeko-bash-installer/-/raw/v4/linuxAIO.sh && bash linuxAIO.sh`
|
||||
2. Install prerequisites (type `1` and press enter)
|
||||
3. Download the bot (type `2` and press enter)
|
||||
4. Exit the installer (type `5` and press enter)
|
||||
4. Exit the installer (type `6` and press enter)
|
||||
5. Copy the creds.yml template `cp nadekobot/output/creds_example.yml nadekobot/output/creds.yml`
|
||||
6. Open `nadekobot/output/creds.yml` with your favorite text editor. We will use nano here
|
||||
- `nano nadekobot/output/creds.yml`
|
||||
@@ -42,19 +55,31 @@ Open Terminal (if you're on an installation with a window manager) and navigate
|
||||
- `CTRL` + `X`
|
||||
- `Y`
|
||||
- `Enter`
|
||||
8. Run the bot (type `3` and press enter)
|
||||
8. Run the installer script again `cd ~ && wget -N https://gitlab.com/Kwoth/nadeko-bash-installer/-/raw/v4/linuxAIO.sh && bash linuxAIO.sh`
|
||||
9. Run the bot (type `3` and press enter)
|
||||
|
||||
##### Source Update Instructions
|
||||
|
||||
1. ⚠ Stop the bot ⚠
|
||||
2. Update and run the **new** installer script `cd ~ && wget -N https://gitlab.com/Kwoth/nadeko-bash-installer/-/raw/master/linuxAIO.sh && bash linuxAIO.sh`
|
||||
2. Update and run the **new** installer script `cd ~ && wget -N https://gitlab.com/Kwoth/nadeko-bash-installer/-/raw/v4/linuxAIO.sh && bash linuxAIO.sh`
|
||||
3. Update the bot (type `2` and press enter)
|
||||
4. Run the bot (type `3` and press enter)
|
||||
5. 🎉
|
||||
|
||||
## **⚠ IF YOU ARE FOLLOWING THE GUIDE ABOVE, IGNORE THIS SECTION ⚠**
|
||||
|
||||
## Linux Release
|
||||
|
||||
**⚠ IF YOU ARE FOLLOWING THE GUIDE ABOVE, IGNORE THIS SECTION ⚠**
|
||||
###### Prerequisites
|
||||
|
||||
1. (Optional) Installing Redis
|
||||
- ubuntu installation command: `sudo apt-get install redis-server`
|
||||
2. Playing music requires `ffmpeg`, `libopus`, `libsodium` and `youtube-dl` (which in turn requires python3)
|
||||
- ubuntu installation command: `sudo apt-get install ffmpeg libopus0 opus-tools libopus-dev libsodium-dev -y`
|
||||
3. Make sure your python is version 3+ with `python --version`
|
||||
- if it's not, you can install python 3 and make it the default with: `sudo apt-get install python3.8 python-is-python3`
|
||||
|
||||
*You can use nadeko bash script [prerequisites installer](https://gitlab.com/Kwoth/nadeko-bash-installer/-/blob/v4/n-prereq.sh) as a reference*
|
||||
|
||||
##### Installation Instructions
|
||||
|
||||
@@ -130,19 +155,42 @@ While there are two run modes built into the installer, these options only run N
|
||||
|
||||
Using `tmux` is the simplest method, and is therefore recommended for most users.
|
||||
|
||||
1. Start a tmux session:
|
||||
- `tmux`
|
||||
2. Navigate to the project's root directory
|
||||
- Project root directory location example: `/home/user/nadekobot/`
|
||||
3. Enter the `output` directory:
|
||||
- `cd output`
|
||||
4. Run the bot using:
|
||||
- `dotnet NadekoBot.dll`
|
||||
5. Detatch the tmux session:
|
||||
**Before proceeding, make sure your bot is not running by either running `.die` in your Discord server or exiting the process with `Ctrl+C`.**
|
||||
|
||||
If you are presented with the installer main menu, exit it by choosing Option `8`.
|
||||
|
||||
1. Create a new session: `tmux new -s nadeko`
|
||||
|
||||
The above command will create a new session named **nadeko** *(you can replace “nadeko” with anything you prefer, it's your session name)*.
|
||||
|
||||
2. Run the installer: `bash linuxAIO.sh`
|
||||
|
||||
3. There are a few options when it comes to running Nadeko.
|
||||
|
||||
- Run `3` to *Run the bot normally*
|
||||
- Run `4` to *Run the bot with Auto Restart* (This is may or may not work)
|
||||
|
||||
4. If option `4` was selected, you have the following options
|
||||
```
|
||||
1. Run Auto Restart normally without updating NadekoBot.
|
||||
2. Run Auto Restart and update NadekoBot.
|
||||
3. Exit
|
||||
|
||||
Choose:
|
||||
[1] to Run NadekoBot with Auto Restart on "die" command without updating.
|
||||
[2] to Run with Auto Updating on restart after using "die" command.
|
||||
```
|
||||
- Run `1` to update the bot upon restart. (This is done using the `.die` command)
|
||||
- Run `2` to restart the bot without updating. (This is also done using the `.die` command)
|
||||
|
||||
5. That's it! to detatch the tmux session:
|
||||
- Press `Ctrl` + `B`
|
||||
- Then press `D`
|
||||
|
||||
Nadeko should now be running in the background of your system. To re-open the tmux session to either update, restart, or whatever, execute `tmux a`.
|
||||
Now check your Discord server, the bot should be online. Nadeko should now be running in the background of your system.
|
||||
|
||||
To re-open the tmux session to either update, restart, or whatever, execute `tmux a -t nadeko`. *(Make sure to replace "nadeko" with your session name. If you didn't change it, leave it as it.)*
|
||||
|
||||
|
||||
### Systemd
|
||||
|
||||
@@ -271,6 +319,26 @@ This method is similar to the one above, but requires one extra step, with the a
|
||||
|
||||
If you want Nadeko to play music for you 24/7 without having to hosting it on your PC and want to keep it cheap, reliable and convenient as possible, you can try Nadeko on Linux Digital Ocean Droplet using the link [DigitalOcean](http://m.do.co/c/46b4d3d44795/) (by using this link, you will get **$10 credit** and also support Nadeko)
|
||||
|
||||
To set up the VPS, please select the options below
|
||||
```
|
||||
These are the min requirements you must follow:
|
||||
|
||||
OS: Any between Ubuntu, Fedora, and Debian
|
||||
|
||||
Plan: Basic
|
||||
|
||||
CPU options: regular with SSD
|
||||
1 GB / 1 CPU
|
||||
25 GB SSD Disk
|
||||
1000 GB transfer
|
||||
|
||||
Note: You can select the cheapest option with 512 MB /1 CPU but this has been a hit or miss.
|
||||
|
||||
Datacenter region: Choose one depending on where you are located.
|
||||
|
||||
Authentication: Password or SSH
|
||||
(Select SSH if you know what you are doing, otherwise choose password)
|
||||
```
|
||||
**Setting up NadekoBot**
|
||||
Assuming you have followed the link above to setup an account and a Droplet with a 64-bit operational system on Digital Ocean and got the `IP address and root password (in your e-mail)` to login, it's time to get started.
|
||||
|
||||
|
@@ -7,7 +7,7 @@ Open Terminal (if you don't know how to, click on the magnifying glass on the to
|
||||
###### Homebrew/wget
|
||||
*Skip this step if you already have homebrew installed*
|
||||
- Copy and paste this command, then press Enter:
|
||||
- `/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"`
|
||||
- `/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"`
|
||||
- Install wget
|
||||
- `brew install wget`
|
||||
|
||||
@@ -31,7 +31,7 @@ sudo ln -s /usr/local/opt/openssl/lib/libssl.1.0.0.dylib /usr/local/lib/
|
||||
|
||||
##### Installation Instructions
|
||||
|
||||
1. Download and run the **new** installer script `cd ~ && wget -N https://gitlab.com/Kwoth/nadeko-bash-installer/-/raw/master/linuxAIO.sh && bash linuxAIO.sh`
|
||||
1. Download and run the **new** installer script `cd ~ && wget -N https://gitlab.com/Kwoth/nadeko-bash-installer/-/raw/v4/linuxAIO.sh && bash linuxAIO.sh`
|
||||
2. Install prerequisites (type `1` and press enter)
|
||||
3. Download the bot (type `2` and press enter)
|
||||
4. Exit the installer in order to set up your `creds.yml`
|
||||
@@ -49,7 +49,7 @@ sudo ln -s /usr/local/opt/openssl/lib/libssl.1.0.0.dylib /usr/local/lib/
|
||||
##### Update Instructions
|
||||
|
||||
1. ⚠ Stop the bot
|
||||
2. Update and run the **new** installer script `cd ~ && wget -N https://gitlab.com/Kwoth/nadeko-bash-installer/-/raw/master/linuxAIO.sh && bash linuxAIO.sh`
|
||||
2. Update and run the **new** installer script `cd ~ && wget -N https://gitlab.com/Kwoth/nadeko-bash-installer/-/raw/v4/linuxAIO.sh && bash linuxAIO.sh`
|
||||
3. Update the bot (type `2` and press enter)
|
||||
4. Run the bot (type `3` and press enter)
|
||||
5. 🎉
|
||||
|
@@ -19,7 +19,7 @@
|
||||
|
||||
**Optional**
|
||||
|
||||
- [Notepad++] (makes it easier to edit your credentials)
|
||||
- [Visual Studio Code](https://code.visualstudio.com/Download) (Highly suggested if you plan on editing files)
|
||||
- [Visual C++ 2010 (x86)] and [Visual C++ 2017 (x64)] (both are required if you want Nadeko to play music - restart Windows after installation)
|
||||
|
||||
#### Setup
|
||||
@@ -31,7 +31,8 @@
|
||||

|
||||
- Click on **`DOWNLOAD`** at the lower right
|
||||

|
||||
- Click on **`Install`** next to **`Redis`**.
|
||||
- Click on **`Install`** next to **`Redis`**.
|
||||
- **(Note: Redis is optional unless you are are using the bot on 2000+ servers)**
|
||||
- Note: If Redis fails to install, install Redis manually here: [Redis Installer](https://github.com/MicrosoftArchive/redis/releases/tag/win-3.0.504) Download and run the **`.msi`** file.
|
||||
- If you will use the music module, click on **`Install`** next to **`FFMPEG`** and **`Youtube-DL`**.
|
||||
- If any dependencies fail to install, you can temporarily disable your Windows Defender/AV until you install them. If you don't want to, then read [the last section of this guide](#Manual-Prerequisite-Installation).
|
||||
@@ -63,9 +64,9 @@ You can still install them manually:
|
||||
- [ffmpeg-32bit] | [ffmpeg-64bit] - Download the **appropriate version** for your system (32 bit if you're running a 32 bit OS, or 64 if you're running a 64bit OS). Unzip it, and move `ffmpeg.exe` to a path that's in your PATH environment variable. If you don't know what that is, then just move the `ffmpeg.exe` file to NadekoBot/system
|
||||
- [youtube-dl] - Click to download the file. Then put `youtube-dl.exe` in a path that's in your PATH environment variable. If you don't know what that is, then just move the `youtube-dl.exe` file to NadekoBot/system
|
||||
|
||||
### Windows From Source
|
||||
## **⚠ IF YOU ARE FOLLOWING THE GUIDE ABOVE, IGNORE THIS SECTION ⚠**
|
||||
|
||||
⚠ IF YOU ARE FOLLOWING THE GUIDE ABOVE, IGNORE THIS SECTION ⚠
|
||||
### Windows From Source
|
||||
|
||||
##### Prerequisites
|
||||
|
||||
|
@@ -17,8 +17,6 @@ To self-host your own Nadeko, use the guides below:
|
||||
- [:material-linux: Linux guide][linux-guide]
|
||||
- [:material-apple: Mac OS guide][macos-guide]
|
||||
|
||||
Alternatively, you may also setup the bot [from source][from-source-guide] if you want to modify the code.
|
||||
|
||||
In case you need any help, join our [Discord server][discord-server] where we may provide support.
|
||||
|
||||
---
|
||||
|
@@ -24,7 +24,7 @@ This part is completely optional, **however it's necessary for music and a few o
|
||||
- Open up `creds.yml` and look for `GoogleAPIKey`, paste your API key after the `:`.
|
||||
- It should look like this:
|
||||
```yml
|
||||
GoogleApiKey: AIzaSyDSci1sdlWQOWNVj1vlXxxxxxbk0oWMEzM
|
||||
GoogleApiKey: 'AIzaSyDSci1sdlWQOWNVj1vlXxxxxxbk0oWMEzM'
|
||||
```
|
||||
- **MashapeKey**
|
||||
- Required for Hearthstone cards.
|
||||
@@ -40,16 +40,19 @@ This part is completely optional, **however it's necessary for music and a few o
|
||||
- For Patreon creators only.
|
||||
- **PatreonCampaignId**
|
||||
- For Patreon creators only. Id of your campaign.
|
||||
- **TwitchClientId**
|
||||
- **TwitchClientId and TwitchClientSecret**
|
||||
- Mandatory for following twitch streams with `.twitch` (or `.stadd` with twitch link)
|
||||
- Go to [apps page](https://dev.twitch.tv/console/apps/create) on twitch and register your application.
|
||||
- Go to [apps page](https://dev.twitch.tv/console) on twitch and register your application.
|
||||
- You need 2FA enabled on twitch in order to create an application
|
||||
- You can set `http://localhost` as the OAuth Redirect URL (and press Add button)
|
||||
- Select `Chat Bot` from the Category dropdown
|
||||
- Once created, clicking on your application will show a new Client ID field
|
||||
- Copy it to your creds.yml as shown below
|
||||
- Once created, `click Manage`
|
||||
- Click `New Secret` and select `OK` in the popup
|
||||
**Note: You will need to generate a new Client Secret everytime you exit the page**
|
||||
- Copy both to your creds.yml as shown below
|
||||
```yml
|
||||
TwitchClientId: "516tr61tr1qweqwe86trg3g"
|
||||
twitchClientId: 516tr61tr1qweqwe86trg3g
|
||||
twitchClientSecret: 16tr61tr1q86tweqwe
|
||||
```
|
||||
- **LocationIqApiKey**
|
||||
- Optional. Used only for the `.time` command. https://locationiq.com api key (register and you will receive the token in the email).
|
||||
@@ -94,7 +97,7 @@ RestartCommand:
|
||||
|
||||
```yml
|
||||
# DO NOT CHANGE
|
||||
version: 1
|
||||
version: 4
|
||||
# Bot token. Do not share with anyone ever -> https://discordapp.com/developers/applications/
|
||||
token: 'MTE5Nzc3MDIxMzE5NTc3NjEw.VlhNCw.BuqJFyzdIUAK1PRf1eK1Cu89Jew'
|
||||
# List of Ids of the users who have bot owner permissions
|
||||
@@ -153,6 +156,13 @@ timezoneDbApiKey:
|
||||
coinmarketcapApiKey:
|
||||
# Api key used for Osu related commands. Obtain this key at https://osu.ppy.sh/p/api
|
||||
osuApiKey: 4c8c8fdffdsfdsfsdfsfa33f3f3140a7d93320d6
|
||||
# Optional Trovo client id.
|
||||
# You should use this if Trovo stream notifications stopped working or you're getting ratelimit errors.
|
||||
trovoClientId:
|
||||
# Obtain by creating an application at https://dev.twitch.tv/console/apps
|
||||
twitchClientId: jf2w6kkyrlzfl6mp1b4k25h4jr6b2o
|
||||
# Obtain by creating an application at https://dev.twitch.tv/console/apps
|
||||
twitchClientSecret: 16tr61tr1q86tweqwe
|
||||
# Command and args which will be used to restart the bot.
|
||||
# Only used if bot is executed directly (NOT through the coordinator)
|
||||
# placeholders:
|
||||
|
252
docs/medusa/creating-a-medusa.md
Normal file
252
docs/medusa/creating-a-medusa.md
Normal file
@@ -0,0 +1,252 @@
|
||||
# Creating A Medusa
|
||||
|
||||
## Theory
|
||||
|
||||
### Introduction
|
||||
|
||||
Medusa system allows you to write independent medusae (known as "modules", "cogs" or "plugins" in other software) which you can then load, unload and update at will without restarting the bot.
|
||||
|
||||
The system itself borrows some design from the current way Nadeko's Modules are written but mostly from never-released `Ayu.Commands` system which was designed to be used for a full Nadeko v3 rewrite.
|
||||
|
||||
The medusa base classes used for development are open source [here](https://gitlab.com/Kwoth/nadekobot/-/tree/v4/src/Nadeko.Medusa) in case you need reference, as there is no generated documentation at the moment.
|
||||
|
||||
### Term list
|
||||
|
||||
#### Medusa
|
||||
|
||||
- The project itself which compiles to a single `.dll` (and some optional auxiliary files), it can contain multiple [Sneks](#snek), [Services](#service), and [ParamParsers](#param-parser)
|
||||
|
||||
#### Snek
|
||||
|
||||
- A class which will be added as a single Module to NadekoBot on load. It also acts as a [lifecycle handler](snek-lifecycle.md) and as a singleton service with the support for initialize and cleanup.
|
||||
- It can contain a Snek (called SubSnek) but only 1 level of nesting is supported (you can only have a snek contain a subsnek, but a subsnek can't contain any other sneks)
|
||||
- Sneks can have their own prefix
|
||||
- For example if you set this to 'test' then a command called 'cmd' will have to be invoked by using `.test cmd` instead of `.cmd`
|
||||
|
||||
#### Snek Command
|
||||
|
||||
- Acts as a normal command
|
||||
- Has context injected as a first argument which controls where the command can be executed
|
||||
- `AnyContext` the command can be executed in both DMs and Servers
|
||||
- `GuildContext` the command can only be executed in Servers
|
||||
- `DmContext` the command can only be executed in DMs
|
||||
- Support the usual features such as default values, leftover, params, etc.
|
||||
- It also supports dependency injection via `[inject]` attribute. These dependencies must come after the context and before any input parameters
|
||||
- Supports `ValueTask`, `Task`, `Task<T>` and `void` return types
|
||||
|
||||
#### Param Parser
|
||||
|
||||
- Allows custom parsing of command arguments into your own types.
|
||||
- Overriding existing parsers (for example for IGuildUser, etc...) can cause issues.
|
||||
|
||||
#### Service
|
||||
|
||||
- Usually not needed.
|
||||
- They are marked with a `[svc]` attribute, and offer a way to inject dependencies to different parts of your medusa.
|
||||
- Transient and Singleton lifetimes are supported.
|
||||
|
||||
### Localization
|
||||
|
||||
Response and command strings can be kept in one of three different places based on whether you plan to allow support for localization
|
||||
|
||||
option 1) `res.yml` and `cmds.yml`
|
||||
|
||||
If you don't plan on having your app localized, but you just *may* in the future, you should keep your strings in the `res.yml` and `cmds.yml` file the root folder of your project, and they will be automatically copied to the output whenever you build your medusa.
|
||||
|
||||
##### Example project folder structure:
|
||||
- uwu/
|
||||
- uwu.csproj
|
||||
- uwu.cs
|
||||
- res.yml
|
||||
- cmds.yml
|
||||
|
||||
##### Example output folder structure:
|
||||
- medusae/uwu/
|
||||
- uwu.dll
|
||||
- res.yml
|
||||
- cmds.yml
|
||||
|
||||
option 2) `strings` folder
|
||||
|
||||
If you plan on having your app localized (or want to allow your consumers to easily add languages themselves), you should keep your response strings in the `strings/res/en-us.yml` and your command strings in `strings/cmds/en-us.yml` file. This will be your base file, and from there you can make support for additional languages, for example `strings/res/ru-ru.yml` and `strings/cmds/ru-ru.yml`
|
||||
|
||||
##### Example project folder structure:
|
||||
- uwu/
|
||||
- uwu.csproj
|
||||
- uwu.cs
|
||||
- strings/
|
||||
- res/
|
||||
- en-us.yml
|
||||
- ru-ru.yml
|
||||
- cmds/
|
||||
- en-us.yml
|
||||
- ru-ru.yml
|
||||
|
||||
##### Example output folder structure:
|
||||
- medusae/uwu/
|
||||
- uwu.dll
|
||||
- strings/
|
||||
- res/
|
||||
- en-us.yml
|
||||
- ru-ru.yml
|
||||
- cmds/
|
||||
- en-us.yml
|
||||
- ru-ru.yml
|
||||
|
||||
option 3) In the code
|
||||
|
||||
If you don't want any auxiliary files, and you don't want to bother making new .yml files to keep your strings in, you can specify the command strings directly in the `[cmd]` attribute itself, and use non-localized methods for message sending in your commands.
|
||||
|
||||
If you update your response strings .yml file(s) while the medusa is loaded and running, running `.stringsreload` will reload the responses without the need to reload the medusa or restart the bot.
|
||||
|
||||
#### Config
|
||||
|
||||
- Medusa config is kept in `medusae/medusa.yml` file
|
||||
- At the moment this config only keeps track of which medusae are currently loaded (they will also be always loaded at startup)
|
||||
- If a medusa is causing issues and you're unable to unload it, you can remove it from the `loaded:` list in this config file and restart the bot. It won't be loaded next time the bot is started up
|
||||
|
||||
#### Unloadability issues
|
||||
|
||||
To make sure your medusa can be properly unloaded/reloaded you must:
|
||||
|
||||
- Make sure that none of your types and objects are referenced by the Bot or Bot's services after the DisposeAsync is called on your Snek instances.
|
||||
|
||||
- Make sure that all of your commands execute quickly and don't have any long running tasks, as they will hold a reference to a type from your assembly
|
||||
|
||||
- If you are still having issues, you can always run `.meunload` followed by a bot restart, or if you want to find what is causing the medusa unloadability issues, you can check the [microsoft's assembly unloadability debugging guide](https://docs.microsoft.com/en-us/dotnet/standard/assembly/unloadability)
|
||||
|
||||
## Practice
|
||||
|
||||
This section will guide you through how to create a simple custom medusa. You can find the entirety of this code hosted [here](https://gitlab.com/nadeko/example_medusa)
|
||||
|
||||
#### Prerequisite
|
||||
- [.net6 sdk](https://dotnet.microsoft.com/en-us/download) installed
|
||||
- Optional: use [vscode](https://code.visualstudio.com/download) to write code
|
||||
|
||||
#### Guide
|
||||
|
||||
|
||||
- Open your favorite terminal and navigate to a folder where you will keep your project .
|
||||
|
||||
- Create a new folder
|
||||
- `mkdir example_medusa`
|
||||
- Create a new .net class library
|
||||
- `dotnet new classlib`
|
||||
- Open the current folder with your favorite editor/IDE. In this case we'll use VsCode
|
||||
- `code .`
|
||||
- Remove the `Class1.cs` file
|
||||
- Replace the contents of the `.csproj` file with the following contents
|
||||
```xml
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net6.0</TargetFramework>
|
||||
|
||||
<!-- Reduces some boilerplate in your .cs files -->
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
|
||||
<!-- Use latest .net features -->
|
||||
<LangVersion>preview</LangVersion>
|
||||
<EnablePreviewFeatures>true</EnablePreviewFeatures>
|
||||
<GenerateRequiresPreviewFeaturesAttribute>true</GenerateRequiresPreviewFeaturesAttribute>
|
||||
|
||||
<!-- tell .net that this library will be used as a plugin -->
|
||||
<EnableDynamicLoading>true</EnableDynamicLoading>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<!-- Base medusa package. You MUST reference this in order to have a working medusa -->
|
||||
<!-- Also, this package comes from MyGet, which requires you to have a NuGet.Config file next to your .csproj -->
|
||||
<PackageReference Include="Nadeko.Medusa" Version="4.3.9">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
</PackageReference>
|
||||
|
||||
<!-- Note: If you want to use NadekoBot services etc... You will have to manually clone
|
||||
the gitlab.com/kwoth/nadekobot repo locally and reference the NadekoBot.csproj because there is no NadekoBot package atm.
|
||||
It is strongly recommended that you checkout a specific tag which matches your version of nadeko,
|
||||
as there could be breaking changes even between minor versions of NadekoBot.
|
||||
For example if you're running NadekoBot 4.1.0 locally for which you want to create a medusa for,
|
||||
you should do "git checkout 4.1.0" in your NadekoBot solution and then reference the NadekoBot.csproj
|
||||
-->
|
||||
</ItemGroup>
|
||||
|
||||
<!-- Copy shortcut and full strings to output (if they exist) -->
|
||||
<ItemGroup>
|
||||
<None Update="res.yml;cmds.yml;strings/**">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</None>
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
|
||||
```
|
||||
- Create a `MySnek.cs` file and add the following contents
|
||||
```cs
|
||||
using Nadeko.Snake;
|
||||
using NadekoBot;
|
||||
using Discord;
|
||||
|
||||
public sealed class MySnek : Snek
|
||||
{
|
||||
[cmd]
|
||||
public async Task Hello(AnyContext ctx)
|
||||
{
|
||||
await ctx.Channel.SendMessageAsync($"Hello everyone!");
|
||||
}
|
||||
|
||||
[cmd]
|
||||
public async Task Hello(AnyContext ctx, IUser target)
|
||||
{
|
||||
await ctx.ConfirmLocalizedAsync("hello", target);
|
||||
}
|
||||
}
|
||||
```
|
||||
- Create `res.yml` and `cmds.yml` files with the following contents
|
||||
`res.yml`
|
||||
```yml
|
||||
medusa.description: "This is my medusa's description"
|
||||
hello: "Hello {0}, from res.yml!"
|
||||
```
|
||||
|
||||
`cmds.yml`
|
||||
```yml
|
||||
hello:
|
||||
desc: "This is a basic hello command"
|
||||
args:
|
||||
- ""
|
||||
- "@Someone"
|
||||
```
|
||||
|
||||
- Add `NuGet.Config` file which will let you use the base Nadeko.Medusa package. This file should always look like this and you shouldn't change it
|
||||
|
||||
```xml
|
||||
<configuration>
|
||||
<packageSources>
|
||||
<add key="nuget.org" value="https://api.nuget.org/v3/index.json" protocolVersion="3" />
|
||||
<add key="nadeko.bot" value="https://www.myget.org/F/nadeko/api/v3/index.json" protocolVersion="3" />
|
||||
</packageSources>
|
||||
</configuration>
|
||||
```
|
||||
|
||||
### Build it
|
||||
|
||||
- Build your Medusa into a dll that Nadeko can load. In your terminal, type:
|
||||
- `dotnet publish -o bin/medusae/example_medusa /p:DebugType=embedded`
|
||||
|
||||
- Done. You can now try it out in action.
|
||||
|
||||
### Try it out
|
||||
|
||||
- Copy the `bin/medusae/example_medusa` folder into your NadekoBot's `data/medusae/` folder. (Nadeko version 4.1.0+)
|
||||
|
||||
- Load it with `.meload example_medusa`
|
||||
|
||||
- In the channel your bot can see, run the following commands to try it out
|
||||
- `.hello` and
|
||||
- `.hello @<someone>`
|
||||
|
||||
- Check its information with
|
||||
- `.meinfo example_medusa`
|
||||
|
||||
- Unload it
|
||||
- `.meunload example_medusa`
|
||||
|
||||
- Congrats! You've just made your first medusa!
|
31
docs/medusa/getting-started.md
Normal file
31
docs/medusa/getting-started.md
Normal file
@@ -0,0 +1,31 @@
|
||||
## Getting Started
|
||||
|
||||
### What is the Medusa system?
|
||||
|
||||
- It is a dynamic module/plugin/cog system for NadekoBot introduced in **NadekoBot 4.1.0**
|
||||
|
||||
- Allows developers to add custom functionality to Nadeko without modifying the original code
|
||||
|
||||
- Allows for those custom features to be updated during bot runtime (if properly written), without the need for bot restart.
|
||||
|
||||
- They are added to `data/medusae` folder and are loaded, unloaded and handled through discord commands.
|
||||
- `.meload` Loads the specified medusa (see `.h .meload`)
|
||||
- `.meunload` Unloads the specified medusa (see `.h .meunload`)
|
||||
- `.meinfo` Checks medusae information (see `.h .meinfo`)
|
||||
- `.melist` Lists the available medusae (see `.h .melist`)
|
||||
|
||||
### How to make one?
|
||||
|
||||
Medusae are written in [C#](https://docs.microsoft.com/en-us/dotnet/csharp/tour-of-csharp/) programming language, so you will need at least low-intermediate knowledge of it in order to make a useful Medusa.
|
||||
|
||||
Follow the [creating a medusa guide](creating-a-medusa.md)
|
||||
|
||||
### Where to get medusae other people made?
|
||||
|
||||
⚠ *It is EXTREMELY, and I repeat **EXTREMELY** dangerous to run medusae of strangers or people you don't FULLY trust.* ⚠
|
||||
⚠ *It can not only lead to your bot being stolen, but it also puts your entire computer and personal files in jeopardy.* ⚠
|
||||
|
||||
**It is strongly recommended to run only the medusae you yourself wrote, and only on a hosted VPS or dedicated server which ONLY hosts your bot, to minimize the potential damage caused by bad actors.**
|
||||
|
||||
No easy way at the moment, except asking in the `#dev-and-modding` chat in [#NadekoLog server](https://discord.nadeko.bot)
|
||||
|
19
docs/medusa/snek-lifecycle.md
Normal file
19
docs/medusa/snek-lifecycle.md
Normal file
@@ -0,0 +1,19 @@
|
||||
# Snek Lifecycle
|
||||
|
||||
*You can override several methods to hook into command handler's lifecycle.
|
||||
These methods start with `Exec*`*
|
||||
|
||||
|
||||
- `ExecOnMessageAsync` runs first right after any message was received
|
||||
- `ExecInputTransformAsync` runs after ExecOnMessageAsync and allows you to transform the message content before the bot looks for the matching command
|
||||
- `ExecPreCommandAsync` runs after a command was found but not executed, allowing you to potentially prevent command execution
|
||||
- `ExecPostCommandAsync` runs if the command was successfully executed
|
||||
- `ExecOnNoCommandAsync` runs instead of ExecPostCommandAsync if no command was found for a message
|
||||
|
||||
|
||||
*Besides that, sneks have 2 methods with which you can initialize and cleanup your snek*
|
||||
|
||||
|
||||
- `InitializeAsync` Runs when the medusa which contains this snek is being loaded
|
||||
- `DisposeAsync` Runs when the medusa which contains this snek is being unloaded
|
||||
|
@@ -73,14 +73,14 @@ Say you want to only enable NSFW commands for a specific role, just do the follo
|
||||
2. `.rm NSFW enable Lewd`
|
||||
- Enables usage of the NSFW module for the Lewd role
|
||||
|
||||
#### How do I disable custom reactions from triggering?
|
||||
#### How do I disable Expressions from triggering?
|
||||
|
||||
If you don't want server or global custom reactions, just block the module that controls their usage:
|
||||
If you don't want server or global Expressions, just block the module that controls their usage:
|
||||
|
||||
1. `.sm ActualCustomReactions disable`
|
||||
- Disables the ActualCustomReactions module from being used
|
||||
1. `.sm ActualExpressions disable`
|
||||
- Disables the ActualExpression module from being used
|
||||
|
||||
**Note**: The `ActualCustomReactions` module controls the usage of custom reactions. The `CustomReactions` module controls commands related to custom reactions (such as `.acr`, `.lcr`, `.crca`, etc).
|
||||
**Note**: The `Expressions` module controls the usage of Expressions. The `Expressions` module controls commands related to Expressions (such as `.acr`, `.lcr`, `.crca`, etc).
|
||||
|
||||
#### I've broken permissions and am stuck, can I reset permissions?
|
||||
|
||||
|
@@ -1,6 +1,6 @@
|
||||
# Placeholders
|
||||
|
||||
Placeholders are used in Quotes, Custom Reactions, Greet/Bye messages, playing statuses, and a few other places.
|
||||
Placeholders are used in Quotes, Expressions, Greet/Bye messages, playing statuses, and a few other places.
|
||||
|
||||
They can be used to make the message more user friendly, generate random numbers or pictures, etc.
|
||||
|
||||
@@ -28,6 +28,8 @@ Some features have their own specific placeholders which are noted in that featu
|
||||
- `%server.id%` - Server ID
|
||||
- `%server.name%` - Server name
|
||||
- `%server.members%` - Member count
|
||||
- `%server.boosters%` - Number of users boosting the server
|
||||
- `%server.boost_level%` - Server Boost level
|
||||
- `%server.time%` - Server time (requires `.timezone` to be set)
|
||||
|
||||
### Channel placeholders
|
||||
@@ -79,16 +81,14 @@ Some features have their own specific placeholders which are noted in that featu
|
||||
|
||||
### Music placeholders
|
||||
|
||||
!!! Note
|
||||
These placeholders will only work in rotating playing statuses.
|
||||
|
||||
- `%music.queued%` - Amount of songs currently queued
|
||||
- `%music.playing%` - Current song name
|
||||
- `%music.queued%` - Number of songs currently queued
|
||||
- `%music.playing%` - Current song name (random playing song if bot is playing on multiple servers)
|
||||
- `%music.servers%` - Number of servers currently listening to music
|
||||
|
||||
### Miscellaneous placeholders
|
||||
|
||||
- `%rngX-Y%` - Returns a random number between X and Y
|
||||
- `%target%` - Returns anything the user has written after the trigger (only works on custom reactions)
|
||||
- `%img:stuff%` - Returns an `imgur.com` search for "stuff" (only works on custom reactions)
|
||||
- `%target%` - Returns anything the user has written after the trigger (only works on Expressions)
|
||||
- `%img:stuff%` - Returns an `imgur.com` search for "stuff" (only works on Expressions)
|
||||
|
||||

|
||||
|
@@ -86,7 +86,9 @@ nav:
|
||||
- Custom Reactions: custom-reactions.md
|
||||
- Placeholders: placeholders.md
|
||||
- Config: config-guide.md
|
||||
- Bot Config: bce-guide.md
|
||||
- Medusa System:
|
||||
- medusa/getting-started.md
|
||||
- medusa/creating-a-medusa.md
|
||||
- medusa/snek-lifecycle.md
|
||||
- Contribution Guide: contribution-guide.md
|
||||
- Donate: donate.md
|
||||
- License: license.md
|
||||
|
11
privacy-policy.md
Normal file
11
privacy-policy.md
Normal file
@@ -0,0 +1,11 @@
|
||||
# Privacy Policy
|
||||
|
||||
## Profile Information
|
||||
Nadeko stores userids, avatars, usernames, discriminators and nicknames of users who were targeted by or have used commands which require Xp, Clubs or Waifu features (not limited to these, as other features may be added over time).
|
||||
|
||||
## Other
|
||||
Nadeko doesn't do analytics, doesn't store messages, doesn't track users, doesn't store their emails etc.
|
||||
Nadeko only stores user settings and states as the result of executed commands or as the effect of administration tools (for example warnings or protection commands).
|
||||
|
||||
## Sensitive Information
|
||||
Nadeko doesn't store sensitive information, and users are strongly discouraged from adding their passwords, keys, or other important information as quotes or expressions.
|
@@ -1,7 +1,6 @@
|
||||
#nullable disable
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.CompilerServices;
|
||||
|
||||
namespace NadekoBot.Common;
|
||||
namespace Nadeko.Common;
|
||||
|
||||
public class AsyncLazy<T> : Lazy<Task<T>>
|
||||
{
|
88
src/Nadeko.Common/Collections/ConcurrentHashSet.cs
Normal file
88
src/Nadeko.Common/Collections/ConcurrentHashSet.cs
Normal file
@@ -0,0 +1,88 @@
|
||||
using System.Diagnostics;
|
||||
|
||||
namespace System.Collections.Generic;
|
||||
|
||||
[DebuggerDisplay("{_backingStore.Count}")]
|
||||
public sealed class ConcurrentHashSet<T> : IReadOnlyCollection<T>, ICollection<T> where T : notnull
|
||||
{
|
||||
private readonly ConcurrentDictionary<T, bool> _backingStore;
|
||||
|
||||
public ConcurrentHashSet()
|
||||
=> _backingStore = new();
|
||||
|
||||
public ConcurrentHashSet(IEnumerable<T> values, IEqualityComparer<T>? comparer = null)
|
||||
=> _backingStore = new(values.Select(x => new KeyValuePair<T, bool>(x, true)), comparer);
|
||||
|
||||
public IEnumerator<T> GetEnumerator()
|
||||
=> _backingStore.Keys.GetEnumerator();
|
||||
|
||||
IEnumerator IEnumerable.GetEnumerator()
|
||||
=> GetEnumerator();
|
||||
|
||||
/// <summary>
|
||||
/// Adds the specified item to the <see cref="ConcurrentHashSet{T}" />.
|
||||
/// </summary>
|
||||
/// <param name="item">The item to add.</param>
|
||||
/// <returns>
|
||||
/// true if the items was added to the <see cref="ConcurrentHashSet{T}" />
|
||||
/// successfully; false if it already exists.
|
||||
/// </returns>
|
||||
/// <exception cref="T:System.OverflowException">
|
||||
/// The <see cref="ConcurrentHashSet{T}" />
|
||||
/// contains too many items.
|
||||
/// </exception>
|
||||
public bool Add(T item)
|
||||
=> _backingStore.TryAdd(item, true);
|
||||
|
||||
void ICollection<T>.Add(T item)
|
||||
=> Add(item);
|
||||
|
||||
public void Clear()
|
||||
=> _backingStore.Clear();
|
||||
|
||||
public bool Contains(T item)
|
||||
=> _backingStore.ContainsKey(item);
|
||||
|
||||
public void CopyTo(T[] array, int arrayIndex)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(array);
|
||||
|
||||
if (arrayIndex < 0)
|
||||
throw new ArgumentOutOfRangeException(nameof(arrayIndex));
|
||||
|
||||
if (arrayIndex >= array.Length)
|
||||
throw new ArgumentOutOfRangeException(nameof(arrayIndex));
|
||||
|
||||
CopyToInternal(array, arrayIndex);
|
||||
}
|
||||
|
||||
private void CopyToInternal(T[] array, int arrayIndex)
|
||||
{
|
||||
var len = array.Length;
|
||||
foreach (var (k, _) in _backingStore)
|
||||
{
|
||||
if (arrayIndex >= len)
|
||||
throw new IndexOutOfRangeException(nameof(arrayIndex));
|
||||
|
||||
array[arrayIndex++] = k;
|
||||
}
|
||||
}
|
||||
|
||||
bool ICollection<T>.Remove(T item)
|
||||
=> TryRemove(item);
|
||||
|
||||
public bool TryRemove(T item)
|
||||
=> _backingStore.TryRemove(item, out _);
|
||||
|
||||
public void RemoveWhere(Func<T, bool> predicate)
|
||||
{
|
||||
foreach (var elem in this.Where(predicate))
|
||||
TryRemove(elem);
|
||||
}
|
||||
|
||||
public int Count
|
||||
=> _backingStore.Count;
|
||||
|
||||
public bool IsReadOnly
|
||||
=> false;
|
||||
}
|
@@ -1,8 +1,11 @@
|
||||
#nullable disable
|
||||
using NadekoBot.Services.Database.Models;
|
||||
using System.Collections;
|
||||
using System.Collections;
|
||||
|
||||
namespace NadekoBot.Common.Collections;
|
||||
namespace Nadeko.Common;
|
||||
|
||||
public interface IIndexed
|
||||
{
|
||||
int Index { get; set; }
|
||||
}
|
||||
|
||||
public class IndexedCollection<T> : IList<T>
|
||||
where T : class, IIndexed
|
@@ -1,6 +1,4 @@
|
||||
using System.Buffers;
|
||||
|
||||
namespace NadekoBot.Extensions;
|
||||
namespace Nadeko.Common;
|
||||
|
||||
// made for expressions because they almost never get added
|
||||
// and they get looped through constantly
|
||||
@@ -32,7 +30,15 @@ public static class ArrayExtensions
|
||||
public static TOut[] Map<TIn, TOut>(this TIn[] arr, Func<TIn, TOut> f)
|
||||
=> Array.ConvertAll(arr, x => f(x));
|
||||
|
||||
public static IReadOnlyCollection<TOut> Map<TIn, TOut>(this IReadOnlyCollection<TIn> col, Func<TIn, TOut> f)
|
||||
/// <summary>
|
||||
/// Creates a new array by applying the specified function to every element in the input array
|
||||
/// </summary>
|
||||
/// <param name="col">Array to modify</param>
|
||||
/// <param name="f">Function to apply</param>
|
||||
/// <typeparam name="TIn">Orignal type of the elements in the array</typeparam>
|
||||
/// <typeparam name="TOut">Output type of the elements of the array</typeparam>
|
||||
/// <returns>New array with updated elements</returns>
|
||||
public static TOut[] Map<TIn, TOut>(this IReadOnlyCollection<TIn> col, Func<TIn, TOut> f)
|
||||
{
|
||||
var toReturn = new TOut[col.Count];
|
||||
|
@@ -1,8 +1,6 @@
|
||||
using NadekoBot.Common.Collections;
|
||||
using NadekoBot.Services.Database.Models;
|
||||
using System.Security.Cryptography;
|
||||
|
||||
namespace NadekoBot.Extensions;
|
||||
namespace Nadeko.Common;
|
||||
|
||||
public static class EnumerableExtensions
|
||||
{
|
35
src/Nadeko.Common/Extensions/HttpClientExtensions.cs
Normal file
35
src/Nadeko.Common/Extensions/HttpClientExtensions.cs
Normal file
@@ -0,0 +1,35 @@
|
||||
using System.Net.Http.Headers;
|
||||
|
||||
namespace Nadeko.Common;
|
||||
|
||||
public static class HttpClientExtensions
|
||||
{
|
||||
public static HttpClient AddFakeHeaders(this HttpClient http)
|
||||
{
|
||||
AddFakeHeaders(http.DefaultRequestHeaders);
|
||||
return http;
|
||||
}
|
||||
|
||||
public static void AddFakeHeaders(this HttpHeaders dict)
|
||||
{
|
||||
dict.Clear();
|
||||
dict.Add("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8");
|
||||
dict.Add("User-Agent",
|
||||
"Mozilla/5.0 (Windows NT 6.1) AppleWebKit/535.1 (KHTML, like Gecko) Chrome/14.0.835.202 Safari/535.1");
|
||||
}
|
||||
|
||||
public static bool IsImage(this HttpResponseMessage msg)
|
||||
=> IsImage(msg, out _);
|
||||
|
||||
public static bool IsImage(this HttpResponseMessage msg, out string? mimeType)
|
||||
{
|
||||
mimeType = msg.Content.Headers.ContentType?.MediaType;
|
||||
if (mimeType is "image/png" or "image/jpeg" or "image/gif")
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public static long GetContentLength(this HttpResponseMessage msg)
|
||||
=> msg.Content.Headers.ContentLength ?? long.MaxValue;
|
||||
}
|
22
src/Nadeko.Common/Extensions/PipeExtensions.cs
Normal file
22
src/Nadeko.Common/Extensions/PipeExtensions.cs
Normal file
@@ -0,0 +1,22 @@
|
||||
namespace Nadeko.Common;
|
||||
|
||||
public delegate TOut PipeFunc<TIn, out TOut>(in TIn a);
|
||||
public delegate TOut PipeFunc<TIn1, TIn2, out TOut>(in TIn1 a, in TIn2 b);
|
||||
|
||||
public static class PipeExtensions
|
||||
{
|
||||
public static TOut Pipe<TIn, TOut>(this TIn a, Func<TIn, TOut> fn)
|
||||
=> fn(a);
|
||||
|
||||
public static TOut Pipe<TIn, TOut>(this TIn a, PipeFunc<TIn, TOut> fn)
|
||||
=> fn(a);
|
||||
|
||||
public static TOut Pipe<TIn1, TIn2, TOut>(this (TIn1, TIn2) a, PipeFunc<TIn1, TIn2, TOut> fn)
|
||||
=> fn(a.Item1, a.Item2);
|
||||
|
||||
public static (TIn, TExtra) With<TIn, TExtra>(this TIn a, TExtra b)
|
||||
=> (a, b);
|
||||
|
||||
public static async Task<TOut> Pipe<TIn, TOut>(this Task<TIn> a, Func<TIn, TOut> fn)
|
||||
=> fn(await a);
|
||||
}
|
1
src/Nadeko.Common/GlobalUsings.cs
Normal file
1
src/Nadeko.Common/GlobalUsings.cs
Normal file
@@ -0,0 +1 @@
|
||||
global using NonBlocking;
|
@@ -1,9 +1,9 @@
|
||||
#nullable disable
|
||||
using Serilog.Events;
|
||||
using Serilog.Sinks.SystemConsole.Themes;
|
||||
using System.Text;
|
||||
using Serilog;
|
||||
|
||||
namespace NadekoBot.Services;
|
||||
namespace Nadeko.Common;
|
||||
|
||||
public static class LogSetup
|
||||
{
|
@@ -1,5 +1,4 @@
|
||||
#nullable disable
|
||||
namespace NadekoBot.Services;
|
||||
namespace Nadeko.Common;
|
||||
|
||||
public static class StandardConversions
|
||||
{
|
@@ -1,7 +1,6 @@
|
||||
#nullable disable
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.CompilerServices;
|
||||
|
||||
namespace NadekoBot.Common;
|
||||
namespace Nadeko.Common;
|
||||
|
||||
// needs proper invalid input check (character array input out of range)
|
||||
// needs negative number support
|
||||
@@ -90,7 +89,7 @@ public readonly struct kwum : IEquatable<kwum>
|
||||
return new(chars);
|
||||
}
|
||||
|
||||
public override bool Equals(object obj)
|
||||
public override bool Equals(object? obj)
|
||||
=> obj is kwum kw && kw == this;
|
||||
|
||||
public bool Equals(kwum other)
|
14
src/Nadeko.Common/Nadeko.Common.csproj
Normal file
14
src/Nadeko.Common/Nadeko.Common.csproj
Normal file
@@ -0,0 +1,14 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net6.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="NonBlocking" Version="2.1.0" />
|
||||
|
||||
<PackageReference Include="Serilog.Sinks.Console" Version="4.0.1" />
|
||||
</ItemGroup>
|
||||
</Project>
|
@@ -1,7 +1,7 @@
|
||||
#nullable disable
|
||||
using System.Security.Cryptography;
|
||||
|
||||
namespace NadekoBot.Common;
|
||||
namespace Nadeko.Common;
|
||||
|
||||
public class NadekoRandom : Random
|
||||
{
|
63
src/Nadeko.Common/QueueRunner.cs
Normal file
63
src/Nadeko.Common/QueueRunner.cs
Normal file
@@ -0,0 +1,63 @@
|
||||
using System.Threading.Channels;
|
||||
using Serilog;
|
||||
|
||||
namespace Nadeko.Common;
|
||||
|
||||
public sealed class QueueRunner
|
||||
{
|
||||
private readonly Channel<Func<Task>> _channel;
|
||||
private readonly int _delayMs;
|
||||
|
||||
public QueueRunner(int delayMs = 0, int maxCapacity = -1)
|
||||
{
|
||||
if (delayMs < 0)
|
||||
throw new ArgumentOutOfRangeException(nameof(delayMs));
|
||||
|
||||
_delayMs = delayMs;
|
||||
_channel = maxCapacity switch
|
||||
{
|
||||
0 or < -1 => throw new ArgumentOutOfRangeException(nameof(maxCapacity)),
|
||||
-1 => Channel.CreateUnbounded<Func<Task>>(new UnboundedChannelOptions()
|
||||
{
|
||||
SingleReader = true,
|
||||
SingleWriter = false,
|
||||
AllowSynchronousContinuations = true,
|
||||
}),
|
||||
_ => Channel.CreateBounded<Func<Task>>(new BoundedChannelOptions(maxCapacity)
|
||||
{
|
||||
Capacity = maxCapacity,
|
||||
FullMode = BoundedChannelFullMode.DropOldest,
|
||||
SingleReader = true,
|
||||
SingleWriter = false,
|
||||
AllowSynchronousContinuations = true
|
||||
})
|
||||
};
|
||||
}
|
||||
|
||||
public async Task RunAsync(CancellationToken cancel = default)
|
||||
{
|
||||
while (true)
|
||||
{
|
||||
var func = await _channel.Reader.ReadAsync(cancel);
|
||||
|
||||
try
|
||||
{
|
||||
await func();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Log.Warning(ex, "Exception executing a staggered func: {ErrorMessage}", ex.Message);
|
||||
}
|
||||
finally
|
||||
{
|
||||
if (_delayMs != 0)
|
||||
{
|
||||
await Task.Delay(_delayMs, cancel);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public ValueTask EnqueueAsync(Func<Task> action)
|
||||
=> _channel.Writer.WriteAsync(action);
|
||||
}
|
19
src/Nadeko.Common/ShmartBankAmount.cs
Normal file
19
src/Nadeko.Common/ShmartBankAmount.cs
Normal file
@@ -0,0 +1,19 @@
|
||||
namespace Nadeko.Common;
|
||||
|
||||
public readonly struct ShmartBankAmount
|
||||
{
|
||||
public long Amount { get; }
|
||||
public ShmartBankAmount(long amount)
|
||||
{
|
||||
Amount = amount;
|
||||
}
|
||||
|
||||
public static implicit operator ShmartBankAmount(long num)
|
||||
=> new(num);
|
||||
|
||||
public static implicit operator long(ShmartBankAmount num)
|
||||
=> num.Amount;
|
||||
|
||||
public static implicit operator ShmartBankAmount(int num)
|
||||
=> new(num);
|
||||
}
|
@@ -1,17 +1,12 @@
|
||||
#nullable disable
|
||||
using System;
|
||||
namespace Nadeko.Common;
|
||||
|
||||
namespace NadekoBot.Common;
|
||||
|
||||
public struct ShmartNumber : IEquatable<ShmartNumber>
|
||||
public readonly struct ShmartNumber : IEquatable<ShmartNumber>
|
||||
{
|
||||
public long Value { get; }
|
||||
public string Input { get; }
|
||||
|
||||
public ShmartNumber(long val, string input = null)
|
||||
public ShmartNumber(long val)
|
||||
{
|
||||
Value = val;
|
||||
Input = input;
|
||||
}
|
||||
|
||||
public static implicit operator ShmartNumber(long num)
|
||||
@@ -26,14 +21,14 @@ public struct ShmartNumber : IEquatable<ShmartNumber>
|
||||
public override string ToString()
|
||||
=> Value.ToString();
|
||||
|
||||
public override bool Equals(object obj)
|
||||
public override bool Equals(object? obj)
|
||||
=> obj is ShmartNumber sn && Equals(sn);
|
||||
|
||||
public bool Equals(ShmartNumber other)
|
||||
=> other.Value == Value;
|
||||
|
||||
public override int GetHashCode()
|
||||
=> Value.GetHashCode() ^ Input.GetHashCode(StringComparison.InvariantCulture);
|
||||
=> Value.GetHashCode();
|
||||
|
||||
public static bool operator ==(ShmartNumber left, ShmartNumber right)
|
||||
=> left.Equals(right);
|
@@ -1,5 +1,5 @@
|
||||
#nullable disable
|
||||
namespace NadekoBot.Modules.Gambling.Common;
|
||||
namespace Nadeko.Econ;
|
||||
|
||||
public class Deck
|
||||
{
|
||||
@@ -272,7 +272,7 @@ public class Deck
|
||||
|
||||
public string GetValueText()
|
||||
=> _cardNames[Number];
|
||||
|
||||
|
||||
public override string ToString()
|
||||
=> _cardNames[Number] + " Of " + Suit;
|
||||
|
5
src/Nadeko.Econ/Deck/NewCard.cs
Normal file
5
src/Nadeko.Econ/Deck/NewCard.cs
Normal file
@@ -0,0 +1,5 @@
|
||||
namespace Nadeko.Econ;
|
||||
|
||||
public abstract record class NewCard<TSuit, TValue>(TSuit Suit, TValue Value)
|
||||
where TSuit : struct, Enum
|
||||
where TValue : struct, Enum;
|
54
src/Nadeko.Econ/Deck/NewDeck.cs
Normal file
54
src/Nadeko.Econ/Deck/NewDeck.cs
Normal file
@@ -0,0 +1,54 @@
|
||||
namespace Nadeko.Econ;
|
||||
|
||||
public abstract class NewDeck<TCard, TSuit, TValue>
|
||||
where TCard: NewCard<TSuit, TValue>
|
||||
where TSuit : struct, Enum
|
||||
where TValue : struct, Enum
|
||||
{
|
||||
protected static readonly TSuit[] _suits = Enum.GetValues<TSuit>();
|
||||
protected static readonly TValue[] _values = Enum.GetValues<TValue>();
|
||||
|
||||
public virtual int CurrentCount
|
||||
=> _cards.Count;
|
||||
|
||||
public virtual int TotalCount { get; }
|
||||
|
||||
protected readonly LinkedList<TCard> _cards = new();
|
||||
public NewDeck()
|
||||
{
|
||||
TotalCount = _suits.Length * _values.Length;
|
||||
}
|
||||
|
||||
public virtual TCard? Draw()
|
||||
{
|
||||
var first = _cards.First;
|
||||
if (first is not null)
|
||||
{
|
||||
_cards.RemoveFirst();
|
||||
return first.Value;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public virtual TCard? Peek(int x = 0)
|
||||
{
|
||||
var card = _cards.First;
|
||||
for (var i = 0; i < x; i++)
|
||||
{
|
||||
card = card?.Next;
|
||||
}
|
||||
|
||||
return card?.Value;
|
||||
}
|
||||
|
||||
public virtual void Shuffle()
|
||||
{
|
||||
var cards = _cards.ToList();
|
||||
var newCards = cards.Shuffle();
|
||||
|
||||
_cards.Clear();
|
||||
foreach (var card in newCards)
|
||||
_cards.AddFirst(card);
|
||||
}
|
||||
}
|
@@ -0,0 +1,28 @@
|
||||
namespace Nadeko.Econ;
|
||||
|
||||
public class MultipleRegularDeck : NewDeck<RegularCard, RegularSuit, RegularValue>
|
||||
{
|
||||
private int Decks { get; }
|
||||
|
||||
public override int TotalCount { get; }
|
||||
|
||||
public MultipleRegularDeck(int decks = 1)
|
||||
{
|
||||
if (decks < 1)
|
||||
throw new ArgumentOutOfRangeException(nameof(decks), "Has to be more than 0");
|
||||
|
||||
Decks = decks;
|
||||
TotalCount = base.TotalCount * decks;
|
||||
|
||||
for (var i = 0; i < Decks; i++)
|
||||
{
|
||||
foreach (var suit in _suits)
|
||||
{
|
||||
foreach (var val in _values)
|
||||
{
|
||||
_cards.AddLast((RegularCard)Activator.CreateInstance(typeof(RegularCard), suit, val)!);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
4
src/Nadeko.Econ/Deck/Regular/RegularCard.cs
Normal file
4
src/Nadeko.Econ/Deck/Regular/RegularCard.cs
Normal file
@@ -0,0 +1,4 @@
|
||||
namespace Nadeko.Econ;
|
||||
|
||||
public sealed record class RegularCard(RegularSuit Suit, RegularValue Value)
|
||||
: NewCard<RegularSuit, RegularValue>(Suit, Value);
|
15
src/Nadeko.Econ/Deck/Regular/RegularDeck.cs
Normal file
15
src/Nadeko.Econ/Deck/Regular/RegularDeck.cs
Normal file
@@ -0,0 +1,15 @@
|
||||
namespace Nadeko.Econ;
|
||||
|
||||
public sealed class RegularDeck : NewDeck<RegularCard, RegularSuit, RegularValue>
|
||||
{
|
||||
public RegularDeck()
|
||||
{
|
||||
foreach (var suit in _suits)
|
||||
{
|
||||
foreach (var val in _values)
|
||||
{
|
||||
_cards.AddLast((RegularCard)Activator.CreateInstance(typeof(RegularCard), suit, val)!);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
56
src/Nadeko.Econ/Deck/Regular/RegularDeckExtensions.cs
Normal file
56
src/Nadeko.Econ/Deck/Regular/RegularDeckExtensions.cs
Normal file
@@ -0,0 +1,56 @@
|
||||
namespace Nadeko.Econ;
|
||||
|
||||
public static class RegularDeckExtensions
|
||||
{
|
||||
public static string GetEmoji(this RegularSuit suit)
|
||||
=> suit switch
|
||||
{
|
||||
RegularSuit.Hearts => "♥️",
|
||||
RegularSuit.Spades => "♠️",
|
||||
RegularSuit.Diamonds => "♦️",
|
||||
_ => "♣️",
|
||||
};
|
||||
|
||||
public static string GetEmoji(this RegularValue value)
|
||||
=> value switch
|
||||
{
|
||||
RegularValue.Ace => "🇦",
|
||||
RegularValue.Two => "2️⃣",
|
||||
RegularValue.Three => "3️⃣",
|
||||
RegularValue.Four => "4️⃣",
|
||||
RegularValue.Five => "5️⃣",
|
||||
RegularValue.Six => "6️⃣",
|
||||
RegularValue.Seven => "7️⃣",
|
||||
RegularValue.Eight => "8️⃣",
|
||||
RegularValue.Nine => "9️⃣",
|
||||
RegularValue.Ten => "🔟",
|
||||
RegularValue.Jack => "🇯",
|
||||
RegularValue.Queen => "🇶",
|
||||
_ => "🇰",
|
||||
};
|
||||
|
||||
public static string GetEmoji(this RegularCard card)
|
||||
=> $"{card.Value.GetEmoji()} {card.Suit.GetEmoji()}";
|
||||
|
||||
public static string GetName(this RegularValue value)
|
||||
=> value.ToString();
|
||||
|
||||
public static string GetName(this RegularSuit suit)
|
||||
=> suit.ToString();
|
||||
|
||||
public static string GetName(this RegularCard card)
|
||||
=> $"{card.Value.ToString()} of {card.Suit.GetName()}";
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
9
src/Nadeko.Econ/Deck/Regular/RegularSuit.cs
Normal file
9
src/Nadeko.Econ/Deck/Regular/RegularSuit.cs
Normal file
@@ -0,0 +1,9 @@
|
||||
namespace Nadeko.Econ;
|
||||
|
||||
public enum RegularSuit
|
||||
{
|
||||
Hearts,
|
||||
Diamonds,
|
||||
Clubs,
|
||||
Spades
|
||||
}
|
18
src/Nadeko.Econ/Deck/Regular/RegularValue.cs
Normal file
18
src/Nadeko.Econ/Deck/Regular/RegularValue.cs
Normal file
@@ -0,0 +1,18 @@
|
||||
namespace Nadeko.Econ;
|
||||
|
||||
public enum RegularValue
|
||||
{
|
||||
Ace = 1,
|
||||
Two = 2,
|
||||
Three = 3,
|
||||
Four = 4,
|
||||
Five = 5,
|
||||
Six = 6,
|
||||
Seven = 7,
|
||||
Eight = 8,
|
||||
Nine = 9,
|
||||
Ten = 10,
|
||||
Jack = 12,
|
||||
Queen = 13,
|
||||
King = 14,
|
||||
}
|
7
src/Nadeko.Econ/Gambling/Betdraw/BetdrawColorGuess.cs
Normal file
7
src/Nadeko.Econ/Gambling/Betdraw/BetdrawColorGuess.cs
Normal file
@@ -0,0 +1,7 @@
|
||||
namespace Nadeko.Econ.Gambling.Betdraw;
|
||||
|
||||
public enum BetdrawColorGuess
|
||||
{
|
||||
Red,
|
||||
Black
|
||||
}
|
86
src/Nadeko.Econ/Gambling/Betdraw/BetdrawGame.cs
Normal file
86
src/Nadeko.Econ/Gambling/Betdraw/BetdrawGame.cs
Normal file
@@ -0,0 +1,86 @@
|
||||
using Serilog;
|
||||
|
||||
namespace Nadeko.Econ.Gambling.Betdraw;
|
||||
|
||||
public sealed class BetdrawGame
|
||||
{
|
||||
private static readonly NadekoRandom _rng = new();
|
||||
private readonly RegularDeck _deck;
|
||||
|
||||
private const decimal SINGLE_GUESS_MULTI = 2.075M;
|
||||
private const decimal DOUBLE_GUESS_MULTI = 4.15M;
|
||||
|
||||
public BetdrawGame()
|
||||
{
|
||||
_deck = new RegularDeck();
|
||||
}
|
||||
|
||||
public BetdrawResult Draw(BetdrawValueGuess? val, BetdrawColorGuess? col, decimal amount)
|
||||
{
|
||||
if (val is null && col is null)
|
||||
throw new ArgumentNullException(nameof(val));
|
||||
|
||||
var card = _deck.Peek(_rng.Next(0, 52))!;
|
||||
|
||||
var realVal = (int)card.Value < 7
|
||||
? BetdrawValueGuess.Low
|
||||
: BetdrawValueGuess.High;
|
||||
|
||||
var realCol = card.Suit is RegularSuit.Diamonds or RegularSuit.Hearts
|
||||
? BetdrawColorGuess.Red
|
||||
: BetdrawColorGuess.Black;
|
||||
|
||||
// if card is 7, autoloss
|
||||
if (card.Value == RegularValue.Seven)
|
||||
{
|
||||
return new()
|
||||
{
|
||||
Won = 0M,
|
||||
Multiplier = 0M,
|
||||
ResultType = BetdrawResultType.Lose,
|
||||
Card = card,
|
||||
};
|
||||
}
|
||||
|
||||
byte win = 0;
|
||||
if (val is BetdrawValueGuess valGuess)
|
||||
{
|
||||
if (realVal != valGuess)
|
||||
return new()
|
||||
{
|
||||
Won = 0M,
|
||||
Multiplier = 0M,
|
||||
ResultType = BetdrawResultType.Lose,
|
||||
Card = card
|
||||
};
|
||||
|
||||
++win;
|
||||
}
|
||||
|
||||
if (col is BetdrawColorGuess colGuess)
|
||||
{
|
||||
if (realCol != colGuess)
|
||||
return new()
|
||||
{
|
||||
Won = 0M,
|
||||
Multiplier = 0M,
|
||||
ResultType = BetdrawResultType.Lose,
|
||||
Card = card
|
||||
};
|
||||
|
||||
++win;
|
||||
}
|
||||
|
||||
var multi = win == 1
|
||||
? SINGLE_GUESS_MULTI
|
||||
: DOUBLE_GUESS_MULTI;
|
||||
|
||||
return new()
|
||||
{
|
||||
Won = amount * multi,
|
||||
Multiplier = multi,
|
||||
ResultType = BetdrawResultType.Win,
|
||||
Card = card
|
||||
};
|
||||
}
|
||||
}
|
9
src/Nadeko.Econ/Gambling/Betdraw/BetdrawResult.cs
Normal file
9
src/Nadeko.Econ/Gambling/Betdraw/BetdrawResult.cs
Normal file
@@ -0,0 +1,9 @@
|
||||
namespace Nadeko.Econ.Gambling.Betdraw;
|
||||
|
||||
public readonly struct BetdrawResult
|
||||
{
|
||||
public decimal Won { get; init; }
|
||||
public decimal Multiplier { get; init; }
|
||||
public BetdrawResultType ResultType { get; init; }
|
||||
public RegularCard Card { get; init; }
|
||||
}
|
7
src/Nadeko.Econ/Gambling/Betdraw/BetdrawResultType.cs
Normal file
7
src/Nadeko.Econ/Gambling/Betdraw/BetdrawResultType.cs
Normal file
@@ -0,0 +1,7 @@
|
||||
namespace Nadeko.Econ.Gambling.Betdraw;
|
||||
|
||||
public enum BetdrawResultType
|
||||
{
|
||||
Win,
|
||||
Lose
|
||||
}
|
7
src/Nadeko.Econ/Gambling/Betdraw/BetdrawValueGuess.cs
Normal file
7
src/Nadeko.Econ/Gambling/Betdraw/BetdrawValueGuess.cs
Normal file
@@ -0,0 +1,7 @@
|
||||
namespace Nadeko.Econ.Gambling.Betdraw;
|
||||
|
||||
public enum BetdrawValueGuess
|
||||
{
|
||||
High,
|
||||
Low,
|
||||
}
|
33
src/Nadeko.Econ/Gambling/Betflip/BetflipGame.cs
Normal file
33
src/Nadeko.Econ/Gambling/Betflip/BetflipGame.cs
Normal file
@@ -0,0 +1,33 @@
|
||||
namespace Nadeko.Econ.Gambling;
|
||||
|
||||
public sealed class BetflipGame
|
||||
{
|
||||
private readonly decimal _winMulti;
|
||||
private static readonly NadekoRandom _rng = new NadekoRandom();
|
||||
|
||||
public BetflipGame(decimal winMulti)
|
||||
{
|
||||
_winMulti = winMulti;
|
||||
}
|
||||
|
||||
public BetflipResult Flip(byte guess, decimal amount)
|
||||
{
|
||||
var side = (byte)_rng.Next(0, 2);
|
||||
if (side == guess)
|
||||
{
|
||||
return new BetflipResult()
|
||||
{
|
||||
Side = side,
|
||||
Won = amount * _winMulti,
|
||||
Multiplier = _winMulti
|
||||
};
|
||||
}
|
||||
|
||||
return new BetflipResult()
|
||||
{
|
||||
Side = side,
|
||||
Won = 0,
|
||||
Multiplier = 0,
|
||||
};
|
||||
}
|
||||
}
|
8
src/Nadeko.Econ/Gambling/Betflip/BetflipResult.cs
Normal file
8
src/Nadeko.Econ/Gambling/Betflip/BetflipResult.cs
Normal file
@@ -0,0 +1,8 @@
|
||||
namespace Nadeko.Econ.Gambling;
|
||||
|
||||
public readonly struct BetflipResult
|
||||
{
|
||||
public decimal Won { get; init; }
|
||||
public byte Side { get; init; }
|
||||
public decimal Multiplier { get; init; }
|
||||
}
|
42
src/Nadeko.Econ/Gambling/Betroll/BetrollGame.cs
Normal file
42
src/Nadeko.Econ/Gambling/Betroll/BetrollGame.cs
Normal file
@@ -0,0 +1,42 @@
|
||||
namespace Nadeko.Econ.Gambling;
|
||||
|
||||
public sealed class BetrollGame
|
||||
{
|
||||
private readonly (int WhenAbove, decimal MultiplyBy)[] _thresholdPairs;
|
||||
private readonly NadekoRandom _rng;
|
||||
|
||||
public BetrollGame(IReadOnlyList<(int WhenAbove, decimal MultiplyBy)> pairs)
|
||||
{
|
||||
_thresholdPairs = pairs.OrderByDescending(x => x.WhenAbove).ToArray();
|
||||
_rng = new();
|
||||
}
|
||||
|
||||
public BetrollResult Roll(decimal amount = 0)
|
||||
{
|
||||
var roll = _rng.Next(1, 101);
|
||||
|
||||
for (var i = 0; i < _thresholdPairs.Length; i++)
|
||||
{
|
||||
ref var pair = ref _thresholdPairs[i];
|
||||
|
||||
if (pair.WhenAbove < roll)
|
||||
{
|
||||
return new()
|
||||
{
|
||||
Multiplier = pair.MultiplyBy,
|
||||
Roll = roll,
|
||||
Threshold = pair.WhenAbove,
|
||||
Won = amount * pair.MultiplyBy
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
return new()
|
||||
{
|
||||
Multiplier = 0,
|
||||
Roll = roll,
|
||||
Threshold = -1,
|
||||
Won = 0,
|
||||
};
|
||||
}
|
||||
}
|
9
src/Nadeko.Econ/Gambling/Betroll/BetrollResult.cs
Normal file
9
src/Nadeko.Econ/Gambling/Betroll/BetrollResult.cs
Normal file
@@ -0,0 +1,9 @@
|
||||
namespace Nadeko.Econ.Gambling;
|
||||
|
||||
public readonly struct BetrollResult
|
||||
{
|
||||
public int Roll { get; init; }
|
||||
public decimal Multiplier { get; init; }
|
||||
public decimal Threshold { get; init; }
|
||||
public decimal Won { get; init; }
|
||||
}
|
75
src/Nadeko.Econ/Gambling/Rps/RpsGame.cs
Normal file
75
src/Nadeko.Econ/Gambling/Rps/RpsGame.cs
Normal file
@@ -0,0 +1,75 @@
|
||||
namespace Nadeko.Econ.Gambling.Rps;
|
||||
|
||||
public sealed class RpsGame
|
||||
{
|
||||
private static readonly NadekoRandom _rng = new NadekoRandom();
|
||||
|
||||
const decimal WIN_MULTI = 1.95m;
|
||||
const decimal DRAW_MULTI = 1m;
|
||||
const decimal LOSE_MULTI = 0m;
|
||||
|
||||
public RpsGame()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public RpsResult Play(RpsPick pick, decimal amount)
|
||||
{
|
||||
var compPick = (RpsPick)_rng.Next(0, 3);
|
||||
if (compPick == pick)
|
||||
{
|
||||
return new()
|
||||
{
|
||||
Won = amount * DRAW_MULTI,
|
||||
Multiplier = DRAW_MULTI,
|
||||
ComputerPick = compPick,
|
||||
Result = RpsResultType.Draw,
|
||||
};
|
||||
}
|
||||
|
||||
if ((compPick == RpsPick.Paper && pick == RpsPick.Rock)
|
||||
|| (compPick == RpsPick.Rock && pick == RpsPick.Scissors)
|
||||
|| (compPick == RpsPick.Scissors && pick == RpsPick.Paper))
|
||||
{
|
||||
return new()
|
||||
{
|
||||
Won = amount * LOSE_MULTI,
|
||||
Multiplier = LOSE_MULTI,
|
||||
Result = RpsResultType.Lose,
|
||||
ComputerPick = compPick,
|
||||
};
|
||||
}
|
||||
|
||||
return new()
|
||||
{
|
||||
Won = amount * WIN_MULTI,
|
||||
Multiplier = WIN_MULTI,
|
||||
Result = RpsResultType.Win,
|
||||
ComputerPick = compPick,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
public enum RpsPick : byte
|
||||
{
|
||||
Rock = 0,
|
||||
Paper = 1,
|
||||
Scissors = 2,
|
||||
}
|
||||
|
||||
public enum RpsResultType : byte
|
||||
{
|
||||
Win,
|
||||
Draw,
|
||||
Lose
|
||||
}
|
||||
|
||||
|
||||
|
||||
public readonly struct RpsResult
|
||||
{
|
||||
public decimal Won { get; init; }
|
||||
public decimal Multiplier { get; init; }
|
||||
public RpsResultType Result { get; init; }
|
||||
public RpsPick ComputerPick { get; init; }
|
||||
}
|
116
src/Nadeko.Econ/Gambling/Slot/SlotGame.cs
Normal file
116
src/Nadeko.Econ/Gambling/Slot/SlotGame.cs
Normal file
@@ -0,0 +1,116 @@
|
||||
namespace Nadeko.Econ.Gambling;
|
||||
|
||||
//here is a payout chart
|
||||
//https://lh6.googleusercontent.com/-i1hjAJy_kN4/UswKxmhrbPI/AAAAAAAAB1U/82wq_4ZZc-Y/DE6B0895-6FC1-48BE-AC4F-14D1B91AB75B.jpg
|
||||
//thanks to judge for helping me with this
|
||||
public class SlotGame
|
||||
{
|
||||
private static readonly NadekoRandom _rng = new NadekoRandom();
|
||||
|
||||
public SlotResult Spin(decimal bet)
|
||||
{
|
||||
var rolls = new[]
|
||||
{
|
||||
(byte)_rng.Next(0, 6),
|
||||
(byte)_rng.Next(0, 6),
|
||||
(byte)_rng.Next(0, 6)
|
||||
};
|
||||
|
||||
ref var a = ref rolls[0];
|
||||
ref var b = ref rolls[1];
|
||||
ref var c = ref rolls[2];
|
||||
|
||||
var multi = 0;
|
||||
var winType = SlotWinType.None;
|
||||
if (a == b && b == c)
|
||||
{
|
||||
if (a == 5)
|
||||
{
|
||||
winType = SlotWinType.TrippleJoker;
|
||||
multi = 30;
|
||||
}
|
||||
else
|
||||
{
|
||||
winType = SlotWinType.TrippleNormal;
|
||||
multi = 10;
|
||||
}
|
||||
}
|
||||
else if (a == 5 && (b == 5 || c == 5)
|
||||
|| (b == 5 && c == 5))
|
||||
{
|
||||
winType = SlotWinType.DoubleJoker;
|
||||
multi = 4;
|
||||
}
|
||||
else if (a == 5 || b == 5 || c == 5)
|
||||
{
|
||||
winType = SlotWinType.SingleJoker;
|
||||
multi = 1;
|
||||
}
|
||||
|
||||
return new()
|
||||
{
|
||||
Won = bet * multi,
|
||||
WinType = winType,
|
||||
Multiplier = multi,
|
||||
Rolls = rolls,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
public enum SlotWinType : byte
|
||||
{
|
||||
None,
|
||||
SingleJoker,
|
||||
DoubleJoker,
|
||||
TrippleNormal,
|
||||
TrippleJoker,
|
||||
}
|
||||
|
||||
/*
|
||||
var rolls = new[]
|
||||
{
|
||||
_rng.Next(default(byte), 6),
|
||||
_rng.Next(default(byte), 6),
|
||||
_rng.Next(default(byte), 6)
|
||||
};
|
||||
|
||||
var multi = 0;
|
||||
var winType = SlotWinType.None;
|
||||
|
||||
ref var a = ref rolls[0];
|
||||
ref var b = ref rolls[1];
|
||||
ref var c = ref rolls[2];
|
||||
if (a == b && b == c)
|
||||
{
|
||||
if (a == 5)
|
||||
{
|
||||
winType = SlotWinType.TrippleJoker;
|
||||
multi = 30;
|
||||
}
|
||||
else
|
||||
{
|
||||
winType = SlotWinType.TrippleNormal;
|
||||
multi = 10;
|
||||
}
|
||||
}
|
||||
else if (a == 5 && (b == 5 || c == 5)
|
||||
|| (b == 5 && c == 5))
|
||||
{
|
||||
winType = SlotWinType.DoubleJoker;
|
||||
multi = 4;
|
||||
}
|
||||
else if (rolls.Any(x => x == 5))
|
||||
{
|
||||
winType = SlotWinType.SingleJoker;
|
||||
multi = 1;
|
||||
}
|
||||
|
||||
return new()
|
||||
{
|
||||
Won = bet * multi,
|
||||
WinType = winType,
|
||||
Multiplier = multi,
|
||||
Rolls = rolls,
|
||||
};
|
||||
}
|
||||
*/
|
9
src/Nadeko.Econ/Gambling/Slot/SlotResult.cs
Normal file
9
src/Nadeko.Econ/Gambling/Slot/SlotResult.cs
Normal file
@@ -0,0 +1,9 @@
|
||||
namespace Nadeko.Econ.Gambling;
|
||||
|
||||
public readonly struct SlotResult
|
||||
{
|
||||
public decimal Multiplier { get; init; }
|
||||
public byte[] Rolls { get; init; }
|
||||
public decimal Won { get; init; }
|
||||
public SlotWinType WinType { get; init; }
|
||||
}
|
9
src/Nadeko.Econ/Gambling/Wof/LuLaResult.cs
Normal file
9
src/Nadeko.Econ/Gambling/Wof/LuLaResult.cs
Normal file
@@ -0,0 +1,9 @@
|
||||
namespace Nadeko.Econ.Gambling;
|
||||
|
||||
public readonly struct LuLaResult
|
||||
{
|
||||
public int Index { get; init; }
|
||||
public decimal Multiplier { get; init; }
|
||||
public decimal Won { get; init; }
|
||||
public IReadOnlyList<decimal> Multipliers { get; init; }
|
||||
}
|
34
src/Nadeko.Econ/Gambling/Wof/WofGame.cs
Normal file
34
src/Nadeko.Econ/Gambling/Wof/WofGame.cs
Normal file
@@ -0,0 +1,34 @@
|
||||
namespace Nadeko.Econ.Gambling;
|
||||
|
||||
public sealed class LulaGame
|
||||
{
|
||||
private static readonly IReadOnlyList<decimal> DEFAULT_MULTIPLIERS = new[] { 1.7M, 1.5M, 0.2M, 0.1M, 0.3M, 0.5M, 1.2M, 2.4M };
|
||||
|
||||
private readonly IReadOnlyList<decimal> _multipliers;
|
||||
private static readonly NadekoRandom _rng = new();
|
||||
|
||||
public LulaGame(IReadOnlyList<decimal> multipliers)
|
||||
{
|
||||
_multipliers = multipliers;
|
||||
}
|
||||
|
||||
public LulaGame() : this(DEFAULT_MULTIPLIERS)
|
||||
{
|
||||
}
|
||||
|
||||
public LuLaResult Spin(long bet)
|
||||
{
|
||||
var result = _rng.Next(0, _multipliers.Count);
|
||||
|
||||
var multi = _multipliers[result];
|
||||
var amount = bet * multi;
|
||||
|
||||
return new()
|
||||
{
|
||||
Index = result,
|
||||
Multiplier = multi,
|
||||
Won = amount,
|
||||
Multipliers = _multipliers.ToArray(),
|
||||
};
|
||||
}
|
||||
}
|
1
src/Nadeko.Econ/GlobalUsings.cs
Normal file
1
src/Nadeko.Econ/GlobalUsings.cs
Normal file
@@ -0,0 +1 @@
|
||||
global using Nadeko.Common;
|
13
src/Nadeko.Econ/Nadeko.Econ.csproj
Normal file
13
src/Nadeko.Econ/Nadeko.Econ.csproj
Normal file
@@ -0,0 +1,13 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net6.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Nadeko.Common\Nadeko.Common.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
10
src/Nadeko.Medusa/Attributes/FilterAttribute.cs
Normal file
10
src/Nadeko.Medusa/Attributes/FilterAttribute.cs
Normal file
@@ -0,0 +1,10 @@
|
||||
namespace Nadeko.Snake;
|
||||
|
||||
/// <summary>
|
||||
/// Overridden to implement custom checks which commands have to pass in order to be executed.
|
||||
/// </summary>
|
||||
[AttributeUsage(AttributeTargets.Method | AttributeTargets.Class, AllowMultiple = true)]
|
||||
public abstract class FilterAttribute : Attribute
|
||||
{
|
||||
public abstract ValueTask<bool> CheckAsync(AnyContext ctx);
|
||||
}
|
10
src/Nadeko.Medusa/Attributes/MedusaPermAttribute.cs
Normal file
10
src/Nadeko.Medusa/Attributes/MedusaPermAttribute.cs
Normal file
@@ -0,0 +1,10 @@
|
||||
namespace Nadeko.Snake;
|
||||
|
||||
/// <summary>
|
||||
/// Used as a marker class for bot_perm and user_perm Attributes
|
||||
/// Has no functionality.
|
||||
/// </summary>
|
||||
public abstract class MedusaPermAttribute : Attribute
|
||||
{
|
||||
|
||||
}
|
7
src/Nadeko.Medusa/Attributes/bot_owner_onlyAttribute.cs
Normal file
7
src/Nadeko.Medusa/Attributes/bot_owner_onlyAttribute.cs
Normal file
@@ -0,0 +1,7 @@
|
||||
namespace Nadeko.Snake;
|
||||
|
||||
[AttributeUsage(AttributeTargets.Method)]
|
||||
public sealed class bot_owner_onlyAttribute : MedusaPermAttribute
|
||||
{
|
||||
|
||||
}
|
23
src/Nadeko.Medusa/Attributes/bot_permAttribute.cs
Normal file
23
src/Nadeko.Medusa/Attributes/bot_permAttribute.cs
Normal file
@@ -0,0 +1,23 @@
|
||||
using Discord;
|
||||
|
||||
namespace Nadeko.Snake;
|
||||
|
||||
[AttributeUsage(AttributeTargets.Method, AllowMultiple = true)]
|
||||
public sealed class bot_permAttribute : MedusaPermAttribute
|
||||
{
|
||||
public GuildPermission? GuildPerm { get; }
|
||||
public ChannelPermission? ChannelPerm { get; }
|
||||
|
||||
|
||||
public bot_permAttribute(GuildPermission perm)
|
||||
{
|
||||
GuildPerm = perm;
|
||||
ChannelPerm = null;
|
||||
}
|
||||
|
||||
public bot_permAttribute(ChannelPermission perm)
|
||||
{
|
||||
ChannelPerm = perm;
|
||||
GuildPerm = null;
|
||||
}
|
||||
}
|
37
src/Nadeko.Medusa/Attributes/cmdAttribute.cs
Normal file
37
src/Nadeko.Medusa/Attributes/cmdAttribute.cs
Normal file
@@ -0,0 +1,37 @@
|
||||
namespace Nadeko.Snake;
|
||||
|
||||
/// <summary>
|
||||
/// Marks a method as a snek command
|
||||
/// </summary>
|
||||
[AttributeUsage(AttributeTargets.Method)]
|
||||
public class cmdAttribute : Attribute
|
||||
{
|
||||
/// <summary>
|
||||
/// Command description. Avoid using, as cmds.yml is preferred
|
||||
/// </summary>
|
||||
public string? desc { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Command args examples. Avoid using, as cmds.yml is preferred
|
||||
/// </summary>
|
||||
public string[]? args { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Command aliases
|
||||
/// </summary>
|
||||
public string[] Aliases { get; }
|
||||
|
||||
public cmdAttribute()
|
||||
{
|
||||
desc = null;
|
||||
args = null;
|
||||
Aliases = Array.Empty<string>();
|
||||
}
|
||||
|
||||
public cmdAttribute(params string[] aliases)
|
||||
{
|
||||
Aliases = aliases;
|
||||
desc = null;
|
||||
args = null;
|
||||
}
|
||||
}
|
10
src/Nadeko.Medusa/Attributes/injectAttribute.cs
Normal file
10
src/Nadeko.Medusa/Attributes/injectAttribute.cs
Normal file
@@ -0,0 +1,10 @@
|
||||
namespace Nadeko.Snake;
|
||||
|
||||
/// <summary>
|
||||
/// Marks services in command arguments for injection.
|
||||
/// The injected services must come after the context and before any input parameters.
|
||||
/// </summary>
|
||||
public class injectAttribute : Attribute
|
||||
{
|
||||
|
||||
}
|
10
src/Nadeko.Medusa/Attributes/leftoverAttribute.cs
Normal file
10
src/Nadeko.Medusa/Attributes/leftoverAttribute.cs
Normal file
@@ -0,0 +1,10 @@
|
||||
namespace Nadeko.Snake;
|
||||
|
||||
/// <summary>
|
||||
/// Marks the parameter to take
|
||||
/// </summary>
|
||||
[AttributeUsage(AttributeTargets.Parameter)]
|
||||
public class leftoverAttribute : Attribute
|
||||
{
|
||||
|
||||
}
|
20
src/Nadeko.Medusa/Attributes/prioAttribute.cs
Normal file
20
src/Nadeko.Medusa/Attributes/prioAttribute.cs
Normal file
@@ -0,0 +1,20 @@
|
||||
namespace Nadeko.Snake;
|
||||
|
||||
/// <summary>
|
||||
/// Sets the priority of a command in case there are multiple commands with the same name but different parameters.
|
||||
/// Higher value means higher priority.
|
||||
/// </summary>
|
||||
[AttributeUsage(AttributeTargets.Method)]
|
||||
public class prioAttribute : Attribute
|
||||
{
|
||||
public int Priority { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Snek command priority
|
||||
/// </summary>
|
||||
/// <param name="priority">Priority value. The higher the value, the higher the priority</param>
|
||||
public prioAttribute(int priority)
|
||||
{
|
||||
Priority = priority;
|
||||
}
|
||||
}
|
23
src/Nadeko.Medusa/Attributes/svcAttribute.cs
Normal file
23
src/Nadeko.Medusa/Attributes/svcAttribute.cs
Normal file
@@ -0,0 +1,23 @@
|
||||
namespace Nadeko.Snake;
|
||||
|
||||
/// <summary>
|
||||
/// Marks the class as a service which can be used within the same Medusa
|
||||
/// </summary>
|
||||
[AttributeUsage(AttributeTargets.Class)]
|
||||
public class svcAttribute : Attribute
|
||||
{
|
||||
public Lifetime Lifetime { get; }
|
||||
public svcAttribute(Lifetime lifetime)
|
||||
{
|
||||
Lifetime = lifetime;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Lifetime for <see cref="svcAttribute"/>
|
||||
/// </summary>
|
||||
public enum Lifetime
|
||||
{
|
||||
Singleton,
|
||||
Transient
|
||||
}
|
22
src/Nadeko.Medusa/Attributes/user_permAttribute.cs
Normal file
22
src/Nadeko.Medusa/Attributes/user_permAttribute.cs
Normal file
@@ -0,0 +1,22 @@
|
||||
using Discord;
|
||||
|
||||
namespace Nadeko.Snake;
|
||||
|
||||
[AttributeUsage(AttributeTargets.Method, AllowMultiple = true)]
|
||||
public sealed class user_permAttribute : MedusaPermAttribute
|
||||
{
|
||||
public GuildPermission? GuildPerm { get; }
|
||||
public ChannelPermission? ChannelPerm { get; }
|
||||
|
||||
public user_permAttribute(GuildPermission perm)
|
||||
{
|
||||
GuildPerm = perm;
|
||||
ChannelPerm = null;
|
||||
}
|
||||
|
||||
public user_permAttribute(ChannelPermission perm)
|
||||
{
|
||||
ChannelPerm = perm;
|
||||
GuildPerm = null;
|
||||
}
|
||||
}
|
52
src/Nadeko.Medusa/Context/AnyContext.cs
Normal file
52
src/Nadeko.Medusa/Context/AnyContext.cs
Normal file
@@ -0,0 +1,52 @@
|
||||
using Discord;
|
||||
using NadekoBot;
|
||||
|
||||
namespace Nadeko.Snake;
|
||||
|
||||
/// <summary>
|
||||
/// Commands which take this class as a first parameter can be executed in both DMs and Servers
|
||||
/// </summary>
|
||||
public abstract class AnyContext
|
||||
{
|
||||
/// <summary>
|
||||
/// Channel from the which the command is invoked
|
||||
/// </summary>
|
||||
public abstract IMessageChannel Channel { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Message which triggered the command
|
||||
/// </summary>
|
||||
public abstract IUserMessage Message { get; }
|
||||
|
||||
/// <summary>
|
||||
/// The user who invoked the command
|
||||
/// </summary>
|
||||
public abstract IUser User { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Bot user
|
||||
/// </summary>
|
||||
public abstract ISelfUser Bot { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Provides access to strings used by this medusa
|
||||
/// </summary>
|
||||
public abstract IMedusaStrings Strings { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets a formatted localized string using a key and arguments which should be formatted in
|
||||
/// </summary>
|
||||
/// <param name="key">The key of the string as specified in localization files</param>
|
||||
/// <param name="args">Arguments (if any) to format in</param>
|
||||
/// <returns>A formatted localized string</returns>
|
||||
public abstract string GetText(string key, object[]? args = null);
|
||||
|
||||
/// <summary>
|
||||
/// Creates a context-aware <see cref="IEmbedBuilder"/> instance
|
||||
/// (future feature for guild-based embed colors)
|
||||
/// Any code dealing with embeds should use it for future-proofness
|
||||
/// instead of manually creating embedbuilder instances
|
||||
/// </summary>
|
||||
/// <returns>A context-aware <see cref="IEmbedBuilder"/> instance </returns>
|
||||
public abstract IEmbedBuilder Embed();
|
||||
}
|
11
src/Nadeko.Medusa/Context/DmContext.cs
Normal file
11
src/Nadeko.Medusa/Context/DmContext.cs
Normal file
@@ -0,0 +1,11 @@
|
||||
using Discord;
|
||||
|
||||
namespace Nadeko.Snake;
|
||||
|
||||
/// <summary>
|
||||
/// Commands which take this type as the first parameter can only be executed in DMs
|
||||
/// </summary>
|
||||
public abstract class DmContext : AnyContext
|
||||
{
|
||||
public abstract override IDMChannel Channel { get; }
|
||||
}
|
12
src/Nadeko.Medusa/Context/GuildContext.cs
Normal file
12
src/Nadeko.Medusa/Context/GuildContext.cs
Normal file
@@ -0,0 +1,12 @@
|
||||
using Discord;
|
||||
|
||||
namespace Nadeko.Snake;
|
||||
|
||||
/// <summary>
|
||||
/// Commands which take this type as a first parameter can only be executed in a server
|
||||
/// </summary>
|
||||
public abstract class GuildContext : AnyContext
|
||||
{
|
||||
public abstract override ITextChannel Channel { get; }
|
||||
public abstract IGuild Guild { get; }
|
||||
}
|
8
src/Nadeko.Medusa/EmbedColor.cs
Normal file
8
src/Nadeko.Medusa/EmbedColor.cs
Normal file
@@ -0,0 +1,8 @@
|
||||
namespace NadekoBot;
|
||||
|
||||
public enum EmbedColor
|
||||
{
|
||||
Ok,
|
||||
Pending,
|
||||
Error
|
||||
}
|
14
src/Nadeko.Medusa/Extensions/EmbedBuilderExtensions.cs
Normal file
14
src/Nadeko.Medusa/Extensions/EmbedBuilderExtensions.cs
Normal file
@@ -0,0 +1,14 @@
|
||||
namespace NadekoBot;
|
||||
|
||||
public static class EmbedBuilderExtensions
|
||||
{
|
||||
public static IEmbedBuilder WithOkColor(this IEmbedBuilder eb)
|
||||
=> eb.WithColor(EmbedColor.Ok);
|
||||
|
||||
public static IEmbedBuilder WithPendingColor(this IEmbedBuilder eb)
|
||||
=> eb.WithColor(EmbedColor.Pending);
|
||||
|
||||
public static IEmbedBuilder WithErrorColor(this IEmbedBuilder eb)
|
||||
=> eb.WithColor(EmbedColor.Error);
|
||||
|
||||
}
|
66
src/Nadeko.Medusa/Extensions/MedusaExtensions.cs
Normal file
66
src/Nadeko.Medusa/Extensions/MedusaExtensions.cs
Normal file
@@ -0,0 +1,66 @@
|
||||
using Discord;
|
||||
using Nadeko.Snake;
|
||||
|
||||
namespace NadekoBot;
|
||||
|
||||
public static class MedusaExtensions
|
||||
{
|
||||
public static Task<IUserMessage> EmbedAsync(this IMessageChannel ch, IEmbedBuilder embed, string msg = "")
|
||||
=> ch.SendMessageAsync(msg,
|
||||
embed: embed.Build(),
|
||||
options: new()
|
||||
{
|
||||
RetryMode = RetryMode.Retry502
|
||||
});
|
||||
|
||||
// unlocalized
|
||||
public static Task<IUserMessage> SendConfirmAsync(this IMessageChannel ch, AnyContext ctx, string msg)
|
||||
=> ch.EmbedAsync(ctx.Embed().WithOkColor().WithDescription(msg));
|
||||
|
||||
public static Task<IUserMessage> SendPendingAsync(this IMessageChannel ch, AnyContext ctx, string msg)
|
||||
=> ch.EmbedAsync(ctx.Embed().WithPendingColor().WithDescription(msg));
|
||||
|
||||
public static Task<IUserMessage> SendErrorAsync(this IMessageChannel ch, AnyContext ctx, string msg)
|
||||
=> ch.EmbedAsync(ctx.Embed().WithErrorColor().WithDescription(msg));
|
||||
|
||||
// unlocalized
|
||||
public static Task<IUserMessage> SendConfirmAsync(this AnyContext ctx, string msg)
|
||||
=> ctx.Channel.SendConfirmAsync(ctx, msg);
|
||||
|
||||
public static Task<IUserMessage> SendPendingAsync(this AnyContext ctx, string msg)
|
||||
=> ctx.Channel.SendPendingAsync(ctx, msg);
|
||||
|
||||
public static Task<IUserMessage> SendErrorAsync(this AnyContext ctx, string msg)
|
||||
=> ctx.Channel.SendErrorAsync(ctx, msg);
|
||||
|
||||
// localized
|
||||
public static Task ConfirmAsync(this AnyContext ctx)
|
||||
=> ctx.Message.AddReactionAsync(new Emoji("✅"));
|
||||
|
||||
public static Task ErrorAsync(this AnyContext ctx)
|
||||
=> ctx.Message.AddReactionAsync(new Emoji("❌"));
|
||||
|
||||
public static Task WarningAsync(this AnyContext ctx)
|
||||
=> ctx.Message.AddReactionAsync(new Emoji("⚠️"));
|
||||
|
||||
public static Task WaitAsync(this AnyContext ctx)
|
||||
=> ctx.Message.AddReactionAsync(new Emoji("🤔"));
|
||||
|
||||
public static Task<IUserMessage> ErrorLocalizedAsync(this AnyContext ctx, string key, params object[]? args)
|
||||
=> ctx.SendErrorAsync(ctx.GetText(key, args));
|
||||
|
||||
public static Task<IUserMessage> PendingLocalizedAsync(this AnyContext ctx, string key, params object[]? args)
|
||||
=> ctx.SendPendingAsync(ctx.GetText(key, args));
|
||||
|
||||
public static Task<IUserMessage> ConfirmLocalizedAsync(this AnyContext ctx, string key, params object[]? args)
|
||||
=> ctx.SendConfirmAsync(ctx.GetText(key, args));
|
||||
|
||||
public static Task<IUserMessage> ReplyErrorLocalizedAsync(this AnyContext ctx, string key, params object[]? args)
|
||||
=> ctx.SendErrorAsync($"{Format.Bold(ctx.User.ToString())} {ctx.GetText(key, args)}");
|
||||
|
||||
public static Task<IUserMessage> ReplyPendingLocalizedAsync(this AnyContext ctx, string key, params object[]? args)
|
||||
=> ctx.SendPendingAsync($"{Format.Bold(ctx.User.ToString())} {ctx.GetText(key, args)}");
|
||||
|
||||
public static Task<IUserMessage> ReplyConfirmLocalizedAsync(this AnyContext ctx, string key, params object[]? args)
|
||||
=> ctx.SendConfirmAsync($"{Format.Bold(ctx.User.ToString())} {ctx.GetText(key, args)}");
|
||||
}
|
@@ -1,23 +1,18 @@
|
||||
#nullable disable
|
||||
using Discord;
|
||||
|
||||
namespace NadekoBot;
|
||||
|
||||
public interface IEmbedBuilder
|
||||
{
|
||||
IEmbedBuilder WithDescription(string desc);
|
||||
IEmbedBuilder WithTitle(string title);
|
||||
IEmbedBuilder WithDescription(string? desc);
|
||||
IEmbedBuilder WithTitle(string? title);
|
||||
IEmbedBuilder AddField(string title, object value, bool isInline = false);
|
||||
IEmbedBuilder WithFooter(string text, string iconUrl = null);
|
||||
IEmbedBuilder WithAuthor(string name, string iconUrl = null, string url = null);
|
||||
IEmbedBuilder WithFooter(string text, string? iconUrl = null);
|
||||
IEmbedBuilder WithAuthor(string name, string? iconUrl = null, string? url = null);
|
||||
IEmbedBuilder WithColor(EmbedColor color);
|
||||
IEmbedBuilder WithDiscordColor(Color color);
|
||||
Embed Build();
|
||||
IEmbedBuilder WithUrl(string url);
|
||||
IEmbedBuilder WithImageUrl(string url);
|
||||
IEmbedBuilder WithThumbnailUrl(string url);
|
||||
}
|
||||
|
||||
public enum EmbedColor
|
||||
{
|
||||
Ok,
|
||||
Pending,
|
||||
Error
|
||||
}
|
23
src/Nadeko.Medusa/Nadeko.Medusa.csproj
Normal file
23
src/Nadeko.Medusa/Nadeko.Medusa.csproj
Normal file
@@ -0,0 +1,23 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net6.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
<LangVersion>preview</LangVersion>
|
||||
<EnablePreviewFeatures>true</EnablePreviewFeatures>
|
||||
<RootNamespace>Nadeko.Snake</RootNamespace>
|
||||
|
||||
<Authors>The NadekoBot Team</Authors>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Discord.Net.Core" Version="3.104.0" />
|
||||
<PackageReference Include="Serilog" Version="2.11.0" />
|
||||
<PackageReference Include="YamlDotNet" Version="11.2.1" />
|
||||
</ItemGroup>
|
||||
|
||||
<PropertyGroup Condition=" '$(Version)' == '' ">
|
||||
<Version>5.0.0</Version>
|
||||
</PropertyGroup>
|
||||
</Project>
|
16
src/Nadeko.Medusa/ParamParser/ParamParser.cs
Normal file
16
src/Nadeko.Medusa/ParamParser/ParamParser.cs
Normal file
@@ -0,0 +1,16 @@
|
||||
namespace Nadeko.Snake;
|
||||
|
||||
/// <summary>
|
||||
/// Overridden to implement parsers for custom types
|
||||
/// </summary>
|
||||
/// <typeparam name="T">Type into which to parse the input</typeparam>
|
||||
public abstract class ParamParser<T>
|
||||
{
|
||||
/// <summary>
|
||||
/// Overridden to implement parsing logic
|
||||
/// </summary>
|
||||
/// <param name="ctx">Context</param>
|
||||
/// <param name="input">Input to parse</param>
|
||||
/// <returns>A <see cref="ParseResult{T}"/> with successful or failed status</returns>
|
||||
public abstract ValueTask<ParseResult<T>> TryParseAsync(AnyContext ctx, string input);
|
||||
}
|
48
src/Nadeko.Medusa/ParamParser/ParseResult.cs
Normal file
48
src/Nadeko.Medusa/ParamParser/ParseResult.cs
Normal file
@@ -0,0 +1,48 @@
|
||||
namespace Nadeko.Snake;
|
||||
|
||||
public readonly struct ParseResult<T>
|
||||
{
|
||||
/// <summary>
|
||||
/// Whether the parsing was successful
|
||||
/// </summary>
|
||||
public bool IsSuccess { get; private init; }
|
||||
|
||||
/// <summary>
|
||||
/// Parsed value. It should only have value if <see cref="IsSuccess"/> is set to true
|
||||
/// </summary>
|
||||
public T? Data { get; private init; }
|
||||
|
||||
/// <summary>
|
||||
/// Instantiate a **successful** parse result
|
||||
/// </summary>
|
||||
/// <param name="data">Parsed value</param>
|
||||
public ParseResult(T data)
|
||||
{
|
||||
Data = data;
|
||||
IsSuccess = true;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Create a new <see cref="ParseResult{T}"/> with IsSuccess = false
|
||||
/// </summary>
|
||||
/// <returns>A new <see cref="ParseResult{T}"/></returns>
|
||||
public static ParseResult<T> Fail()
|
||||
=> new ParseResult<T>
|
||||
{
|
||||
IsSuccess = false,
|
||||
Data = default,
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
/// Create a new <see cref="ParseResult{T}"/> with IsSuccess = true
|
||||
/// </summary>
|
||||
/// <param name="obj">Value of the parsed object</param>
|
||||
/// <returns>A new <see cref="ParseResult{T}"/></returns>
|
||||
public static ParseResult<T> Success(T obj)
|
||||
=> new ParseResult<T>
|
||||
{
|
||||
IsSuccess = true,
|
||||
Data = obj,
|
||||
};
|
||||
}
|
1
src/Nadeko.Medusa/README.md
Normal file
1
src/Nadeko.Medusa/README.md
Normal file
@@ -0,0 +1 @@
|
||||
This is the library which is the base of any medusa.
|
143
src/Nadeko.Medusa/Snek.cs
Normal file
143
src/Nadeko.Medusa/Snek.cs
Normal file
@@ -0,0 +1,143 @@
|
||||
using Discord;
|
||||
|
||||
namespace Nadeko.Snake;
|
||||
|
||||
/// <summary>
|
||||
/// The base class which will be loaded as a module into NadekoBot
|
||||
/// Any user-defined snek has to inherit from this class.
|
||||
/// Sneks get instantiated ONLY ONCE during the loading,
|
||||
/// and any snek commands will be executed on the same instance.
|
||||
/// </summary>
|
||||
public abstract class Snek : IAsyncDisposable
|
||||
{
|
||||
/// <summary>
|
||||
/// Name of the snek. Defaults to the lowercase class name
|
||||
/// </summary>
|
||||
public virtual string Name
|
||||
=> GetType().Name.ToLowerInvariant();
|
||||
|
||||
/// <summary>
|
||||
/// The prefix required before the command name. For example
|
||||
/// if you set this to 'test' then a command called 'cmd' will have to be invoked by using
|
||||
/// '.test cmd' instead of `.cmd`
|
||||
/// </summary>
|
||||
public virtual string Prefix
|
||||
=> string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// Executed once this snek has been instantiated and before any command is executed.
|
||||
/// </summary>
|
||||
/// <returns>A <see cref="ValueTask"/> representing completion</returns>
|
||||
public virtual ValueTask InitializeAsync()
|
||||
=> default;
|
||||
|
||||
/// <summary>
|
||||
/// Override to cleanup any resources or references which might hold this snek in memory
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public virtual ValueTask DisposeAsync()
|
||||
=> default;
|
||||
|
||||
/// <summary>
|
||||
/// This method is called right after the message was received by the bot.
|
||||
/// You can use this method to make the bot conditionally ignore some messages and prevent further processing.
|
||||
/// <para>Execution order:</para>
|
||||
/// <para>
|
||||
/// *<see cref="ExecOnMessageAsync"/>* →
|
||||
/// <see cref="ExecInputTransformAsync"/> →
|
||||
/// <see cref="ExecPreCommandAsync"/> →
|
||||
/// <see cref="ExecPostCommandAsync"/> OR <see cref="ExecOnNoCommandAsync"/>
|
||||
/// </para>
|
||||
/// </summary>
|
||||
/// <param name="guild">Guild in which the message was sent</param>
|
||||
/// <param name="msg">Message received by the bot</param>
|
||||
/// <returns>A <see cref="ValueTask"/> representing whether the message should be ignored and not processed further</returns>
|
||||
public virtual ValueTask<bool> ExecOnMessageAsync(IGuild? guild, IUserMessage msg)
|
||||
=> default;
|
||||
|
||||
/// <summary>
|
||||
/// Override this method to modify input before the bot searches for any commands matching the input
|
||||
/// Executed after <see cref="ExecOnMessageAsync"/>
|
||||
/// This is useful if you want to reinterpret the message under some conditions
|
||||
/// <para>Execution order:</para>
|
||||
/// <para>
|
||||
/// <see cref="ExecOnMessageAsync"/> →
|
||||
/// *<see cref="ExecInputTransformAsync"/>* →
|
||||
/// <see cref="ExecPreCommandAsync"/> →
|
||||
/// <see cref="ExecPostCommandAsync"/> OR <see cref="ExecOnNoCommandAsync"/>
|
||||
/// </para>
|
||||
/// </summary>
|
||||
/// <param name="guild">Guild in which the message was sent</param>
|
||||
/// <param name="channel">Channel in which the message was sent</param>
|
||||
/// <param name="user">User who sent the message</param>
|
||||
/// <param name="input">Content of the message</param>
|
||||
/// <returns>A <see cref="ValueTask"/> representing new, potentially modified content</returns>
|
||||
public virtual ValueTask<string?> ExecInputTransformAsync(
|
||||
IGuild? guild,
|
||||
IMessageChannel channel,
|
||||
IUser user,
|
||||
string input
|
||||
)
|
||||
=> default;
|
||||
|
||||
/// <summary>
|
||||
/// This method is called after the command was found but not executed,
|
||||
/// and can be used to prevent the command's execution.
|
||||
/// The command information doesn't have to be from this snek as this method
|
||||
/// will be called when *any* command from any module or snek was found.
|
||||
/// You can choose to prevent the execution of the command by returning "true" value.
|
||||
/// <para>Execution order:</para>
|
||||
/// <para>
|
||||
/// <see cref="ExecOnMessageAsync"/> →
|
||||
/// <see cref="ExecInputTransformAsync"/> →
|
||||
/// *<see cref="ExecPreCommandAsync"/>* →
|
||||
/// <see cref="ExecPostCommandAsync"/> OR <see cref="ExecOnNoCommandAsync"/>
|
||||
/// </para>
|
||||
/// </summary>
|
||||
/// <param name="context">Command context</param>
|
||||
/// <param name="moduleName">Name of the snek or module from which the command originates</param>
|
||||
/// <param name="commandName">Name of the command which is about to be executed</param>
|
||||
/// <returns>A <see cref="ValueTask"/> representing whether the execution should be blocked</returns>
|
||||
public virtual ValueTask<bool> ExecPreCommandAsync(
|
||||
AnyContext context,
|
||||
string moduleName,
|
||||
string commandName
|
||||
)
|
||||
=> default;
|
||||
|
||||
/// <summary>
|
||||
/// This method is called after the command was succesfully executed.
|
||||
/// If this method was called, then <see cref="ExecOnNoCommandAsync"/> will not be executed
|
||||
/// <para>Execution order:</para>
|
||||
/// <para>
|
||||
/// <see cref="ExecOnMessageAsync"/> →
|
||||
/// <see cref="ExecInputTransformAsync"/> →
|
||||
/// <see cref="ExecPreCommandAsync"/> →
|
||||
/// *<see cref="ExecPostCommandAsync"/>* OR <see cref="ExecOnNoCommandAsync"/>
|
||||
/// </para>
|
||||
/// </summary>
|
||||
/// <returns>A <see cref="ValueTask"/> representing completion</returns>
|
||||
public virtual ValueTask ExecPostCommandAsync(AnyContext ctx, string moduleName, string commandName)
|
||||
=> default;
|
||||
|
||||
/// <summary>
|
||||
/// This method is called if no command was found for the input.
|
||||
/// Useful if you want to have games or features which take arbitrary input
|
||||
/// but ignore any messages which were blocked or caused a command execution
|
||||
/// If this method was called, then <see cref="ExecPostCommandAsync"/> will not be executed
|
||||
/// <para>Execution order:</para>
|
||||
/// <para>
|
||||
/// <see cref="ExecOnMessageAsync"/> →
|
||||
/// <see cref="ExecInputTransformAsync"/> →
|
||||
/// <see cref="ExecPreCommandAsync"/> →
|
||||
/// <see cref="ExecPostCommandAsync"/> OR *<see cref="ExecOnNoCommandAsync"/>*
|
||||
/// </para>
|
||||
/// </summary>
|
||||
/// <returns>A <see cref="ValueTask"/> representing completion</returns>
|
||||
public virtual ValueTask ExecOnNoCommandAsync(IGuild? guild, IUserMessage msg)
|
||||
=> default;
|
||||
}
|
||||
|
||||
public readonly struct ExecResponse
|
||||
{
|
||||
}
|
24
src/Nadeko.Medusa/Strings/CommandStrings.cs
Normal file
24
src/Nadeko.Medusa/Strings/CommandStrings.cs
Normal file
@@ -0,0 +1,24 @@
|
||||
using YamlDotNet.Serialization;
|
||||
|
||||
namespace Nadeko.Snake;
|
||||
|
||||
public readonly struct CommandStrings
|
||||
{
|
||||
public CommandStrings(string? desc, string[]? args)
|
||||
{
|
||||
Desc = desc;
|
||||
Args = args;
|
||||
}
|
||||
|
||||
[YamlMember(Alias = "desc")]
|
||||
public string? Desc { get; init; }
|
||||
|
||||
[YamlMember(Alias = "args")]
|
||||
public string[]? Args { get; init; }
|
||||
|
||||
public void Deconstruct(out string? desc, out string[]? args)
|
||||
{
|
||||
desc = Desc;
|
||||
args = Args;
|
||||
}
|
||||
}
|
15
src/Nadeko.Medusa/Strings/IMedusaStrings.cs
Normal file
15
src/Nadeko.Medusa/Strings/IMedusaStrings.cs
Normal file
@@ -0,0 +1,15 @@
|
||||
using System.Globalization;
|
||||
|
||||
namespace Nadeko.Snake;
|
||||
|
||||
/// <summary>
|
||||
/// Defines methods to retrieve and reload medusa strings
|
||||
/// </summary>
|
||||
public interface IMedusaStrings
|
||||
{
|
||||
// string GetText(string key, ulong? guildId = null, params object[] data);
|
||||
string? GetText(string key, CultureInfo locale, params object[] data);
|
||||
void Reload();
|
||||
CommandStrings GetCommandStrings(string commandName, CultureInfo cultureInfo);
|
||||
string? GetDescription(CultureInfo? locale);
|
||||
}
|
28
src/Nadeko.Medusa/Strings/IMedusaStringsProvider.cs
Normal file
28
src/Nadeko.Medusa/Strings/IMedusaStringsProvider.cs
Normal file
@@ -0,0 +1,28 @@
|
||||
namespace Nadeko.Snake;
|
||||
|
||||
/// <summary>
|
||||
/// Implemented by classes which provide localized strings in their own ways
|
||||
/// </summary>
|
||||
public interface IMedusaStringsProvider
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets localized string
|
||||
/// </summary>
|
||||
/// <param name="localeName">Language name</param>
|
||||
/// <param name="key">String key</param>
|
||||
/// <returns>Localized string</returns>
|
||||
string? GetText(string localeName, string key);
|
||||
|
||||
/// <summary>
|
||||
/// Reloads string cache
|
||||
/// </summary>
|
||||
void Reload();
|
||||
|
||||
// /// <summary>
|
||||
// /// Gets command arg examples and description
|
||||
// /// </summary>
|
||||
// /// <param name="localeName">Language name</param>
|
||||
// /// <param name="commandName">Command name</param>
|
||||
// CommandStrings GetCommandStrings(string localeName, string commandName);
|
||||
CommandStrings? GetCommandStrings(string localeName, string commandName);
|
||||
}
|
40
src/Nadeko.Medusa/Strings/LocalMedusaStringsProvider.cs
Normal file
40
src/Nadeko.Medusa/Strings/LocalMedusaStringsProvider.cs
Normal file
@@ -0,0 +1,40 @@
|
||||
namespace Nadeko.Snake;
|
||||
|
||||
public class LocalMedusaStringsProvider : IMedusaStringsProvider
|
||||
{
|
||||
private readonly StringsLoader _source;
|
||||
private IReadOnlyDictionary<string, IReadOnlyDictionary<string, string>> _responseStrings;
|
||||
private IReadOnlyDictionary<string, IReadOnlyDictionary<string, CommandStrings>> _commandStrings;
|
||||
|
||||
public LocalMedusaStringsProvider(StringsLoader source)
|
||||
{
|
||||
_source = source;
|
||||
_responseStrings = _source.GetResponseStrings();
|
||||
_commandStrings = _source.GetCommandStrings();
|
||||
}
|
||||
|
||||
public void Reload()
|
||||
{
|
||||
_responseStrings = _source.GetResponseStrings();
|
||||
_commandStrings = _source.GetCommandStrings();
|
||||
}
|
||||
|
||||
|
||||
public string? GetText(string localeName, string key)
|
||||
{
|
||||
if (_responseStrings.TryGetValue(localeName.ToLowerInvariant(), out var langStrings)
|
||||
&& langStrings.TryGetValue(key.ToLowerInvariant(), out var text))
|
||||
return text;
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public CommandStrings? GetCommandStrings(string localeName, string commandName)
|
||||
{
|
||||
if (_commandStrings.TryGetValue(localeName.ToLowerInvariant(), out var langStrings)
|
||||
&& langStrings.TryGetValue(commandName.ToLowerInvariant(), out var strings))
|
||||
return strings;
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
79
src/Nadeko.Medusa/Strings/MedusaStrings.cs
Normal file
79
src/Nadeko.Medusa/Strings/MedusaStrings.cs
Normal file
@@ -0,0 +1,79 @@
|
||||
using System.Globalization;
|
||||
using Serilog;
|
||||
|
||||
namespace Nadeko.Snake;
|
||||
|
||||
public class MedusaStrings : IMedusaStrings
|
||||
{
|
||||
/// <summary>
|
||||
/// Used as failsafe in case response key doesn't exist in the selected or default language.
|
||||
/// </summary>
|
||||
private readonly CultureInfo _usCultureInfo = new("en-US");
|
||||
|
||||
private readonly IMedusaStringsProvider _stringsProvider;
|
||||
|
||||
public MedusaStrings(IMedusaStringsProvider stringsProvider)
|
||||
{
|
||||
_stringsProvider = stringsProvider;
|
||||
}
|
||||
|
||||
private string? GetString(string key, CultureInfo cultureInfo)
|
||||
=> _stringsProvider.GetText(cultureInfo.Name, key);
|
||||
|
||||
public string? GetText(string key, CultureInfo cultureInfo)
|
||||
=> GetString(key, cultureInfo)
|
||||
?? GetString(key, _usCultureInfo);
|
||||
|
||||
public string? GetText(string key, CultureInfo cultureInfo, params object[] data)
|
||||
{
|
||||
var text = GetText(key, cultureInfo);
|
||||
|
||||
if (string.IsNullOrWhiteSpace(text))
|
||||
return null;
|
||||
|
||||
try
|
||||
{
|
||||
return string.Format(text, data);
|
||||
}
|
||||
catch (FormatException)
|
||||
{
|
||||
Log.Warning(" Key '{Key}' is not properly formatted in '{LanguageName}' response strings",
|
||||
key,
|
||||
cultureInfo.Name);
|
||||
|
||||
return $"⚠️ Response string key '{key}' is not properly formatted. Please report this.\n\n{text}";
|
||||
}
|
||||
}
|
||||
|
||||
public CommandStrings GetCommandStrings(string commandName, CultureInfo cultureInfo)
|
||||
{
|
||||
var cmdStrings = _stringsProvider.GetCommandStrings(cultureInfo.Name, commandName);
|
||||
if (cmdStrings is null)
|
||||
{
|
||||
if (cultureInfo.Name == _usCultureInfo.Name)
|
||||
{
|
||||
Log.Warning("'{CommandName}' doesn't exist in 'en-US' command strings for one of the medusae",
|
||||
commandName);
|
||||
|
||||
return new(null, null);
|
||||
}
|
||||
|
||||
Log.Information("Missing '{CommandName}' command strings for the '{LocaleName}' locale",
|
||||
commandName,
|
||||
cultureInfo.Name);
|
||||
|
||||
return GetCommandStrings(commandName, _usCultureInfo);
|
||||
}
|
||||
|
||||
return cmdStrings.Value;
|
||||
}
|
||||
|
||||
public string? GetDescription(CultureInfo? locale = null)
|
||||
=> GetText("medusa.description", locale ?? _usCultureInfo);
|
||||
|
||||
public static MedusaStrings CreateDefault(string basePath)
|
||||
=> new MedusaStrings(new LocalMedusaStringsProvider(new(basePath)));
|
||||
|
||||
public void Reload()
|
||||
=> _stringsProvider.Reload();
|
||||
}
|
137
src/Nadeko.Medusa/Strings/StringsLoader.cs
Normal file
137
src/Nadeko.Medusa/Strings/StringsLoader.cs
Normal file
@@ -0,0 +1,137 @@
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using Serilog;
|
||||
using YamlDotNet.Serialization;
|
||||
|
||||
namespace Nadeko.Snake;
|
||||
|
||||
/// <summary>
|
||||
/// Loads strings from the shortcut or localizable path
|
||||
/// </summary>
|
||||
public class StringsLoader
|
||||
{
|
||||
private readonly string _localizableResponsesPath;
|
||||
private readonly string _shortcutResponsesFile;
|
||||
|
||||
private readonly string _localizableCommandsPath;
|
||||
private readonly string _shortcutCommandsFile;
|
||||
|
||||
public StringsLoader(string basePath)
|
||||
{
|
||||
_localizableResponsesPath = Path.Join(basePath, "strings/res");
|
||||
_shortcutResponsesFile = Path.Join(basePath, "res.yml");
|
||||
|
||||
_localizableCommandsPath = Path.Join(basePath, "strings/cmds");
|
||||
_shortcutCommandsFile = Path.Join(basePath, "cmds.yml");
|
||||
}
|
||||
|
||||
public IReadOnlyDictionary<string, IReadOnlyDictionary<string, CommandStrings>> GetCommandStrings()
|
||||
{
|
||||
var outputDict = new Dictionary<string, IReadOnlyDictionary<string, CommandStrings>>();
|
||||
|
||||
if (File.Exists(_shortcutCommandsFile))
|
||||
{
|
||||
if (TryLoadCommandsFromFile(_shortcutCommandsFile, out var dict, out _))
|
||||
{
|
||||
outputDict["en-us"] = dict;
|
||||
}
|
||||
|
||||
return outputDict;
|
||||
}
|
||||
|
||||
if (Directory.Exists(_localizableCommandsPath))
|
||||
{
|
||||
foreach (var cmdsFile in Directory.EnumerateFiles(_localizableCommandsPath))
|
||||
{
|
||||
if (TryLoadCommandsFromFile(cmdsFile, out var dict, out var locale) && locale is not null)
|
||||
{
|
||||
outputDict[locale.ToLowerInvariant()] = dict;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return outputDict;
|
||||
}
|
||||
|
||||
|
||||
private static readonly IDeserializer _deserializer = new DeserializerBuilder().Build();
|
||||
private static bool TryLoadCommandsFromFile(string file,
|
||||
[NotNullWhen(true)] out IReadOnlyDictionary<string, CommandStrings>? strings,
|
||||
out string? localeName)
|
||||
{
|
||||
try
|
||||
{
|
||||
var text = File.ReadAllText(file);
|
||||
strings = _deserializer.Deserialize<Dictionary<string, CommandStrings>?>(text)
|
||||
?? new();
|
||||
localeName = GetLocaleName(file);
|
||||
return true;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Log.Error(ex, "Error loading {FileName} command strings: {ErrorMessage}", file, ex.Message);
|
||||
}
|
||||
|
||||
strings = null;
|
||||
localeName = null;
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
public IReadOnlyDictionary<string, IReadOnlyDictionary<string, string>> GetResponseStrings()
|
||||
{
|
||||
var outputDict = new Dictionary<string, IReadOnlyDictionary<string, string>>();
|
||||
|
||||
// try to load a shortcut file
|
||||
if (File.Exists(_shortcutResponsesFile))
|
||||
{
|
||||
if (TryLoadResponsesFromFile(_shortcutResponsesFile, out var dict, out _))
|
||||
{
|
||||
outputDict["en-us"] = dict;
|
||||
}
|
||||
|
||||
return outputDict;
|
||||
}
|
||||
|
||||
if (!Directory.Exists(_localizableResponsesPath))
|
||||
return outputDict;
|
||||
|
||||
// if shortcut file doesn't exist, try to load localizable files
|
||||
foreach (var file in Directory.GetFiles(_localizableResponsesPath))
|
||||
{
|
||||
if (TryLoadResponsesFromFile(file, out var strings, out var localeName) && localeName is not null)
|
||||
{
|
||||
outputDict[localeName.ToLowerInvariant()] = strings;
|
||||
}
|
||||
}
|
||||
|
||||
return outputDict;
|
||||
}
|
||||
|
||||
private static bool TryLoadResponsesFromFile(string file,
|
||||
[NotNullWhen(true)] out IReadOnlyDictionary<string, string>? strings,
|
||||
out string? localeName)
|
||||
{
|
||||
try
|
||||
{
|
||||
strings = _deserializer.Deserialize<Dictionary<string, string>?>(File.ReadAllText(file));
|
||||
if (strings is null)
|
||||
{
|
||||
localeName = null;
|
||||
return false;
|
||||
}
|
||||
|
||||
localeName = GetLocaleName(file).ToLowerInvariant();
|
||||
return true;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Log.Error(ex, "Error loading {FileName} response strings: {ErrorMessage}", file, ex.Message);
|
||||
strings = null;
|
||||
localeName = null;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private static string GetLocaleName(string fileName)
|
||||
=> Path.GetFileNameWithoutExtension(fileName);
|
||||
}
|
2
src/Nadeko.Medusa/pack-and-push.ps1
Normal file
2
src/Nadeko.Medusa/pack-and-push.ps1
Normal file
@@ -0,0 +1,2 @@
|
||||
dotnet pack -o bin/Release/packed
|
||||
dotnet nuget push bin/Release/packed/ --api-key $env:nadeko_myget_api_key --source https://www.myget.org/F/nadeko/api/v2/package
|
@@ -15,6 +15,9 @@ namespace NadekoBot.Services
|
||||
.MinimumLevel.Override("System", LogEventLevel.Information)
|
||||
.MinimumLevel.Override("Microsoft.AspNetCore", LogEventLevel.Warning)
|
||||
.Enrich.FromLogContext()
|
||||
.WriteTo.File("coord.log", LogEventLevel.Information,
|
||||
rollOnFileSizeLimit: true,
|
||||
fileSizeLimitBytes: 10_000_000)
|
||||
.WriteTo.Console(LogEventLevel.Information,
|
||||
theme: GetTheme(),
|
||||
outputTemplate: "[{Timestamp:HH:mm:ss} {Level:u3}] | #{LogSource} | {Message:lj}{NewLine}{Exception}")
|
||||
|
@@ -9,9 +9,10 @@
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Grpc.AspNetCore" Version="2.42.0" />
|
||||
<PackageReference Include="Serilog" Version="2.10.0" />
|
||||
<PackageReference Include="Grpc.AspNetCore" Version="2.47.0" />
|
||||
<PackageReference Include="Serilog" Version="2.11.0" />
|
||||
<PackageReference Include="Serilog.Sinks.Console" Version="4.0.1" />
|
||||
<PackageReference Include="Serilog.Sinks.File" Version="5.0.0" />
|
||||
<PackageReference Include="YamlDotNet" Version="11.2.1" />
|
||||
</ItemGroup>
|
||||
|
||||
|
@@ -114,14 +114,6 @@ namespace NadekoBot.Coordinator
|
||||
StartShard(shardId);
|
||||
break;
|
||||
}
|
||||
|
||||
if (status.Process is null or {HasExited: true})
|
||||
{
|
||||
Log.Warning("Shard {ShardId} is starting (process)...", shardId);
|
||||
hadAction = true;
|
||||
StartShard(shardId);
|
||||
break;
|
||||
}
|
||||
|
||||
if (DateTime.UtcNow - status.LastUpdate >
|
||||
TimeSpan.FromSeconds(_config.UnresponsiveSec))
|
||||
@@ -139,6 +131,24 @@ namespace NadekoBot.Coordinator
|
||||
StartShard(shardId);
|
||||
break;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
if (status.Process is null or { HasExited: true })
|
||||
{
|
||||
Log.Warning("Shard {ShardId} is starting (process)...", shardId);
|
||||
hadAction = true;
|
||||
StartShard(shardId);
|
||||
break;
|
||||
}
|
||||
}
|
||||
catch (InvalidOperationException)
|
||||
{
|
||||
Log.Warning("Process for shard {ShardId} is bugged... ", shardId);
|
||||
hadAction = true;
|
||||
StartShard(shardId);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -161,17 +171,13 @@ namespace NadekoBot.Coordinator
|
||||
var status = _shardStatuses[shardId];
|
||||
try
|
||||
{
|
||||
if (status.Process is { HasExited: false } p)
|
||||
{
|
||||
try
|
||||
{
|
||||
p.Kill(true);
|
||||
}
|
||||
catch
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
status.Process?.Kill(true);
|
||||
}
|
||||
catch
|
||||
{
|
||||
}
|
||||
try
|
||||
{
|
||||
status.Process?.Dispose();
|
||||
}
|
||||
catch
|
||||
@@ -280,10 +286,10 @@ namespace NadekoBot.Coordinator
|
||||
for (var shardId = 0; shardId < _shardStatuses.Length; shardId++)
|
||||
{
|
||||
var status = _shardStatuses[shardId];
|
||||
if (status.Process is { } p)
|
||||
if (status.Process is Process p)
|
||||
{
|
||||
p.Kill();
|
||||
p.Dispose();
|
||||
try{p.Kill();} catch {}
|
||||
try{p.Dispose();} catch {}
|
||||
_shardStatuses[shardId] = status with
|
||||
{
|
||||
Process = null,
|
||||
|
@@ -1,323 +1,336 @@
|
||||
#nullable enable
|
||||
using System;
|
||||
using System.CodeDom.Compiler;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Immutable;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using Microsoft.CodeAnalysis;
|
||||
using Microsoft.CodeAnalysis.CSharp;
|
||||
using Microsoft.CodeAnalysis.CSharp.Syntax;
|
||||
using Microsoft.CodeAnalysis.Text;
|
||||
|
||||
namespace NadekoBot.Generators.Command;
|
||||
|
||||
[Generator]
|
||||
public class CommandAttributesGenerator : IIncrementalGenerator
|
||||
{
|
||||
public const string ATTRIBUTE = @"// <AutoGenerated />
|
||||
|
||||
namespace NadekoBot.Common;
|
||||
|
||||
[System.AttributeUsage(System.AttributeTargets.Method)]
|
||||
public class CmdAttribute : System.Attribute
|
||||
{
|
||||
|
||||
}";
|
||||
|
||||
public class MethodModel
|
||||
{
|
||||
public string? Namespace { get; }
|
||||
public IReadOnlyCollection<string> Classes { get; }
|
||||
public string ReturnType { get; }
|
||||
public string MethodName { get; }
|
||||
public IEnumerable<string> Params { get; }
|
||||
|
||||
public MethodModel(string? ns, IReadOnlyCollection<string> classes, string returnType, string methodName, IEnumerable<string> @params)
|
||||
{
|
||||
Namespace = ns;
|
||||
Classes = classes;
|
||||
ReturnType = returnType;
|
||||
MethodName = methodName;
|
||||
Params = @params;
|
||||
}
|
||||
}
|
||||
|
||||
public class FileModel
|
||||
{
|
||||
public string? Namespace { get; }
|
||||
public IReadOnlyCollection<string> ClassHierarchy { get; }
|
||||
public IReadOnlyCollection<MethodModel> Methods { get; }
|
||||
|
||||
public FileModel(string? ns, IReadOnlyCollection<string> classHierarchy, IReadOnlyCollection<MethodModel> methods)
|
||||
{
|
||||
Namespace = ns;
|
||||
ClassHierarchy = classHierarchy;
|
||||
Methods = methods;
|
||||
}
|
||||
}
|
||||
|
||||
public void Initialize(IncrementalGeneratorInitializationContext context)
|
||||
{
|
||||
// #if DEBUG
|
||||
// SpinWait.SpinUntil(() => Debugger.IsAttached);
|
||||
// #endif
|
||||
context.RegisterPostInitializationOutput(static ctx => ctx.AddSource(
|
||||
"CmdAttribute.g.cs",
|
||||
SourceText.From(ATTRIBUTE, Encoding.UTF8)));
|
||||
|
||||
var methods = context.SyntaxProvider
|
||||
.CreateSyntaxProvider(
|
||||
static (node, _) => node is MethodDeclarationSyntax { AttributeLists.Count: > 0 },
|
||||
static (ctx, cancel) => Transform(ctx, cancel))
|
||||
.Where(static m => m is not null)
|
||||
.Where(static m => m?.ChildTokens().Any(static x => x.IsKind(SyntaxKind.PublicKeyword)) ?? false);
|
||||
|
||||
var compilationMethods = context.CompilationProvider.Combine(methods.Collect());
|
||||
|
||||
context.RegisterSourceOutput(compilationMethods,
|
||||
static (ctx, tuple) => RegisterAction(in ctx, tuple.Left, in tuple.Right));
|
||||
}
|
||||
|
||||
private static void RegisterAction(in SourceProductionContext ctx,
|
||||
Compilation comp,
|
||||
in ImmutableArray<MethodDeclarationSyntax?> methods)
|
||||
{
|
||||
if (methods is { IsDefaultOrEmpty: true })
|
||||
return;
|
||||
|
||||
var models = GetModels(comp, methods, ctx.CancellationToken);
|
||||
|
||||
foreach (var model in models)
|
||||
{
|
||||
var name = $"{model.Namespace}.{string.Join(".", model.ClassHierarchy)}.g.cs";
|
||||
try
|
||||
{
|
||||
Debug.WriteLine($"Writing {name}");
|
||||
var source = GetSourceText(model);
|
||||
ctx.AddSource(name, SourceText.From(source, Encoding.UTF8));
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Debug.WriteLine($"Error writing source file {name}\n" + ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static string GetSourceText(FileModel model)
|
||||
{
|
||||
using var sw = new StringWriter();
|
||||
using var tw = new IndentedTextWriter(sw);
|
||||
|
||||
tw.WriteLine("// <AutoGenerated />");
|
||||
tw.WriteLine("#pragma warning disable CS1066");
|
||||
|
||||
if (model.Namespace is not null)
|
||||
{
|
||||
tw.WriteLine($"namespace {model.Namespace};");
|
||||
tw.WriteLine();
|
||||
}
|
||||
|
||||
foreach (var className in model.ClassHierarchy)
|
||||
{
|
||||
tw.WriteLine($"public partial class {className}");
|
||||
tw.WriteLine("{");
|
||||
tw.Indent ++;
|
||||
}
|
||||
|
||||
foreach (var method in model.Methods)
|
||||
{
|
||||
tw.WriteLine("[NadekoCommand]");
|
||||
tw.WriteLine("[NadekoDescription]");
|
||||
tw.WriteLine("[Aliases]");
|
||||
tw.WriteLine($"public partial {method.ReturnType} {method.MethodName}({string.Join(", ", method.Params)});");
|
||||
}
|
||||
|
||||
foreach (var _ in model.ClassHierarchy)
|
||||
{
|
||||
tw.Indent --;
|
||||
tw.WriteLine("}");
|
||||
}
|
||||
|
||||
tw.Flush();
|
||||
return sw.ToString();
|
||||
}
|
||||
|
||||
private static IReadOnlyCollection<FileModel> GetModels(Compilation compilation,
|
||||
in ImmutableArray<MethodDeclarationSyntax?> inputMethods,
|
||||
CancellationToken cancel)
|
||||
{
|
||||
var models = new List<FileModel>();
|
||||
|
||||
var methods = inputMethods
|
||||
.Where(static x => x is not null)
|
||||
.Distinct();
|
||||
|
||||
var methodModels = methods
|
||||
.Select(x => MethodDeclarationToMethodModel(compilation, x!));
|
||||
|
||||
var groups = methodModels
|
||||
.GroupBy(static x => $"{x.Namespace}.{string.Join(".", x.Classes)}");
|
||||
|
||||
foreach (var group in groups)
|
||||
{
|
||||
if (cancel.IsCancellationRequested)
|
||||
return new Collection<FileModel>();
|
||||
|
||||
if (group is null)
|
||||
continue;
|
||||
|
||||
var elems = group.ToList();
|
||||
if (elems.Count is 0)
|
||||
continue;
|
||||
|
||||
var model = new FileModel(
|
||||
methods: elems,
|
||||
ns: elems[0].Namespace,
|
||||
classHierarchy: elems[0].Classes
|
||||
);
|
||||
|
||||
models.Add(model);
|
||||
}
|
||||
|
||||
|
||||
return models;
|
||||
}
|
||||
|
||||
private static MethodModel MethodDeclarationToMethodModel(Compilation comp, MethodDeclarationSyntax decl)
|
||||
{
|
||||
// SpinWait.SpinUntil(static () => Debugger.IsAttached);
|
||||
|
||||
var semanticModel = comp.GetSemanticModel(decl.SyntaxTree);
|
||||
var methodModel = new MethodModel(
|
||||
@params: decl.ParameterList.Parameters
|
||||
.Where(p => p.Type is not null)
|
||||
.Select(p =>
|
||||
{
|
||||
var prefix = p.Modifiers.Any(static x => x.IsKind(SyntaxKind.ParamsKeyword))
|
||||
? "params "
|
||||
: string.Empty;
|
||||
|
||||
var type = semanticModel
|
||||
.GetTypeInfo(p.Type!)
|
||||
.Type
|
||||
?.ToDisplayString(SymbolDisplayFormat.FullyQualifiedFormat);
|
||||
|
||||
|
||||
var name = p.Identifier.Text;
|
||||
|
||||
var suffix = string.Empty;
|
||||
if (p.Default is not null)
|
||||
{
|
||||
if (p.Default.Value is LiteralExpressionSyntax)
|
||||
{
|
||||
suffix = " = " + p.Default.Value;
|
||||
}
|
||||
else if (p.Default.Value is MemberAccessExpressionSyntax maes)
|
||||
{
|
||||
var maesSemModel = comp.GetSemanticModel(maes.SyntaxTree);
|
||||
var sym = maesSemModel.GetSymbolInfo(maes.Name);
|
||||
if (sym.Symbol is null)
|
||||
{
|
||||
suffix = " = " + p.Default.Value;
|
||||
}
|
||||
else
|
||||
{
|
||||
suffix = " = " + sym.Symbol.ToDisplayString();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $"{prefix}{type} {name}{suffix}";
|
||||
})
|
||||
.ToList(),
|
||||
methodName: decl.Identifier.Text,
|
||||
returnType: decl.ReturnType.ToString(),
|
||||
ns: GetNamespace(decl),
|
||||
classes: GetClasses(decl)
|
||||
);
|
||||
|
||||
return methodModel;
|
||||
}
|
||||
|
||||
//https://github.com/andrewlock/NetEscapades.EnumGenerators/blob/main/src/NetEscapades.EnumGenerators/EnumGenerator.cs
|
||||
static string? GetNamespace(MethodDeclarationSyntax declarationSyntax)
|
||||
{
|
||||
// determine the namespace the class is declared in, if any
|
||||
string? nameSpace = null;
|
||||
var parentOfInterest = declarationSyntax.Parent;
|
||||
while (parentOfInterest is not null)
|
||||
{
|
||||
parentOfInterest = parentOfInterest.Parent;
|
||||
|
||||
if (parentOfInterest is BaseNamespaceDeclarationSyntax ns)
|
||||
{
|
||||
nameSpace = ns.Name.ToString();
|
||||
while (true)
|
||||
{
|
||||
if (ns.Parent is not NamespaceDeclarationSyntax parent)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
ns = parent;
|
||||
nameSpace = $"{ns.Name}.{nameSpace}";
|
||||
}
|
||||
|
||||
return nameSpace;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return nameSpace;
|
||||
}
|
||||
|
||||
static IReadOnlyCollection<string> GetClasses(MethodDeclarationSyntax declarationSyntax)
|
||||
{
|
||||
// determine the namespace the class is declared in, if any
|
||||
var classes = new LinkedList<string>();
|
||||
var parentOfInterest = declarationSyntax.Parent;
|
||||
while (parentOfInterest is not null)
|
||||
{
|
||||
if (parentOfInterest is ClassDeclarationSyntax cds)
|
||||
{
|
||||
classes.AddFirst(cds.Identifier.ToString());
|
||||
}
|
||||
|
||||
parentOfInterest = parentOfInterest.Parent;
|
||||
}
|
||||
|
||||
Debug.WriteLine($"Method {declarationSyntax.Identifier.Text} has {classes.Count} classes");
|
||||
|
||||
return classes;
|
||||
}
|
||||
|
||||
private static MethodDeclarationSyntax? Transform(GeneratorSyntaxContext ctx, CancellationToken cancel)
|
||||
{
|
||||
var methodDecl = ctx.Node as MethodDeclarationSyntax;
|
||||
if (methodDecl is null)
|
||||
return default;
|
||||
|
||||
foreach (var attListSyntax in methodDecl.AttributeLists)
|
||||
{
|
||||
foreach (var attSyntax in attListSyntax.Attributes)
|
||||
{
|
||||
if (cancel.IsCancellationRequested)
|
||||
return default;
|
||||
|
||||
var symbol = ctx.SemanticModel.GetSymbolInfo(attSyntax).Symbol;
|
||||
if (symbol is not IMethodSymbol attSymbol)
|
||||
continue;
|
||||
|
||||
if (attSymbol.ContainingType.ToDisplayString() == "NadekoBot.Common.CmdAttribute")
|
||||
return methodDecl;
|
||||
}
|
||||
}
|
||||
|
||||
return default;
|
||||
}
|
||||
}
|
||||
// #nullable enable
|
||||
// using System;
|
||||
// using System.CodeDom.Compiler;
|
||||
// using System.Collections.Generic;
|
||||
// using System.Collections.Immutable;
|
||||
// using System.Collections.ObjectModel;
|
||||
// using System.Diagnostics;
|
||||
// using System.IO;
|
||||
// using System.Linq;
|
||||
// using System.Text;
|
||||
// using System.Threading;
|
||||
// using Microsoft.CodeAnalysis;
|
||||
// using Microsoft.CodeAnalysis.CSharp;
|
||||
// using Microsoft.CodeAnalysis.CSharp.Syntax;
|
||||
// using Microsoft.CodeAnalysis.Text;
|
||||
//
|
||||
// namespace NadekoBot.Generators.Command;
|
||||
//
|
||||
// [Generator]
|
||||
// public class CommandAttributesGenerator : IIncrementalGenerator
|
||||
// {
|
||||
// public const string ATTRIBUTE = @"// <AutoGenerated />
|
||||
//
|
||||
// namespace NadekoBot.Common;
|
||||
//
|
||||
// [System.AttributeUsage(System.AttributeTargets.Method)]
|
||||
// public class CmdAttribute : System.Attribute
|
||||
// {
|
||||
//
|
||||
// }";
|
||||
//
|
||||
// public class MethodModel
|
||||
// {
|
||||
// public string? Namespace { get; }
|
||||
// public IReadOnlyCollection<string> Classes { get; }
|
||||
// public string ReturnType { get; }
|
||||
// public string MethodName { get; }
|
||||
// public IEnumerable<string> Params { get; }
|
||||
//
|
||||
// public MethodModel(string? ns, IReadOnlyCollection<string> classes, string returnType, string methodName, IEnumerable<string> @params)
|
||||
// {
|
||||
// Namespace = ns;
|
||||
// Classes = classes;
|
||||
// ReturnType = returnType;
|
||||
// MethodName = methodName;
|
||||
// Params = @params;
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// public class FileModel
|
||||
// {
|
||||
// public string? Namespace { get; }
|
||||
// public IReadOnlyCollection<string> ClassHierarchy { get; }
|
||||
// public IReadOnlyCollection<MethodModel> Methods { get; }
|
||||
//
|
||||
// public FileModel(string? ns, IReadOnlyCollection<string> classHierarchy, IReadOnlyCollection<MethodModel> methods)
|
||||
// {
|
||||
// Namespace = ns;
|
||||
// ClassHierarchy = classHierarchy;
|
||||
// Methods = methods;
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// public void Initialize(IncrementalGeneratorInitializationContext context)
|
||||
// {
|
||||
// // #if DEBUG
|
||||
// // if (!Debugger.IsAttached)
|
||||
// // Debugger.Launch();
|
||||
// // // SpinWait.SpinUntil(() => Debugger.IsAttached);
|
||||
// // #endif
|
||||
// context.RegisterPostInitializationOutput(static ctx => ctx.AddSource(
|
||||
// "CmdAttribute.g.cs",
|
||||
// SourceText.From(ATTRIBUTE, Encoding.UTF8)));
|
||||
//
|
||||
// var methods = context.SyntaxProvider
|
||||
// .CreateSyntaxProvider(
|
||||
// static (node, _) => node is MethodDeclarationSyntax { AttributeLists.Count: > 0 },
|
||||
// static (ctx, cancel) => Transform(ctx, cancel))
|
||||
// .Where(static m => m is not null)
|
||||
// .Where(static m => m?.ChildTokens().Any(static x => x.IsKind(SyntaxKind.PublicKeyword)) ?? false);
|
||||
//
|
||||
// var compilationMethods = context.CompilationProvider.Combine(methods.Collect());
|
||||
//
|
||||
// context.RegisterSourceOutput(compilationMethods,
|
||||
// static (ctx, tuple) => RegisterAction(in ctx, tuple.Left, in tuple.Right));
|
||||
// }
|
||||
//
|
||||
// private static void RegisterAction(in SourceProductionContext ctx,
|
||||
// Compilation comp,
|
||||
// in ImmutableArray<MethodDeclarationSyntax?> methods)
|
||||
// {
|
||||
// if (methods is { IsDefaultOrEmpty: true })
|
||||
// return;
|
||||
//
|
||||
// var models = GetModels(comp, methods, ctx.CancellationToken);
|
||||
//
|
||||
// foreach (var model in models)
|
||||
// {
|
||||
// var name = $"{model.Namespace}.{string.Join(".", model.ClassHierarchy)}.g.cs";
|
||||
// try
|
||||
// {
|
||||
// var source = GetSourceText(model);
|
||||
// ctx.AddSource(name, SourceText.From(source, Encoding.UTF8));
|
||||
// }
|
||||
// catch (Exception ex)
|
||||
// {
|
||||
// Console.WriteLine($"Error writing source file {name}\n" + ex);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// private static string GetSourceText(FileModel model)
|
||||
// {
|
||||
// using var sw = new StringWriter();
|
||||
// using var tw = new IndentedTextWriter(sw);
|
||||
//
|
||||
// tw.WriteLine("// <AutoGenerated />");
|
||||
// tw.WriteLine("#pragma warning disable CS1066");
|
||||
//
|
||||
// if (model.Namespace is not null)
|
||||
// {
|
||||
// tw.WriteLine($"namespace {model.Namespace};");
|
||||
// tw.WriteLine();
|
||||
// }
|
||||
//
|
||||
// foreach (var className in model.ClassHierarchy)
|
||||
// {
|
||||
// tw.WriteLine($"public partial class {className}");
|
||||
// tw.WriteLine("{");
|
||||
// tw.Indent ++;
|
||||
// }
|
||||
//
|
||||
// foreach (var method in model.Methods)
|
||||
// {
|
||||
// tw.WriteLine("[NadekoCommand]");
|
||||
// tw.WriteLine("[NadekoDescription]");
|
||||
// tw.WriteLine("[Aliases]");
|
||||
// tw.WriteLine($"public partial {method.ReturnType} {method.MethodName}({string.Join(", ", method.Params)});");
|
||||
// }
|
||||
//
|
||||
// foreach (var _ in model.ClassHierarchy)
|
||||
// {
|
||||
// tw.Indent --;
|
||||
// tw.WriteLine("}");
|
||||
// }
|
||||
//
|
||||
// tw.Flush();
|
||||
// return sw.ToString();
|
||||
// }
|
||||
//
|
||||
// private static IReadOnlyCollection<FileModel> GetModels(Compilation compilation,
|
||||
// in ImmutableArray<MethodDeclarationSyntax?> inputMethods,
|
||||
// CancellationToken cancel)
|
||||
// {
|
||||
// var models = new List<FileModel>();
|
||||
//
|
||||
// var methods = inputMethods
|
||||
// .Where(static x => x is not null)
|
||||
// .Distinct();
|
||||
//
|
||||
// var methodModels = methods
|
||||
// .Select(x => MethodDeclarationToMethodModel(compilation, x!))
|
||||
// .Where(static x => x is not null)
|
||||
// .Cast<MethodModel>();
|
||||
//
|
||||
// var groups = methodModels
|
||||
// .GroupBy(static x => $"{x.Namespace}.{string.Join(".", x.Classes)}");
|
||||
//
|
||||
// foreach (var group in groups)
|
||||
// {
|
||||
// if (cancel.IsCancellationRequested)
|
||||
// return new Collection<FileModel>();
|
||||
//
|
||||
// if (group is null)
|
||||
// continue;
|
||||
//
|
||||
// var elems = group.ToList();
|
||||
// if (elems.Count is 0)
|
||||
// continue;
|
||||
//
|
||||
// var model = new FileModel(
|
||||
// methods: elems,
|
||||
// ns: elems[0].Namespace,
|
||||
// classHierarchy: elems![0].Classes
|
||||
// );
|
||||
//
|
||||
// models.Add(model);
|
||||
// }
|
||||
//
|
||||
//
|
||||
// return models;
|
||||
// }
|
||||
//
|
||||
// private static MethodModel? MethodDeclarationToMethodModel(Compilation comp, MethodDeclarationSyntax decl)
|
||||
// {
|
||||
// // SpinWait.SpinUntil(static () => Debugger.IsAttached);
|
||||
//
|
||||
// SemanticModel semanticModel;
|
||||
// try
|
||||
// {
|
||||
// semanticModel = comp.GetSemanticModel(decl.SyntaxTree);
|
||||
// }
|
||||
// catch
|
||||
// {
|
||||
// // for some reason this method can throw "Not part of this compilation" argument exception
|
||||
// return null;
|
||||
// }
|
||||
//
|
||||
// var methodModel = new MethodModel(
|
||||
// @params: decl.ParameterList.Parameters
|
||||
// .Where(p => p.Type is not null)
|
||||
// .Select(p =>
|
||||
// {
|
||||
// var prefix = p.Modifiers.Any(static x => x.IsKind(SyntaxKind.ParamsKeyword))
|
||||
// ? "params "
|
||||
// : string.Empty;
|
||||
//
|
||||
// var type = semanticModel
|
||||
// .GetTypeInfo(p.Type!)
|
||||
// .Type
|
||||
// ?.ToDisplayString(SymbolDisplayFormat.FullyQualifiedFormat);
|
||||
//
|
||||
//
|
||||
// var name = p.Identifier.Text;
|
||||
//
|
||||
// var suffix = string.Empty;
|
||||
// if (p.Default is not null)
|
||||
// {
|
||||
// if (p.Default.Value is LiteralExpressionSyntax)
|
||||
// {
|
||||
// suffix = " = " + p.Default.Value;
|
||||
// }
|
||||
// else if (p.Default.Value is MemberAccessExpressionSyntax maes)
|
||||
// {
|
||||
// var maesSemModel = comp.GetSemanticModel(maes.SyntaxTree);
|
||||
// var sym = maesSemModel.GetSymbolInfo(maes.Name);
|
||||
// if (sym.Symbol is null)
|
||||
// {
|
||||
// suffix = " = " + p.Default.Value;
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// suffix = " = " + sym.Symbol.ToDisplayString();
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// return $"{prefix}{type} {name}{suffix}";
|
||||
// })
|
||||
// .ToList(),
|
||||
// methodName: decl.Identifier.Text,
|
||||
// returnType: decl.ReturnType.ToString(),
|
||||
// ns: GetNamespace(decl),
|
||||
// classes: GetClasses(decl)
|
||||
// );
|
||||
//
|
||||
// return methodModel;
|
||||
// }
|
||||
//
|
||||
// //https://github.com/andrewlock/NetEscapades.EnumGenerators/blob/main/src/NetEscapades.EnumGenerators/EnumGenerator.cs
|
||||
// static string? GetNamespace(MethodDeclarationSyntax declarationSyntax)
|
||||
// {
|
||||
// // determine the namespace the class is declared in, if any
|
||||
// string? nameSpace = null;
|
||||
// var parentOfInterest = declarationSyntax.Parent;
|
||||
// while (parentOfInterest is not null)
|
||||
// {
|
||||
// parentOfInterest = parentOfInterest.Parent;
|
||||
//
|
||||
// if (parentOfInterest is BaseNamespaceDeclarationSyntax ns)
|
||||
// {
|
||||
// nameSpace = ns.Name.ToString();
|
||||
// while (true)
|
||||
// {
|
||||
// if (ns.Parent is not NamespaceDeclarationSyntax parent)
|
||||
// {
|
||||
// break;
|
||||
// }
|
||||
//
|
||||
// ns = parent;
|
||||
// nameSpace = $"{ns.Name}.{nameSpace}";
|
||||
// }
|
||||
//
|
||||
// return nameSpace;
|
||||
// }
|
||||
//
|
||||
// }
|
||||
//
|
||||
// return nameSpace;
|
||||
// }
|
||||
//
|
||||
// static IReadOnlyCollection<string> GetClasses(MethodDeclarationSyntax declarationSyntax)
|
||||
// {
|
||||
// // determine the namespace the class is declared in, if any
|
||||
// var classes = new LinkedList<string>();
|
||||
// var parentOfInterest = declarationSyntax.Parent;
|
||||
// while (parentOfInterest is not null)
|
||||
// {
|
||||
// if (parentOfInterest is ClassDeclarationSyntax cds)
|
||||
// {
|
||||
// classes.AddFirst(cds.Identifier.ToString());
|
||||
// }
|
||||
//
|
||||
// parentOfInterest = parentOfInterest.Parent;
|
||||
// }
|
||||
//
|
||||
// Debug.WriteLine($"Method {declarationSyntax.Identifier.Text} has {classes.Count} classes");
|
||||
//
|
||||
// return classes;
|
||||
// }
|
||||
//
|
||||
// private static MethodDeclarationSyntax? Transform(GeneratorSyntaxContext ctx, CancellationToken cancel)
|
||||
// {
|
||||
// var methodDecl = ctx.Node as MethodDeclarationSyntax;
|
||||
// if (methodDecl is null)
|
||||
// return default;
|
||||
//
|
||||
// foreach (var attListSyntax in methodDecl.AttributeLists)
|
||||
// {
|
||||
// foreach (var attSyntax in attListSyntax.Attributes)
|
||||
// {
|
||||
// if (cancel.IsCancellationRequested)
|
||||
// return default;
|
||||
//
|
||||
// var symbol = ctx.SemanticModel.GetSymbolInfo(attSyntax).Symbol;
|
||||
// if (symbol is not IMethodSymbol attSymbol)
|
||||
// continue;
|
||||
//
|
||||
// if (attSymbol.ContainingType.ToDisplayString() == "NadekoBot.Common.CmdAttribute")
|
||||
// return methodDecl;
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// return default;
|
||||
// }
|
||||
// }
|
@@ -62,6 +62,7 @@ namespace NadekoBot.Generators
|
||||
sw.WriteLine("{");
|
||||
sw.Indent++;
|
||||
|
||||
var typedParamStrings = new List<string>(10);
|
||||
foreach (var field in fields)
|
||||
{
|
||||
var matches = Regex.Matches(field.Value, @"{(?<num>\d)[}:]");
|
||||
@@ -71,20 +72,30 @@ namespace NadekoBot.Generators
|
||||
max = Math.Max(max, int.Parse(match.Groups["num"].Value) + 1);
|
||||
}
|
||||
|
||||
List<string> typedParamStrings = new List<string>();
|
||||
var paramStrings = string.Empty;
|
||||
typedParamStrings.Clear();
|
||||
var typeParams = new string[max];
|
||||
var passedParamString = string.Empty;
|
||||
for (var i = 0; i < max; i++)
|
||||
{
|
||||
typedParamStrings.Add($"object p{i}");
|
||||
paramStrings += $", p{i}";
|
||||
typedParamStrings.Add($"in T{i} p{i}");
|
||||
passedParamString += $", p{i}";
|
||||
typeParams[i] = $"T{i}";
|
||||
}
|
||||
|
||||
|
||||
var sig = string.Empty;
|
||||
if(max > 0)
|
||||
var typeParamStr = string.Empty;
|
||||
if (max > 0)
|
||||
{
|
||||
sig = $"({string.Join(", ", typedParamStrings)})";
|
||||
|
||||
sw.WriteLine($"public static LocStr {field.Name}{sig} => new LocStr(\"{field.Name}\"{paramStrings});");
|
||||
typeParamStr = $"<{string.Join(", ", typeParams)}>";
|
||||
}
|
||||
|
||||
sw.WriteLine("public static LocStr {0}{1}{2} => new LocStr(\"{3}\"{4});",
|
||||
field.Name,
|
||||
typeParamStr,
|
||||
sig,
|
||||
field.Name,
|
||||
passedParamString);
|
||||
}
|
||||
|
||||
sw.Indent--;
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user