aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Dockerfile5
-rw-r--r--Pipfile4
-rw-r--r--Pipfile.lock419
-rw-r--r--bot/__init__.py10
-rw-r--r--bot/__main__.py9
-rw-r--r--bot/bot.py148
-rw-r--r--bot/cogs/alias.py70
-rw-r--r--bot/cogs/antimalware.py28
-rw-r--r--bot/cogs/antispam.py9
-rw-r--r--bot/cogs/bot.py4
-rw-r--r--bot/cogs/defcon.py16
-rw-r--r--bot/cogs/doc.py4
-rw-r--r--bot/cogs/error_handler.py32
-rw-r--r--bot/cogs/extensions.py2
-rw-r--r--bot/cogs/filter_lists.py273
-rw-r--r--bot/cogs/filtering.py115
-rw-r--r--bot/cogs/help.py38
-rw-r--r--bot/cogs/help_channels.py93
-rw-r--r--bot/cogs/information.py117
-rw-r--r--bot/cogs/moderation/modlog.py4
-rw-r--r--bot/cogs/moderation/scheduler.py10
-rw-r--r--bot/cogs/moderation/silence.py3
-rw-r--r--bot/cogs/moderation/utils.py2
-rw-r--r--bot/cogs/off_topic_names.py31
-rw-r--r--bot/cogs/reddit.py3
-rw-r--r--bot/cogs/reminders.py31
-rw-r--r--bot/cogs/site.py10
-rw-r--r--bot/cogs/snekbox.py4
-rw-r--r--bot/cogs/source.py22
-rw-r--r--bot/cogs/tags.py4
-rw-r--r--bot/cogs/utils.py2
-rw-r--r--bot/cogs/watchchannels/bigbrother.py6
-rw-r--r--bot/cogs/watchchannels/talentpool.py60
-rw-r--r--bot/cogs/watchchannels/watchchannel.py10
-rw-r--r--bot/cogs/wolfram.py280
-rw-r--r--bot/command.py18
-rw-r--r--bot/constants.py49
-rw-r--r--bot/converters.py115
-rw-r--r--bot/pagination.py174
-rw-r--r--bot/resources/tags/ask.md9
-rw-r--r--bot/resources/tags/kindling-projects.md3
-rw-r--r--bot/resources/tags/traceback.md2
-rw-r--r--bot/rules/__init__.py1
-rw-r--r--bot/rules/discord_emojis.py4
-rw-r--r--bot/rules/everyone_ping.py41
-rw-r--r--bot/utils/messages.py13
-rw-r--r--bot/utils/redis_cache.py17
-rw-r--r--bot/utils/regex.py12
-rw-r--r--config-default.yml181
-rw-r--r--tests/bot/cogs/test_antimalware.py46
-rw-r--r--tests/bot/cogs/test_cogs.py1
-rw-r--r--tests/bot/cogs/test_information.py87
-rw-r--r--tests/bot/test_pagination.py15
53 files changed, 1347 insertions, 1319 deletions
diff --git a/Dockerfile b/Dockerfile
index 0b1674e7a..06a538b2a 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -6,11 +6,6 @@ ENV PIP_NO_CACHE_DIR=false \
PIPENV_IGNORE_VIRTUALENVS=1 \
PIPENV_NOSPIN=1
-RUN apt-get -y update \
- && apt-get install -y \
- git \
- && rm -rf /var/lib/apt/lists/*
-
# Install pipenv
RUN pip install -U pipenv
diff --git a/Pipfile b/Pipfile
index 2d6b45aa9..6fff2223e 100644
--- a/Pipfile
+++ b/Pipfile
@@ -12,7 +12,7 @@ beautifulsoup4 = "~=4.9"
colorama = {version = "~=0.4.3",sys_platform = "== 'win32'"}
coloredlogs = "~=14.0"
deepdiff = "~=4.0"
-discord-py = {git = "https://github.com/Rapptz/discord.py.git",ref = "0bc15fa130b8f01fe2d67446a2184d474b0d0ba7"}
+discord.py = "~=1.4.0"
fakeredis = "~=1.4"
feedparser = "~=5.2"
fuzzywuzzy = "~=0.17"
@@ -28,7 +28,7 @@ statsd = "~=3.3"
[dev-packages]
coverage = "~=5.0"
-flake8 = "~=3.7"
+flake8 = "~=3.8"
flake8-annotations = "~=2.0"
flake8-bugbear = "~=20.1"
flake8-docstrings = "~=1.4"
diff --git a/Pipfile.lock b/Pipfile.lock
index 4b9d092d4..50ddd478c 100644
--- a/Pipfile.lock
+++ b/Pipfile.lock
@@ -1,7 +1,7 @@
{
"_meta": {
"hash": {
- "sha256": "8a53baefbbd2a0f3fbaf831f028b23d257a5e28b5efa1260661d74604f4113b8"
+ "sha256": "1905fd7eb15074ddbf04f2177b6cdd65edc4c74cb5fcbf4e6ca08ef649ba8a3c"
},
"pipfile-spec": 6,
"requires": {
@@ -60,11 +60,11 @@
},
"aiormq": {
"hashes": [
- "sha256:41a9d4eb17db805f30ed172f3f609fe0c2b16657fb15b1b67df19d251dd93c0d",
- "sha256:7c19477a9450824cb79f9949fd238f4148e2c0dca67756a2868863c387209f04"
+ "sha256:106695a836f19c1af6c46b58e8aac80e00f86c5b3287a3c6483a1ee369cc95c9",
+ "sha256:9f6dbf6155fe2b7a3d24bf68de97fb812db0fac0a54e96bc1af14ea95078ba7f"
],
"markers": "python_version >= '3.6'",
- "version": "==3.2.2"
+ "version": "==3.2.3"
},
"alabaster": {
"hashes": [
@@ -115,36 +115,36 @@
},
"cffi": {
"hashes": [
- "sha256:001bf3242a1bb04d985d63e138230802c6c8d4db3668fb545fb5005ddf5bb5ff",
- "sha256:00789914be39dffba161cfc5be31b55775de5ba2235fe49aa28c148236c4e06b",
- "sha256:028a579fc9aed3af38f4892bdcc7390508adabc30c6af4a6e4f611b0c680e6ac",
- "sha256:14491a910663bf9f13ddf2bc8f60562d6bc5315c1f09c704937ef17293fb85b0",
- "sha256:1cae98a7054b5c9391eb3249b86e0e99ab1e02bb0cc0575da191aedadbdf4384",
- "sha256:2089ed025da3919d2e75a4d963d008330c96751127dd6f73c8dc0c65041b4c26",
- "sha256:2d384f4a127a15ba701207f7639d94106693b6cd64173d6c8988e2c25f3ac2b6",
- "sha256:337d448e5a725bba2d8293c48d9353fc68d0e9e4088d62a9571def317797522b",
- "sha256:399aed636c7d3749bbed55bc907c3288cb43c65c4389964ad5ff849b6370603e",
- "sha256:3b911c2dbd4f423b4c4fcca138cadde747abdb20d196c4a48708b8a2d32b16dd",
- "sha256:3d311bcc4a41408cf5854f06ef2c5cab88f9fded37a3b95936c9879c1640d4c2",
- "sha256:62ae9af2d069ea2698bf536dcfe1e4eed9090211dbaafeeedf5cb6c41b352f66",
- "sha256:66e41db66b47d0d8672d8ed2708ba91b2f2524ece3dee48b5dfb36be8c2f21dc",
- "sha256:675686925a9fb403edba0114db74e741d8181683dcf216be697d208857e04ca8",
- "sha256:7e63cbcf2429a8dbfe48dcc2322d5f2220b77b2e17b7ba023d6166d84655da55",
- "sha256:8a6c688fefb4e1cd56feb6c511984a6c4f7ec7d2a1ff31a10254f3c817054ae4",
- "sha256:8c0ffc886aea5df6a1762d0019e9cb05f825d0eec1f520c51be9d198701daee5",
- "sha256:95cd16d3dee553f882540c1ffe331d085c9e629499ceadfbda4d4fde635f4b7d",
- "sha256:99f748a7e71ff382613b4e1acc0ac83bf7ad167fb3802e35e90d9763daba4d78",
- "sha256:b8c78301cefcf5fd914aad35d3c04c2b21ce8629b5e4f4e45ae6812e461910fa",
- "sha256:c420917b188a5582a56d8b93bdd8e0f6eca08c84ff623a4c16e809152cd35793",
- "sha256:c43866529f2f06fe0edc6246eb4faa34f03fe88b64a0a9a942561c8e22f4b71f",
- "sha256:cab50b8c2250b46fe738c77dbd25ce017d5e6fb35d3407606e7a4180656a5a6a",
- "sha256:cef128cb4d5e0b3493f058f10ce32365972c554572ff821e175dbc6f8ff6924f",
- "sha256:cf16e3cf6c0a5fdd9bc10c21687e19d29ad1fe863372b5543deaec1039581a30",
- "sha256:e56c744aa6ff427a607763346e4170629caf7e48ead6921745986db3692f987f",
- "sha256:e577934fc5f8779c554639376beeaa5657d54349096ef24abe8c74c5d9c117c3",
- "sha256:f2b0fa0c01d8a0c7483afd9f31d7ecf2d71760ca24499c8697aeb5ca37dc090c"
- ],
- "version": "==1.14.0"
+ "sha256:267adcf6e68d77ba154334a3e4fc921b8e63cbb38ca00d33d40655d4228502bc",
+ "sha256:26f33e8f6a70c255767e3c3f957ccafc7f1f706b966e110b855bfe944511f1f9",
+ "sha256:3cd2c044517f38d1b577f05927fb9729d3396f1d44d0c659a445599e79519792",
+ "sha256:4a03416915b82b81af5502459a8a9dd62a3c299b295dcdf470877cb948d655f2",
+ "sha256:4ce1e995aeecf7cc32380bc11598bfdfa017d592259d5da00fc7ded11e61d022",
+ "sha256:4f53e4128c81ca3212ff4cf097c797ab44646a40b42ec02a891155cd7a2ba4d8",
+ "sha256:4fa72a52a906425416f41738728268072d5acfd48cbe7796af07a923236bcf96",
+ "sha256:66dd45eb9530e3dde8f7c009f84568bc7cac489b93d04ac86e3111fb46e470c2",
+ "sha256:6923d077d9ae9e8bacbdb1c07ae78405a9306c8fd1af13bfa06ca891095eb995",
+ "sha256:833401b15de1bb92791d7b6fb353d4af60dc688eaa521bd97203dcd2d124a7c1",
+ "sha256:8416ed88ddc057bab0526d4e4e9f3660f614ac2394b5e019a628cdfff3733849",
+ "sha256:892daa86384994fdf4856cb43c93f40cbe80f7f95bb5da94971b39c7f54b3a9c",
+ "sha256:98be759efdb5e5fa161e46d404f4e0ce388e72fbf7d9baf010aff16689e22abe",
+ "sha256:a6d28e7f14ecf3b2ad67c4f106841218c8ab12a0683b1528534a6c87d2307af3",
+ "sha256:b1d6ebc891607e71fd9da71688fcf332a6630b7f5b7f5549e6e631821c0e5d90",
+ "sha256:b2a2b0d276a136146e012154baefaea2758ef1f56ae9f4e01c612b0831e0bd2f",
+ "sha256:b87dfa9f10a470eee7f24234a37d1d5f51e5f5fa9eeffda7c282e2b8f5162eb1",
+ "sha256:bac0d6f7728a9cc3c1e06d4fcbac12aaa70e9379b3025b27ec1226f0e2d404cf",
+ "sha256:c991112622baee0ae4d55c008380c32ecfd0ad417bcd0417ba432e6ba7328caa",
+ "sha256:cda422d54ee7905bfc53ee6915ab68fe7b230cacf581110df4272ee10462aadc",
+ "sha256:d3148b6ba3923c5850ea197a91a42683f946dba7e8eb82dfa211ab7e708de939",
+ "sha256:d6033b4ffa34ef70f0b8086fd4c3df4bf801fee485a8a7d4519399818351aa8e",
+ "sha256:ddff0b2bd7edcc8c82d1adde6dbbf5e60d57ce985402541cd2985c27f7bec2a0",
+ "sha256:e23cb7f1d8e0f93addf0cae3c5b6f00324cccb4a7949ee558d7b6ca973ab8ae9",
+ "sha256:effd2ba52cee4ceff1a77f20d2a9f9bf8d50353c854a282b8760ac15b9833168",
+ "sha256:f90c2267101010de42f7273c94a1f026e56cbc043f9330acd8a80e64300aba33",
+ "sha256:f960375e9823ae6a07072ff7f8a85954e5a6434f97869f50d0e41649a1c8144f",
+ "sha256:fcf32bf76dc25e30ed793145a57426064520890d7c02866eb93d3e4abe516948"
+ ],
+ "version": "==1.14.1"
},
"chardet": {
"hashes": [
@@ -177,9 +177,22 @@
"index": "pypi",
"version": "==4.3.2"
},
- "discord-py": {
- "git": "https://github.com/Rapptz/discord.py.git",
- "ref": "0bc15fa130b8f01fe2d67446a2184d474b0d0ba7"
+ "discord": {
+ "hashes": [
+ "sha256:9d4debb4a37845543bd4b92cb195bc53a302797333e768e70344222857ff1559",
+ "sha256:ff6653655e342e7721dfb3f10421345fd852c2a33f2cca912b1c39b3778a9429"
+ ],
+ "index": "pypi",
+ "py": "~=1.4.0",
+ "version": "==1.0.1"
+ },
+ "discord.py": {
+ "hashes": [
+ "sha256:2b1846bfa382b54f4eace8e437a9f59f185388c5b08749ac0e1bbd98e05bfde5",
+ "sha256:f3db9531fccc391f51de65cfa46133106a9ba12ff2927aca6c14bffd3b7f17b5"
+ ],
+ "markers": "python_full_version >= '3.5.3'",
+ "version": "==1.4.0"
},
"docutils": {
"hashes": [
@@ -191,11 +204,11 @@
},
"fakeredis": {
"hashes": [
- "sha256:4d170886865a91dbc8b7f8cbd4e5d488f4c5f2f25dfae127f001617bbe9e8f97",
- "sha256:647b2593d349d9d4e566c8dadb2e4c71ba35be5bdc4f1f7ac2d565a12a965053"
+ "sha256:790c85ad0f3b2967aba1f51767021bc59760fcb612159584be018ea7384f7fd2",
+ "sha256:fdfe06f277092d022c271fcaefdc1f0c8d9bfa8cb15374cae41d66a20bd96d2b"
],
"index": "pypi",
- "version": "==1.4.1"
+ "version": "==1.4.2"
},
"feedparser": {
"hashes": [
@@ -216,49 +229,55 @@
},
"hiredis": {
"hashes": [
- "sha256:01b577f84c20ecc9c07fc4c184231b08e3c3942de096fa99978e053de231c423",
- "sha256:01ff0900134166961c9e339df77c33b72f7edc5cb41739f0babcd9faa345926e",
- "sha256:03ed34a13316d0c34213c4fd46e0fa3a5299073f4d4f08e93fed8c2108b399b3",
- "sha256:040436e91df5143aff9e0debb49530d0b17a6bd52200ce568621c31ef581b10d",
- "sha256:091eb38fbf968d1c5b703e412bbbd25f43a7967d8400842cee33a5a07b33c27b",
- "sha256:102f9b9dc6ed57feb3a7c9bdf7e71cb7c278fe8df1edfcfe896bc3e0c2be9447",
- "sha256:2b4b392c7e3082860c8371fab3ae762139090f9115819e12d9f56060f9ede05d",
- "sha256:2c9cc0b986397b833073f466e6b9e9c70d1d4dc2c2c1b3e9cae3a23102ff296c",
- "sha256:2fa65a9df683bca72073cd77709ddeb289ea2b114d3775d225fbbcc5faf808c5",
- "sha256:38437a681f17c975fd22349e72c29bc643f8e7eb2d6dc5df419eac59afa4d7ce",
- "sha256:3b3428fa3cf1ee178807b52c9bee8950ab94cd4eaa9bfae8c1bbae3c49501d34",
- "sha256:3dd8c2fae7f5494978facb0e93297dd627b1a3f536f3b070cf0a7d9157a07dcb",
- "sha256:4414a96c212e732723b5c3d7c04d386ebbb2ec359e1de646322cbc3f875cbd0d",
- "sha256:48c627581ad4ef60adbac980981407939acf13a0e18f093502c7b542223c4f19",
- "sha256:4a60e71625a2d78d8ab84dfb2fa2cfd9458c964b6e6c04fea76d9ade153fb371",
- "sha256:585ace09f434e43d8a8dbeb366865b1a044d7c06319b3c7372a0a00e63b860f4",
- "sha256:74b364b3f06c9cf0a53f7df611045bc9437ed972a283fa1f0b12537236d23ddc",
- "sha256:75c65c3850e89e9daa68d1b9bedd5806f177d60aa5a7b0953b4829481cfc1f72",
- "sha256:7f052de8bf744730a9120dbdc67bfeb7605a01f69fb8e7ba5c475af33c24e145",
- "sha256:8113a7d5e87ecf57cd4ae263cc9e429adb9a3e59f5a7768da5d3312a8d0a051a",
- "sha256:84857ce239eb8ed191ac78e77ff65d52902f00f30f4ee83bf80eb71da73b70e6",
- "sha256:8644a48ddc4a40b3e3a6b9443f396c2ee353afb2d45656c4fc68d04a82e8e3f7",
- "sha256:936aa565e673536e8a211e43ec43197406f24cd1f290138bd143765079c8ba00",
- "sha256:9afeb88c67bbc663b9f27385c496da056d06ad87f55df6e393e1516cfecb0461",
- "sha256:9d62cc7880110e4f83b0a51d218f465d3095e2751fbddd34e553dbd106a929ff",
- "sha256:a1fadd062fc8d647ff39220c57ea2b48c99bb73f18223828ec97f88fc27e7898",
- "sha256:a7754a783b1e5d6f627c19d099b178059c62f782ab62b4d8ba165b9fbc2ee34c",
- "sha256:aa59dd63bb3f736de4fc2d080114429d5d369dfb3265f771778e8349d67a97a4",
- "sha256:ae2ee0992f8de249715435942137843a93db204dd7db1e7cc9bdc5a8436443e8",
- "sha256:b36842d7cf32929d568f37ec5b3173b72b2ec6572dec4d6be6ce774762215aee",
- "sha256:bcbf9379c553b5facc6c04c1e5569b44b38ff16bcbf354676287698d61ee0c92",
- "sha256:cbccbda6f1c62ab460449d9c85fdf24d0d32a6bf45176581151e53cc26a5d910",
- "sha256:d0caf98dfb8af395d6732bd16561c0a2458851bea522e39f12f04802dbf6f502",
- "sha256:d6456afeddba036def1a36d8a2758eca53202308d83db20ab5d0b66590919627",
- "sha256:dbaef9a21a4f10bc281684ee4124f169e62bb533c2a92b55f8c06f64f9af7b8f",
- "sha256:dce84916c09aaece006272b37234ae84a8ed13abb3a4d341a23933b8701abfb5",
- "sha256:eb8c9c8b9869539d58d60ff4a28373a22514d40495911451343971cb4835b7a9",
- "sha256:efc98b14ee3a8595e40b1425e8d42f5fd26f11a7b215a81ef9259068931754f4",
- "sha256:fa2dc05b87d97acc1c6ae63f3e0f39eae5246565232484b08db6bf2dc1580678",
- "sha256:fe7d6ce9f6a5fbe24f09d95ea93e9c7271abc4e1565da511e1449b107b4d7848"
+ "sha256:06a039208f83744a702279b894c8cf24c14fd63c59cd917dcde168b79eef0680",
+ "sha256:0a909bf501459062aa1552be1461456518f367379fdc9fdb1f2ca5e4a1fdd7c0",
+ "sha256:18402d9e54fb278cb9a8c638df6f1550aca36a009d47ecf5aa263a38600f35b0",
+ "sha256:1e4cbbc3858ec7e680006e5ca590d89a5e083235988f26a004acf7244389ac01",
+ "sha256:23344e3c2177baf6975fbfa361ed92eb7d36d08f454636e5054b3faa7c2aff8a",
+ "sha256:289b31885b4996ce04cadfd5fc03d034dce8e2a8234479f7c9e23b9e245db06b",
+ "sha256:2c1c570ae7bf1bab304f29427e2475fe1856814312c4a1cf1cd0ee133f07a3c6",
+ "sha256:2c227c0ed371771ffda256034427320870e8ea2e4fd0c0a618c766e7c49aad73",
+ "sha256:3bb9b63d319402cead8bbd9dd55dca3b667d2997e9a0d8a1f9b6cc274db4baee",
+ "sha256:3ef2183de67b59930d2db8b8e8d4d58e00a50fcc5e92f4f678f6eed7a1c72d55",
+ "sha256:43b8ed3dbfd9171e44c554cb4acf4ee4505caa84c5e341858b50ea27dd2b6e12",
+ "sha256:47bcf3c5e6c1e87ceb86cdda2ee983fa0fe56a999e6185099b3c93a223f2fa9b",
+ "sha256:5263db1e2e1e8ae30500cdd75a979ff99dcc184201e6b4b820d0de74834d2323",
+ "sha256:5b1451727f02e7acbdf6aae4e06d75f66ee82966ff9114550381c3271a90f56c",
+ "sha256:6996883a8a6ff9117cbb3d6f5b0dcbbae6fb9e31e1a3e4e2f95e0214d9a1c655",
+ "sha256:6c96f64a54f030366657a54bb90b3093afc9c16c8e0dfa29fc0d6dbe169103a5",
+ "sha256:7332d5c3e35154cd234fd79573736ddcf7a0ade7a986db35b6196b9171493e75",
+ "sha256:7885b6f32c4a898e825bb7f56f36a02781ac4a951c63e4169f0afcf9c8c30dfb",
+ "sha256:7b0f63f10a166583ab744a58baad04e0f52cfea1ac27bfa1b0c21a48d1003c23",
+ "sha256:819f95d4eba3f9e484dd115ab7ab72845cf766b84286a00d4ecf76d33f1edca1",
+ "sha256:8968eeaa4d37a38f8ca1f9dbe53526b69628edc9c42229a5b2f56d98bb828c1f",
+ "sha256:89ebf69cb19a33d625db72d2ac589d26e936b8f7628531269accf4a3196e7872",
+ "sha256:8daecd778c1da45b8bd54fd41ffcd471a86beed3d8e57a43acf7a8d63bba4058",
+ "sha256:955ba8ea73cf3ed8bd2f963b4cb9f8f0dcb27becd2f4b3dd536fd24c45533454",
+ "sha256:964f18a59f5a64c0170f684c417f4fe3e695a536612e13074c4dd5d1c6d7c882",
+ "sha256:969843fbdfbf56cdb71da6f0bdf50f9985b8b8aeb630102945306cf10a9c6af2",
+ "sha256:996021ef33e0f50b97ff2d6b5f422a0fe5577de21a8873b58a779a5ddd1c3132",
+ "sha256:9e9c9078a7ce07e6fce366bd818be89365a35d2e4b163268f0ca9ba7e13bb2f6",
+ "sha256:a04901757cb0fb0f5602ac11dda48f5510f94372144d06c2563ba56c480b467c",
+ "sha256:a7bf1492429f18d205f3a818da3ff1f242f60aa59006e53dee00b4ef592a3363",
+ "sha256:aa0af2deb166a5e26e0d554b824605e660039b161e37ed4f01b8d04beec184f3",
+ "sha256:abfb15a6a7822f0fae681785cb38860e7a2cb1616a708d53df557b3d76c5bfd4",
+ "sha256:b253fe4df2afea4dfa6b1fa8c5fef212aff8bcaaeb4207e81eed05cb5e4a7919",
+ "sha256:b27f082f47d23cffc4cf1388b84fdc45c4ef6015f906cd7e0d988d9e35d36349",
+ "sha256:b33aea449e7f46738811fbc6f0b3177c6777a572207412bbbf6f525ffed001ae",
+ "sha256:b44f9421c4505c548435244d74037618f452844c5d3c67719d8a55e2613549da",
+ "sha256:bcc371151d1512201d0214c36c0c150b1dc64f19c2b1a8c9cb1d7c7c15ebd93f",
+ "sha256:c2851deeabd96d3f6283e9c6b26e0bfed4de2dc6fb15edf913e78b79fc5909ed",
+ "sha256:cdfd501c7ac5b198c15df800a3a34c38345f5182e5f80770caf362bccca65628",
+ "sha256:d2c0caffa47606d6d7c8af94ba42547bd2a441f06c74fd90a1ffe328524a6c64",
+ "sha256:dcb2db95e629962db5a355047fb8aefb012df6c8ae608930d391619dbd96fd86",
+ "sha256:e0eeb9c112fec2031927a1745788a181d0eecbacbed941fc5c4f7bc3f7b273bf",
+ "sha256:e154891263306200260d7f3051982774d7b9ef35af3509d5adbbe539afd2610c",
+ "sha256:e2e023a42dcbab8ed31f97c2bcdb980b7fbe0ada34037d87ba9d799664b58ded",
+ "sha256:e64be68255234bb489a574c4f2f8df7029c98c81ec4d160d6cd836e7f0679390",
+ "sha256:e82d6b930e02e80e5109b678c663a9ed210680ded81c1abaf54635d88d1da298"
],
"markers": "python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3'",
- "version": "==1.0.1"
+ "version": "==1.1.0"
},
"humanfriendly": {
"hashes": [
@@ -294,36 +313,40 @@
},
"lxml": {
"hashes": [
- "sha256:06748c7192eab0f48e3d35a7adae609a329c6257495d5e53878003660dc0fec6",
- "sha256:0790ddca3f825dd914978c94c2545dbea5f56f008b050e835403714babe62a5f",
- "sha256:1aa7a6197c1cdd65d974f3e4953764eee3d9c7b67e3966616b41fab7f8f516b7",
- "sha256:22c6d34fdb0e65d5f782a4d1a1edb52e0a8365858dafb1c08cb1d16546cf0786",
- "sha256:2754d4406438c83144f9ffd3628bbe2dcc6d62b20dbc5c1ec4bc4385e5d44b42",
- "sha256:27ee0faf8077c7c1a589573b1450743011117f1aa1a91d5ae776bbc5ca6070f2",
- "sha256:2b02c106709466a93ed424454ce4c970791c486d5fcdf52b0d822a7e29789626",
- "sha256:2d1ddce96cf15f1254a68dba6935e6e0f1fe39247de631c115e84dd404a6f031",
- "sha256:4f282737d187ae723b2633856085c31ae5d4d432968b7f3f478a48a54835f5c4",
- "sha256:51bb4edeb36d24ec97eb3e6a6007be128b720114f9a875d6b370317d62ac80b9",
- "sha256:7eee37c1b9815e6505847aa5e68f192e8a1b730c5c7ead39ff317fde9ce29448",
- "sha256:7fd88cb91a470b383aafad554c3fe1ccf6dfb2456ff0e84b95335d582a799804",
- "sha256:9144ce36ca0824b29ebc2e02ca186e54040ebb224292072250467190fb613b96",
- "sha256:925baf6ff1ef2c45169f548cc85204433e061360bfa7d01e1be7ae38bef73194",
- "sha256:a636346c6c0e1092ffc202d97ec1843a75937d8c98aaf6771348ad6422e44bb0",
- "sha256:a87dbee7ad9dce3aaefada2081843caf08a44a8f52e03e0a4cc5819f8398f2f4",
- "sha256:a9e3b8011388e7e373565daa5e92f6c9cb844790dc18e43073212bb3e76f7007",
- "sha256:afb53edf1046599991fb4a7d03e601ab5f5422a5435c47ee6ba91ec3b61416a6",
- "sha256:b26719890c79a1dae7d53acac5f089d66fd8cc68a81f4e4bd355e45470dc25e1",
- "sha256:b7462cdab6fffcda853338e1741ce99706cdf880d921b5a769202ea7b94e8528",
- "sha256:b77975465234ff49fdad871c08aa747aae06f5e5be62866595057c43f8d2f62c",
- "sha256:c47a8a5d00060122ca5908909478abce7bbf62d812e3fc35c6c802df8fb01fe7",
- "sha256:c79e5debbe092e3c93ca4aee44c9a7631bdd407b2871cb541b979fd350bbbc29",
- "sha256:d8d40e0121ca1606aa9e78c28a3a7d88a05c06b3ca61630242cded87d8ce55fa",
- "sha256:ee2be8b8f72a2772e72ab926a3bccebf47bb727bda41ae070dc91d1fb759b726",
- "sha256:f95d28193c3863132b1f55c1056036bf580b5a488d908f7d22a04ace8935a3a9",
- "sha256:fadd2a63a2bfd7fb604508e553d1cf68eca250b2fbdbd81213b5f6f2fbf23529"
- ],
- "index": "pypi",
- "version": "==4.5.1"
+ "sha256:05a444b207901a68a6526948c7cc8f9fe6d6f24c70781488e32fd74ff5996e3f",
+ "sha256:08fc93257dcfe9542c0a6883a25ba4971d78297f63d7a5a26ffa34861ca78730",
+ "sha256:107781b213cf7201ec3806555657ccda67b1fccc4261fb889ef7fc56976db81f",
+ "sha256:121b665b04083a1e85ff1f5243d4a93aa1aaba281bc12ea334d5a187278ceaf1",
+ "sha256:1fa21263c3aba2b76fd7c45713d4428dbcc7644d73dcf0650e9d344e433741b3",
+ "sha256:2b30aa2bcff8e958cd85d907d5109820b01ac511eae5b460803430a7404e34d7",
+ "sha256:4b4a111bcf4b9c948e020fd207f915c24a6de3f1adc7682a2d92660eb4e84f1a",
+ "sha256:5591c4164755778e29e69b86e425880f852464a21c7bb53c7ea453bbe2633bbe",
+ "sha256:59daa84aef650b11bccd18f99f64bfe44b9f14a08a28259959d33676554065a1",
+ "sha256:5a9c8d11aa2c8f8b6043d845927a51eb9102eb558e3f936df494e96393f5fd3e",
+ "sha256:5dd20538a60c4cc9a077d3b715bb42307239fcd25ef1ca7286775f95e9e9a46d",
+ "sha256:74f48ec98430e06c1fa8949b49ebdd8d27ceb9df8d3d1c92e1fdc2773f003f20",
+ "sha256:786aad2aa20de3dbff21aab86b2fb6a7be68064cbbc0219bde414d3a30aa47ae",
+ "sha256:7ad7906e098ccd30d8f7068030a0b16668ab8aa5cda6fcd5146d8d20cbaa71b5",
+ "sha256:80a38b188d20c0524fe8959c8ce770a8fdf0e617c6912d23fc97c68301bb9aba",
+ "sha256:8f0ec6b9b3832e0bd1d57af41f9238ea7709bbd7271f639024f2fc9d3bb01293",
+ "sha256:92282c83547a9add85ad658143c76a64a8d339028926d7dc1998ca029c88ea6a",
+ "sha256:94150231f1e90c9595ccc80d7d2006c61f90a5995db82bccbca7944fd457f0f6",
+ "sha256:9dc9006dcc47e00a8a6a029eb035c8f696ad38e40a27d073a003d7d1443f5d88",
+ "sha256:a76979f728dd845655026ab991df25d26379a1a8fc1e9e68e25c7eda43004bed",
+ "sha256:aa8eba3db3d8761db161003e2d0586608092e217151d7458206e243be5a43843",
+ "sha256:bea760a63ce9bba566c23f726d72b3c0250e2fa2569909e2d83cda1534c79443",
+ "sha256:c3f511a3c58676147c277eff0224c061dd5a6a8e1373572ac817ac6324f1b1e0",
+ "sha256:c9d317efde4bafbc1561509bfa8a23c5cab66c44d49ab5b63ff690f5159b2304",
+ "sha256:cc411ad324a4486b142c41d9b2b6a722c534096963688d879ea6fa8a35028258",
+ "sha256:cdc13a1682b2a6241080745b1953719e7fe0850b40a5c71ca574f090a1391df6",
+ "sha256:cfd7c5dd3c35c19cec59c63df9571c67c6d6e5c92e0fe63517920e97f61106d1",
+ "sha256:e1cacf4796b20865789083252186ce9dc6cc59eca0c2e79cca332bdff24ac481",
+ "sha256:e70d4e467e243455492f5de463b72151cc400710ac03a0678206a5f27e79ddef",
+ "sha256:ecc930ae559ea8a43377e8b60ca6f8d61ac532fc57efb915d899de4a67928efd",
+ "sha256:f161af26f596131b63b236372e4ce40f3167c1b5b5d459b29d2514bd8c9dc9ee"
+ ],
+ "index": "pypi",
+ "version": "==4.5.2"
},
"markdownify": {
"hashes": [
@@ -532,11 +555,11 @@
},
"sentry-sdk": {
"hashes": [
- "sha256:da06bc3641e81ec2c942f87a0676cd9180044fa3d1697524a0005345997542e2",
- "sha256:e80d61af85d99a1222c1a3e2a24023618374cd50a99673aa7fa3cf920e7d813b"
+ "sha256:21b17d6aa064c0fb703a7c00f77cf6c9c497cf2f83345c28892980a5e742d116",
+ "sha256:4fc97114c77d005467b9b1a29f042e2bc01923cb683b0ef0bbda46e79fa12532"
],
"index": "pypi",
- "version": "==0.16.0"
+ "version": "==0.16.3"
},
"six": {
"hashes": [
@@ -634,62 +657,34 @@
},
"urllib3": {
"hashes": [
- "sha256:3018294ebefce6572a474f0604c2021e33b3fd8006ecd11d62107a5d2a963527",
- "sha256:88206b0eb87e6d677d424843ac5209e3fb9d0190d0ee169599165ec25e9d9115"
+ "sha256:91056c15fa70756691db97756772bb1eb9678fa585d9184f24534b100dc60f4a",
+ "sha256:e7983572181f5e1522d9c98453462384ee92a0be7fac5f1413a1e35c56cc0461"
],
"markers": "python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3, 3.4' and python_version < '4'",
- "version": "==1.25.9"
- },
- "websockets": {
- "hashes": [
- "sha256:0e4fb4de42701340bd2353bb2eee45314651caa6ccee80dbd5f5d5978888fed5",
- "sha256:1d3f1bf059d04a4e0eb4985a887d49195e15ebabc42364f4eb564b1d065793f5",
- "sha256:20891f0dddade307ffddf593c733a3fdb6b83e6f9eef85908113e628fa5a8308",
- "sha256:295359a2cc78736737dd88c343cd0747546b2174b5e1adc223824bcaf3e164cb",
- "sha256:2db62a9142e88535038a6bcfea70ef9447696ea77891aebb730a333a51ed559a",
- "sha256:3762791ab8b38948f0c4d281c8b2ddfa99b7e510e46bd8dfa942a5fff621068c",
- "sha256:3db87421956f1b0779a7564915875ba774295cc86e81bc671631379371af1170",
- "sha256:3ef56fcc7b1ff90de46ccd5a687bbd13a3180132268c4254fc0fa44ecf4fc422",
- "sha256:4f9f7d28ce1d8f1295717c2c25b732c2bc0645db3215cf757551c392177d7cb8",
- "sha256:5c01fd846263a75bc8a2b9542606927cfad57e7282965d96b93c387622487485",
- "sha256:5c65d2da8c6bce0fca2528f69f44b2f977e06954c8512a952222cea50dad430f",
- "sha256:751a556205d8245ff94aeef23546a1113b1dd4f6e4d102ded66c39b99c2ce6c8",
- "sha256:7ff46d441db78241f4c6c27b3868c9ae71473fe03341340d2dfdbe8d79310acc",
- "sha256:965889d9f0e2a75edd81a07592d0ced54daa5b0785f57dc429c378edbcffe779",
- "sha256:9b248ba3dd8a03b1a10b19efe7d4f7fa41d158fdaa95e2cf65af5a7b95a4f989",
- "sha256:9bef37ee224e104a413f0780e29adb3e514a5b698aabe0d969a6ba426b8435d1",
- "sha256:c1ec8db4fac31850286b7cd3b9c0e1b944204668b8eb721674916d4e28744092",
- "sha256:c8a116feafdb1f84607cb3b14aa1418424ae71fee131642fc568d21423b51824",
- "sha256:ce85b06a10fc65e6143518b96d3dca27b081a740bae261c2fb20375801a9d56d",
- "sha256:d705f8aeecdf3262379644e4b55107a3b55860eb812b673b28d0fbc347a60c55",
- "sha256:e898a0863421650f0bebac8ba40840fc02258ef4714cb7e1fd76b6a6354bda36",
- "sha256:f8a7bff6e8664afc4e6c28b983845c5bc14965030e3fb98789734d416af77c4b"
- ],
- "markers": "python_full_version >= '3.6.1'",
- "version": "==8.1"
+ "version": "==1.25.10"
},
"yarl": {
"hashes": [
- "sha256:0c2ab325d33f1b824734b3ef51d4d54a54e0e7a23d13b86974507602334c2cce",
- "sha256:0ca2f395591bbd85ddd50a82eb1fde9c1066fafe888c5c7cc1d810cf03fd3cc6",
- "sha256:2098a4b4b9d75ee352807a95cdf5f10180db903bc5b7270715c6bbe2551f64ce",
- "sha256:25e66e5e2007c7a39541ca13b559cd8ebc2ad8fe00ea94a2aad28a9b1e44e5ae",
- "sha256:26d7c90cb04dee1665282a5d1a998defc1a9e012fdca0f33396f81508f49696d",
- "sha256:308b98b0c8cd1dfef1a0311dc5e38ae8f9b58349226aa0533f15a16717ad702f",
- "sha256:3ce3d4f7c6b69c4e4f0704b32eca8123b9c58ae91af740481aa57d7857b5e41b",
- "sha256:58cd9c469eced558cd81aa3f484b2924e8897049e06889e8ff2510435b7ef74b",
- "sha256:5b10eb0e7f044cf0b035112446b26a3a2946bca9d7d7edb5e54a2ad2f6652abb",
- "sha256:6faa19d3824c21bcbfdfce5171e193c8b4ddafdf0ac3f129ccf0cdfcb083e462",
- "sha256:944494be42fa630134bf907714d40207e646fd5a94423c90d5b514f7b0713fea",
- "sha256:a161de7e50224e8e3de6e184707476b5a989037dcb24292b391a3d66ff158e70",
- "sha256:a4844ebb2be14768f7994f2017f70aca39d658a96c786211be5ddbe1c68794c1",
- "sha256:c2b509ac3d4b988ae8769901c66345425e361d518aecbe4acbfc2567e416626a",
- "sha256:c9959d49a77b0e07559e579f38b2f3711c2b8716b8410b320bf9713013215a1b",
- "sha256:d8cdee92bc930d8b09d8bd2043cedd544d9c8bd7436a77678dd602467a993080",
- "sha256:e15199cdb423316e15f108f51249e44eb156ae5dba232cb73be555324a1d49c2"
+ "sha256:040b237f58ff7d800e6e0fd89c8439b841f777dd99b4a9cca04d6935564b9409",
+ "sha256:17668ec6722b1b7a3a05cc0167659f6c95b436d25a36c2d52db0eca7d3f72593",
+ "sha256:3a584b28086bc93c888a6c2aa5c92ed1ae20932f078c46509a66dce9ea5533f2",
+ "sha256:4439be27e4eee76c7632c2427ca5e73703151b22cae23e64adb243a9c2f565d8",
+ "sha256:48e918b05850fffb070a496d2b5f97fc31d15d94ca33d3d08a4f86e26d4e7c5d",
+ "sha256:9102b59e8337f9874638fcfc9ac3734a0cfadb100e47d55c20d0dc6087fb4692",
+ "sha256:9b930776c0ae0c691776f4d2891ebc5362af86f152dd0da463a6614074cb1b02",
+ "sha256:b3b9ad80f8b68519cc3372a6ca85ae02cc5a8807723ac366b53c0f089db19e4a",
+ "sha256:bc2f976c0e918659f723401c4f834deb8a8e7798a71be4382e024bcc3f7e23a8",
+ "sha256:c22c75b5f394f3d47105045ea551e08a3e804dc7e01b37800ca35b58f856c3d6",
+ "sha256:c52ce2883dc193824989a9b97a76ca86ecd1fa7955b14f87bf367a61b6232511",
+ "sha256:ce584af5de8830d8701b8979b18fcf450cef9a382b1a3c8ef189bedc408faf1e",
+ "sha256:da456eeec17fa8aa4594d9a9f27c0b1060b6a75f2419fe0c00609587b2695f4a",
+ "sha256:db6db0f45d2c63ddb1a9d18d1b9b22f308e52c83638c26b422d520a815c4b3fb",
+ "sha256:df89642981b94e7db5596818499c4b2219028f2a528c9c37cc1de45bf2fd3a3f",
+ "sha256:f18d68f2be6bf0e89f1521af2b1bb46e66ab0018faafa81d70f358153170a317",
+ "sha256:f379b7f83f23fe12823085cd6b906edc49df969eb99757f58ff382349a3303c6"
],
"markers": "python_version >= '3.5'",
- "version": "==1.4.2"
+ "version": "==1.5.1"
}
},
"develop": {
@@ -710,51 +705,51 @@
},
"cfgv": {
"hashes": [
- "sha256:1ccf53320421aeeb915275a196e23b3b8ae87dea8ac6698b1638001d4a486d53",
- "sha256:c8e8f552ffcc6194f4e18dd4f68d9aef0c0d58ae7e7be8c82bee3c5e9edfa513"
+ "sha256:32e43d604bbe7896fe7c248a9c2276447dbef840feb28fe20494f62af110211d",
+ "sha256:cf22deb93d4bcf92f345a5c3cd39d3d41d6340adc60c78bbbd6588c384fda6a1"
],
"markers": "python_full_version >= '3.6.1'",
- "version": "==3.1.0"
+ "version": "==3.2.0"
},
"coverage": {
"hashes": [
- "sha256:0fc4e0d91350d6f43ef6a61f64a48e917637e1dcfcba4b4b7d543c628ef82c2d",
- "sha256:10f2a618a6e75adf64329f828a6a5b40244c1c50f5ef4ce4109e904e69c71bd2",
- "sha256:12eaccd86d9a373aea59869bc9cfa0ab6ba8b1477752110cb4c10d165474f703",
- "sha256:1874bdc943654ba46d28f179c1846f5710eda3aeb265ff029e0ac2b52daae404",
- "sha256:1dcebae667b73fd4aa69237e6afb39abc2f27520f2358590c1b13dd90e32abe7",
- "sha256:1e58fca3d9ec1a423f1b7f2aa34af4f733cbfa9020c8fe39ca451b6071237405",
- "sha256:214eb2110217f2636a9329bc766507ab71a3a06a8ea30cdeebb47c24dce5972d",
- "sha256:25fe74b5b2f1b4abb11e103bb7984daca8f8292683957d0738cd692f6a7cc64c",
- "sha256:32ecee61a43be509b91a526819717d5e5650e009a8d5eda8631a59c721d5f3b6",
- "sha256:3740b796015b889e46c260ff18b84683fa2e30f0f75a171fb10d2bf9fb91fc70",
- "sha256:3b2c34690f613525672697910894b60d15800ac7e779fbd0fccf532486c1ba40",
- "sha256:41d88736c42f4a22c494c32cc48a05828236e37c991bd9760f8923415e3169e4",
- "sha256:42fa45a29f1059eda4d3c7b509589cc0343cd6bbf083d6118216830cd1a51613",
- "sha256:4bb385a747e6ae8a65290b3df60d6c8a692a5599dc66c9fa3520e667886f2e10",
- "sha256:509294f3e76d3f26b35083973fbc952e01e1727656d979b11182f273f08aa80b",
- "sha256:5c74c5b6045969b07c9fb36b665c9cac84d6c174a809fc1b21bdc06c7836d9a0",
- "sha256:60a3d36297b65c7f78329b80120f72947140f45b5c7a017ea730f9112b40f2ec",
- "sha256:6f91b4492c5cde83bfe462f5b2b997cdf96a138f7c58b1140f05de5751623cf1",
- "sha256:7403675df5e27745571aba1c957c7da2dacb537c21e14007ec3a417bf31f7f3d",
- "sha256:87bdc8135b8ee739840eee19b184804e5d57f518578ffc797f5afa2c3c297913",
- "sha256:8a3decd12e7934d0254939e2bf434bf04a5890c5bf91a982685021786a08087e",
- "sha256:9702e2cb1c6dec01fb8e1a64c015817c0800a6eca287552c47a5ee0ebddccf62",
- "sha256:a4d511012beb967a39580ba7d2549edf1e6865a33e5fe51e4dce550522b3ac0e",
- "sha256:bbb387811f7a18bdc61a2ea3d102be0c7e239b0db9c83be7bfa50f095db5b92a",
- "sha256:bfcc811883699ed49afc58b1ed9f80428a18eb9166422bce3c31a53dba00fd1d",
- "sha256:c32aa13cc3fe86b0f744dfe35a7f879ee33ac0a560684fef0f3e1580352b818f",
- "sha256:ca63dae130a2e788f2b249200f01d7fa240f24da0596501d387a50e57aa7075e",
- "sha256:d54d7ea74cc00482a2410d63bf10aa34ebe1c49ac50779652106c867f9986d6b",
- "sha256:d67599521dff98ec8c34cd9652cbcfe16ed076a2209625fca9dc7419b6370e5c",
- "sha256:d82db1b9a92cb5c67661ca6616bdca6ff931deceebb98eecbd328812dab52032",
- "sha256:d9ad0a988ae20face62520785ec3595a5e64f35a21762a57d115dae0b8fb894a",
- "sha256:ebf2431b2d457ae5217f3a1179533c456f3272ded16f8ed0b32961a6d90e38ee",
- "sha256:ed9a21502e9223f563e071759f769c3d6a2e1ba5328c31e86830368e8d78bc9c",
- "sha256:f50632ef2d749f541ca8e6c07c9928a37f87505ce3a9f20c8446ad310f1aa87b"
- ],
- "index": "pypi",
- "version": "==5.2"
+ "sha256:098a703d913be6fbd146a8c50cc76513d726b022d170e5e98dc56d958fd592fb",
+ "sha256:16042dc7f8e632e0dcd5206a5095ebd18cb1d005f4c89694f7f8aafd96dd43a3",
+ "sha256:1adb6be0dcef0cf9434619d3b892772fdb48e793300f9d762e480e043bd8e716",
+ "sha256:27ca5a2bc04d68f0776f2cdcb8bbd508bbe430a7bf9c02315cd05fb1d86d0034",
+ "sha256:28f42dc5172ebdc32622a2c3f7ead1b836cdbf253569ae5673f499e35db0bac3",
+ "sha256:2fcc8b58953d74d199a1a4d633df8146f0ac36c4e720b4a1997e9b6327af43a8",
+ "sha256:304fbe451698373dc6653772c72c5d5e883a4aadaf20343592a7abb2e643dae0",
+ "sha256:30bc103587e0d3df9e52cd9da1dd915265a22fad0b72afe54daf840c984b564f",
+ "sha256:40f70f81be4d34f8d491e55936904db5c527b0711b2a46513641a5729783c2e4",
+ "sha256:4186fc95c9febeab5681bc3248553d5ec8c2999b8424d4fc3a39c9cba5796962",
+ "sha256:46794c815e56f1431c66d81943fa90721bb858375fb36e5903697d5eef88627d",
+ "sha256:4869ab1c1ed33953bb2433ce7b894a28d724b7aa76c19b11e2878034a4e4680b",
+ "sha256:4f6428b55d2916a69f8d6453e48a505c07b2245653b0aa9f0dee38785939f5e4",
+ "sha256:52f185ffd3291196dc1aae506b42e178a592b0b60a8610b108e6ad892cfc1bb3",
+ "sha256:538f2fd5eb64366f37c97fdb3077d665fa946d2b6d95447622292f38407f9258",
+ "sha256:64c4f340338c68c463f1b56e3f2f0423f7b17ba6c3febae80b81f0e093077f59",
+ "sha256:675192fca634f0df69af3493a48224f211f8db4e84452b08d5fcebb9167adb01",
+ "sha256:700997b77cfab016533b3e7dbc03b71d33ee4df1d79f2463a318ca0263fc29dd",
+ "sha256:8505e614c983834239f865da2dd336dcf9d72776b951d5dfa5ac36b987726e1b",
+ "sha256:962c44070c281d86398aeb8f64e1bf37816a4dfc6f4c0f114756b14fc575621d",
+ "sha256:9e536783a5acee79a9b308be97d3952b662748c4037b6a24cbb339dc7ed8eb89",
+ "sha256:9ea749fd447ce7fb1ac71f7616371f04054d969d412d37611716721931e36efd",
+ "sha256:a34cb28e0747ea15e82d13e14de606747e9e484fb28d63c999483f5d5188e89b",
+ "sha256:a3ee9c793ffefe2944d3a2bd928a0e436cd0ac2d9e3723152d6fd5398838ce7d",
+ "sha256:aab75d99f3f2874733946a7648ce87a50019eb90baef931698f96b76b6769a46",
+ "sha256:b1ed2bdb27b4c9fc87058a1cb751c4df8752002143ed393899edb82b131e0546",
+ "sha256:b360d8fd88d2bad01cb953d81fd2edd4be539df7bfec41e8753fe9f4456a5082",
+ "sha256:b8f58c7db64d8f27078cbf2a4391af6aa4e4767cc08b37555c4ae064b8558d9b",
+ "sha256:c1bbb628ed5192124889b51204de27c575b3ffc05a5a91307e7640eff1d48da4",
+ "sha256:c2ff24df02a125b7b346c4c9078c8936da06964cc2d276292c357d64378158f8",
+ "sha256:c890728a93fffd0407d7d37c1e6083ff3f9f211c83b4316fae3778417eab9811",
+ "sha256:c96472b8ca5dc135fb0aa62f79b033f02aa434fb03a8b190600a5ae4102df1fd",
+ "sha256:ce7866f29d3025b5b34c2e944e66ebef0d92e4a4f2463f7266daa03a1332a651",
+ "sha256:e26c993bd4b220429d4ec8c1468eca445a4064a61c74ca08da7429af9bc53bb0"
+ ],
+ "index": "pypi",
+ "version": "==5.2.1"
},
"distlib": {
"hashes": [
@@ -780,11 +775,11 @@
},
"flake8-annotations": {
"hashes": [
- "sha256:babc81a17a5f1a63464195917e20d3e8663fb712b3633d4522dbfc407cff31b3",
- "sha256:fcd833b415726a7a374922c95a5c47a7a4d8ea71cb4a586369c665e7476146e1"
+ "sha256:7816a5d8f65ffdf37b8e21e5b17e0fd1e492aa92638573276de066e889a22b26",
+ "sha256:8d18db74a750dd97f40b483cc3ef80d07d03f687525bad8fd83365dcd3bfd414"
],
"index": "pypi",
- "version": "==2.2.0"
+ "version": "==2.3.0"
},
"flake8-bugbear": {
"hashes": [
@@ -842,11 +837,11 @@
},
"identify": {
"hashes": [
- "sha256:c4d07f2b979e3931894170a9e0d4b8281e6905ea6d018c326f7ffefaf20db680",
- "sha256:dac33eff90d57164e289fb20bf4e131baef080947ee9bf45efcd0da8d19064bf"
+ "sha256:110ed090fec6bce1aabe3c72d9258a9de82207adeaa5a05cd75c635880312f9a",
+ "sha256:ccd88716b890ecbe10920659450a635d2d25de499b9a638525a48b48261d989b"
],
"markers": "python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3'",
- "version": "==1.4.21"
+ "version": "==1.4.25"
},
"mccabe": {
"hashes": [
@@ -950,11 +945,11 @@
},
"virtualenv": {
"hashes": [
- "sha256:c11a475400e98450403c0364eb3a2d25d42f71cf1493da64390487b666de4324",
- "sha256:e10cc66f40cbda459720dfe1d334c4dc15add0d80f09108224f171006a97a172"
+ "sha256:7b54fd606a1b85f83de49ad8d80dbec08e983a2d2f96685045b262ebc7481ee5",
+ "sha256:8cd7b2a4850b003a11be2fc213e206419efab41115cc14bca20e69654f2ac08e"
],
"markers": "python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3'",
- "version": "==20.0.26"
+ "version": "==20.0.30"
}
}
}
diff --git a/bot/__init__.py b/bot/__init__.py
index d63086fe2..3ee70c4e9 100644
--- a/bot/__init__.py
+++ b/bot/__init__.py
@@ -2,10 +2,14 @@ import asyncio
import logging
import os
import sys
+from functools import partial, partialmethod
from logging import Logger, handlers
from pathlib import Path
import coloredlogs
+from discord.ext import commands
+
+from bot.command import Command
TRACE_LEVEL = logging.TRACE = 5
logging.addLevelName(TRACE_LEVEL, "TRACE")
@@ -66,3 +70,9 @@ logging.getLogger(__name__)
# On Windows, the selector event loop is required for aiodns.
if os.name == "nt":
asyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy())
+
+
+# Monkey-patch discord.py decorators to use the Command subclass which supports root aliases.
+# Must be patched before any cogs are added.
+commands.command = partial(commands.command, cls=Command)
+commands.GroupMixin.command = partialmethod(commands.GroupMixin.command, cls=Command)
diff --git a/bot/__main__.py b/bot/__main__.py
index 5382f5502..fe2cf90e6 100644
--- a/bot/__main__.py
+++ b/bot/__main__.py
@@ -34,21 +34,20 @@ bot = Bot(
)
# Internal/debug
+bot.load_extension("bot.cogs.config_verifier")
bot.load_extension("bot.cogs.error_handler")
bot.load_extension("bot.cogs.filtering")
bot.load_extension("bot.cogs.logging")
bot.load_extension("bot.cogs.security")
-bot.load_extension("bot.cogs.config_verifier")
# Commands, etc
bot.load_extension("bot.cogs.antimalware")
bot.load_extension("bot.cogs.antispam")
bot.load_extension("bot.cogs.bot")
bot.load_extension("bot.cogs.clean")
+bot.load_extension("bot.cogs.doc")
bot.load_extension("bot.cogs.extensions")
bot.load_extension("bot.cogs.help")
-
-bot.load_extension("bot.cogs.doc")
bot.load_extension("bot.cogs.verification")
# Feature cogs
@@ -57,11 +56,12 @@ bot.load_extension("bot.cogs.defcon")
bot.load_extension("bot.cogs.dm_relay")
bot.load_extension("bot.cogs.duck_pond")
bot.load_extension("bot.cogs.eval")
+bot.load_extension("bot.cogs.filter_lists")
bot.load_extension("bot.cogs.information")
bot.load_extension("bot.cogs.jams")
bot.load_extension("bot.cogs.moderation")
-bot.load_extension("bot.cogs.python_news")
bot.load_extension("bot.cogs.off_topic_names")
+bot.load_extension("bot.cogs.python_news")
bot.load_extension("bot.cogs.reddit")
bot.load_extension("bot.cogs.reminders")
bot.load_extension("bot.cogs.site")
@@ -74,7 +74,6 @@ bot.load_extension("bot.cogs.token_remover")
bot.load_extension("bot.cogs.utils")
bot.load_extension("bot.cogs.watchchannels")
bot.load_extension("bot.cogs.webhook_remover")
-bot.load_extension("bot.cogs.wolfram")
if constants.HelpChannels.enable:
bot.load_extension("bot.cogs.help_channels")
diff --git a/bot/bot.py b/bot/bot.py
index 313652d11..d25074fd9 100644
--- a/bot/bot.py
+++ b/bot/bot.py
@@ -2,7 +2,8 @@ import asyncio
import logging
import socket
import warnings
-from typing import Optional
+from collections import defaultdict
+from typing import Dict, Optional
import aiohttp
import aioredis
@@ -34,6 +35,7 @@ class Bot(commands.Bot):
self.redis_ready = asyncio.Event()
self.redis_closed = False
self.api_client = api.APIClient(loop=self.loop)
+ self.filter_list_cache = defaultdict(dict)
self._connector = None
self._resolver = None
@@ -49,6 +51,13 @@ class Bot(commands.Bot):
self.stats = AsyncStatsClient(self.loop, statsd_url, 8125, prefix="bot")
+ async def cache_filter_list_data(self) -> None:
+ """Cache all the data in the FilterList on the site."""
+ full_cache = await self.api_client.get('bot/filter-lists')
+
+ for item in full_cache:
+ self.insert_item_into_filter_list_cache(item)
+
async def _create_redis_session(self) -> None:
"""
Create the Redis connection pool, and then open the redis event gate.
@@ -73,11 +82,74 @@ class Bot(commands.Bot):
self.redis_closed = False
self.redis_ready.set()
+ def _recreate(self) -> None:
+ """Re-create the connector, aiohttp session, the APIClient and the Redis session."""
+ # Use asyncio for DNS resolution instead of threads so threads aren't spammed.
+ # Doesn't seem to have any state with regards to being closed, so no need to worry?
+ self._resolver = aiohttp.AsyncResolver()
+
+ # Its __del__ does send a warning but it doesn't always show up for some reason.
+ if self._connector and not self._connector._closed:
+ log.warning(
+ "The previous connector was not closed; it will remain open and be overwritten"
+ )
+
+ if self.redis_session and not self.redis_session.closed:
+ log.warning(
+ "The previous redis pool was not closed; it will remain open and be overwritten"
+ )
+
+ # Create the redis session
+ self.loop.create_task(self._create_redis_session())
+
+ # Use AF_INET as its socket family to prevent HTTPS related problems both locally
+ # and in production.
+ self._connector = aiohttp.TCPConnector(
+ resolver=self._resolver,
+ family=socket.AF_INET,
+ )
+
+ # Client.login() will call HTTPClient.static_login() which will create a session using
+ # this connector attribute.
+ self.http.connector = self._connector
+
+ # Its __del__ does send a warning but it doesn't always show up for some reason.
+ if self.http_session and not self.http_session.closed:
+ log.warning(
+ "The previous session was not closed; it will remain open and be overwritten"
+ )
+
+ self.http_session = aiohttp.ClientSession(connector=self._connector)
+ self.api_client.recreate(force=True, connector=self._connector)
+
+ # Build the FilterList cache
+ self.loop.create_task(self.cache_filter_list_data())
+
def add_cog(self, cog: commands.Cog) -> None:
"""Adds a "cog" to the bot and logs the operation."""
super().add_cog(cog)
log.info(f"Cog loaded: {cog.qualified_name}")
+ def add_command(self, command: commands.Command) -> None:
+ """Add `command` as normal and then add its root aliases to the bot."""
+ super().add_command(command)
+ self._add_root_aliases(command)
+
+ def remove_command(self, name: str) -> Optional[commands.Command]:
+ """
+ Remove a command/alias as normal and then remove its root aliases from the bot.
+
+ Individual root aliases cannot be removed by this function.
+ To remove them, either remove the entire command or manually edit `bot.all_commands`.
+ """
+ command = super().remove_command(name)
+ if command is None:
+ # Even if it's a root alias, there's no way to get the Bot instance to remove the alias.
+ return
+
+ self._remove_root_aliases(command)
+ return command
+
def clear(self) -> None:
"""
Clears the internal state of the bot and recreates the connector and sessions.
@@ -113,52 +185,25 @@ class Bot(commands.Bot):
self.redis_ready.clear()
await self.redis_session.wait_closed()
+ def insert_item_into_filter_list_cache(self, item: Dict[str, str]) -> None:
+ """Add an item to the bots filter_list_cache."""
+ type_ = item["type"]
+ allowed = item["allowed"]
+ content = item["content"]
+
+ self.filter_list_cache[f"{type_}.{allowed}"][content] = {
+ "id": item["id"],
+ "comment": item["comment"],
+ "created_at": item["created_at"],
+ "updated_at": item["updated_at"],
+ }
+
async def login(self, *args, **kwargs) -> None:
"""Re-create the connector and set up sessions before logging into Discord."""
self._recreate()
await self.stats.create_socket()
await super().login(*args, **kwargs)
- def _recreate(self) -> None:
- """Re-create the connector, aiohttp session, the APIClient and the Redis session."""
- # Use asyncio for DNS resolution instead of threads so threads aren't spammed.
- # Doesn't seem to have any state with regards to being closed, so no need to worry?
- self._resolver = aiohttp.AsyncResolver()
-
- # Its __del__ does send a warning but it doesn't always show up for some reason.
- if self._connector and not self._connector._closed:
- log.warning(
- "The previous connector was not closed; it will remain open and be overwritten"
- )
-
- if self.redis_session and not self.redis_session.closed:
- log.warning(
- "The previous redis pool was not closed; it will remain open and be overwritten"
- )
-
- # Create the redis session
- self.loop.create_task(self._create_redis_session())
-
- # Use AF_INET as its socket family to prevent HTTPS related problems both locally
- # and in production.
- self._connector = aiohttp.TCPConnector(
- resolver=self._resolver,
- family=socket.AF_INET,
- )
-
- # Client.login() will call HTTPClient.static_login() which will create a session using
- # this connector attribute.
- self.http.connector = self._connector
-
- # Its __del__ does send a warning but it doesn't always show up for some reason.
- if self.http_session and not self.http_session.closed:
- log.warning(
- "The previous session was not closed; it will remain open and be overwritten"
- )
-
- self.http_session = aiohttp.ClientSession(connector=self._connector)
- self.api_client.recreate(force=True, connector=self._connector)
-
async def on_guild_available(self, guild: discord.Guild) -> None:
"""
Set the internal guild available event when constants.Guild.id becomes available.
@@ -210,3 +255,24 @@ class Bot(commands.Bot):
scope.set_extra("kwargs", kwargs)
log.exception(f"Unhandled exception in {event}.")
+
+ def _add_root_aliases(self, command: commands.Command) -> None:
+ """Recursively add root aliases for `command` and any of its subcommands."""
+ if isinstance(command, commands.Group):
+ for subcommand in command.commands:
+ self._add_root_aliases(subcommand)
+
+ for alias in getattr(command, "root_aliases", ()):
+ if alias in self.all_commands:
+ raise commands.CommandRegistrationError(alias, alias_conflict=True)
+
+ self.all_commands[alias] = command
+
+ def _remove_root_aliases(self, command: commands.Command) -> None:
+ """Recursively remove root aliases for `command` and any of its subcommands."""
+ if isinstance(command, commands.Group):
+ for subcommand in command.commands:
+ self._remove_root_aliases(subcommand)
+
+ for alias in getattr(command, "root_aliases", ()):
+ self.all_commands.pop(alias, None)
diff --git a/bot/cogs/alias.py b/bot/cogs/alias.py
index 55c7efe65..c6ba8d6f3 100644
--- a/bot/cogs/alias.py
+++ b/bot/cogs/alias.py
@@ -3,13 +3,12 @@ import logging
from discord import Colour, Embed
from discord.ext.commands import (
- Cog, Command, Context, Greedy,
+ Cog, Command, Context,
clean_content, command, group,
)
from bot.bot import Bot
-from bot.cogs.extensions import Extension
-from bot.converters import FetchedMember, TagNameConverter
+from bot.converters import TagNameConverter
from bot.pagination import LinePaginator
log = logging.getLogger(__name__)
@@ -51,56 +50,6 @@ class Alias (Cog):
ctx, embed, empty=False, max_lines=20
)
- @command(name="resources", aliases=("resource",), hidden=True)
- async def site_resources_alias(self, ctx: Context) -> None:
- """Alias for invoking <prefix>site resources."""
- await self.invoke(ctx, "site resources")
-
- @command(name="tools", hidden=True)
- async def site_tools_alias(self, ctx: Context) -> None:
- """Alias for invoking <prefix>site tools."""
- await self.invoke(ctx, "site tools")
-
- @command(name="watch", hidden=True)
- async def bigbrother_watch_alias(self, ctx: Context, user: FetchedMember, *, reason: str) -> None:
- """Alias for invoking <prefix>bigbrother watch [user] [reason]."""
- await self.invoke(ctx, "bigbrother watch", user, reason=reason)
-
- @command(name="unwatch", hidden=True)
- async def bigbrother_unwatch_alias(self, ctx: Context, user: FetchedMember, *, reason: str) -> None:
- """Alias for invoking <prefix>bigbrother unwatch [user] [reason]."""
- await self.invoke(ctx, "bigbrother unwatch", user, reason=reason)
-
- @command(name="home", hidden=True)
- async def site_home_alias(self, ctx: Context) -> None:
- """Alias for invoking <prefix>site home."""
- await self.invoke(ctx, "site home")
-
- @command(name="faq", hidden=True)
- async def site_faq_alias(self, ctx: Context) -> None:
- """Alias for invoking <prefix>site faq."""
- await self.invoke(ctx, "site faq")
-
- @command(name="rules", aliases=("rule",), hidden=True)
- async def site_rules_alias(self, ctx: Context, rules: Greedy[int], *_: str) -> None:
- """Alias for invoking <prefix>site rules."""
- await self.invoke(ctx, "site rules", *rules)
-
- @command(name="reload", hidden=True)
- async def extensions_reload_alias(self, ctx: Context, *extensions: Extension) -> None:
- """Alias for invoking <prefix>extensions reload [extensions...]."""
- await self.invoke(ctx, "extensions reload", *extensions)
-
- @command(name="defon", hidden=True)
- async def defcon_enable_alias(self, ctx: Context) -> None:
- """Alias for invoking <prefix>defcon enable."""
- await self.invoke(ctx, "defcon enable")
-
- @command(name="defoff", hidden=True)
- async def defcon_disable_alias(self, ctx: Context) -> None:
- """Alias for invoking <prefix>defcon disable."""
- await self.invoke(ctx, "defcon disable")
-
@command(name="exception", hidden=True)
async def tags_get_traceback_alias(self, ctx: Context) -> None:
"""Alias for invoking <prefix>tags get traceback."""
@@ -132,21 +81,6 @@ class Alias (Cog):
"""Alias for invoking <prefix>docs get [symbol]."""
await self.invoke(ctx, "docs get", symbol)
- @command(name="nominate", hidden=True)
- async def nomination_add_alias(self, ctx: Context, user: FetchedMember, *, reason: str) -> None:
- """Alias for invoking <prefix>talentpool add [user] [reason]."""
- await self.invoke(ctx, "talentpool add", user, reason=reason)
-
- @command(name="unnominate", hidden=True)
- async def nomination_end_alias(self, ctx: Context, user: FetchedMember, *, reason: str) -> None:
- """Alias for invoking <prefix>nomination end [user] [reason]."""
- await self.invoke(ctx, "nomination end", user, reason=reason)
-
- @command(name="nominees", hidden=True)
- async def nominees_alias(self, ctx: Context) -> None:
- """Alias for invoking <prefix>tp watched."""
- await self.invoke(ctx, "talentpool watched")
-
def setup(bot: Bot) -> None:
"""Load the Alias cog."""
diff --git a/bot/cogs/antimalware.py b/bot/cogs/antimalware.py
index ea257442e..7894ec48f 100644
--- a/bot/cogs/antimalware.py
+++ b/bot/cogs/antimalware.py
@@ -6,7 +6,7 @@ from discord import Embed, Message, NotFound
from discord.ext.commands import Cog
from bot.bot import Bot
-from bot.constants import AntiMalware as AntiMalwareConfig, Channels, STAFF_ROLES, URLs
+from bot.constants import Channels, STAFF_ROLES, URLs
log = logging.getLogger(__name__)
@@ -27,7 +27,7 @@ TXT_EMBED_DESCRIPTION = (
DISALLOWED_EMBED_DESCRIPTION = (
"It looks like you tried to attach file type(s) that we do not allow ({blocked_extensions_str}). "
- f"We currently allow the following file types: **{', '.join(AntiMalwareConfig.whitelist)}**.\n\n"
+ "We currently allow the following file types: **{joined_whitelist}**.\n\n"
"Feel free to ask in {meta_channel_mention} if you think this is a mistake."
)
@@ -38,6 +38,16 @@ class AntiMalware(Cog):
def __init__(self, bot: Bot):
self.bot = bot
+ def _get_whitelisted_file_formats(self) -> list:
+ """Get the file formats currently on the whitelist."""
+ return self.bot.filter_list_cache['FILE_FORMAT.True'].keys()
+
+ def _get_disallowed_extensions(self, message: Message) -> t.Iterable[str]:
+ """Get an iterable containing all the disallowed extensions of attachments."""
+ file_extensions = {splitext(attachment.filename.lower())[1] for attachment in message.attachments}
+ extensions_blocked = file_extensions - set(self._get_whitelisted_file_formats())
+ return extensions_blocked
+
@Cog.listener()
async def on_message(self, message: Message) -> None:
"""Identify messages with prohibited attachments."""
@@ -45,13 +55,17 @@ class AntiMalware(Cog):
if not message.attachments or not message.guild:
return
+ # Ignore webhook and bot messages
+ if message.webhook_id or message.author.bot:
+ return
+
# Check if user is staff, if is, return
# Since we only care that roles exist to iterate over, check for the attr rather than a User/Member instance
if hasattr(message.author, "roles") and any(role.id in STAFF_ROLES for role in message.author.roles):
return
embed = Embed()
- extensions_blocked = self.get_disallowed_extensions(message)
+ extensions_blocked = self._get_disallowed_extensions(message)
blocked_extensions_str = ', '.join(extensions_blocked)
if ".py" in extensions_blocked:
# Short-circuit on *.py files to provide a pastebin link
@@ -63,6 +77,7 @@ class AntiMalware(Cog):
elif extensions_blocked:
meta_channel = self.bot.get_channel(Channels.meta)
embed.description = DISALLOWED_EMBED_DESCRIPTION.format(
+ joined_whitelist=', '.join(self._get_whitelisted_file_formats()),
blocked_extensions_str=blocked_extensions_str,
meta_channel_mention=meta_channel.mention,
)
@@ -81,13 +96,6 @@ class AntiMalware(Cog):
except NotFound:
log.info(f"Tried to delete message `{message.id}`, but message could not be found.")
- @classmethod
- def get_disallowed_extensions(cls, message: Message) -> t.Iterable[str]:
- """Get an iterable containing all the disallowed extensions of attachments."""
- file_extensions = {splitext(attachment.filename.lower())[1] for attachment in message.attachments}
- extensions_blocked = file_extensions - set(AntiMalwareConfig.whitelist)
- return extensions_blocked
-
def setup(bot: Bot) -> None:
"""Load the AntiMalware cog."""
diff --git a/bot/cogs/antispam.py b/bot/cogs/antispam.py
index 0bcca578d..3ad487d8c 100644
--- a/bot/cogs/antispam.py
+++ b/bot/cogs/antispam.py
@@ -27,14 +27,18 @@ log = logging.getLogger(__name__)
RULE_FUNCTION_MAPPING = {
'attachments': rules.apply_attachments,
'burst': rules.apply_burst,
- 'burst_shared': rules.apply_burst_shared,
+ # burst shared is temporarily disabled due to a bug
+ # 'burst_shared': rules.apply_burst_shared,
'chars': rules.apply_chars,
'discord_emojis': rules.apply_discord_emojis,
'duplicates': rules.apply_duplicates,
'links': rules.apply_links,
'mentions': rules.apply_mentions,
'newlines': rules.apply_newlines,
- 'role_mentions': rules.apply_role_mentions
+ 'role_mentions': rules.apply_role_mentions,
+ # the everyone filter is temporarily disabled until
+ # it has been improved.
+ # 'everyone_ping': rules.apply_everyone_ping,
}
@@ -219,7 +223,6 @@ class AntiSpam(Cog):
# Get context and make sure the bot becomes the actor of infraction by patching the `author` attributes
context = await self.bot.get_context(msg)
context.author = self.bot.user
- context.message.author = self.bot.user
# Since we're going to invoke the tempmute command directly, we need to manually call the converter.
dt_remove_role_after = await self.expiration_date_converter.convert(context, f"{remove_role_after}S")
diff --git a/bot/cogs/bot.py b/bot/cogs/bot.py
index 79510739c..ddd1cef8d 100644
--- a/bot/cogs/bot.py
+++ b/bot/cogs/bot.py
@@ -9,6 +9,7 @@ from discord.ext.commands import Cog, Context, command, group
from bot.bot import Bot
from bot.cogs.token_remover import TokenRemover
+from bot.cogs.webhook_remover import WEBHOOK_URL_RE
from bot.constants import Categories, Channels, DEBUG_MODE, Guild, MODERATION_ROLES, Roles, URLs
from bot.decorators import with_role
from bot.utils.messages import wait_for_deletion
@@ -240,6 +241,7 @@ class BotCog(Cog, name="Bot"):
and not msg.author.bot
and len(msg.content.splitlines()) > 3
and not TokenRemover.find_token_in_message(msg)
+ and not WEBHOOK_URL_RE.search(msg.content)
)
if parse_codeblock: # no token in the msg
@@ -337,7 +339,7 @@ class BotCog(Cog, name="Bot"):
self.codeblock_message_ids[msg.id] = bot_message.id
self.bot.loop.create_task(
- wait_for_deletion(bot_message, user_ids=(msg.author.id,), client=self.bot)
+ wait_for_deletion(bot_message, (msg.author.id,), self.bot)
)
else:
return
diff --git a/bot/cogs/defcon.py b/bot/cogs/defcon.py
index 4c0ad5914..9087ac454 100644
--- a/bot/cogs/defcon.py
+++ b/bot/cogs/defcon.py
@@ -10,7 +10,7 @@ from discord.ext.commands import Cog, Context, group
from bot.bot import Bot
from bot.cogs.moderation import ModLog
-from bot.constants import Channels, Colours, Emojis, Event, Icons, Roles
+from bot.constants import Channels, Colours, Emojis, Event, Icons, MODERATION_ROLES, Roles
from bot.decorators import with_role
log = logging.getLogger(__name__)
@@ -119,7 +119,7 @@ class Defcon(Cog):
)
@group(name='defcon', aliases=('dc',), invoke_without_command=True)
- @with_role(Roles.admins, Roles.owners)
+ @with_role(*MODERATION_ROLES)
async def defcon_group(self, ctx: Context) -> None:
"""Check the DEFCON status or run a subcommand."""
await ctx.send_help(ctx.command)
@@ -162,8 +162,8 @@ class Defcon(Cog):
self.bot.stats.gauge("defcon.threshold", days)
- @defcon_group.command(name='enable', aliases=('on', 'e'))
- @with_role(Roles.admins, Roles.owners)
+ @defcon_group.command(name='enable', aliases=('on', 'e'), root_aliases=("defon",))
+ @with_role(*MODERATION_ROLES)
async def enable_command(self, ctx: Context) -> None:
"""
Enable DEFCON mode. Useful in a pinch, but be sure you know what you're doing!
@@ -175,8 +175,8 @@ class Defcon(Cog):
await self._defcon_action(ctx, days=0, action=Action.ENABLED)
await self.update_channel_topic()
- @defcon_group.command(name='disable', aliases=('off', 'd'))
- @with_role(Roles.admins, Roles.owners)
+ @defcon_group.command(name='disable', aliases=('off', 'd'), root_aliases=("defoff",))
+ @with_role(*MODERATION_ROLES)
async def disable_command(self, ctx: Context) -> None:
"""Disable DEFCON mode. Useful in a pinch, but be sure you know what you're doing!"""
self.enabled = False
@@ -184,7 +184,7 @@ class Defcon(Cog):
await self.update_channel_topic()
@defcon_group.command(name='status', aliases=('s',))
- @with_role(Roles.admins, Roles.owners)
+ @with_role(*MODERATION_ROLES)
async def status_command(self, ctx: Context) -> None:
"""Check the current status of DEFCON mode."""
embed = Embed(
@@ -196,7 +196,7 @@ class Defcon(Cog):
await ctx.send(embed=embed)
@defcon_group.command(name='days')
- @with_role(Roles.admins, Roles.owners)
+ @with_role(*MODERATION_ROLES)
async def days_command(self, ctx: Context, days: int) -> None:
"""Set how old an account must be to join the server, in days, with DEFCON mode enabled."""
self.days = timedelta(days=days)
diff --git a/bot/cogs/doc.py b/bot/cogs/doc.py
index 204cffb37..30c793c75 100644
--- a/bot/cogs/doc.py
+++ b/bot/cogs/doc.py
@@ -23,6 +23,7 @@ from bot.constants import MODERATION_ROLES, RedirectOutput
from bot.converters import ValidPythonIdentifier, ValidURL
from bot.decorators import with_role
from bot.pagination import LinePaginator
+from bot.utils.messages import wait_for_deletion
log = logging.getLogger(__name__)
@@ -391,7 +392,8 @@ class Doc(commands.Cog):
await error_message.delete(delay=NOT_FOUND_DELETE_DELAY)
await ctx.message.delete(delay=NOT_FOUND_DELETE_DELAY)
else:
- await ctx.send(embed=doc_embed)
+ msg = await ctx.send(embed=doc_embed)
+ await wait_for_deletion(msg, (ctx.author.id,), client=self.bot)
@docs_group.command(name='set', aliases=('s',))
@with_role(*MODERATION_ROLES)
diff --git a/bot/cogs/error_handler.py b/bot/cogs/error_handler.py
index a9c6d50b7..c643d346e 100644
--- a/bot/cogs/error_handler.py
+++ b/bot/cogs/error_handler.py
@@ -2,12 +2,13 @@ import contextlib
import logging
import typing as t
+from discord import Embed
from discord.ext.commands import Cog, Context, errors
from sentry_sdk import push_scope
from bot.api import ResponseCodeError
from bot.bot import Bot
-from bot.constants import Channels
+from bot.constants import Channels, Colours
from bot.converters import TagNameConverter
from bot.errors import LockedResourceError
from bot.utils.checks import InWhitelistCheckFailure
@@ -21,6 +22,14 @@ class ErrorHandler(Cog):
def __init__(self, bot: Bot):
self.bot = bot
+ def _get_error_embed(self, title: str, body: str) -> Embed:
+ """Return an embed that contains the exception."""
+ return Embed(
+ title=title,
+ colour=Colours.soft_red,
+ description=body
+ )
+
@Cog.listener()
async def on_command_error(self, ctx: Context, e: errors.CommandError) -> None:
"""
@@ -165,25 +174,34 @@ class ErrorHandler(Cog):
prepared_help_command = self.get_help_command(ctx)
if isinstance(e, errors.MissingRequiredArgument):
- await ctx.send(f"Missing required argument `{e.param.name}`.")
+ embed = self._get_error_embed("Missing required argument", e.param.name)
+ await ctx.send(embed=embed)
await prepared_help_command
self.bot.stats.incr("errors.missing_required_argument")
elif isinstance(e, errors.TooManyArguments):
- await ctx.send("Too many arguments provided.")
+ embed = self._get_error_embed("Too many arguments", str(e))
+ await ctx.send(embed=embed)
await prepared_help_command
self.bot.stats.incr("errors.too_many_arguments")
elif isinstance(e, errors.BadArgument):
- await ctx.send("Bad argument: Please double-check your input arguments and try again.\n")
+ embed = self._get_error_embed("Bad argument", str(e))
+ await ctx.send(embed=embed)
await prepared_help_command
self.bot.stats.incr("errors.bad_argument")
elif isinstance(e, errors.BadUnionArgument):
- await ctx.send(f"Bad argument: {e}\n```{e.errors[-1]}```")
+ embed = self._get_error_embed("Bad argument", f"{e}\n{e.errors[-1]}")
+ await ctx.send(embed=embed)
self.bot.stats.incr("errors.bad_union_argument")
elif isinstance(e, errors.ArgumentParsingError):
- await ctx.send(f"Argument parsing error: {e}")
+ embed = self._get_error_embed("Argument parsing error", str(e))
+ await ctx.send(embed=embed)
self.bot.stats.incr("errors.argument_parsing_error")
else:
- await ctx.send("Something about your input seems off. Check the arguments:")
+ embed = self._get_error_embed(
+ "Input error",
+ "Something about your input seems off. Check the arguments and try again."
+ )
+ await ctx.send(embed=embed)
await prepared_help_command
self.bot.stats.incr("errors.other_user_input_error")
diff --git a/bot/cogs/extensions.py b/bot/cogs/extensions.py
index 365f198ff..396e406b0 100644
--- a/bot/cogs/extensions.py
+++ b/bot/cogs/extensions.py
@@ -107,7 +107,7 @@ class Extensions(commands.Cog):
await ctx.send(msg)
- @extensions_group.command(name="reload", aliases=("r",))
+ @extensions_group.command(name="reload", aliases=("r",), root_aliases=("reload",))
async def reload_command(self, ctx: Context, *extensions: Extension) -> None:
r"""
Reload extensions given their fully qualified or unqualified names.
diff --git a/bot/cogs/filter_lists.py b/bot/cogs/filter_lists.py
new file mode 100644
index 000000000..c15adc461
--- /dev/null
+++ b/bot/cogs/filter_lists.py
@@ -0,0 +1,273 @@
+import logging
+from typing import Optional
+
+from discord import Colour, Embed
+from discord.ext.commands import BadArgument, Cog, Context, IDConverter, group
+
+from bot import constants
+from bot.api import ResponseCodeError
+from bot.bot import Bot
+from bot.converters import ValidDiscordServerInvite, ValidFilterListType
+from bot.pagination import LinePaginator
+from bot.utils.checks import with_role_check
+
+log = logging.getLogger(__name__)
+
+
+class FilterLists(Cog):
+ """Commands for blacklisting and whitelisting things."""
+
+ methods_with_filterlist_types = [
+ "allow_add",
+ "allow_delete",
+ "allow_get",
+ "deny_add",
+ "deny_delete",
+ "deny_get",
+ ]
+
+ def __init__(self, bot: Bot) -> None:
+ self.bot = bot
+ self.bot.loop.create_task(self._amend_docstrings())
+
+ async def _amend_docstrings(self) -> None:
+ """Add the valid FilterList types to the docstrings, so they'll appear in !help invocations."""
+ await self.bot.wait_until_guild_available()
+
+ # Add valid filterlist types to the docstrings
+ valid_types = await ValidFilterListType.get_valid_types(self.bot)
+ valid_types = [f"`{type_.lower()}`" for type_ in valid_types]
+
+ for method_name in self.methods_with_filterlist_types:
+ command = getattr(self, method_name)
+ command.help = (
+ f"{command.help}\n\nValid **list_type** values are {', '.join(valid_types)}."
+ )
+
+ async def _add_data(
+ self,
+ ctx: Context,
+ allowed: bool,
+ list_type: ValidFilterListType,
+ content: str,
+ comment: Optional[str] = None,
+ ) -> None:
+ """Add an item to a filterlist."""
+ allow_type = "whitelist" if allowed else "blacklist"
+
+ # If this is a server invite, we gotta validate it.
+ if list_type == "GUILD_INVITE":
+ guild_data = await self._validate_guild_invite(ctx, content)
+ content = guild_data.get("id")
+
+ # Unless the user has specified another comment, let's
+ # use the server name as the comment so that the list
+ # of guild IDs will be more easily readable when we
+ # display it.
+ if not comment:
+ comment = guild_data.get("name")
+
+ # If it's a file format, let's make sure it has a leading dot.
+ elif list_type == "FILE_FORMAT" and not content.startswith("."):
+ content = f".{content}"
+
+ # Try to add the item to the database
+ log.trace(f"Trying to add the {content} item to the {list_type} {allow_type}")
+ payload = {
+ "allowed": allowed,
+ "type": list_type,
+ "content": content,
+ "comment": comment,
+ }
+
+ try:
+ item = await self.bot.api_client.post(
+ "bot/filter-lists",
+ json=payload
+ )
+ except ResponseCodeError as e:
+ if e.status == 400:
+ await ctx.message.add_reaction("❌")
+ log.debug(
+ f"{ctx.author} tried to add data to a {allow_type}, but the API returned 400, "
+ "probably because the request violated the UniqueConstraint."
+ )
+ raise BadArgument(
+ f"Unable to add the item to the {allow_type}. "
+ "The item probably already exists. Keep in mind that a "
+ "blacklist and a whitelist for the same item cannot co-exist, "
+ "and we do not permit any duplicates."
+ )
+ raise
+
+ # Insert the item into the cache
+ self.bot.insert_item_into_filter_list_cache(item)
+ await ctx.message.add_reaction("✅")
+
+ async def _delete_data(self, ctx: Context, allowed: bool, list_type: ValidFilterListType, content: str) -> None:
+ """Remove an item from a filterlist."""
+ allow_type = "whitelist" if allowed else "blacklist"
+
+ # If this is a server invite, we need to convert it.
+ if list_type == "GUILD_INVITE" and not IDConverter()._get_id_match(content):
+ guild_data = await self._validate_guild_invite(ctx, content)
+ content = guild_data.get("id")
+
+ # If it's a file format, let's make sure it has a leading dot.
+ elif list_type == "FILE_FORMAT" and not content.startswith("."):
+ content = f".{content}"
+
+ # Find the content and delete it.
+ log.trace(f"Trying to delete the {content} item from the {list_type} {allow_type}")
+ item = self.bot.filter_list_cache[f"{list_type}.{allowed}"].get(content)
+
+ if item is not None:
+ try:
+ await self.bot.api_client.delete(
+ f"bot/filter-lists/{item['id']}"
+ )
+ del self.bot.filter_list_cache[f"{list_type}.{allowed}"][content]
+ await ctx.message.add_reaction("✅")
+ except ResponseCodeError as e:
+ log.debug(
+ f"{ctx.author} tried to delete an item with the id {item['id']}, but "
+ f"the API raised an unexpected error: {e}"
+ )
+ await ctx.message.add_reaction("❌")
+ else:
+ await ctx.message.add_reaction("❌")
+
+ async def _list_all_data(self, ctx: Context, allowed: bool, list_type: ValidFilterListType) -> None:
+ """Paginate and display all items in a filterlist."""
+ allow_type = "whitelist" if allowed else "blacklist"
+ result = self.bot.filter_list_cache[f"{list_type}.{allowed}"]
+
+ # Build a list of lines we want to show in the paginator
+ lines = []
+ for content, metadata in result.items():
+ line = f"• `{content}`"
+
+ if comment := metadata.get("comment"):
+ line += f" - {comment}"
+
+ lines.append(line)
+ lines = sorted(lines)
+
+ # Build the embed
+ list_type_plural = list_type.lower().replace("_", " ").title() + "s"
+ embed = Embed(
+ title=f"{allow_type.title()}ed {list_type_plural} ({len(result)} total)",
+ colour=Colour.blue()
+ )
+ log.trace(f"Trying to list {len(result)} items from the {list_type.lower()} {allow_type}")
+
+ if result:
+ await LinePaginator.paginate(lines, ctx, embed, max_lines=15, empty=False)
+ else:
+ embed.description = "Hmmm, seems like there's nothing here yet."
+ await ctx.send(embed=embed)
+ await ctx.message.add_reaction("❌")
+
+ async def _sync_data(self, ctx: Context) -> None:
+ """Syncs the filterlists with the API."""
+ try:
+ log.trace("Attempting to sync FilterList cache with data from the API.")
+ await self.bot.cache_filter_list_data()
+ await ctx.message.add_reaction("✅")
+ except ResponseCodeError as e:
+ log.debug(
+ f"{ctx.author} tried to sync FilterList cache data but "
+ f"the API raised an unexpected error: {e}"
+ )
+ await ctx.message.add_reaction("❌")
+
+ @staticmethod
+ async def _validate_guild_invite(ctx: Context, invite: str) -> dict:
+ """
+ Validates a guild invite, and returns the guild info as a dict.
+
+ Will raise a BadArgument if the guild invite is invalid.
+ """
+ log.trace(f"Attempting to validate whether or not {invite} is a guild invite.")
+ validator = ValidDiscordServerInvite()
+ guild_data = await validator.convert(ctx, invite)
+
+ # If we make it this far without raising a BadArgument, the invite is
+ # valid. Let's return a dict of guild information.
+ log.trace(f"{invite} validated as server invite. Converting to ID.")
+ return guild_data
+
+ @group(aliases=("allowlist", "allow", "al", "wl"))
+ async def whitelist(self, ctx: Context) -> None:
+ """Group for whitelisting commands."""
+ if not ctx.invoked_subcommand:
+ await ctx.send_help(ctx.command)
+
+ @group(aliases=("denylist", "deny", "bl", "dl"))
+ async def blacklist(self, ctx: Context) -> None:
+ """Group for blacklisting commands."""
+ if not ctx.invoked_subcommand:
+ await ctx.send_help(ctx.command)
+
+ @whitelist.command(name="add", aliases=("a", "set"))
+ async def allow_add(
+ self,
+ ctx: Context,
+ list_type: ValidFilterListType,
+ content: str,
+ *,
+ comment: Optional[str] = None,
+ ) -> None:
+ """Add an item to the specified allowlist."""
+ await self._add_data(ctx, True, list_type, content, comment)
+
+ @blacklist.command(name="add", aliases=("a", "set"))
+ async def deny_add(
+ self,
+ ctx: Context,
+ list_type: ValidFilterListType,
+ content: str,
+ *,
+ comment: Optional[str] = None,
+ ) -> None:
+ """Add an item to the specified denylist."""
+ await self._add_data(ctx, False, list_type, content, comment)
+
+ @whitelist.command(name="remove", aliases=("delete", "rm",))
+ async def allow_delete(self, ctx: Context, list_type: ValidFilterListType, content: str) -> None:
+ """Remove an item from the specified allowlist."""
+ await self._delete_data(ctx, True, list_type, content)
+
+ @blacklist.command(name="remove", aliases=("delete", "rm",))
+ async def deny_delete(self, ctx: Context, list_type: ValidFilterListType, content: str) -> None:
+ """Remove an item from the specified denylist."""
+ await self._delete_data(ctx, False, list_type, content)
+
+ @whitelist.command(name="get", aliases=("list", "ls", "fetch", "show"))
+ async def allow_get(self, ctx: Context, list_type: ValidFilterListType) -> None:
+ """Get the contents of a specified allowlist."""
+ await self._list_all_data(ctx, True, list_type)
+
+ @blacklist.command(name="get", aliases=("list", "ls", "fetch", "show"))
+ async def deny_get(self, ctx: Context, list_type: ValidFilterListType) -> None:
+ """Get the contents of a specified denylist."""
+ await self._list_all_data(ctx, False, list_type)
+
+ @whitelist.command(name="sync", aliases=("s",))
+ async def allow_sync(self, ctx: Context) -> None:
+ """Syncs both allowlists and denylists with the API."""
+ await self._sync_data(ctx)
+
+ @blacklist.command(name="sync", aliases=("s",))
+ async def deny_sync(self, ctx: Context) -> None:
+ """Syncs both allowlists and denylists with the API."""
+ await self._sync_data(ctx)
+
+ def cog_check(self, ctx: Context) -> bool:
+ """Only allow moderators to invoke the commands in this cog."""
+ return with_role_check(ctx, *constants.MODERATION_ROLES)
+
+
+def setup(bot: Bot) -> None:
+ """Load the FilterLists cog."""
+ bot.add_cog(FilterLists(bot))
diff --git a/bot/cogs/filtering.py b/bot/cogs/filtering.py
index 29aac812f..99b659bff 100644
--- a/bot/cogs/filtering.py
+++ b/bot/cogs/filtering.py
@@ -11,6 +11,7 @@ from discord import Colour, HTTPException, Member, Message, NotFound, TextChanne
from discord.ext.commands import Cog
from discord.utils import escape_markdown
+from bot.api import ResponseCodeError
from bot.bot import Bot
from bot.cogs.moderation import ModLog
from bot.constants import (
@@ -18,44 +19,18 @@ from bot.constants import (
Filter, Icons, URLs
)
from bot.utils.redis_cache import RedisCache
+from bot.utils.regex import INVITE_RE
from bot.utils.scheduling import Scheduler
log = logging.getLogger(__name__)
-INVITE_RE = re.compile(
- r"(?:discord(?:[\.,]|dot)gg|" # Could be discord.gg/
- r"discord(?:[\.,]|dot)com(?:\/|slash)invite|" # or discord.com/invite/
- r"discordapp(?:[\.,]|dot)com(?:\/|slash)invite|" # or discordapp.com/invite/
- r"discord(?:[\.,]|dot)me|" # or discord.me
- r"discord(?:[\.,]|dot)io" # or discord.io.
- r")(?:[\/]|slash)" # / or 'slash'
- r"([a-zA-Z0-9]+)", # the invite code itself
- flags=re.IGNORECASE
-)
-
+# Regular expressions
SPOILER_RE = re.compile(r"(\|\|.+?\|\|)", re.DOTALL)
URL_RE = re.compile(r"(https?://[^\s]+)", flags=re.IGNORECASE)
ZALGO_RE = re.compile(r"[\u0300-\u036F\u0489]")
-WORD_WATCHLIST_PATTERNS = [
- re.compile(fr'\b{expression}\b', flags=re.IGNORECASE) for expression in Filter.word_watchlist
-]
-TOKEN_WATCHLIST_PATTERNS = [
- re.compile(fr'{expression}', flags=re.IGNORECASE) for expression in Filter.token_watchlist
-]
-WATCHLIST_PATTERNS = WORD_WATCHLIST_PATTERNS + TOKEN_WATCHLIST_PATTERNS
-
+# Other constants.
DAYS_BETWEEN_ALERTS = 3
-
-
-def expand_spoilers(text: str) -> str:
- """Return a string containing all interpretations of a spoilered message."""
- split_text = SPOILER_RE.split(text)
- return ''.join(
- split_text[0::2] + split_text[1::2] + split_text
- )
-
-
OFFENSIVE_MSG_DELETE_TIME = timedelta(days=Filter.offensive_msg_delete_days)
@@ -125,6 +100,22 @@ class Filtering(Cog):
self.bot.loop.create_task(self.reschedule_offensive_msg_deletion())
+ def cog_unload(self) -> None:
+ """Cancel scheduled tasks."""
+ self.scheduler.cancel_all()
+
+ def _get_filterlist_items(self, list_type: str, *, allowed: bool) -> list:
+ """Fetch items from the filter_list_cache."""
+ return self.bot.filter_list_cache[f"{list_type.upper()}.{allowed}"].keys()
+
+ @staticmethod
+ def _expand_spoilers(text: str) -> str:
+ """Return a string containing all interpretations of a spoilered message."""
+ split_text = SPOILER_RE.split(text)
+ return ''.join(
+ split_text[0::2] + split_text[1::2] + split_text
+ )
+
@property
def mod_log(self) -> ModLog:
"""Get currently loaded ModLog cog instance."""
@@ -134,7 +125,10 @@ class Filtering(Cog):
async def on_message(self, msg: Message) -> None:
"""Invoke message filter for new messages."""
await self._filter_message(msg)
- await self.check_bad_words_in_name(msg.author)
+
+ # Ignore webhook messages.
+ if msg.webhook_id is None:
+ await self.check_bad_words_in_name(msg.author)
@Cog.listener()
async def on_message_edit(self, before: Message, after: Message) -> None:
@@ -149,12 +143,12 @@ class Filtering(Cog):
delta = relativedelta(after.edited_at, before.edited_at).microseconds
await self._filter_message(after, delta)
- @staticmethod
- def get_name_matches(name: str) -> List[re.Match]:
+ def get_name_matches(self, name: str) -> List[re.Match]:
"""Check bad words from passed string (name). Return list of matches."""
matches = []
- for pattern in WATCHLIST_PATTERNS:
- if match := pattern.search(name):
+ watchlist_patterns = self._get_filterlist_items('filter_token', allowed=False)
+ for pattern in watchlist_patterns:
+ if match := re.search(pattern, name, flags=re.IGNORECASE):
matches.append(match)
return matches
@@ -308,9 +302,16 @@ class Filtering(Cog):
'delete_date': delete_date
}
- await self.bot.api_client.post('bot/offensive-messages', json=data)
- self.schedule_msg_delete(data)
- log.trace(f"Offensive message {msg.id} will be deleted on {delete_date}")
+ try:
+ await self.bot.api_client.post('bot/offensive-messages', json=data)
+ except ResponseCodeError as e:
+ if e.status == 400 and "already exists" in e.response_json.get("id", [""])[0]:
+ log.debug(f"Offensive message {msg.id} already exists.")
+ else:
+ log.error(f"Offensive message {msg.id} failed to post: {e}")
+ else:
+ self.schedule_msg_delete(data)
+ log.trace(f"Offensive message {msg.id} will be deleted on {delete_date}")
if is_private:
channel_str = "via DM"
@@ -370,14 +371,14 @@ class Filtering(Cog):
# They have no data so additional embeds can't be created for them.
if name == "filter_invites" and match is not True:
additional_embeds = []
- for invite, data in match.items():
+ for _, data in match.items():
embed = discord.Embed(description=(
f"**Members:**\n{data['members']}\n"
f"**Active:**\n{data['active']}"
))
embed.set_author(name=data["name"])
embed.set_thumbnail(url=data["icon"])
- embed.set_footer(text=f"Guild Invite Code: {invite}")
+ embed.set_footer(text=f"Guild ID: {data['id']}")
additional_embeds.append(embed)
additional_embeds_msg = "For the following guild(s):"
@@ -403,8 +404,7 @@ class Filtering(Cog):
and not msg.author.bot # Author not a bot
)
- @staticmethod
- async def _has_watch_regex_match(text: str) -> Union[bool, re.Match]:
+ async def _has_watch_regex_match(self, text: str) -> Union[bool, re.Match]:
"""
Return True if `text` matches any regex from `word_watchlist` or `token_watchlist` configs.
@@ -412,26 +412,27 @@ class Filtering(Cog):
matched as-is. Spoilers are expanded, if any, and URLs are ignored.
"""
if SPOILER_RE.search(text):
- text = expand_spoilers(text)
+ text = self._expand_spoilers(text)
# Make sure it's not a URL
if URL_RE.search(text):
return False
- for pattern in WATCHLIST_PATTERNS:
- match = pattern.search(text)
+ watchlist_patterns = self._get_filterlist_items('filter_token', allowed=False)
+ for pattern in watchlist_patterns:
+ match = re.search(pattern, text, flags=re.IGNORECASE)
if match:
return match
- @staticmethod
- async def _has_urls(text: str) -> bool:
+ async def _has_urls(self, text: str) -> bool:
"""Returns True if the text contains one of the blacklisted URLs from the config file."""
if not URL_RE.search(text):
return False
text = text.lower()
+ domain_blacklist = self._get_filterlist_items("domain_name", allowed=False)
- for url in Filter.domain_blacklist:
+ for url in domain_blacklist:
if url.lower() in text:
return True
@@ -455,7 +456,7 @@ class Filtering(Cog):
Attempts to catch some of common ways to try to cheat the system.
"""
- # Remove backslashes to prevent escape character around fuckery like
+ # Remove backslashes to prevent escape character aroundfuckery like
# discord\.gg/gdudes-pony-farm
text = text.replace("\\", "")
@@ -476,9 +477,22 @@ class Filtering(Cog):
# between invalid and expired invites
return True
- guild_id = int(guild.get("id"))
+ guild_id = guild.get("id")
+ guild_invite_whitelist = self._get_filterlist_items("guild_invite", allowed=True)
+ guild_invite_blacklist = self._get_filterlist_items("guild_invite", allowed=False)
+
+ # Is this invite allowed?
+ guild_partnered_or_verified = (
+ 'PARTNERED' in guild.get("features", [])
+ or 'VERIFIED' in guild.get("features", [])
+ )
+ invite_not_allowed = (
+ guild_id in guild_invite_blacklist # Blacklisted guilds are never permitted.
+ or guild_id not in guild_invite_whitelist # Whitelisted guilds are always permitted.
+ and not guild_partnered_or_verified # Otherwise guilds have to be Verified or Partnered.
+ )
- if guild_id not in Filter.guild_invite_whitelist:
+ if invite_not_allowed:
guild_icon_hash = guild["icon"]
guild_icon = (
"https://cdn.discordapp.com/icons/"
@@ -487,6 +501,7 @@ class Filtering(Cog):
invite_data[invite] = {
"name": guild["name"],
+ "id": guild['id'],
"icon": guild_icon,
"members": response["approximate_member_count"],
"active": response["approximate_presence_count"]
diff --git a/bot/cogs/help.py b/bot/cogs/help.py
index 3d1d6fd10..99d503f5c 100644
--- a/bot/cogs/help.py
+++ b/bot/cogs/help.py
@@ -1,50 +1,28 @@
import itertools
import logging
-from asyncio import TimeoutError
from collections import namedtuple
from contextlib import suppress
from typing import List, Union
-from discord import Colour, Embed, Member, Message, NotFound, Reaction, User
+from discord import Colour, Embed
from discord.ext.commands import Bot, Cog, Command, Context, Group, HelpCommand
from fuzzywuzzy import fuzz, process
from fuzzywuzzy.utils import full_process
from bot import constants
-from bot.constants import Channels, Emojis, STAFF_ROLES
+from bot.constants import Channels, STAFF_ROLES
from bot.decorators import redirect_output
from bot.pagination import LinePaginator
+from bot.utils.messages import wait_for_deletion
log = logging.getLogger(__name__)
COMMANDS_PER_PAGE = 8
-DELETE_EMOJI = Emojis.trashcan
PREFIX = constants.Bot.prefix
Category = namedtuple("Category", ["name", "description", "cogs"])
-async def help_cleanup(bot: Bot, author: Member, message: Message) -> None:
- """
- Runs the cleanup for the help command.
-
- Adds the :trashcan: reaction that, when clicked, will delete the help message.
- After a 300 second timeout, the reaction will be removed.
- """
- def check(reaction: Reaction, user: User) -> bool:
- """Checks the reaction is :trashcan:, the author is original author and messages are the same."""
- return str(reaction) == DELETE_EMOJI and user.id == author.id and reaction.message.id == message.id
-
- await message.add_reaction(DELETE_EMOJI)
-
- with suppress(NotFound):
- try:
- await bot.wait_for("reaction_add", check=check, timeout=300)
- await message.delete()
- except TimeoutError:
- await message.remove_reaction(DELETE_EMOJI, bot.user)
-
-
class HelpQueryNotFound(ValueError):
"""
Raised when a HelpSession Query doesn't match a command or cog.
@@ -189,7 +167,9 @@ class CustomHelpCommand(HelpCommand):
command_details = f"**```{PREFIX}{name} {command.signature}```**\n"
# show command aliases
- aliases = ", ".join(f"`{alias}`" if not parent else f"`{parent} {alias}`" for alias in command.aliases)
+ aliases = [f"`{alias}`" if not parent else f"`{parent} {alias}`" for alias in command.aliases]
+ aliases += [f"`{alias}`" for alias in getattr(command, "root_aliases", ())]
+ aliases = ", ".join(sorted(aliases))
if aliases:
command_details += f"**Can also use:** {aliases}\n\n"
@@ -206,7 +186,7 @@ class CustomHelpCommand(HelpCommand):
"""Send help for a single command."""
embed = await self.command_formatting(command)
message = await self.context.send(embed=embed)
- await help_cleanup(self.context.bot, self.context.author, message)
+ await wait_for_deletion(message, (self.context.author.id,), self.context.bot)
@staticmethod
def get_commands_brief_details(commands_: List[Command], return_as_list: bool = False) -> Union[List[str], str]:
@@ -245,7 +225,7 @@ class CustomHelpCommand(HelpCommand):
embed.description += f"\n**Subcommands:**\n{command_details}"
message = await self.context.send(embed=embed)
- await help_cleanup(self.context.bot, self.context.author, message)
+ await wait_for_deletion(message, (self.context.author.id,), self.context.bot)
async def send_cog_help(self, cog: Cog) -> None:
"""Send help for a cog."""
@@ -261,7 +241,7 @@ class CustomHelpCommand(HelpCommand):
embed.description += f"\n\n**Commands:**\n{command_details}"
message = await self.context.send(embed=embed)
- await help_cleanup(self.context.bot, self.context.author, message)
+ await wait_for_deletion(message, (self.context.author.id,), self.context.bot)
@staticmethod
def _category_key(command: Command) -> str:
diff --git a/bot/cogs/help_channels.py b/bot/cogs/help_channels.py
index 1be980472..0f9cac89e 100644
--- a/bot/cogs/help_channels.py
+++ b/bot/cogs/help_channels.py
@@ -36,7 +36,7 @@ the **Help: Dormant** category.
Try to write the best question you can by providing a detailed description and telling us what \
you've tried already. For more information on asking a good question, \
-check out our guide on [asking good questions]({ASKING_GUIDE_URL}).
+check out our guide on **[asking good questions]({ASKING_GUIDE_URL})**.
"""
DORMANT_MSG = f"""
@@ -47,7 +47,7 @@ channel until it becomes available again.
If your question wasn't answered yet, you can claim a new help channel from the \
**Help: Available** category by simply asking your question again. Consider rephrasing the \
question to maximize your chance of getting a good answer. If you're not sure how, have a look \
-through our guide for [asking a good question]({ASKING_GUIDE_URL}).
+through our guide for **[asking a good question]({ASKING_GUIDE_URL})**.
"""
CoroutineFunc = t.Callable[..., t.Coroutine]
@@ -215,9 +215,6 @@ class HelpChannels(commands.Cog):
log.trace("close command invoked; checking if the channel is in-use.")
if ctx.channel.category == self.in_use_category:
if await self.dormant_check(ctx):
-
- # Remove the claimant and the cooldown role
- await self.help_channel_claimants.delete(ctx.channel.id)
await self.remove_cooldown_role(ctx.author)
# Ignore missing task when cooldown has passed but the channel still isn't dormant.
@@ -551,20 +548,9 @@ class HelpChannels(commands.Cog):
A caller argument is provided for metrics.
"""
- msg_id = await self.question_messages.pop(channel.id)
-
- try:
- await self.bot.http.unpin_message(channel.id, msg_id)
- except discord.HTTPException as e:
- if e.code == 10008:
- log.trace(f"Message {msg_id} don't exist, can't unpin.")
- else:
- log.warn(f"Got unexpected status {e.code} when unpinning message {msg_id}: {e.text}")
- else:
- log.trace(f"Unpinned message {msg_id}.")
-
log.info(f"Moving #{channel} ({channel.id}) to the Dormant category.")
+ await self.help_channel_claimants.delete(channel.id)
await self.move_to_bottom_position(
channel=channel,
category_id=constants.Categories.help_dormant,
@@ -587,6 +573,8 @@ class HelpChannels(commands.Cog):
embed = discord.Embed(description=DORMANT_MSG)
await channel.send(embed=embed)
+ await self.unpin(channel)
+
log.trace(f"Pushing #{channel} ({channel.id}) into the channel queue.")
self.channel_queue.put_nowait(channel)
self.report_stats()
@@ -704,15 +692,8 @@ class HelpChannels(commands.Cog):
log.info(f"Channel #{channel} was claimed by `{message.author.id}`.")
await self.move_to_in_use(channel)
await self.revoke_send_permissions(message.author)
- # Pin message for better access and store this to cache
- try:
- await message.pin()
- except discord.NotFound:
- log.info(f"Pinning message {message.id} ({channel}) failed because message got deleted.")
- except discord.HTTPException as e:
- log.info(f"Pinning message {message.id} ({channel.id}) failed with code {e.code}", exc_info=e)
- else:
- await self.question_messages.set(channel.id, message.id)
+
+ await self.pin(message)
# Add user with channel for dormant check.
await self.help_channel_claimants.set(channel.id, message.author.id)
@@ -754,9 +735,22 @@ class HelpChannels(commands.Cog):
self.scheduler.schedule_later(delay, msg.channel.id, self.move_idle_channel(msg.channel))
async def is_empty(self, channel: discord.TextChannel) -> bool:
- """Return True if the most recent message in `channel` is the bot's `AVAILABLE_MSG`."""
- msg = await self.get_last_message(channel)
- return self.match_bot_embed(msg, AVAILABLE_MSG)
+ """Return True if there's an AVAILABLE_MSG and the messages leading up are bot messages."""
+ log.trace(f"Checking if #{channel} ({channel.id}) is empty.")
+
+ # A limit of 100 results in a single API call.
+ # If AVAILABLE_MSG isn't found within 100 messages, then assume the channel is not empty.
+ # Not gonna do an extensive search for it cause it's too expensive.
+ async for msg in channel.history(limit=100):
+ if not msg.author.bot:
+ log.trace(f"#{channel} ({channel.id}) has a non-bot message.")
+ return False
+
+ if self.match_bot_embed(msg, AVAILABLE_MSG):
+ log.trace(f"#{channel} ({channel.id}) has the available message embed.")
+ return True
+
+ return False
async def check_cooldowns(self) -> None:
"""Remove expired cooldowns and re-schedule active ones."""
@@ -863,6 +857,47 @@ class HelpChannels(commands.Cog):
log.trace(f"Channel #{channel} ({channel_id}) retrieved.")
return channel
+ async def pin_wrapper(self, msg_id: int, channel: discord.TextChannel, *, pin: bool) -> bool:
+ """
+ Pin message `msg_id` in `channel` if `pin` is True or unpin if it's False.
+
+ Return True if successful and False otherwise.
+ """
+ channel_str = f"#{channel} ({channel.id})"
+ if pin:
+ func = self.bot.http.pin_message
+ verb = "pin"
+ else:
+ func = self.bot.http.unpin_message
+ verb = "unpin"
+
+ try:
+ await func(channel.id, msg_id)
+ except discord.HTTPException as e:
+ if e.code == 10008:
+ log.debug(f"Message {msg_id} in {channel_str} doesn't exist; can't {verb}.")
+ else:
+ log.exception(
+ f"Error {verb}ning message {msg_id} in {channel_str}: {e.status} ({e.code})"
+ )
+ return False
+ else:
+ log.trace(f"{verb.capitalize()}ned message {msg_id} in {channel_str}.")
+ return True
+
+ async def pin(self, message: discord.Message) -> None:
+ """Pin an initial question `message` and store it in a cache."""
+ if await self.pin_wrapper(message.id, message.channel, pin=True):
+ await self.question_messages.set(message.channel.id, message.id)
+
+ async def unpin(self, channel: discord.TextChannel) -> None:
+ """Unpin the initial question message sent in `channel`."""
+ msg_id = await self.question_messages.pop(channel.id)
+ if msg_id is None:
+ log.debug(f"#{channel} ({channel.id}) doesn't have a message pinned.")
+ else:
+ await self.pin_wrapper(msg_id, channel, pin=False)
+
async def wait_for_dormant_channel(self) -> discord.TextChannel:
"""Wait for a dormant channel to become available in the queue and return it."""
log.trace("Waiting for a dormant channel.")
diff --git a/bot/cogs/information.py b/bot/cogs/information.py
index 8982196d1..55ecb2836 100644
--- a/bot/cogs/information.py
+++ b/bot/cogs/information.py
@@ -4,9 +4,9 @@ import pprint
import textwrap
from collections import Counter, defaultdict
from string import Template
-from typing import Any, Mapping, Optional, Union
+from typing import Any, Mapping, Optional, Tuple, Union
-from discord import ChannelType, Colour, Embed, Guild, Member, Message, Role, Status, utils
+from discord import ChannelType, Colour, CustomActivity, Embed, Guild, Member, Message, Role, Status, utils
from discord.abc import GuildChannel
from discord.ext.commands import BucketType, Cog, Context, Paginator, command, group
from discord.utils import escape_markdown
@@ -20,6 +20,12 @@ from bot.utils.time import time_since
log = logging.getLogger(__name__)
+STATUS_EMOTES = {
+ Status.offline: constants.Emojis.status_offline,
+ Status.dnd: constants.Emojis.status_dnd,
+ Status.idle: constants.Emojis.status_idle
+}
+
class Information(Cog):
"""A cog with commands for generating embeds with server info, such as server stats and user info."""
@@ -211,53 +217,88 @@ class Information(Cog):
# Custom status
custom_status = ''
for activity in user.activities:
- # Check activity.state for None value if user has a custom status set
- # This guards against a custom status with an emoji but no text, which will cause
- # escape_markdown to raise an exception
- # This can be reworked after a move to d.py 1.3.0+, which adds a CustomActivity class
- if activity.name == 'Custom Status' and activity.state:
- state = escape_markdown(activity.state)
- custom_status = f'Status: {state}\n'
+ if isinstance(activity, CustomActivity):
+ state = ""
+
+ if activity.name:
+ state = escape_markdown(activity.name)
+
+ emoji = ""
+ if activity.emoji:
+ # If an emoji is unicode use the emoji, else write the emote like :abc:
+ if not activity.emoji.id:
+ emoji += activity.emoji.name + " "
+ else:
+ emoji += f"`:{activity.emoji.name}:` "
+
+ custom_status = f'Status: {emoji}{state}\n'
name = str(user)
if user.nick:
name = f"{user.nick} ({name})"
+ badges = []
+
+ for badge, is_set in user.public_flags:
+ if is_set and (emoji := getattr(constants.Emojis, f"badge_{badge}", None)):
+ badges.append(emoji)
+
joined = time_since(user.joined_at, max_units=3)
roles = ", ".join(role.mention for role in user.roles[1:])
- description = [
- textwrap.dedent(f"""
- **User Information**
- Created: {created}
- Profile: {user.mention}
- ID: {user.id}
- {custom_status}
- **Member Information**
- Joined: {joined}
- Roles: {roles or None}
- """).strip()
+ desktop_status = STATUS_EMOTES.get(user.desktop_status, constants.Emojis.status_online)
+ web_status = STATUS_EMOTES.get(user.web_status, constants.Emojis.status_online)
+ mobile_status = STATUS_EMOTES.get(user.mobile_status, constants.Emojis.status_online)
+
+ fields = [
+ (
+ "User information",
+ textwrap.dedent(f"""
+ Created: {created}
+ Profile: {user.mention}
+ ID: {user.id}
+ {custom_status}
+ """).strip()
+ ),
+ (
+ "Member information",
+ textwrap.dedent(f"""
+ Joined: {joined}
+ Roles: {roles or None}
+ """).strip()
+ ),
+ (
+ "Status",
+ textwrap.dedent(f"""
+ {desktop_status} Desktop
+ {web_status} Web
+ {mobile_status} Mobile
+ """).strip()
+ )
]
# Show more verbose output in moderation channels for infractions and nominations
if ctx.channel.id in constants.MODERATION_CHANNELS:
- description.append(await self.expanded_user_infraction_counts(user))
- description.append(await self.user_nomination_counts(user))
+ fields.append(await self.expanded_user_infraction_counts(user))
+ fields.append(await self.user_nomination_counts(user))
else:
- description.append(await self.basic_user_infraction_counts(user))
+ fields.append(await self.basic_user_infraction_counts(user))
# Let's build the embed now
embed = Embed(
title=name,
- description="\n\n".join(description)
+ description=" ".join(badges)
)
+ for field_name, field_content in fields:
+ embed.add_field(name=field_name, value=field_content, inline=False)
+
embed.set_thumbnail(url=user.avatar_url_as(static_format="png"))
embed.colour = user.top_role.colour if roles else Colour.blurple()
return embed
- async def basic_user_infraction_counts(self, member: Member) -> str:
+ async def basic_user_infraction_counts(self, member: Member) -> Tuple[str, str]:
"""Gets the total and active infraction counts for the given `member`."""
infractions = await self.bot.api_client.get(
'bot/infractions',
@@ -270,11 +311,11 @@ class Information(Cog):
total_infractions = len(infractions)
active_infractions = sum(infraction['active'] for infraction in infractions)
- infraction_output = f"**Infractions**\nTotal: {total_infractions}\nActive: {active_infractions}"
+ infraction_output = f"Total: {total_infractions}\nActive: {active_infractions}"
- return infraction_output
+ return "Infractions", infraction_output
- async def expanded_user_infraction_counts(self, member: Member) -> str:
+ async def expanded_user_infraction_counts(self, member: Member) -> Tuple[str, str]:
"""
Gets expanded infraction counts for the given `member`.
@@ -288,9 +329,9 @@ class Information(Cog):
}
)
- infraction_output = ["**Infractions**"]
+ infraction_output = []
if not infractions:
- infraction_output.append("This user has never received an infraction.")
+ infraction_output.append("No infractions")
else:
# Count infractions split by `type` and `active` status for this user
infraction_types = set()
@@ -313,9 +354,9 @@ class Information(Cog):
infraction_output.append(line)
- return "\n".join(infraction_output)
+ return "Infractions", "\n".join(infraction_output)
- async def user_nomination_counts(self, member: Member) -> str:
+ async def user_nomination_counts(self, member: Member) -> Tuple[str, str]:
"""Gets the active and historical nomination counts for the given `member`."""
nominations = await self.bot.api_client.get(
'bot/nominations',
@@ -324,21 +365,21 @@ class Information(Cog):
}
)
- output = ["**Nominations**"]
+ output = []
if not nominations:
- output.append("This user has never been nominated.")
+ output.append("No nominations")
else:
count = len(nominations)
is_currently_nominated = any(nomination["active"] for nomination in nominations)
nomination_noun = "nomination" if count == 1 else "nominations"
if is_currently_nominated:
- output.append(f"This user is **currently** nominated ({count} {nomination_noun} in total).")
+ output.append(f"This user is **currently** nominated\n({count} {nomination_noun} in total)")
else:
output.append(f"This user has {count} historical {nomination_noun}, but is currently not nominated.")
- return "\n".join(output)
+ return "Nominations", "\n".join(output)
def format_fields(self, mapping: Mapping[str, Any], field_width: Optional[int] = None) -> str:
"""Format a mapping to be readable to a human."""
@@ -376,7 +417,7 @@ class Information(Cog):
return out.rstrip()
@cooldown_with_role_bypass(2, 60 * 3, BucketType.member, bypass_roles=constants.STAFF_ROLES)
- @group(invoke_without_command=True)
+ @group(invoke_without_command=True, enabled=False)
@in_whitelist(channels=(constants.Channels.bot_commands,), roles=constants.STAFF_ROLES)
async def raw(self, ctx: Context, *, message: Message, json: bool = False) -> None:
"""Shows information about the raw API response."""
@@ -411,7 +452,7 @@ class Information(Cog):
for page in paginator.pages:
await ctx.send(page)
- @raw.command()
+ @raw.command(enabled=False)
async def json(self, ctx: Context, message: Message) -> None:
"""Shows information about the raw API response in a copy-pasteable Python format."""
await ctx.invoke(self.raw, message=message, json=True)
diff --git a/bot/cogs/moderation/modlog.py b/bot/cogs/moderation/modlog.py
index 0a63f57b8..5f30d3744 100644
--- a/bot/cogs/moderation/modlog.py
+++ b/bot/cogs/moderation/modlog.py
@@ -120,6 +120,10 @@ class ModLog(Cog, name="ModLog"):
else:
content = "@everyone"
+ # Truncate content to 2000 characters and append an ellipsis.
+ if content and len(content) > 2000:
+ content = content[:2000 - 3] + "..."
+
channel = self.bot.get_channel(channel_id)
log_message = await channel.send(
content=content,
diff --git a/bot/cogs/moderation/scheduler.py b/bot/cogs/moderation/scheduler.py
index 601e238c9..051f6c52c 100644
--- a/bot/cogs/moderation/scheduler.py
+++ b/bot/cogs/moderation/scheduler.py
@@ -31,6 +31,10 @@ class InfractionScheduler:
self.bot.loop.create_task(self.reschedule_infractions(supported_infractions))
+ def cog_unload(self) -> None:
+ """Cancel scheduled tasks."""
+ self.scheduler.cancel_all()
+
@property
def mod_log(self) -> ModLog:
"""Get the currently loaded ModLog cog instance."""
@@ -157,6 +161,7 @@ class InfractionScheduler:
self.schedule_expiration(infraction)
except discord.HTTPException as e:
# Accordingly display that applying the infraction failed.
+ # Don't use ctx.message.author; antispam only patches ctx.author.
confirm_msg = ":x: failed to apply"
expiry_msg = ""
log_content = ctx.author.mention
@@ -186,6 +191,7 @@ class InfractionScheduler:
await ctx.send(f"{dm_result}{confirm_msg}{infr_message}.")
# Send a log message to the mod log.
+ # Don't use ctx.message.author for the actor; antispam only patches ctx.author.
log.trace(f"Sending apply mod log for infraction #{id_}.")
await self.mod_log.send_log_message(
icon_url=icon,
@@ -194,7 +200,7 @@ class InfractionScheduler:
thumbnail=user.avatar_url_as(static_format="png"),
text=textwrap.dedent(f"""
Member: {user.mention} (`{user.id}`)
- Actor: {ctx.message.author}{dm_log_text}{expiry_log_text}
+ Actor: {ctx.author}{dm_log_text}{expiry_log_text}
Reason: {reason}
"""),
content=log_content,
@@ -238,7 +244,7 @@ class InfractionScheduler:
log_text = await self.deactivate_infraction(response[0], send_log=False)
log_text["Member"] = f"{user.mention}(`{user.id}`)"
- log_text["Actor"] = str(ctx.message.author)
+ log_text["Actor"] = str(ctx.author)
log_content = None
id_ = response[0]['id']
footer = f"ID: {id_}"
diff --git a/bot/cogs/moderation/silence.py b/bot/cogs/moderation/silence.py
index ae4fb7b64..f8a6592bc 100644
--- a/bot/cogs/moderation/silence.py
+++ b/bot/cogs/moderation/silence.py
@@ -152,7 +152,8 @@ class Silence(commands.Cog):
return False
def cog_unload(self) -> None:
- """Send alert with silenced channels on unload."""
+ """Send alert with silenced channels and cancel scheduled tasks on unload."""
+ self.scheduler.cancel_all()
if self.muted_channels:
channels_string = ''.join(channel.mention for channel in self.muted_channels)
message = f"<@&{Roles.moderators}> channels left silenced on cog unload: {channels_string}"
diff --git a/bot/cogs/moderation/utils.py b/bot/cogs/moderation/utils.py
index fb55287b6..f21272102 100644
--- a/bot/cogs/moderation/utils.py
+++ b/bot/cogs/moderation/utils.py
@@ -70,7 +70,7 @@ async def post_infraction(
log.trace(f"Posting {infr_type} infraction for {user} to the API.")
payload = {
- "actor": ctx.message.author.id,
+ "actor": ctx.author.id, # Don't use ctx.message.author; antispam only patches ctx.author.
"hidden": hidden,
"reason": reason,
"type": infr_type,
diff --git a/bot/cogs/off_topic_names.py b/bot/cogs/off_topic_names.py
index 201579a0b..ce95450e0 100644
--- a/bot/cogs/off_topic_names.py
+++ b/bot/cogs/off_topic_names.py
@@ -4,46 +4,19 @@ import logging
from datetime import datetime, timedelta
from discord import Colour, Embed
-from discord.ext.commands import BadArgument, Cog, Context, Converter, group
+from discord.ext.commands import Cog, Context, group
from bot.api import ResponseCodeError
from bot.bot import Bot
from bot.constants import Channels, MODERATION_ROLES
+from bot.converters import OffTopicName
from bot.decorators import with_role
from bot.pagination import LinePaginator
-
CHANNELS = (Channels.off_topic_0, Channels.off_topic_1, Channels.off_topic_2)
log = logging.getLogger(__name__)
-class OffTopicName(Converter):
- """A converter that ensures an added off-topic name is valid."""
-
- @staticmethod
- async def convert(ctx: Context, argument: str) -> str:
- """Attempt to replace any invalid characters with their approximate Unicode equivalent."""
- allowed_characters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ!?'`-"
-
- # Chain multiple words to a single one
- argument = "-".join(argument.split())
-
- if not (2 <= len(argument) <= 96):
- raise BadArgument("Channel name must be between 2 and 96 chars long")
-
- elif not all(c.isalnum() or c in allowed_characters for c in argument):
- raise BadArgument(
- "Channel name must only consist of "
- "alphanumeric characters, minus signs or apostrophes."
- )
-
- # Replace invalid characters with unicode alternatives.
- table = str.maketrans(
- allowed_characters, '𝖠𝖡𝖢𝖣𝖤𝖥𝖦𝖧𝖨𝖩𝖪𝖫𝖬𝖭𝖮𝖯𝖰𝖱𝖲𝖳𝖴𝖵𝖶𝖷𝖸𝖹ǃ?’’-'
- )
- return argument.translate(table)
-
-
async def update_names(bot: Bot) -> None:
"""Background updater task that performs the daily channel name update."""
while True:
diff --git a/bot/cogs/reddit.py b/bot/cogs/reddit.py
index d853ab2ea..5d9e2c20b 100644
--- a/bot/cogs/reddit.py
+++ b/bot/cogs/reddit.py
@@ -10,6 +10,7 @@ from aiohttp import BasicAuth, ClientError
from discord import Colour, Embed, TextChannel
from discord.ext.commands import Cog, Context, group
from discord.ext.tasks import loop
+from discord.utils import escape_markdown
from bot.bot import Bot
from bot.constants import Channels, ERROR_REPLIES, Emojis, Reddit as RedditConfig, STAFF_ROLES, Webhooks
@@ -187,6 +188,8 @@ class Reddit(Cog):
author = data["author"]
title = textwrap.shorten(data["title"], width=64, placeholder="...")
+ # Normal brackets interfere with Markdown.
+ title = escape_markdown(title).replace("[", "⦋").replace("]", "⦌")
link = self.URL + data["permalink"]
embed.description += (
diff --git a/bot/cogs/reminders.py b/bot/cogs/reminders.py
index 25b2c9421..ca17b7e7a 100644
--- a/bot/cogs/reminders.py
+++ b/bot/cogs/reminders.py
@@ -12,10 +12,10 @@ from dateutil.relativedelta import relativedelta
from discord.ext.commands import Cog, Context, Greedy, group
from bot.bot import Bot
-from bot.constants import Guild, Icons, MODERATION_ROLES, POSITIVE_REPLIES, STAFF_ROLES
+from bot.constants import Guild, Icons, MODERATION_ROLES, POSITIVE_REPLIES, Roles, STAFF_ROLES
from bot.converters import Duration
from bot.pagination import LinePaginator
-from bot.utils.checks import without_role_check
+from bot.utils.checks import with_role_check, without_role_check
from bot.utils.lock import lock_arg
from bot.utils.messages import send_denial
from bot.utils.scheduling import Scheduler
@@ -39,6 +39,10 @@ class Reminders(Cog):
self.bot.loop.create_task(self.reschedule_reminders())
+ def cog_unload(self) -> None:
+ """Cancel scheduled tasks."""
+ self.scheduler.cancel_all()
+
async def reschedule_reminders(self) -> None:
"""Get all current reminders from the API and reschedule them."""
await self.bot.wait_until_guild_available()
@@ -376,6 +380,8 @@ class Reminders(Cog):
@lock_arg(NAMESPACE, "id_", raise_error=True)
async def edit_reminder(self, ctx: Context, id_: int, payload: dict) -> None:
"""Edits a reminder with the given payload, then sends a confirmation message."""
+ if not await self._can_modify(ctx, id_):
+ return
reminder = await self._edit_reminder(id_, payload)
# Parse the reminder expiration back into a datetime
@@ -394,6 +400,9 @@ class Reminders(Cog):
@lock_arg(NAMESPACE, "id_", raise_error=True)
async def delete_reminder(self, ctx: Context, id_: int) -> None:
"""Delete one of your active reminders."""
+ if not await self._can_modify(ctx, id_):
+ return
+
await self.bot.api_client.delete(f"bot/reminders/{id_}")
self.scheduler.cancel(id_)
@@ -404,6 +413,24 @@ class Reminders(Cog):
delivery_dt=None,
)
+ async def _can_modify(self, ctx: Context, reminder_id: t.Union[str, int]) -> bool:
+ """
+ Check whether the reminder can be modified by the ctx author.
+
+ The check passes when the user is an admin, or if they created the reminder.
+ """
+ if with_role_check(ctx, Roles.admins):
+ return True
+
+ api_response = await self.bot.api_client.get(f"bot/reminders/{reminder_id}")
+ if not api_response["author"] == ctx.author.id:
+ log.debug(f"{ctx.author} is not the reminder author and does not pass the check.")
+ await send_denial(ctx, "You can't modify reminders of other users!")
+ return False
+
+ log.debug(f"{ctx.author} is the reminder author and passes the check.")
+ return True
+
def setup(bot: Bot) -> None:
"""Load the Reminders cog."""
diff --git a/bot/cogs/site.py b/bot/cogs/site.py
index ac29daa1d..2d3a3d9f3 100644
--- a/bot/cogs/site.py
+++ b/bot/cogs/site.py
@@ -23,7 +23,7 @@ class Site(Cog):
"""Commands for getting info about our website."""
await ctx.send_help(ctx.command)
- @site_group.command(name="home", aliases=("about",))
+ @site_group.command(name="home", aliases=("about",), root_aliases=("home",))
async def site_main(self, ctx: Context) -> None:
"""Info about the website itself."""
url = f"{URLs.site_schema}{URLs.site}/"
@@ -40,7 +40,7 @@ class Site(Cog):
await ctx.send(embed=embed)
- @site_group.command(name="resources")
+ @site_group.command(name="resources", root_aliases=("resources", "resource"))
async def site_resources(self, ctx: Context) -> None:
"""Info about the site's Resources page."""
learning_url = f"{PAGES_URL}/resources"
@@ -56,7 +56,7 @@ class Site(Cog):
await ctx.send(embed=embed)
- @site_group.command(name="tools")
+ @site_group.command(name="tools", root_aliases=("tools",))
async def site_tools(self, ctx: Context) -> None:
"""Info about the site's Tools page."""
tools_url = f"{PAGES_URL}/resources/tools"
@@ -87,7 +87,7 @@ class Site(Cog):
await ctx.send(embed=embed)
- @site_group.command(name="faq")
+ @site_group.command(name="faq", root_aliases=("faq",))
async def site_faq(self, ctx: Context) -> None:
"""Info about the site's FAQ page."""
url = f"{PAGES_URL}/frequently-asked-questions"
@@ -104,7 +104,7 @@ class Site(Cog):
await ctx.send(embed=embed)
- @site_group.command(aliases=['r', 'rule'], name='rules')
+ @site_group.command(name="rules", aliases=("r", "rule"), root_aliases=("rules", "rule"))
async def site_rules(self, ctx: Context, *rules: int) -> None:
"""Provides a link to all rules or, if specified, displays specific rule(s)."""
rules_embed = Embed(title='Rules', color=Colour.blurple())
diff --git a/bot/cogs/snekbox.py b/bot/cogs/snekbox.py
index 52c8b6f88..63e6d7f31 100644
--- a/bot/cogs/snekbox.py
+++ b/bot/cogs/snekbox.py
@@ -220,9 +220,7 @@ class Snekbox(Cog):
response = await ctx.send("Attempt to circumvent filter detected. Moderator team has been alerted.")
else:
response = await ctx.send(msg)
- self.bot.loop.create_task(
- wait_for_deletion(response, user_ids=(ctx.author.id,), client=ctx.bot)
- )
+ self.bot.loop.create_task(wait_for_deletion(response, (ctx.author.id,), ctx.bot))
log.info(f"{ctx.author}'s job had a return code of {results['returncode']}")
return response
diff --git a/bot/cogs/source.py b/bot/cogs/source.py
index f1db745cd..205e0ba81 100644
--- a/bot/cogs/source.py
+++ b/bot/cogs/source.py
@@ -60,11 +60,12 @@ class BotSource(commands.Cog):
await ctx.send(embed=embed)
def get_source_link(self, source_item: SourceType) -> Tuple[str, str, Optional[int]]:
- """Build GitHub link of source item, return this link, file location and first line number."""
- if isinstance(source_item, commands.HelpCommand):
- src = type(source_item)
- filename = inspect.getsourcefile(src)
- elif isinstance(source_item, commands.Command):
+ """
+ Build GitHub link of source item, return this link, file location and first line number.
+
+ Raise BadArgument if `source_item` is a dynamically-created object (e.g. via internal eval).
+ """
+ if isinstance(source_item, commands.Command):
if source_item.cog_name == "Alias":
cmd_name = source_item.callback.__name__.replace("_alias", "")
cmd = self.bot.get_command(cmd_name.replace("_", " "))
@@ -78,10 +79,17 @@ class BotSource(commands.Cog):
filename = tags_cog._cache[source_item]["location"]
else:
src = type(source_item)
- filename = inspect.getsourcefile(src)
+ try:
+ filename = inspect.getsourcefile(src)
+ except TypeError:
+ raise commands.BadArgument("Cannot get source for a dynamically-created object.")
if not isinstance(source_item, str):
- lines, first_line_no = inspect.getsourcelines(src)
+ try:
+ lines, first_line_no = inspect.getsourcelines(src)
+ except OSError:
+ raise commands.BadArgument("Cannot get source for a dynamically-created object.")
+
lines_extension = f"#L{first_line_no}-L{first_line_no+len(lines)-1}"
else:
first_line_no = None
diff --git a/bot/cogs/tags.py b/bot/cogs/tags.py
index 3d76c5c08..d01647312 100644
--- a/bot/cogs/tags.py
+++ b/bot/cogs/tags.py
@@ -236,7 +236,7 @@ class Tags(Cog):
await wait_for_deletion(
await ctx.send(embed=Embed.from_dict(tag['embed'])),
[ctx.author.id],
- client=self.bot
+ self.bot
)
elif founds and len(tag_name) >= 3:
await wait_for_deletion(
@@ -247,7 +247,7 @@ class Tags(Cog):
)
),
[ctx.author.id],
- client=self.bot
+ self.bot
)
else:
diff --git a/bot/cogs/utils.py b/bot/cogs/utils.py
index 91c6cb36e..d96abbd5a 100644
--- a/bot/cogs/utils.py
+++ b/bot/cogs/utils.py
@@ -232,6 +232,8 @@ class Utils(Cog):
A maximum of 20 options can be provided, as Discord supports a max of 20
reactions on a single message.
"""
+ if len(title) > 256:
+ raise BadArgument("The title cannot be longer than 256 characters.")
if len(options) < 2:
raise BadArgument("Please provide at least 2 options.")
if len(options) > 20:
diff --git a/bot/cogs/watchchannels/bigbrother.py b/bot/cogs/watchchannels/bigbrother.py
index 4d27a6333..11ab8917a 100644
--- a/bot/cogs/watchchannels/bigbrother.py
+++ b/bot/cogs/watchchannels/bigbrother.py
@@ -59,7 +59,7 @@ class BigBrother(WatchChannel, Cog, name="Big Brother"):
"""
await ctx.invoke(self.watched_command, oldest_first=True, update_cache=update_cache)
- @bigbrother_group.command(name='watch', aliases=('w',))
+ @bigbrother_group.command(name='watch', aliases=('w',), root_aliases=('watch',))
@with_role(*MODERATION_ROLES)
async def watch_command(self, ctx: Context, user: FetchedMember, *, reason: str) -> None:
"""
@@ -70,7 +70,7 @@ class BigBrother(WatchChannel, Cog, name="Big Brother"):
"""
await self.apply_watch(ctx, user, reason)
- @bigbrother_group.command(name='unwatch', aliases=('uw',))
+ @bigbrother_group.command(name='unwatch', aliases=('uw',), root_aliases=('unwatch',))
@with_role(*MODERATION_ROLES)
async def unwatch_command(self, ctx: Context, user: FetchedMember, *, reason: str) -> None:
"""Stop relaying messages by the given `user`."""
@@ -131,8 +131,8 @@ class BigBrother(WatchChannel, Cog, name="Big Brother"):
active_watches = await self.bot.api_client.get(
self.api_endpoint,
params=ChainMap(
+ {"user__id": str(user.id)},
self.api_default_params,
- {"user__id": str(user.id)}
)
)
if active_watches:
diff --git a/bot/cogs/watchchannels/talentpool.py b/bot/cogs/watchchannels/talentpool.py
index 89256e92e..76d6fe9bd 100644
--- a/bot/cogs/watchchannels/talentpool.py
+++ b/bot/cogs/watchchannels/talentpool.py
@@ -1,8 +1,9 @@
import logging
import textwrap
from collections import ChainMap
+from typing import Union
-from discord import Color, Embed, Member
+from discord import Color, Embed, Member, User
from discord.ext.commands import Cog, Context, group
from bot.api import ResponseCodeError
@@ -36,7 +37,7 @@ class TalentPool(WatchChannel, Cog, name="Talentpool"):
"""Highlights the activity of helper nominees by relaying their messages to the talent pool channel."""
await ctx.send_help(ctx.command)
- @nomination_group.command(name='watched', aliases=('all', 'list'))
+ @nomination_group.command(name='watched', aliases=('all', 'list'), root_aliases=("nominees",))
@with_role(*MODERATION_ROLES)
async def watched_command(
self, ctx: Context, oldest_first: bool = False, update_cache: bool = True
@@ -62,7 +63,7 @@ class TalentPool(WatchChannel, Cog, name="Talentpool"):
"""
await ctx.invoke(self.watched_command, oldest_first=True, update_cache=update_cache)
- @nomination_group.command(name='watch', aliases=('w', 'add', 'a'))
+ @nomination_group.command(name='watch', aliases=('w', 'add', 'a'), root_aliases=("nominate",))
@with_role(*STAFF_ROLES)
async def watch_command(self, ctx: Context, user: FetchedMember, *, reason: str) -> None:
"""
@@ -156,7 +157,7 @@ class TalentPool(WatchChannel, Cog, name="Talentpool"):
max_size=1000
)
- @nomination_group.command(name='unwatch', aliases=('end', ))
+ @nomination_group.command(name='unwatch', aliases=('end', ), root_aliases=("unnominate",))
@with_role(*MODERATION_ROLES)
async def unwatch_command(self, ctx: Context, user: FetchedMember, *, reason: str) -> None:
"""
@@ -164,25 +165,10 @@ class TalentPool(WatchChannel, Cog, name="Talentpool"):
Providing a `reason` is required.
"""
- active_nomination = await self.bot.api_client.get(
- self.api_endpoint,
- params=ChainMap(
- self.api_default_params,
- {"user__id": str(user.id)}
- )
- )
-
- if not active_nomination:
+ if await self.unwatch(user.id, reason):
+ await ctx.send(f":white_check_mark: Messages sent by {user} will no longer be relayed")
+ else:
await ctx.send(":x: The specified user does not have an active nomination")
- return
-
- [nomination] = active_nomination
- await self.bot.api_client.patch(
- f"{self.api_endpoint}/{nomination['id']}",
- json={'end_reason': reason, 'active': False}
- )
- await ctx.send(f":white_check_mark: Messages sent by {user} will no longer be relayed")
- self._remove_user(user.id)
@nomination_group.group(name='edit', aliases=('e',), invoke_without_command=True)
@with_role(*MODERATION_ROLES)
@@ -220,6 +206,36 @@ class TalentPool(WatchChannel, Cog, name="Talentpool"):
await ctx.send(f":white_check_mark: Updated the {field} of the nomination!")
+ @Cog.listener()
+ async def on_member_ban(self, guild: Guild, user: Union[User, Member]) -> None:
+ """Remove `user` from the talent pool after they are banned."""
+ await self.unwatch(user.id, "User was banned.")
+
+ async def unwatch(self, user_id: int, reason: str) -> bool:
+ """End the active nomination of a user with the given reason and return True on success."""
+ active_nomination = await self.bot.api_client.get(
+ self.api_endpoint,
+ params=ChainMap(
+ {"user__id": str(user_id)},
+ self.api_default_params,
+ )
+ )
+
+ if not active_nomination:
+ log.debug(f"No active nominate exists for {user_id=}")
+ return False
+
+ log.info(f"Ending nomination: {user_id=} {reason=}")
+
+ nomination = active_nomination[0]
+ await self.bot.api_client.patch(
+ f"{self.api_endpoint}/{nomination['id']}",
+ json={'end_reason': reason, 'active': False}
+ )
+ self._remove_user(user_id)
+
+ return True
+
def _nomination_to_string(self, nomination_object: dict) -> str:
"""Creates a string representation of a nomination."""
guild = self.bot.get_guild(Guild.id)
diff --git a/bot/cogs/watchchannels/watchchannel.py b/bot/cogs/watchchannels/watchchannel.py
index 044077350..a58b604c0 100644
--- a/bot/cogs/watchchannels/watchchannel.py
+++ b/bot/cogs/watchchannels/watchchannel.py
@@ -15,6 +15,8 @@ from discord.ext.commands import Cog, Context
from bot.api import ResponseCodeError
from bot.bot import Bot
from bot.cogs.moderation import ModLog
+from bot.cogs.token_remover import TokenRemover
+from bot.cogs.webhook_remover import WEBHOOK_URL_RE
from bot.constants import BigBrother as BigBrotherConfig, Guild as GuildConfig, Icons
from bot.pagination import LinePaginator
from bot.utils import CogABCMeta, messages
@@ -226,14 +228,16 @@ class WatchChannel(metaclass=CogABCMeta):
await self.send_header(msg)
- cleaned_content = msg.clean_content
-
- if cleaned_content:
+ if TokenRemover.find_token_in_message(msg) or WEBHOOK_URL_RE.search(msg.content):
+ cleaned_content = "Content is censored because it contains a bot or webhook token."
+ elif cleaned_content := msg.clean_content:
# Put all non-media URLs in a code block to prevent embeds
media_urls = {embed.url for embed in msg.embeds if embed.type in ("image", "video")}
for url in URL_RE.findall(cleaned_content):
if url not in media_urls:
cleaned_content = cleaned_content.replace(url, f"`{url}`")
+
+ if cleaned_content:
await self.webhook_send(
cleaned_content,
username=msg.author.display_name,
diff --git a/bot/cogs/wolfram.py b/bot/cogs/wolfram.py
deleted file mode 100644
index e6cae3bb8..000000000
--- a/bot/cogs/wolfram.py
+++ /dev/null
@@ -1,280 +0,0 @@
-import logging
-from io import BytesIO
-from typing import Callable, List, Optional, Tuple
-from urllib import parse
-
-import discord
-from dateutil.relativedelta import relativedelta
-from discord import Embed
-from discord.ext import commands
-from discord.ext.commands import BucketType, Cog, Context, check, group
-
-from bot.bot import Bot
-from bot.constants import Colours, STAFF_ROLES, Wolfram
-from bot.pagination import ImagePaginator
-from bot.utils.time import humanize_delta
-
-log = logging.getLogger(__name__)
-
-APPID = Wolfram.key
-DEFAULT_OUTPUT_FORMAT = "JSON"
-QUERY = "http://api.wolframalpha.com/v2/{request}?{data}"
-WOLF_IMAGE = "https://www.symbols.com/gi.php?type=1&id=2886&i=1"
-
-MAX_PODS = 20
-
-# Allows for 10 wolfram calls pr user pr day
-usercd = commands.CooldownMapping.from_cooldown(Wolfram.user_limit_day, 60*60*24, BucketType.user)
-
-# Allows for max api requests / days in month per day for the entire guild (Temporary)
-guildcd = commands.CooldownMapping.from_cooldown(Wolfram.guild_limit_day, 60*60*24, BucketType.guild)
-
-
-async def send_embed(
- ctx: Context,
- message_txt: str,
- colour: int = Colours.soft_red,
- footer: str = None,
- img_url: str = None,
- f: discord.File = None
-) -> None:
- """Generate & send a response embed with Wolfram as the author."""
- embed = Embed(colour=colour)
- embed.description = message_txt
- embed.set_author(name="Wolfram Alpha",
- icon_url=WOLF_IMAGE,
- url="https://www.wolframalpha.com/")
- if footer:
- embed.set_footer(text=footer)
-
- if img_url:
- embed.set_image(url=img_url)
-
- await ctx.send(embed=embed, file=f)
-
-
-def custom_cooldown(*ignore: List[int]) -> Callable:
- """
- Implement per-user and per-guild cooldowns for requests to the Wolfram API.
-
- A list of roles may be provided to ignore the per-user cooldown
- """
- async def predicate(ctx: Context) -> bool:
- if ctx.invoked_with == 'help':
- # if the invoked command is help we don't want to increase the ratelimits since it's not actually
- # invoking the command/making a request, so instead just check if the user/guild are on cooldown.
- guild_cooldown = not guildcd.get_bucket(ctx.message).get_tokens() == 0 # if guild is on cooldown
- if not any(r.id in ignore for r in ctx.author.roles): # check user bucket if user is not ignored
- return guild_cooldown and not usercd.get_bucket(ctx.message).get_tokens() == 0
- return guild_cooldown
-
- user_bucket = usercd.get_bucket(ctx.message)
-
- if all(role.id not in ignore for role in ctx.author.roles):
- user_rate = user_bucket.update_rate_limit()
-
- if user_rate:
- # Can't use api; cause: member limit
- delta = relativedelta(seconds=int(user_rate))
- cooldown = humanize_delta(delta)
- message = (
- "You've used up your limit for Wolfram|Alpha requests.\n"
- f"Cooldown: {cooldown}"
- )
- await send_embed(ctx, message)
- return False
-
- guild_bucket = guildcd.get_bucket(ctx.message)
- guild_rate = guild_bucket.update_rate_limit()
-
- # Repr has a token attribute to read requests left
- log.debug(guild_bucket)
-
- if guild_rate:
- # Can't use api; cause: guild limit
- message = (
- "The max limit of requests for the server has been reached for today.\n"
- f"Cooldown: {int(guild_rate)}"
- )
- await send_embed(ctx, message)
- return False
-
- return True
- return check(predicate)
-
-
-async def get_pod_pages(ctx: Context, bot: Bot, query: str) -> Optional[List[Tuple]]:
- """Get the Wolfram API pod pages for the provided query."""
- async with ctx.channel.typing():
- url_str = parse.urlencode({
- "input": query,
- "appid": APPID,
- "output": DEFAULT_OUTPUT_FORMAT,
- "format": "image,plaintext"
- })
- request_url = QUERY.format(request="query", data=url_str)
-
- async with bot.http_session.get(request_url) as response:
- json = await response.json(content_type='text/plain')
-
- result = json["queryresult"]
-
- if result["error"]:
- # API key not set up correctly
- if result["error"]["msg"] == "Invalid appid":
- message = "Wolfram API key is invalid or missing."
- log.warning(
- "API key seems to be missing, or invalid when "
- f"processing a wolfram request: {url_str}, Response: {json}"
- )
- await send_embed(ctx, message)
- return
-
- message = "Something went wrong internally with your request, please notify staff!"
- log.warning(f"Something went wrong getting a response from wolfram: {url_str}, Response: {json}")
- await send_embed(ctx, message)
- return
-
- if not result["success"]:
- message = f"I couldn't find anything for {query}."
- await send_embed(ctx, message)
- return
-
- if not result["numpods"]:
- message = "Could not find any results."
- await send_embed(ctx, message)
- return
-
- pods = result["pods"]
- pages = []
- for pod in pods[:MAX_PODS]:
- subs = pod.get("subpods")
-
- for sub in subs:
- title = sub.get("title") or sub.get("plaintext") or sub.get("id", "")
- img = sub["img"]["src"]
- pages.append((title, img))
- return pages
-
-
-class Wolfram(Cog):
- """Commands for interacting with the Wolfram|Alpha API."""
-
- def __init__(self, bot: Bot):
- self.bot = bot
-
- @group(name="wolfram", aliases=("wolf", "wa"), invoke_without_command=True)
- @custom_cooldown(*STAFF_ROLES)
- async def wolfram_command(self, ctx: Context, *, query: str) -> None:
- """Requests all answers on a single image, sends an image of all related pods."""
- url_str = parse.urlencode({
- "i": query,
- "appid": APPID,
- })
- query = QUERY.format(request="simple", data=url_str)
-
- # Give feedback that the bot is working.
- async with ctx.channel.typing():
- async with self.bot.http_session.get(query) as response:
- status = response.status
- image_bytes = await response.read()
-
- f = discord.File(BytesIO(image_bytes), filename="image.png")
- image_url = "attachment://image.png"
-
- if status == 501:
- message = "Failed to get response"
- footer = ""
- color = Colours.soft_red
- elif status == 400:
- message = "No input found"
- footer = ""
- color = Colours.soft_red
- elif status == 403:
- message = "Wolfram API key is invalid or missing."
- footer = ""
- color = Colours.soft_red
- else:
- message = ""
- footer = "View original for a bigger picture."
- color = Colours.soft_orange
-
- # Sends a "blank" embed if no request is received, unsure how to fix
- await send_embed(ctx, message, color, footer=footer, img_url=image_url, f=f)
-
- @wolfram_command.command(name="page", aliases=("pa", "p"))
- @custom_cooldown(*STAFF_ROLES)
- async def wolfram_page_command(self, ctx: Context, *, query: str) -> None:
- """
- Requests a drawn image of given query.
-
- Keywords worth noting are, "like curve", "curve", "graph", "pokemon", etc.
- """
- pages = await get_pod_pages(ctx, self.bot, query)
-
- if not pages:
- return
-
- embed = Embed()
- embed.set_author(name="Wolfram Alpha",
- icon_url=WOLF_IMAGE,
- url="https://www.wolframalpha.com/")
- embed.colour = Colours.soft_orange
-
- await ImagePaginator.paginate(pages, ctx, embed)
-
- @wolfram_command.command(name="cut", aliases=("c",))
- @custom_cooldown(*STAFF_ROLES)
- async def wolfram_cut_command(self, ctx: Context, *, query: str) -> None:
- """
- Requests a drawn image of given query.
-
- Keywords worth noting are, "like curve", "curve", "graph", "pokemon", etc.
- """
- pages = await get_pod_pages(ctx, self.bot, query)
-
- if not pages:
- return
-
- if len(pages) >= 2:
- page = pages[1]
- else:
- page = pages[0]
-
- await send_embed(ctx, page[0], colour=Colours.soft_orange, img_url=page[1])
-
- @wolfram_command.command(name="short", aliases=("sh", "s"))
- @custom_cooldown(*STAFF_ROLES)
- async def wolfram_short_command(self, ctx: Context, *, query: str) -> None:
- """Requests an answer to a simple question."""
- url_str = parse.urlencode({
- "i": query,
- "appid": APPID,
- })
- query = QUERY.format(request="result", data=url_str)
-
- # Give feedback that the bot is working.
- async with ctx.channel.typing():
- async with self.bot.http_session.get(query) as response:
- status = response.status
- response_text = await response.text()
-
- if status == 501:
- message = "Failed to get response"
- color = Colours.soft_red
- elif status == 400:
- message = "No input found"
- color = Colours.soft_red
- elif response_text == "Error 1: Invalid appid":
- message = "Wolfram API key is invalid or missing."
- color = Colours.soft_red
- else:
- message = response_text
- color = Colours.soft_orange
-
- await send_embed(ctx, message, color)
-
-
-def setup(bot: Bot) -> None:
- """Load the Wolfram cog."""
- bot.add_cog(Wolfram(bot))
diff --git a/bot/command.py b/bot/command.py
new file mode 100644
index 000000000..0fb900f7b
--- /dev/null
+++ b/bot/command.py
@@ -0,0 +1,18 @@
+from discord.ext import commands
+
+
+class Command(commands.Command):
+ """
+ A `discord.ext.commands.Command` subclass which supports root aliases.
+
+ A `root_aliases` keyword argument is added, which is a sequence of alias names that will act as
+ top-level commands rather than being aliases of the command's group. It's stored as an attribute
+ also named `root_aliases`.
+ """
+
+ def __init__(self, *args, **kwargs):
+ super().__init__(*args, **kwargs)
+ self.root_aliases = kwargs.get("root_aliases", [])
+
+ if not isinstance(self.root_aliases, (list, tuple)):
+ raise TypeError("Root aliases of a command must be a list or a tuple of strings.")
diff --git a/bot/constants.py b/bot/constants.py
index cf4f3f666..17fe34e95 100644
--- a/bot/constants.py
+++ b/bot/constants.py
@@ -227,10 +227,6 @@ class Filter(metaclass=YAMLGetter):
ping_everyone: bool
offensive_msg_delete_days: int
- guild_invite_whitelist: List[int]
- domain_blacklist: List[str]
- word_watchlist: List[str]
- token_watchlist: List[str]
channel_whitelist: List[int]
role_whitelist: List[int]
@@ -272,6 +268,17 @@ class Emojis(metaclass=YAMLGetter):
status_idle: str
status_dnd: str
+ badge_staff: str
+ badge_partner: str
+ badge_hypesquad: str
+ badge_bug_hunter: str
+ badge_hypesquad_bravery: str
+ badge_hypesquad_brilliance: str
+ badge_hypesquad_balance: str
+ badge_early_supporter: str
+ badge_bug_hunter_level_2: str
+ badge_verified_bot_developer: str
+
incident_actioned: str
incident_unactioned: str
incident_investigating: str
@@ -489,25 +496,13 @@ class URLs(metaclass=YAMLGetter):
bot_avatar: str
github_bot_repo: str
- # Site endpoints
+ # Base site vars
site: str
site_api: str
- site_superstarify_api: str
- site_logs_api: str
- site_logs_view: str
- site_reminders_api: str
- site_reminders_user_api: str
site_schema: str
- site_settings_api: str
- site_tags_api: str
- site_user_api: str
- site_user_complete_api: str
- site_infractions: str
- site_infractions_user: str
- site_infractions_type: str
- site_infractions_by_id: str
- site_infractions_user_type_current: str
- site_infractions_user_type: str
+
+ # Site endpoints
+ site_logs_view: str
paste_service: str
@@ -519,14 +514,6 @@ class Reddit(metaclass=YAMLGetter):
secret: Optional[str]
-class Wolfram(metaclass=YAMLGetter):
- section = "wolfram"
-
- user_limit_day: int
- guild_limit_day: int
- key: Optional[str]
-
-
class AntiSpam(metaclass=YAMLGetter):
section = 'anti_spam'
@@ -537,12 +524,6 @@ class AntiSpam(metaclass=YAMLGetter):
rules: Dict[str, Dict[str, int]]
-class AntiMalware(metaclass=YAMLGetter):
- section = "anti_malware"
-
- whitelist: list
-
-
class BigBrother(metaclass=YAMLGetter):
section = 'big_brother'
diff --git a/bot/converters.py b/bot/converters.py
index 4a0633951..1358cbf1e 100644
--- a/bot/converters.py
+++ b/bot/converters.py
@@ -9,8 +9,11 @@ import dateutil.tz
import discord
from aiohttp import ClientConnectorError
from dateutil.relativedelta import relativedelta
-from discord.ext.commands import BadArgument, Context, Converter, UserConverter
+from discord.ext.commands import BadArgument, Bot, Context, Converter, IDConverter, UserConverter
+from bot.api import ResponseCodeError
+from bot.constants import URLs
+from bot.utils.regex import INVITE_RE
log = logging.getLogger(__name__)
@@ -34,6 +37,90 @@ def allowed_strings(*values, preserve_case: bool = False) -> t.Callable[[str], s
return converter
+class ValidDiscordServerInvite(Converter):
+ """
+ A converter that validates whether a given string is a valid Discord server invite.
+
+ Raises 'BadArgument' if:
+ - The string is not a valid Discord server invite.
+ - The string is valid, but is an invite for a group DM.
+ - The string is valid, but is expired.
+
+ Returns a (partial) guild object if:
+ - The string is a valid vanity
+ - The string is a full invite URI
+ - The string contains the invite code (the stuff after discord.gg/)
+
+ See the Discord API docs for documentation on the guild object:
+ https://discord.com/developers/docs/resources/guild#guild-object
+ """
+
+ async def convert(self, ctx: Context, server_invite: str) -> dict:
+ """Check whether the string is a valid Discord server invite."""
+ invite_code = INVITE_RE.search(server_invite)
+ if invite_code:
+ response = await ctx.bot.http_session.get(
+ f"{URLs.discord_invite_api}/{invite_code[1]}"
+ )
+ if response.status != 404:
+ invite_data = await response.json()
+ return invite_data.get("guild")
+
+ id_converter = IDConverter()
+ if id_converter._get_id_match(server_invite):
+ raise BadArgument("Guild IDs are not supported, only invites.")
+
+ raise BadArgument("This does not appear to be a valid Discord server invite.")
+
+
+class ValidFilterListType(Converter):
+ """
+ A converter that checks whether the given string is a valid FilterList type.
+
+ Raises `BadArgument` if the argument is not a valid FilterList type, and simply
+ passes through the given argument otherwise.
+ """
+
+ @staticmethod
+ async def get_valid_types(bot: Bot) -> list:
+ """
+ Try to get a list of valid filter list types.
+
+ Raise a BadArgument if the API can't respond.
+ """
+ try:
+ valid_types = await bot.api_client.get('bot/filter-lists/get-types')
+ except ResponseCodeError:
+ raise BadArgument("Cannot validate list_type: Unable to fetch valid types from API.")
+
+ return [enum for enum, classname in valid_types]
+
+ async def convert(self, ctx: Context, list_type: str) -> str:
+ """Checks whether the given string is a valid FilterList type."""
+ valid_types = await self.get_valid_types(ctx.bot)
+ list_type = list_type.upper()
+
+ if list_type not in valid_types:
+
+ # Maybe the user is using the plural form of this type,
+ # e.g. "guild_invites" instead of "guild_invite".
+ #
+ # This code will support the simple plural form (a single 's' at the end),
+ # which works for all current list types, but if a list type is added in the future
+ # which has an irregular plural form (like 'ies'), this code will need to be
+ # refactored to support this.
+ if list_type.endswith("S") and list_type[:-1] in valid_types:
+ list_type = list_type[:-1]
+
+ else:
+ valid_types_list = '\n'.join([f"• {type_.lower()}" for type_ in valid_types])
+ raise BadArgument(
+ f"You have provided an invalid list type!\n\n"
+ f"Please provide one of the following: \n{valid_types_list}"
+ )
+ return list_type
+
+
class ValidPythonIdentifier(Converter):
"""
A converter that checks whether the given string is a valid Python identifier.
@@ -237,6 +324,32 @@ class Duration(DurationDelta):
raise BadArgument(f"`{duration}` results in a datetime outside the supported range.")
+class OffTopicName(Converter):
+ """A converter that ensures an added off-topic name is valid."""
+
+ async def convert(self, ctx: Context, argument: str) -> str:
+ """Attempt to replace any invalid characters with their approximate Unicode equivalent."""
+ allowed_characters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ!?'`-"
+
+ # Chain multiple words to a single one
+ argument = "-".join(argument.split())
+
+ if not (2 <= len(argument) <= 96):
+ raise BadArgument("Channel name must be between 2 and 96 chars long")
+
+ elif not all(c.isalnum() or c in allowed_characters for c in argument):
+ raise BadArgument(
+ "Channel name must only consist of "
+ "alphanumeric characters, minus signs or apostrophes."
+ )
+
+ # Replace invalid characters with unicode alternatives.
+ table = str.maketrans(
+ allowed_characters, '𝖠𝖡𝖢𝖣𝖤𝖥𝖦𝖧𝖨𝖩𝖪𝖫𝖬𝖭𝖮𝖯𝖰𝖱𝖲𝖳𝖴𝖵𝖶𝖷𝖸𝖹ǃ?’’-'
+ )
+ return argument.translate(table)
+
+
class ISODateTime(Converter):
"""Converts an ISO-8601 datetime string into a datetime.datetime."""
diff --git a/bot/pagination.py b/bot/pagination.py
index 94c2d7c0c..182b2fa76 100644
--- a/bot/pagination.py
+++ b/bot/pagination.py
@@ -313,8 +313,6 @@ class LinePaginator(Paginator):
log.debug(f"Got first page reaction - changing to page 1/{len(paginator.pages)}")
- embed.description = ""
- await message.edit(embed=embed)
embed.description = paginator.pages[current_page]
if footer_text:
embed.set_footer(text=f"{footer_text} (Page {current_page + 1}/{len(paginator.pages)})")
@@ -328,8 +326,6 @@ class LinePaginator(Paginator):
log.debug(f"Got last page reaction - changing to page {current_page + 1}/{len(paginator.pages)}")
- embed.description = ""
- await message.edit(embed=embed)
embed.description = paginator.pages[current_page]
if footer_text:
embed.set_footer(text=f"{footer_text} (Page {current_page + 1}/{len(paginator.pages)})")
@@ -347,8 +343,6 @@ class LinePaginator(Paginator):
current_page -= 1
log.debug(f"Got previous page reaction - changing to page {current_page + 1}/{len(paginator.pages)}")
- embed.description = ""
- await message.edit(embed=embed)
embed.description = paginator.pages[current_page]
if footer_text:
@@ -368,8 +362,6 @@ class LinePaginator(Paginator):
current_page += 1
log.debug(f"Got next page reaction - changing to page {current_page + 1}/{len(paginator.pages)}")
- embed.description = ""
- await message.edit(embed=embed)
embed.description = paginator.pages[current_page]
if footer_text:
@@ -382,169 +374,3 @@ class LinePaginator(Paginator):
log.debug("Ending pagination and clearing reactions.")
with suppress(discord.NotFound):
await message.clear_reactions()
-
-
-class ImagePaginator(Paginator):
- """
- Helper class that paginates images for embeds in messages.
-
- Close resemblance to LinePaginator, except focuses on images over text.
-
- Refer to ImagePaginator.paginate for documentation on how to use.
- """
-
- def __init__(self, prefix: str = "", suffix: str = ""):
- super().__init__(prefix, suffix)
- self._current_page = [prefix]
- self.images = []
- self._pages = []
- self._count = 0
-
- def add_line(self, line: str = '', *, empty: bool = False) -> None:
- """Adds a line to each page."""
- if line:
- self._count = len(line)
- else:
- self._count = 0
- self._current_page.append(line)
- self.close_page()
-
- def add_image(self, image: str = None) -> None:
- """Adds an image to a page."""
- self.images.append(image)
-
- @classmethod
- async def paginate(
- cls,
- pages: t.List[t.Tuple[str, str]],
- ctx: Context, embed: discord.Embed,
- prefix: str = "",
- suffix: str = "",
- timeout: int = 300,
- exception_on_empty_embed: bool = False
- ) -> t.Optional[discord.Message]:
- """
- Use a paginator and set of reactions to provide pagination over a set of title/image pairs.
-
- The reactions are used to switch page, or to finish with pagination.
-
- When used, this will send a message using `ctx.send()` and apply a set of reactions to it. These reactions may
- be used to change page, or to remove pagination from the message.
-
- Note: Pagination will be removed automatically if no reaction is added for five minutes (300 seconds).
-
- Example:
- >>> embed = discord.Embed()
- >>> embed.set_author(name="Some Operation", url=url, icon_url=icon)
- >>> await ImagePaginator.paginate(pages, ctx, embed)
- """
- def check_event(reaction_: discord.Reaction, member: discord.Member) -> bool:
- """Checks each reaction added, if it matches our conditions pass the wait_for."""
- return all((
- # Reaction is on the same message sent
- reaction_.message.id == message.id,
- # The reaction is part of the navigation menu
- str(reaction_.emoji) in PAGINATION_EMOJI,
- # The reactor is not a bot
- not member.bot
- ))
-
- paginator = cls(prefix=prefix, suffix=suffix)
- current_page = 0
-
- if not pages:
- if exception_on_empty_embed:
- log.exception("Pagination asked for empty image list")
- raise EmptyPaginatorEmbed("No images to paginate")
-
- log.debug("No images to add to paginator, adding '(no images to display)' message")
- pages.append(("(no images to display)", ""))
-
- for text, image_url in pages:
- paginator.add_line(text)
- paginator.add_image(image_url)
-
- embed.description = paginator.pages[current_page]
- image = paginator.images[current_page]
-
- if image:
- embed.set_image(url=image)
-
- if len(paginator.pages) <= 1:
- return await ctx.send(embed=embed)
-
- embed.set_footer(text=f"Page {current_page + 1}/{len(paginator.pages)}")
- message = await ctx.send(embed=embed)
-
- for emoji in PAGINATION_EMOJI:
- await message.add_reaction(emoji)
-
- while True:
- # Start waiting for reactions
- try:
- reaction, user = await ctx.bot.wait_for("reaction_add", timeout=timeout, check=check_event)
- except asyncio.TimeoutError:
- log.debug("Timed out waiting for a reaction")
- break # We're done, no reactions for the last 5 minutes
-
- # Deletes the users reaction
- await message.remove_reaction(reaction.emoji, user)
-
- # Delete reaction press - [:trashcan:]
- if str(reaction.emoji) == DELETE_EMOJI:
- log.debug("Got delete reaction")
- return await message.delete()
-
- # First reaction press - [:track_previous:]
- if reaction.emoji == FIRST_EMOJI:
- if current_page == 0:
- log.debug("Got first page reaction, but we're on the first page - ignoring")
- continue
-
- current_page = 0
- reaction_type = "first"
-
- # Last reaction press - [:track_next:]
- if reaction.emoji == LAST_EMOJI:
- if current_page >= len(paginator.pages) - 1:
- log.debug("Got last page reaction, but we're on the last page - ignoring")
- continue
-
- current_page = len(paginator.pages) - 1
- reaction_type = "last"
-
- # Previous reaction press - [:arrow_left: ]
- if reaction.emoji == LEFT_EMOJI:
- if current_page <= 0:
- log.debug("Got previous page reaction, but we're on the first page - ignoring")
- continue
-
- current_page -= 1
- reaction_type = "previous"
-
- # Next reaction press - [:arrow_right:]
- if reaction.emoji == RIGHT_EMOJI:
- if current_page >= len(paginator.pages) - 1:
- log.debug("Got next page reaction, but we're on the last page - ignoring")
- continue
-
- current_page += 1
- reaction_type = "next"
-
- # Magic happens here, after page and reaction_type is set
- embed.description = ""
- await message.edit(embed=embed)
- embed.description = paginator.pages[current_page]
-
- image = paginator.images[current_page]
- if image:
- embed.set_image(url=image)
-
- embed.set_footer(text=f"Page {current_page + 1}/{len(paginator.pages)}")
- log.debug(f"Got {reaction_type} page reaction - changing to page {current_page + 1}/{len(paginator.pages)}")
-
- await message.edit(embed=embed)
-
- log.debug("Ending pagination and clearing reactions.")
- with suppress(discord.NotFound):
- await message.clear_reactions()
diff --git a/bot/resources/tags/ask.md b/bot/resources/tags/ask.md
deleted file mode 100644
index e2c2a88f6..000000000
--- a/bot/resources/tags/ask.md
+++ /dev/null
@@ -1,9 +0,0 @@
-Asking good questions will yield a much higher chance of a quick response:
-
-• Don't ask to ask your question, just go ahead and tell us your problem.
-• Don't ask if anyone is knowledgeable in some area, filtering serves no purpose.
-• Try to solve the problem on your own first, we're not going to write code for you.
-• Show us the code you've tried and any errors or unexpected results it's giving.
-• Be patient while we're helping you.
-
-You can find a much more detailed explanation [on our website](https://pythondiscord.com/pages/asking-good-questions/).
diff --git a/bot/resources/tags/kindling-projects.md b/bot/resources/tags/kindling-projects.md
new file mode 100644
index 000000000..54ed8c961
--- /dev/null
+++ b/bot/resources/tags/kindling-projects.md
@@ -0,0 +1,3 @@
+**Kindling Projects**
+
+The [Kindling projects page](https://nedbatchelder.com/text/kindling.html) on Ned Batchelder's website contains a list of projects and ideas programmers can tackle to build their skills and knowledge.
diff --git a/bot/resources/tags/traceback.md b/bot/resources/tags/traceback.md
index 46ef40aa1..e770fa86d 100644
--- a/bot/resources/tags/traceback.md
+++ b/bot/resources/tags/traceback.md
@@ -11,7 +11,7 @@ ZeroDivisionError: integer division or modulo by zero
```
The best way to read your traceback is bottom to top.
-• Identify the exception raised (e.g. ZeroDivisonError)
+• Identify the exception raised (e.g. ZeroDivisionError)
• Make note of the line number, and navigate there in your program.
• Try to understand why the error occurred.
diff --git a/bot/rules/__init__.py b/bot/rules/__init__.py
index a01ceae73..8a69cadee 100644
--- a/bot/rules/__init__.py
+++ b/bot/rules/__init__.py
@@ -10,3 +10,4 @@ from .links import apply as apply_links
from .mentions import apply as apply_mentions
from .newlines import apply as apply_newlines
from .role_mentions import apply as apply_role_mentions
+from .everyone_ping import apply as apply_everyone_ping
diff --git a/bot/rules/discord_emojis.py b/bot/rules/discord_emojis.py
index 5bab514f2..6e47f0197 100644
--- a/bot/rules/discord_emojis.py
+++ b/bot/rules/discord_emojis.py
@@ -5,6 +5,7 @@ from discord import Member, Message
DISCORD_EMOJI_RE = re.compile(r"<:\w+:\d+>")
+CODE_BLOCK_RE = re.compile(r"```.*?```", flags=re.DOTALL)
async def apply(
@@ -17,8 +18,9 @@ async def apply(
if msg.author == last_message.author
)
+ # Get rid of code blocks in the message before searching for emojis.
total_emojis = sum(
- len(DISCORD_EMOJI_RE.findall(msg.content))
+ len(DISCORD_EMOJI_RE.findall(CODE_BLOCK_RE.sub("", msg.content)))
for msg in relevant_messages
)
diff --git a/bot/rules/everyone_ping.py b/bot/rules/everyone_ping.py
new file mode 100644
index 000000000..89d9fe570
--- /dev/null
+++ b/bot/rules/everyone_ping.py
@@ -0,0 +1,41 @@
+import random
+import re
+from typing import Dict, Iterable, List, Optional, Tuple
+
+from discord import Embed, Member, Message
+
+from bot.constants import Colours, Guild, NEGATIVE_REPLIES
+
+# Generate regex for checking for pings:
+guild_id = Guild.id
+EVERYONE_RE_INLINE_CODE = re.compile(rf"^(?!`).*@everyone.*(?!`)$|^(?!`).*<@&{guild_id}>.*(?!`)$")
+EVERYONE_RE_MULTILINE_CODE = re.compile(rf"^(?!```).*@everyone.*(?!```)$|^(?!```).*<@&{guild_id}>.*(?!```)$")
+
+
+async def apply(
+ last_message: Message,
+ recent_messages: List[Message],
+ config: Dict[str, int],
+) -> Optional[Tuple[str, Iterable[Member], Iterable[Message]]]:
+ """Detects if a user has sent an '@everyone' ping."""
+ relevant_messages = tuple(msg for msg in recent_messages if msg.author == last_message.author)
+
+ everyone_messages_count = 0
+ for msg in relevant_messages:
+ num_everyone_pings_inline = len(re.findall(EVERYONE_RE_INLINE_CODE, msg.content))
+ num_everyone_pings_multiline = len(re.findall(EVERYONE_RE_MULTILINE_CODE, msg.content))
+ if num_everyone_pings_inline and num_everyone_pings_multiline:
+ everyone_messages_count += 1
+
+ if everyone_messages_count > config["max"]:
+ # Send the channel an embed giving the user more info:
+ embed_text = f"Please don't try to ping {last_message.guild.member_count:,} people."
+ embed = Embed(title=random.choice(NEGATIVE_REPLIES), description=embed_text, colour=Colours.soft_red)
+ await last_message.channel.send(embed=embed)
+
+ return (
+ "pinged the everyone role",
+ (last_message.author,),
+ relevant_messages,
+ )
+ return None
diff --git a/bot/utils/messages.py b/bot/utils/messages.py
index 670289941..aa8f17f75 100644
--- a/bot/utils/messages.py
+++ b/bot/utils/messages.py
@@ -19,25 +19,20 @@ log = logging.getLogger(__name__)
async def wait_for_deletion(
message: Message,
user_ids: Sequence[Snowflake],
+ client: Client,
deletion_emojis: Sequence[str] = (Emojis.trashcan,),
timeout: float = 60 * 5,
attach_emojis: bool = True,
- client: Optional[Client] = None
) -> None:
"""
Wait for up to `timeout` seconds for a reaction by any of the specified `user_ids` to delete the message.
An `attach_emojis` bool may be specified to determine whether to attach the given
- `deletion_emojis` to the message in the given `context`
-
- A `client` instance may be optionally specified, otherwise client will be taken from the
- guild of the message.
+ `deletion_emojis` to the message in the given `context`.
"""
- if message.guild is None and client is None:
+ if message.guild is None:
raise ValueError("Message must be sent on a guild")
- bot = client or message.guild.me
-
if attach_emojis:
for emoji in deletion_emojis:
await message.add_reaction(emoji)
@@ -51,7 +46,7 @@ async def wait_for_deletion(
)
with contextlib.suppress(asyncio.TimeoutError):
- await bot.wait_for('reaction_add', check=check, timeout=timeout)
+ await client.wait_for('reaction_add', check=check, timeout=timeout)
await message.delete()
diff --git a/bot/utils/redis_cache.py b/bot/utils/redis_cache.py
index 58cfe1df5..52b689b49 100644
--- a/bot/utils/redis_cache.py
+++ b/bot/utils/redis_cache.py
@@ -226,7 +226,6 @@ class RedisCache:
for attribute in vars(instance).values():
if isinstance(attribute, Bot):
self.bot = attribute
- self._redis = self.bot.redis_session
return self
else:
error_message = (
@@ -251,7 +250,7 @@ class RedisCache:
value = self._value_to_typestring(value)
log.trace(f"Setting {key} to {value}.")
- await self._redis.hset(self._namespace, key, value)
+ await self.bot.redis_session.hset(self._namespace, key, value)
async def get(self, key: RedisKeyType, default: Optional[RedisValueType] = None) -> Optional[RedisValueType]:
"""Get an item from the Redis cache."""
@@ -259,7 +258,7 @@ class RedisCache:
key = self._key_to_typestring(key)
log.trace(f"Attempting to retrieve {key}.")
- value = await self._redis.hget(self._namespace, key)
+ value = await self.bot.redis_session.hget(self._namespace, key)
if value is None:
log.trace(f"Value not found, returning default value {default}")
@@ -281,7 +280,7 @@ class RedisCache:
key = self._key_to_typestring(key)
log.trace(f"Attempting to delete {key}.")
- return await self._redis.hdel(self._namespace, key)
+ return await self.bot.redis_session.hdel(self._namespace, key)
async def contains(self, key: RedisKeyType) -> bool:
"""
@@ -291,7 +290,7 @@ class RedisCache:
"""
await self._validate_cache()
key = self._key_to_typestring(key)
- exists = await self._redis.hexists(self._namespace, key)
+ exists = await self.bot.redis_session.hexists(self._namespace, key)
log.trace(f"Testing if {key} exists in the RedisCache - Result is {exists}")
return exists
@@ -314,7 +313,7 @@ class RedisCache:
"""
await self._validate_cache()
items = self._dict_from_typestring(
- await self._redis.hgetall(self._namespace)
+ await self.bot.redis_session.hgetall(self._namespace)
).items()
log.trace(f"Retrieving all key/value pairs from cache, total of {len(items)} items.")
@@ -323,7 +322,7 @@ class RedisCache:
async def length(self) -> int:
"""Return the number of items in the Redis cache."""
await self._validate_cache()
- number_of_items = await self._redis.hlen(self._namespace)
+ number_of_items = await self.bot.redis_session.hlen(self._namespace)
log.trace(f"Returning length. Result is {number_of_items}.")
return number_of_items
@@ -335,7 +334,7 @@ class RedisCache:
"""Deletes the entire hash from the Redis cache."""
await self._validate_cache()
log.trace("Clearing the cache of all key/value pairs.")
- await self._redis.delete(self._namespace)
+ await self.bot.redis_session.delete(self._namespace)
async def pop(self, key: RedisKeyType, default: Optional[RedisValueType] = None) -> RedisValueType:
"""Get the item, remove it from the cache, and provide a default if not found."""
@@ -364,7 +363,7 @@ class RedisCache:
"""
await self._validate_cache()
log.trace(f"Updating the cache with the following items:\n{items}")
- await self._redis.hmset_dict(self._namespace, self._dict_to_typestring(items))
+ await self.bot.redis_session.hmset_dict(self._namespace, self._dict_to_typestring(items))
async def increment(self, key: RedisKeyType, amount: Optional[int, float] = 1) -> None:
"""
diff --git a/bot/utils/regex.py b/bot/utils/regex.py
new file mode 100644
index 000000000..0d2068f90
--- /dev/null
+++ b/bot/utils/regex.py
@@ -0,0 +1,12 @@
+import re
+
+INVITE_RE = re.compile(
+ r"(?:discord(?:[\.,]|dot)gg|" # Could be discord.gg/
+ r"discord(?:[\.,]|dot)com(?:\/|slash)invite|" # or discord.com/invite/
+ r"discordapp(?:[\.,]|dot)com(?:\/|slash)invite|" # or discordapp.com/invite/
+ r"discord(?:[\.,]|dot)me|" # or discord.me
+ r"discord(?:[\.,]|dot)io" # or discord.io.
+ r")(?:[\/]|slash)" # / or 'slash'
+ r"([a-zA-Z0-9\-]+)", # the invite code itself
+ flags=re.IGNORECASE
+)
diff --git a/config-default.yml b/config-default.yml
index fc093cc32..6e7cff92d 100644
--- a/config-default.yml
+++ b/config-default.yml
@@ -38,6 +38,17 @@ style:
status_dnd: "<:status_dnd:470326272082313216>"
status_offline: "<:status_offline:470326266537705472>"
+ badge_staff: "<:discord_staff:743882896498098226>"
+ badge_partner: "<:partner:748666453242413136>"
+ badge_hypesquad: "<:hypesquad_events:743882896892362873>"
+ badge_bug_hunter: "<:bug_hunter_lvl1:743882896372269137>"
+ badge_hypesquad_bravery: "<:hypesquad_bravery:743882896745693335>"
+ badge_hypesquad_brilliance: "<:hypesquad_brilliance:743882896938631248>"
+ badge_hypesquad_balance: "<:hypesquad_balance:743882896460480625>"
+ badge_early_supporter: "<:early_supporter:743882896909140058>"
+ badge_bug_hunter_level_2: "<:bug_hunter_lvl2:743882896611344505>"
+ badge_verified_bot_developer: "<:verified_bot_dev:743882897299210310>"
+
incident_actioned: "<:incident_actioned:719645530128646266>"
incident_unactioned: "<:incident_unactioned:719645583245180960>"
incident_investigating: "<:incident_investigating:719645658671480924>"
@@ -278,107 +289,6 @@ filter:
ping_everyone: true
offensive_msg_delete_days: 7 # How many days before deleting an offensive message?
- guild_invite_whitelist:
- - 280033776820813825 # Functional Programming
- - 267624335836053506 # Python Discord
- - 440186186024222721 # Python Discord: Emojis 1
- - 578587418123304970 # Python Discord: Emojis 2
- - 273944235143593984 # STEM
- - 348658686962696195 # RLBot
- - 531221516914917387 # Pallets
- - 249111029668249601 # Gentoo
- - 327254708534116352 # Adafruit
- - 544525886180032552 # kennethreitz.org
- - 590806733924859943 # Discord Hack Week
- - 423249981340778496 # Kivy
- - 197038439483310086 # Discord Testers
- - 286633898581164032 # Ren'Py
- - 349505959032389632 # PyGame
- - 438622377094414346 # Pyglet
- - 524691714909274162 # Panda3D
- - 336642139381301249 # discord.py
- - 405403391410438165 # Sentdex
- - 172018499005317120 # The Coding Den
- - 666560367173828639 # PyWeek
- - 702724176489873509 # Microsoft Python
- - 150662382874525696 # Microsoft Community
- - 81384788765712384 # Discord API
- - 613425648685547541 # Discord Developers
- - 185590609631903755 # Blender Hub
- - 420324994703163402 # /r/FlutterDev
- - 488751051629920277 # Python Atlanta
- - 143867839282020352 # C#
- - 159039020565790721 # Django
- - 238666723824238602 # Programming Discussions
- - 433980600391696384 # JetBrains Community
- - 204621105720328193 # Raspberry Pi
- - 244230771232079873 # Programmers Hangout
- - 239433591950540801 # SpeakJS
- - 174075418410876928 # DevCord
- - 489222168727519232 # Unity
- - 494558898880118785 # Programmer Humor
-
- domain_blacklist:
- - pornhub.com
- - liveleak.com
- - grabify.link
- - bmwforum.co
- - leancoding.co
- - spottyfly.com
- - stopify.co
- - yoütu.be
- - discörd.com
- - minecräft.com
- - freegiftcards.co
- - disçordapp.com
- - fortnight.space
- - fortnitechat.site
- - joinmy.site
- - curiouscat.club
- - catsnthings.fun
- - yourtube.site
- - youtubeshort.watch
- - catsnthing.com
- - youtubeshort.pro
- - canadianlumberjacks.online
- - poweredbydialup.club
- - poweredbydialup.online
- - poweredbysecurity.org
- - poweredbysecurity.online
- - ssteam.site
- - steamwalletgift.com
- - discord.gift
- - lmgtfy.com
-
- word_watchlist:
- - goo+ks*
- - ky+s+
- - ki+ke+s*
- - beaner+s?
- - coo+ns*
- - nig+lets*
- - slant-eyes*
- - towe?l-?head+s*
- - chi*n+k+s*
- - spick*s*
- - kill* +(?:yo)?urself+
- - jew+s*
- - suicide
- - rape
- - (re+)tar+(d+|t+)(ed)?
- - ta+r+d+
- - cunts*
- - trann*y
- - shemale
-
- token_watchlist:
- - fa+g+s*
- - 卐
- - 卍
- - cuck(?!oo+)
- - nigg+(?:e*r+|a+h*?|u+h+)s?
- - fag+o+t+s*
-
# Censor doesn't apply to these
channel_whitelist:
- *ADMINS
@@ -410,24 +320,7 @@ urls:
site_staff: &STAFF !JOIN ["staff.", *DOMAIN]
site_schema: &SCHEMA "https://"
- site_bigbrother_api: !JOIN [*SCHEMA, *API, "/bot/bigbrother"]
- site_docs_api: !JOIN [*SCHEMA, *API, "/bot/docs"]
- site_superstarify_api: !JOIN [*SCHEMA, *API, "/bot/superstarify"]
- site_infractions: !JOIN [*SCHEMA, *API, "/bot/infractions"]
- site_infractions_user: !JOIN [*SCHEMA, *API, "/bot/infractions/user/{user_id}"]
- site_infractions_type: !JOIN [*SCHEMA, *API, "/bot/infractions/type/{infraction_type}"]
- site_infractions_by_id: !JOIN [*SCHEMA, *API, "/bot/infractions/id/{infraction_id}"]
- site_infractions_user_type_current: !JOIN [*SCHEMA, *API, "/bot/infractions/user/{user_id}/{infraction_type}/current"]
- site_infractions_user_type: !JOIN [*SCHEMA, *API, "/bot/infractions/user/{user_id}/{infraction_type}"]
- site_logs_api: !JOIN [*SCHEMA, *API, "/bot/logs"]
site_logs_view: !JOIN [*SCHEMA, *STAFF, "/bot/logs"]
- site_off_topic_names_api: !JOIN [*SCHEMA, *API, "/bot/off-topic-names"]
- site_reminders_api: !JOIN [*SCHEMA, *API, "/bot/reminders"]
- site_reminders_user_api: !JOIN [*SCHEMA, *API, "/bot/reminders/user"]
- site_settings_api: !JOIN [*SCHEMA, *API, "/bot/settings"]
- site_tags_api: !JOIN [*SCHEMA, *API, "/bot/tags"]
- site_user_api: !JOIN [*SCHEMA, *API, "/bot/users"]
- site_user_complete_api: !JOIN [*SCHEMA, *API, "/bot/users/complete"]
paste_service: !JOIN [*SCHEMA, *PASTE, "/{key}"]
# Snekbox
@@ -459,6 +352,14 @@ anti_spam:
interval: 10
max: 7
+ # Burst shared it (temporarily) disabled to prevent
+ # the bug that triggers multiple infractions/DMs per
+ # user. It also tends to catch a lot of innocent users
+ # now that we're so big.
+ # burst_shared:
+ # interval: 10
+ # max: 20
+
chars:
interval: 5
max: 3_000
@@ -488,34 +389,11 @@ anti_spam:
interval: 10
max: 3
-
-anti_malware:
- whitelist:
- - '.3gp'
- - '.3g2'
- - '.avi'
- - '.bmp'
- - '.gif'
- - '.h264'
- - '.jpg'
- - '.jpeg'
- - '.m4v'
- - '.mkv'
- - '.mov'
- - '.mp4'
- - '.mpeg'
- - '.mpg'
- - '.png'
- - '.tiff'
- - '.wmv'
- - '.svg'
- - '.psd' # Photoshop
- - '.ai' # Illustrator
- - '.aep' # After Effects
- - '.xcf' # GIMP
- - '.mp3'
- - '.wav'
- - '.ogg'
+ # The everyone ping filter is temporarily disabled
+ # until we've fixed a couple of bugs.
+ # everyone_ping:
+ # interval: 10
+ # max: 0
reddit:
@@ -525,13 +403,6 @@ reddit:
secret: !ENV "REDDIT_SECRET"
-wolfram:
- # Max requests per day.
- user_limit_day: 10
- guild_limit_day: 67
- key: !ENV "WOLFRAM_API_KEY"
-
-
big_brother:
log_delay: 15
header_message_limit: 15
@@ -558,8 +429,8 @@ help_channels:
# Allowed duration of inactivity before making a channel dormant
idle_minutes: 30
- # Allowed duration of inactivity when question message deleted
- # and no one other sent before message making channel dormant.
+ # Allowed duration of inactivity when channel is empty (due to deleted messages)
+ # before message making a channel dormant
deleted_idle_minutes: 5
# Maximum number of channels to put in the available category
diff --git a/tests/bot/cogs/test_antimalware.py b/tests/bot/cogs/test_antimalware.py
index f219fc1ba..f50c0492d 100644
--- a/tests/bot/cogs/test_antimalware.py
+++ b/tests/bot/cogs/test_antimalware.py
@@ -1,28 +1,35 @@
import unittest
-from unittest.mock import AsyncMock, Mock, patch
+from unittest.mock import AsyncMock, Mock
from discord import NotFound
from bot.cogs import antimalware
-from bot.constants import AntiMalware as AntiMalwareConfig, Channels, STAFF_ROLES
+from bot.constants import Channels, STAFF_ROLES
from tests.helpers import MockAttachment, MockBot, MockMessage, MockRole
-MODULE = "bot.cogs.antimalware"
-
-@patch(f"{MODULE}.AntiMalwareConfig.whitelist", new=[".first", ".second", ".third"])
class AntiMalwareCogTests(unittest.IsolatedAsyncioTestCase):
"""Test the AntiMalware cog."""
def setUp(self):
"""Sets up fresh objects for each test."""
self.bot = MockBot()
+ self.bot.filter_list_cache = {
+ "FILE_FORMAT.True": {
+ ".first": {},
+ ".second": {},
+ ".third": {},
+ }
+ }
self.cog = antimalware.AntiMalware(self.bot)
self.message = MockMessage()
+ self.message.webhook_id = None
+ self.message.author.bot = None
+ self.whitelist = [".first", ".second", ".third"]
async def test_message_with_allowed_attachment(self):
"""Messages with allowed extensions should not be deleted"""
- attachment = MockAttachment(filename=f"python{AntiMalwareConfig.whitelist[0]}")
+ attachment = MockAttachment(filename="python.first")
self.message.attachments = [attachment]
await self.cog.on_message(self.message)
@@ -43,6 +50,26 @@ class AntiMalwareCogTests(unittest.IsolatedAsyncioTestCase):
self.message.delete.assert_not_called()
+ async def test_webhook_message_with_illegal_extension(self):
+ """A webhook message containing an illegal extension should be ignored."""
+ attachment = MockAttachment(filename="python.disallowed")
+ self.message.webhook_id = 697140105563078727
+ self.message.attachments = [attachment]
+
+ await self.cog.on_message(self.message)
+
+ self.message.delete.assert_not_called()
+
+ async def test_bot_message_with_illegal_extension(self):
+ """A bot message containing an illegal extension should be ignored."""
+ attachment = MockAttachment(filename="python.disallowed")
+ self.message.author.bot = 409107086526644234
+ self.message.attachments = [attachment]
+
+ await self.cog.on_message(self.message)
+
+ self.message.delete.assert_not_called()
+
async def test_message_with_illegal_extension_gets_deleted(self):
"""A message containing an illegal extension should send an embed."""
attachment = MockAttachment(filename="python.disallowed")
@@ -93,7 +120,7 @@ class AntiMalwareCogTests(unittest.IsolatedAsyncioTestCase):
self.assertEqual(embed.description, antimalware.TXT_EMBED_DESCRIPTION.format.return_value)
antimalware.TXT_EMBED_DESCRIPTION.format.assert_called_with(cmd_channel_mention=cmd_channel.mention)
- async def test_other_disallowed_extention_embed_description(self):
+ async def test_other_disallowed_extension_embed_description(self):
"""Test the description for a non .py/.txt disallowed extension."""
attachment = MockAttachment(filename="python.disallowed")
self.message.attachments = [attachment]
@@ -109,6 +136,7 @@ class AntiMalwareCogTests(unittest.IsolatedAsyncioTestCase):
self.assertEqual(embed.description, antimalware.DISALLOWED_EMBED_DESCRIPTION.format.return_value)
antimalware.DISALLOWED_EMBED_DESCRIPTION.format.assert_called_with(
+ joined_whitelist=", ".join(self.whitelist),
blocked_extensions_str=".disallowed",
meta_channel_mention=meta_channel.mention
)
@@ -135,7 +163,7 @@ class AntiMalwareCogTests(unittest.IsolatedAsyncioTestCase):
"""The return value should include all non-whitelisted extensions."""
test_values = (
([], []),
- (AntiMalwareConfig.whitelist, []),
+ (self.whitelist, []),
([".first"], []),
([".first", ".disallowed"], [".disallowed"]),
([".disallowed"], [".disallowed"]),
@@ -145,7 +173,7 @@ class AntiMalwareCogTests(unittest.IsolatedAsyncioTestCase):
for extensions, expected_disallowed_extensions in test_values:
with self.subTest(extensions=extensions, expected_disallowed_extensions=expected_disallowed_extensions):
self.message.attachments = [MockAttachment(filename=f"filename{extension}") for extension in extensions]
- disallowed_extensions = self.cog.get_disallowed_extensions(self.message)
+ disallowed_extensions = self.cog._get_disallowed_extensions(self.message)
self.assertCountEqual(disallowed_extensions, expected_disallowed_extensions)
diff --git a/tests/bot/cogs/test_cogs.py b/tests/bot/cogs/test_cogs.py
index fdda59a8f..30a04422a 100644
--- a/tests/bot/cogs/test_cogs.py
+++ b/tests/bot/cogs/test_cogs.py
@@ -53,6 +53,7 @@ class CommandNameTests(unittest.TestCase):
"""Return a list of all qualified names, including aliases, for the `command`."""
names = [f"{command.full_parent_name} {alias}".strip() for alias in command.aliases]
names.append(command.qualified_name)
+ names += getattr(command, "root_aliases", [])
return names
diff --git a/tests/bot/cogs/test_information.py b/tests/bot/cogs/test_information.py
index 79c0e0ad3..77b0ddf17 100644
--- a/tests/bot/cogs/test_information.py
+++ b/tests/bot/cogs/test_information.py
@@ -215,10 +215,10 @@ class UserInfractionHelperMethodTests(unittest.TestCase):
with self.subTest(method=method, api_response=api_response, expected_lines=expected_lines):
self.bot.api_client.get.return_value = api_response
- expected_output = "\n".join(default_header + expected_lines)
+ expected_output = "\n".join(expected_lines)
actual_output = asyncio.run(method(self.member))
- self.assertEqual(expected_output, actual_output)
+ self.assertEqual((default_header, expected_output), actual_output)
def test_basic_user_infraction_counts_returns_correct_strings(self):
"""The method should correctly list both the total and active number of non-hidden infractions."""
@@ -249,7 +249,7 @@ class UserInfractionHelperMethodTests(unittest.TestCase):
},
)
- header = ["**Infractions**"]
+ header = "Infractions"
self._method_subtests(self.cog.basic_user_infraction_counts, test_values, header)
@@ -258,7 +258,7 @@ class UserInfractionHelperMethodTests(unittest.TestCase):
test_values = (
{
"api response": [],
- "expected_lines": ["This user has never received an infraction."],
+ "expected_lines": ["No infractions"],
},
# Shows non-hidden inactive infraction as expected
{
@@ -304,7 +304,7 @@ class UserInfractionHelperMethodTests(unittest.TestCase):
},
)
- header = ["**Infractions**"]
+ header = "Infractions"
self._method_subtests(self.cog.expanded_user_infraction_counts, test_values, header)
@@ -313,15 +313,15 @@ class UserInfractionHelperMethodTests(unittest.TestCase):
test_values = (
{
"api response": [],
- "expected_lines": ["This user has never been nominated."],
+ "expected_lines": ["No nominations"],
},
{
"api response": [{'active': True}],
- "expected_lines": ["This user is **currently** nominated (1 nomination in total)."],
+ "expected_lines": ["This user is **currently** nominated", "(1 nomination in total)"],
},
{
"api response": [{'active': True}, {'active': False}],
- "expected_lines": ["This user is **currently** nominated (2 nominations in total)."],
+ "expected_lines": ["This user is **currently** nominated", "(2 nominations in total)"],
},
{
"api response": [{'active': False}],
@@ -334,7 +334,7 @@ class UserInfractionHelperMethodTests(unittest.TestCase):
)
- header = ["**Nominations**"]
+ header = "Nominations"
self._method_subtests(self.cog.user_nomination_counts, test_values, header)
@@ -350,7 +350,10 @@ class UserEmbedTests(unittest.TestCase):
self.bot.api_client.get = unittest.mock.AsyncMock()
self.cog = information.Information(self.bot)
- @unittest.mock.patch(f"{COG_PATH}.basic_user_infraction_counts", new=unittest.mock.AsyncMock(return_value=""))
+ @unittest.mock.patch(
+ f"{COG_PATH}.basic_user_infraction_counts",
+ new=unittest.mock.AsyncMock(return_value=("Infractions", "basic infractions"))
+ )
def test_create_user_embed_uses_string_representation_of_user_in_title_if_nick_is_not_available(self):
"""The embed should use the string representation of the user if they don't have a nick."""
ctx = helpers.MockContext(channel=helpers.MockTextChannel(id=1))
@@ -362,7 +365,10 @@ class UserEmbedTests(unittest.TestCase):
self.assertEqual(embed.title, "Mr. Hemlock")
- @unittest.mock.patch(f"{COG_PATH}.basic_user_infraction_counts", new=unittest.mock.AsyncMock(return_value=""))
+ @unittest.mock.patch(
+ f"{COG_PATH}.basic_user_infraction_counts",
+ new=unittest.mock.AsyncMock(return_value=("Infractions", "basic infractions"))
+ )
def test_create_user_embed_uses_nick_in_title_if_available(self):
"""The embed should use the nick if it's available."""
ctx = helpers.MockContext(channel=helpers.MockTextChannel(id=1))
@@ -374,7 +380,10 @@ class UserEmbedTests(unittest.TestCase):
self.assertEqual(embed.title, "Cat lover (Mr. Hemlock)")
- @unittest.mock.patch(f"{COG_PATH}.basic_user_infraction_counts", new=unittest.mock.AsyncMock(return_value=""))
+ @unittest.mock.patch(
+ f"{COG_PATH}.basic_user_infraction_counts",
+ new=unittest.mock.AsyncMock(return_value=("Infractions", "basic infractions"))
+ )
def test_create_user_embed_ignores_everyone_role(self):
"""Created `!user` embeds should not contain mention of the @everyone-role."""
ctx = helpers.MockContext(channel=helpers.MockTextChannel(id=1))
@@ -386,8 +395,8 @@ class UserEmbedTests(unittest.TestCase):
embed = asyncio.run(self.cog.create_user_embed(ctx, user))
- self.assertIn("&Admins", embed.description)
- self.assertNotIn("&Everyone", embed.description)
+ self.assertIn("&Admins", embed.fields[1].value)
+ self.assertNotIn("&Everyone", embed.fields[1].value)
@unittest.mock.patch(f"{COG_PATH}.expanded_user_infraction_counts", new_callable=unittest.mock.AsyncMock)
@unittest.mock.patch(f"{COG_PATH}.user_nomination_counts", new_callable=unittest.mock.AsyncMock)
@@ -398,8 +407,8 @@ class UserEmbedTests(unittest.TestCase):
moderators_role = helpers.MockRole(name='Moderators')
moderators_role.colour = 100
- infraction_counts.return_value = "expanded infractions info"
- nomination_counts.return_value = "nomination info"
+ infraction_counts.return_value = ("Infractions", "expanded infractions info")
+ nomination_counts.return_value = ("Nominations", "nomination info")
user = helpers.MockMember(id=314, roles=[moderators_role], top_role=moderators_role)
embed = asyncio.run(self.cog.create_user_embed(ctx, user))
@@ -409,20 +418,19 @@ class UserEmbedTests(unittest.TestCase):
self.assertEqual(
textwrap.dedent(f"""
- **User Information**
Created: {"1 year ago"}
Profile: {user.mention}
ID: {user.id}
+ """).strip(),
+ embed.fields[0].value
+ )
- **Member Information**
+ self.assertEqual(
+ textwrap.dedent(f"""
Joined: {"1 year ago"}
Roles: &Moderators
-
- expanded infractions info
-
- nomination info
""").strip(),
- embed.description
+ embed.fields[1].value
)
@unittest.mock.patch(f"{COG_PATH}.basic_user_infraction_counts", new_callable=unittest.mock.AsyncMock)
@@ -433,7 +441,7 @@ class UserEmbedTests(unittest.TestCase):
moderators_role = helpers.MockRole(name='Moderators')
moderators_role.colour = 100
- infraction_counts.return_value = "basic infractions info"
+ infraction_counts.return_value = ("Infractions", "basic infractions info")
user = helpers.MockMember(id=314, roles=[moderators_role], top_role=moderators_role)
embed = asyncio.run(self.cog.create_user_embed(ctx, user))
@@ -442,21 +450,30 @@ class UserEmbedTests(unittest.TestCase):
self.assertEqual(
textwrap.dedent(f"""
- **User Information**
Created: {"1 year ago"}
Profile: {user.mention}
ID: {user.id}
+ """).strip(),
+ embed.fields[0].value
+ )
- **Member Information**
+ self.assertEqual(
+ textwrap.dedent(f"""
Joined: {"1 year ago"}
Roles: &Moderators
-
- basic infractions info
""").strip(),
- embed.description
+ embed.fields[1].value
+ )
+
+ self.assertEqual(
+ "basic infractions info",
+ embed.fields[3].value
)
- @unittest.mock.patch(f"{COG_PATH}.basic_user_infraction_counts", new=unittest.mock.AsyncMock(return_value=""))
+ @unittest.mock.patch(
+ f"{COG_PATH}.basic_user_infraction_counts",
+ new=unittest.mock.AsyncMock(return_value=("Infractions", "basic infractions"))
+ )
def test_create_user_embed_uses_top_role_colour_when_user_has_roles(self):
"""The embed should be created with the colour of the top role, if a top role is available."""
ctx = helpers.MockContext()
@@ -469,7 +486,10 @@ class UserEmbedTests(unittest.TestCase):
self.assertEqual(embed.colour, discord.Colour(moderators_role.colour))
- @unittest.mock.patch(f"{COG_PATH}.basic_user_infraction_counts", new=unittest.mock.AsyncMock(return_value=""))
+ @unittest.mock.patch(
+ f"{COG_PATH}.basic_user_infraction_counts",
+ new=unittest.mock.AsyncMock(return_value=("Infractions", "basic infractions"))
+ )
def test_create_user_embed_uses_blurple_colour_when_user_has_no_roles(self):
"""The embed should be created with a blurple colour if the user has no assigned roles."""
ctx = helpers.MockContext()
@@ -479,7 +499,10 @@ class UserEmbedTests(unittest.TestCase):
self.assertEqual(embed.colour, discord.Colour.blurple())
- @unittest.mock.patch(f"{COG_PATH}.basic_user_infraction_counts", new=unittest.mock.AsyncMock(return_value=""))
+ @unittest.mock.patch(
+ f"{COG_PATH}.basic_user_infraction_counts",
+ new=unittest.mock.AsyncMock(return_value=("Infractions", "basic infractions"))
+ )
def test_create_user_embed_uses_png_format_of_user_avatar_as_thumbnail(self):
"""The embed thumbnail should be set to the user's avatar in `png` format."""
ctx = helpers.MockContext()
diff --git a/tests/bot/test_pagination.py b/tests/bot/test_pagination.py
index ce880d457..630f2516d 100644
--- a/tests/bot/test_pagination.py
+++ b/tests/bot/test_pagination.py
@@ -44,18 +44,3 @@ class LinePaginatorTests(TestCase):
self.paginator.add_line('x' * (self.paginator.scale_to_size + 1))
# Note: item at index 1 is the truncated line, index 0 is prefix
self.assertEqual(self.paginator._current_page[1], 'x' * self.paginator.scale_to_size)
-
-
-class ImagePaginatorTests(TestCase):
- """Tests functionality of the `ImagePaginator`."""
-
- def setUp(self):
- """Create a paginator for the test method."""
- self.paginator = pagination.ImagePaginator()
-
- def test_add_image_appends_image(self):
- """`add_image` appends the image to the image list."""
- image = 'lemon'
- self.paginator.add_image(image)
-
- assert self.paginator.images == [image]