From 97969daa7ada513beeefd6d355de39d957d38c4b Mon Sep 17 00:00:00 2001 From: wangyanbao666 Date: Wed, 3 Aug 2022 19:51:19 +0800 Subject: [PATCH 1/5] profile --- src/abstract_commands/draw_data.py | 26 +++++++ src/commands/profile.ts | 114 +++++++++++++++++++++++++++++ 2 files changed, 140 insertions(+) create mode 100644 src/abstract_commands/draw_data.py create mode 100644 src/commands/profile.ts diff --git a/src/abstract_commands/draw_data.py b/src/abstract_commands/draw_data.py new file mode 100644 index 0000000..494b4cf --- /dev/null +++ b/src/abstract_commands/draw_data.py @@ -0,0 +1,26 @@ +import matplotlib.pyplot as plt +import sys +import json +import ast + + +def draw_data(last_changes): + l = len(last_changes) + plt.plot(list(range(1,l+1)), last_changes, color="red", marker="o") + for a, b in zip(list(range(1,l+1)), last_changes): + plt.annotate(b, # this is the text + (a, b), # these are the coordinates to position the label + textcoords="offset points", # how to position the text + xytext=(0, 6), # distance from text to points (x,y) + ha='center') # horizontal alignment can be left, right or center + plt.title(f'rating changes in last {l} games') + plt.ylabel('rating change') + plt.xticks(range(1,l+1)) + plt.grid(True) + plt.savefig("saved_img") +# plt.show() + +input = ast.literal_eval(sys.argv[1]) +print("kkk") +draw_data(input) +sys.stdout.flush() \ No newline at end of file diff --git a/src/commands/profile.ts b/src/commands/profile.ts new file mode 100644 index 0000000..a1964fa --- /dev/null +++ b/src/commands/profile.ts @@ -0,0 +1,114 @@ +import {ApplicationCommandOptionTypes} from "discord.js/typings/enums"; +import {ICommand} from "wokcommands"; +import { Guild } from "../entities/Guild"; + +import {Queue} from "../entities/queues/Queue"; +import { User } from "../entities/User"; +import {ensure} from "../utils/general"; +import {PlayerStats} from "../entities/queues/PlayerStats"; +import {Leaderboard} from "../entities/queues/Leaderboard"; + +export default { + category: "General", + description: "List all the profile of a user", + + slash: true, + testOnly: true, + guildOnly: true, + + options: [ + { + name: "user", + description: "Specify a user to see its profile", + type: ApplicationCommandOptionTypes.USER, + required: false, + }, + { + name: "leaderboard_uuid", + description: "Show the profile from this leaderboard.", + type: ApplicationCommandOptionTypes.INTEGER, + required: false, + }, + { + name: "queue_uuid", + description: "Show the profile from the leaderboard of this queue.", + type: ApplicationCommandOptionTypes.INTEGER, + required: false, + }, + ], + + callback: async ({interaction,guild,channel}) => { + const {options, channelId, guildId} = interaction; + + // ensure that the command is being run in a server + if (!channelId || !guildId) { + return "This command can only be run in a text channel in a server"; + } + + // get the command parameters + const user_discord = options.getUser("user") ?? interaction.user; + const leaderboard_uuid = options.getInteger("leaderboard_uuid") ?? -1; + const queue_uuid = options.getInteger("queue_uuid") ?? -1; + + const discordId = user_discord.id; + let user = await User.findOneBy({discordId:discordId}); + if (!user){ + let guild = await Guild.findOneBy({id: guildId}); + if (!guild) { + guild = new Guild(guildId); + } + user = new User(discordId, {guilds: [guild]}); + await user.save(); + } + + let playerStats; + // if queue_uuid is provided + if (queue_uuid>0){ + const queue = await Queue.findOne({where:{uuid:queue_uuid}, relations:{leaderboard:true}}); + if (!queue){ + return `Queue with ID ${queue_uuid} does not exist in this channel`; + } + const leaderboard = ensure(queue.leaderboard); + const uuid = leaderboard.uuid; + playerStats = await PlayerStats.findOne({where:{leaderboard:{uuid}, user:{discordId}},relations:{leaderboard:true, user:true}}); + + if (!playerStats){ + playerStats = new PlayerStats(user,leaderboard); + await playerStats.save(); + } + } + + // if leaderboard_uuid is provided + else if (leaderboard_uuid>0){ + const leaderboard = await Leaderboard.findOneBy({uuid:leaderboard_uuid}); + if (!leaderboard){ + return `Leaderboard with ID ${queue_uuid} does not exist in this channel` + } + playerStats = await PlayerStats.findOne({where:{leaderboard:{uuid:leaderboard_uuid}, user:{discordId}},relations:{leaderboard:true, user:true}}); + if (!playerStats){ + playerStats = new PlayerStats(user,leaderboard); + await playerStats.save(); + } + } + + // if none of them is provided + else { + const queues = await Queue.find({relations:{leaderboard: true}}); + if (queues.length !== 1){ + return "Please specify a queue or a leaderboard" + } + const queue = queues[0]; + const leaderboard = ensure(queue.leaderboard); + const uuid = leaderboard.uuid; + playerStats = await PlayerStats.findOne({where:{leaderboard:{uuid}, user:{discordId}}, relations:{leaderboard:true, user:true}}); + + if (!playerStats){ + playerStats = new PlayerStats(user,leaderboard); + await playerStats.save(); + } + } + + return await playerStats.getPlayerStatsEmbed(guild!, channel); + + }, +} as ICommand; \ No newline at end of file From 88e74abcba7d5999c81dc087e0a08fb308416282 Mon Sep 17 00:00:00 2001 From: wangyanbao666 Date: Sun, 7 Aug 2022 21:29:24 +0800 Subject: [PATCH 2/5] implement profile --- package-lock.json | 309 +++++++++++++++++++++++++--- src/commands/profile.ts | 186 +++++++++++++++-- src/commands/rating/rating_reset.ts | 118 +++++++++-- src/commands/rating/rating_set.ts | 104 ++++++++-- src/features/expired-ban.ts | 36 ++++ 5 files changed, 671 insertions(+), 82 deletions(-) create mode 100644 src/features/expired-ban.ts diff --git a/package-lock.json b/package-lock.json index 4731f3b..efac3a0 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1804,6 +1804,13 @@ "safe-buffer": "~5.1.1" } }, + "node_modules/core-util-is": { + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/core-util-is/-/core-util-is-1.0.3.tgz", + "integrity": "sha512-ZQBvi1DcpJ4GDqanjucZ2Hj3wEO5pZDS89BWbkcrvdxksJorwUDDZamX9ldFkp9aw2lmBDLgkObEA4DWNJ9FYQ==", + "optional": true, + "peer": true + }, "node_modules/create-require": { "version": "1.1.1", "resolved": "https://registry.npmjs.org/create-require/-/create-require-1.1.1.tgz", @@ -1898,9 +1905,11 @@ } }, "node_modules/denque": { - "version": "2.1.0", - "resolved": "https://registry.npmjs.org/denque/-/denque-2.1.0.tgz", - "integrity": "sha512-HVQE3AAb/pxF8fQAoiqpvg9i3evqug3hoiwakOyZAwJm+6vZehbkYXZ0l4JxS+I3QxM97v5aaRNhj8v5oBhekw==", + "version": "1.5.1", + "resolved": "https://registry.npmjs.org/denque/-/denque-1.5.1.tgz", + "integrity": "sha512-XwE+iZ4D6ZUB7mfYRMb5wByE8L74HCn30FBN7sWnXksWc1LO1bPDl67pBR9o/kC4z/xSNAwkMYcGgqDV3BE3Hw==", + "optional": true, + "peer": true, "engines": { "node": ">=0.10" } @@ -2490,6 +2499,13 @@ "url": "https://github.com/sponsors/sindresorhus" } }, + "node_modules/isarray": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/isarray/-/isarray-1.0.0.tgz", + "integrity": "sha512-VLghIWNM6ELQzo7zwmcg0NmTVyWKYjvIeM83yjp0wRDTmUnrM678fQbcKBo6n2CJEF0szoG//ytg+TKla89ALQ==", + "optional": true, + "peer": true + }, "node_modules/isexe": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/isexe/-/isexe-2.0.0.tgz", @@ -3371,20 +3387,43 @@ "integrity": "sha512-gKLcREMhtuZRwRAfqP3RFW+TK4JqApVBtOIftVgjuABpAtpxhPGaDcfvbhNvD0B8iD1oUr/txX35NjcaY6Ns/A==" }, "node_modules/mongodb": { - "version": "4.7.0", - "resolved": "https://registry.npmjs.org/mongodb/-/mongodb-4.7.0.tgz", - "integrity": "sha512-HhVar6hsUeMAVlIbwQwWtV36iyjKd9qdhY+s4wcU8K6TOj4Q331iiMy+FoPuxEntDIijTYWivwFJkLv8q/ZgvA==", + "version": "3.7.3", + "resolved": "https://registry.npmjs.org/mongodb/-/mongodb-3.7.3.tgz", + "integrity": "sha512-Psm+g3/wHXhjBEktkxXsFMZvd3nemI0r3IPsE0bU+4//PnvNWKkzhZcEsbPcYiWqe8XqXJJEg4Tgtr7Raw67Yw==", + "optional": true, + "peer": true, "dependencies": { - "bson": "^4.6.3", - "denque": "^2.0.1", - "mongodb-connection-string-url": "^2.5.2", - "socks": "^2.6.2" + "bl": "^2.2.1", + "bson": "^1.1.4", + "denque": "^1.4.1", + "optional-require": "^1.1.8", + "safe-buffer": "^5.1.2" }, "engines": { - "node": ">=12.9.0" + "node": ">=4" }, "optionalDependencies": { - "saslprep": "^1.0.3" + "saslprep": "^1.0.0" + }, + "peerDependenciesMeta": { + "aws4": { + "optional": true + }, + "bson-ext": { + "optional": true + }, + "kerberos": { + "optional": true + }, + "mongodb-client-encryption": { + "optional": true + }, + "mongodb-extjson": { + "optional": true + }, + "snappy": { + "optional": true + } } }, "node_modules/mongodb-connection-string-url": { @@ -3427,6 +3466,60 @@ "node": ">=12" } }, + "node_modules/mongodb/node_modules/bl": { + "version": "2.2.1", + "resolved": "https://registry.npmjs.org/bl/-/bl-2.2.1.tgz", + "integrity": "sha512-6Pesp1w0DEX1N550i/uGV/TqucVL4AM/pgThFSN/Qq9si1/DF9aIHs1BxD8V/QU0HoeHO6cQRTAuYnLPKq1e4g==", + "optional": true, + "peer": true, + "dependencies": { + "readable-stream": "^2.3.5", + "safe-buffer": "^5.1.1" + } + }, + "node_modules/mongodb/node_modules/bson": { + "version": "1.1.6", + "resolved": "https://registry.npmjs.org/bson/-/bson-1.1.6.tgz", + "integrity": "sha512-EvVNVeGo4tHxwi8L6bPj3y3itEvStdwvvlojVxxbyYfoaxJ6keLgrTuKdyfEAszFK+H3olzBuafE0yoh0D1gdg==", + "optional": true, + "peer": true, + "engines": { + "node": ">=0.6.19" + } + }, + "node_modules/mongodb/node_modules/readable-stream": { + "version": "2.3.7", + "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-2.3.7.tgz", + "integrity": "sha512-Ebho8K4jIbHAxnuxi7o42OrZgF/ZTNcsZj6nRKyUmkhLFq8CHItp/fy6hQZuZmP/n3yZ9VBUbp4zz/mX8hmYPw==", + "optional": true, + "peer": true, + "dependencies": { + "core-util-is": "~1.0.0", + "inherits": "~2.0.3", + "isarray": "~1.0.0", + "process-nextick-args": "~2.0.0", + "safe-buffer": "~5.1.1", + "string_decoder": "~1.1.1", + "util-deprecate": "~1.0.1" + } + }, + "node_modules/mongodb/node_modules/safe-buffer": { + "version": "5.1.2", + "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.1.2.tgz", + "integrity": "sha512-Gd2UZBJDkXlY7GbJxfsE8/nvKkUEU1G38c1siN6QP6a9PT9MmHB8GnpscSmMJSoF8LOIrt8ud/wPtojys4G6+g==", + "optional": true, + "peer": true + }, + "node_modules/mongodb/node_modules/string_decoder": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-1.1.1.tgz", + "integrity": "sha512-n/ShnvDi6FHbbVfviro+WojiFzv+s8MPMHBczVePfUpDJLwoLT0ht1l4YwBCbi8pJAveEEdnkHyPyTP/mzRfwg==", + "optional": true, + "peer": true, + "dependencies": { + "safe-buffer": "~5.1.0" + } + }, "node_modules/mongoose": { "version": "6.4.5", "resolved": "https://registry.npmjs.org/mongoose/-/mongoose-6.4.5.tgz", @@ -3448,6 +3541,31 @@ "url": "https://opencollective.com/mongoose" } }, + "node_modules/mongoose/node_modules/denque": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/denque/-/denque-2.0.1.tgz", + "integrity": "sha512-tfiWc6BQLXNLpNiR5iGd0Ocu3P3VpxfzFiqubLgMfhfOw9WyvgJBd46CClNn9k3qfbjvT//0cf7AlYRX/OslMQ==", + "engines": { + "node": ">=0.10" + } + }, + "node_modules/mongoose/node_modules/mongodb": { + "version": "4.7.0", + "resolved": "https://registry.npmjs.org/mongodb/-/mongodb-4.7.0.tgz", + "integrity": "sha512-HhVar6hsUeMAVlIbwQwWtV36iyjKd9qdhY+s4wcU8K6TOj4Q331iiMy+FoPuxEntDIijTYWivwFJkLv8q/ZgvA==", + "dependencies": { + "bson": "^4.6.3", + "denque": "^2.0.1", + "mongodb-connection-string-url": "^2.5.2", + "socks": "^2.6.2" + }, + "engines": { + "node": ">=12.9.0" + }, + "optionalDependencies": { + "saslprep": "^1.0.3" + } + }, "node_modules/mongoose/node_modules/ms": { "version": "2.1.3", "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.3.tgz", @@ -3689,6 +3807,19 @@ "url": "https://github.com/sponsors/sindresorhus" } }, + "node_modules/optional-require": { + "version": "1.1.8", + "resolved": "https://registry.npmjs.org/optional-require/-/optional-require-1.1.8.tgz", + "integrity": "sha512-jq83qaUb0wNg9Krv1c5OQ+58EK+vHde6aBPzLvPPqJm89UQWsvSuFy9X/OSNJnFeSOKo7btE0n8Nl2+nE+z5nA==", + "optional": true, + "peer": true, + "dependencies": { + "require-at": "^1.0.6" + }, + "engines": { + "node": ">=4" + } + }, "node_modules/p-limit": { "version": "3.1.0", "resolved": "https://registry.npmjs.org/p-limit/-/p-limit-3.1.0.tgz", @@ -3899,6 +4030,13 @@ "url": "https://github.com/chalk/ansi-styles?sponsor=1" } }, + "node_modules/process-nextick-args": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/process-nextick-args/-/process-nextick-args-2.0.1.tgz", + "integrity": "sha512-3ouUOpQhtgrbOa17J7+uxOTpITYWaGP7/AhoR3+A+/1e9skrzelGi/dXzEYyvbxubEF6Wn2ypscTKiKJFFn1ag==", + "optional": true, + "peer": true + }, "node_modules/prompts": { "version": "2.4.2", "resolved": "https://registry.npmjs.org/prompts/-/prompts-2.4.2.tgz", @@ -3993,6 +4131,16 @@ "resolved": "https://registry.npmjs.org/reflect-metadata/-/reflect-metadata-0.1.13.tgz", "integrity": "sha512-Ts1Y/anZELhSsjMcU605fU9RE4Oi3p5ORujwbIKXfWa+0Zxs510Qrmrce5/Jowq3cHSZSJqBjypxmHarc+vEWg==" }, + "node_modules/require-at": { + "version": "1.0.6", + "resolved": "https://registry.npmjs.org/require-at/-/require-at-1.0.6.tgz", + "integrity": "sha512-7i1auJbMUrXEAZCOQ0VNJgmcT2VOKPRl2YGJwgpHpC9CE91Mv4/4UYIUm4chGJaI381ZDq1JUicFii64Hapd8g==", + "optional": true, + "peer": true, + "engines": { + "node": ">=4" + } + }, "node_modules/require-directory": { "version": "2.1.1", "resolved": "https://registry.npmjs.org/require-directory/-/require-directory-2.1.1.tgz", @@ -6489,6 +6637,13 @@ "safe-buffer": "~5.1.1" } }, + "core-util-is": { + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/core-util-is/-/core-util-is-1.0.3.tgz", + "integrity": "sha512-ZQBvi1DcpJ4GDqanjucZ2Hj3wEO5pZDS89BWbkcrvdxksJorwUDDZamX9ldFkp9aw2lmBDLgkObEA4DWNJ9FYQ==", + "optional": true, + "peer": true + }, "create-require": { "version": "1.1.1", "resolved": "https://registry.npmjs.org/create-require/-/create-require-1.1.1.tgz", @@ -6550,9 +6705,11 @@ "integrity": "sha512-ZySD7Nf91aLB0RxL4KGrKHBXl7Eds1DAmEdcoVawXnLD7SDhpNgtuII2aAkg7a7QS41jxPSZ17p4VdGnMHk3MQ==" }, "denque": { - "version": "2.1.0", - "resolved": "https://registry.npmjs.org/denque/-/denque-2.1.0.tgz", - "integrity": "sha512-HVQE3AAb/pxF8fQAoiqpvg9i3evqug3hoiwakOyZAwJm+6vZehbkYXZ0l4JxS+I3QxM97v5aaRNhj8v5oBhekw==" + "version": "1.5.1", + "resolved": "https://registry.npmjs.org/denque/-/denque-1.5.1.tgz", + "integrity": "sha512-XwE+iZ4D6ZUB7mfYRMb5wByE8L74HCn30FBN7sWnXksWc1LO1bPDl67pBR9o/kC4z/xSNAwkMYcGgqDV3BE3Hw==", + "optional": true, + "peer": true }, "detect-libc": { "version": "2.0.1", @@ -6978,6 +7135,13 @@ "integrity": "sha512-hFoiJiTl63nn+kstHGBtewWSKnQLpyb155KHheA1l39uvtO9nWIop1p3udqPcUd/xbF1VLMO4n7OI6p7RbngDg==", "dev": true }, + "isarray": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/isarray/-/isarray-1.0.0.tgz", + "integrity": "sha512-VLghIWNM6ELQzo7zwmcg0NmTVyWKYjvIeM83yjp0wRDTmUnrM678fQbcKBo6n2CJEF0szoG//ytg+TKla89ALQ==", + "optional": true, + "peer": true + }, "isexe": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/isexe/-/isexe-2.0.0.tgz", @@ -7651,15 +7815,71 @@ "integrity": "sha512-gKLcREMhtuZRwRAfqP3RFW+TK4JqApVBtOIftVgjuABpAtpxhPGaDcfvbhNvD0B8iD1oUr/txX35NjcaY6Ns/A==" }, "mongodb": { - "version": "4.7.0", - "resolved": "https://registry.npmjs.org/mongodb/-/mongodb-4.7.0.tgz", - "integrity": "sha512-HhVar6hsUeMAVlIbwQwWtV36iyjKd9qdhY+s4wcU8K6TOj4Q331iiMy+FoPuxEntDIijTYWivwFJkLv8q/ZgvA==", - "requires": { - "bson": "^4.6.3", - "denque": "^2.0.1", - "mongodb-connection-string-url": "^2.5.2", - "saslprep": "^1.0.3", - "socks": "^2.6.2" + "version": "3.7.3", + "resolved": "https://registry.npmjs.org/mongodb/-/mongodb-3.7.3.tgz", + "integrity": "sha512-Psm+g3/wHXhjBEktkxXsFMZvd3nemI0r3IPsE0bU+4//PnvNWKkzhZcEsbPcYiWqe8XqXJJEg4Tgtr7Raw67Yw==", + "optional": true, + "peer": true, + "requires": { + "bl": "^2.2.1", + "bson": "^1.1.4", + "denque": "^1.4.1", + "optional-require": "^1.1.8", + "safe-buffer": "^5.1.2", + "saslprep": "^1.0.0" + }, + "dependencies": { + "bl": { + "version": "2.2.1", + "resolved": "https://registry.npmjs.org/bl/-/bl-2.2.1.tgz", + "integrity": "sha512-6Pesp1w0DEX1N550i/uGV/TqucVL4AM/pgThFSN/Qq9si1/DF9aIHs1BxD8V/QU0HoeHO6cQRTAuYnLPKq1e4g==", + "optional": true, + "peer": true, + "requires": { + "readable-stream": "^2.3.5", + "safe-buffer": "^5.1.1" + } + }, + "bson": { + "version": "1.1.6", + "resolved": "https://registry.npmjs.org/bson/-/bson-1.1.6.tgz", + "integrity": "sha512-EvVNVeGo4tHxwi8L6bPj3y3itEvStdwvvlojVxxbyYfoaxJ6keLgrTuKdyfEAszFK+H3olzBuafE0yoh0D1gdg==", + "optional": true, + "peer": true + }, + "readable-stream": { + "version": "2.3.7", + "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-2.3.7.tgz", + "integrity": "sha512-Ebho8K4jIbHAxnuxi7o42OrZgF/ZTNcsZj6nRKyUmkhLFq8CHItp/fy6hQZuZmP/n3yZ9VBUbp4zz/mX8hmYPw==", + "optional": true, + "peer": true, + "requires": { + "core-util-is": "~1.0.0", + "inherits": "~2.0.3", + "isarray": "~1.0.0", + "process-nextick-args": "~2.0.0", + "safe-buffer": "~5.1.1", + "string_decoder": "~1.1.1", + "util-deprecate": "~1.0.1" + } + }, + "safe-buffer": { + "version": "5.1.2", + "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.1.2.tgz", + "integrity": "sha512-Gd2UZBJDkXlY7GbJxfsE8/nvKkUEU1G38c1siN6QP6a9PT9MmHB8GnpscSmMJSoF8LOIrt8ud/wPtojys4G6+g==", + "optional": true, + "peer": true + }, + "string_decoder": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-1.1.1.tgz", + "integrity": "sha512-n/ShnvDi6FHbbVfviro+WojiFzv+s8MPMHBczVePfUpDJLwoLT0ht1l4YwBCbi8pJAveEEdnkHyPyTP/mzRfwg==", + "optional": true, + "peer": true, + "requires": { + "safe-buffer": "~5.1.0" + } + } } }, "mongodb-connection-string-url": { @@ -7709,6 +7929,23 @@ "sift": "16.0.0" }, "dependencies": { + "denque": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/denque/-/denque-2.0.1.tgz", + "integrity": "sha512-tfiWc6BQLXNLpNiR5iGd0Ocu3P3VpxfzFiqubLgMfhfOw9WyvgJBd46CClNn9k3qfbjvT//0cf7AlYRX/OslMQ==" + }, + "mongodb": { + "version": "4.7.0", + "resolved": "https://registry.npmjs.org/mongodb/-/mongodb-4.7.0.tgz", + "integrity": "sha512-HhVar6hsUeMAVlIbwQwWtV36iyjKd9qdhY+s4wcU8K6TOj4Q331iiMy+FoPuxEntDIijTYWivwFJkLv8q/ZgvA==", + "requires": { + "bson": "^4.6.3", + "denque": "^2.0.1", + "mongodb-connection-string-url": "^2.5.2", + "saslprep": "^1.0.3", + "socks": "^2.6.2" + } + }, "ms": { "version": "2.1.3", "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.3.tgz", @@ -7889,6 +8126,16 @@ "mimic-fn": "^2.1.0" } }, + "optional-require": { + "version": "1.1.8", + "resolved": "https://registry.npmjs.org/optional-require/-/optional-require-1.1.8.tgz", + "integrity": "sha512-jq83qaUb0wNg9Krv1c5OQ+58EK+vHde6aBPzLvPPqJm89UQWsvSuFy9X/OSNJnFeSOKo7btE0n8Nl2+nE+z5nA==", + "optional": true, + "peer": true, + "requires": { + "require-at": "^1.0.6" + } + }, "p-limit": { "version": "3.1.0", "resolved": "https://registry.npmjs.org/p-limit/-/p-limit-3.1.0.tgz", @@ -8045,6 +8292,13 @@ } } }, + "process-nextick-args": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/process-nextick-args/-/process-nextick-args-2.0.1.tgz", + "integrity": "sha512-3ouUOpQhtgrbOa17J7+uxOTpITYWaGP7/AhoR3+A+/1e9skrzelGi/dXzEYyvbxubEF6Wn2ypscTKiKJFFn1ag==", + "optional": true, + "peer": true + }, "prompts": { "version": "2.4.2", "resolved": "https://registry.npmjs.org/prompts/-/prompts-2.4.2.tgz", @@ -8123,6 +8377,13 @@ "resolved": "https://registry.npmjs.org/reflect-metadata/-/reflect-metadata-0.1.13.tgz", "integrity": "sha512-Ts1Y/anZELhSsjMcU605fU9RE4Oi3p5ORujwbIKXfWa+0Zxs510Qrmrce5/Jowq3cHSZSJqBjypxmHarc+vEWg==" }, + "require-at": { + "version": "1.0.6", + "resolved": "https://registry.npmjs.org/require-at/-/require-at-1.0.6.tgz", + "integrity": "sha512-7i1auJbMUrXEAZCOQ0VNJgmcT2VOKPRl2YGJwgpHpC9CE91Mv4/4UYIUm4chGJaI381ZDq1JUicFii64Hapd8g==", + "optional": true, + "peer": true + }, "require-directory": { "version": "2.1.1", "resolved": "https://registry.npmjs.org/require-directory/-/require-directory-2.1.1.tgz", diff --git a/src/commands/profile.ts b/src/commands/profile.ts index a1964fa..21fb3e7 100644 --- a/src/commands/profile.ts +++ b/src/commands/profile.ts @@ -7,6 +7,9 @@ import { User } from "../entities/User"; import {ensure} from "../utils/general"; import {PlayerStats} from "../entities/queues/PlayerStats"; import {Leaderboard} from "../entities/queues/Leaderboard"; +import { MessageEmbed } from "discord.js"; +import { Match } from "../entities/matches/Match"; +import { Player } from "../entities/matches/Player"; export default { category: "General", @@ -23,12 +26,6 @@ export default { type: ApplicationCommandOptionTypes.USER, required: false, }, - { - name: "leaderboard_uuid", - description: "Show the profile from this leaderboard.", - type: ApplicationCommandOptionTypes.INTEGER, - required: false, - }, { name: "queue_uuid", description: "Show the profile from the leaderboard of this queue.", @@ -47,8 +44,8 @@ export default { // get the command parameters const user_discord = options.getUser("user") ?? interaction.user; - const leaderboard_uuid = options.getInteger("leaderboard_uuid") ?? -1; const queue_uuid = options.getInteger("queue_uuid") ?? -1; + let leaderboard; const discordId = user_discord.id; let user = await User.findOneBy({discordId:discordId}); @@ -68,7 +65,7 @@ export default { if (!queue){ return `Queue with ID ${queue_uuid} does not exist in this channel`; } - const leaderboard = ensure(queue.leaderboard); + leaderboard = ensure(queue.leaderboard); const uuid = leaderboard.uuid; playerStats = await PlayerStats.findOne({where:{leaderboard:{uuid}, user:{discordId}},relations:{leaderboard:true, user:true}}); @@ -79,26 +76,26 @@ export default { } // if leaderboard_uuid is provided - else if (leaderboard_uuid>0){ - const leaderboard = await Leaderboard.findOneBy({uuid:leaderboard_uuid}); - if (!leaderboard){ - return `Leaderboard with ID ${queue_uuid} does not exist in this channel` - } - playerStats = await PlayerStats.findOne({where:{leaderboard:{uuid:leaderboard_uuid}, user:{discordId}},relations:{leaderboard:true, user:true}}); - if (!playerStats){ - playerStats = new PlayerStats(user,leaderboard); - await playerStats.save(); - } - } + // else if (leaderboard_uuid>0){ + // const leaderboard = await Leaderboard.findOneBy({uuid:leaderboard_uuid}); + // if (!leaderboard){ + // return `Leaderboard with ID ${queue_uuid} does not exist in this channel` + // } + // playerStats = await PlayerStats.findOne({where:{leaderboard:{uuid:leaderboard_uuid}, user:{discordId}},relations:{leaderboard:true, user:true}}); + // if (!playerStats){ + // playerStats = new PlayerStats(user,leaderboard); + // await playerStats.save(); + // } + // } // if none of them is provided else { const queues = await Queue.find({relations:{leaderboard: true}}); if (queues.length !== 1){ - return "Please specify a queue or a leaderboard" + return "Please specify a queue" } const queue = queues[0]; - const leaderboard = ensure(queue.leaderboard); + leaderboard = ensure(queue.leaderboard); const uuid = leaderboard.uuid; playerStats = await PlayerStats.findOne({where:{leaderboard:{uuid}, user:{discordId}}, relations:{leaderboard:true, user:true}}); @@ -108,7 +105,152 @@ export default { } } - return await playerStats.getPlayerStatsEmbed(guild!, channel); + const username = (await guild?.members.fetch(discordId)!).nickname!; + const leaderboard_uuid = leaderboard.uuid; + console.log(username) + + let playersStats = await PlayerStats.find({where:{leaderboard:{uuid:leaderboard_uuid}}}) + playersStats.sort((a,b) => { return a.rating - b.rating }); + + let rank = 0; + for (let p of playersStats){ + rank += 1; + if (p.user.discordId === discordId){ + break; + } + } + + let winrate = 0; + if (playerStats.numGames !== 0){ + winrate = playerStats.numWins/playerStats.numGames; + } + + let Tier; + let tier = Math.max(Math.floor((playerStats.rating-1000)/100),0) + switch (tier){ + case 0: + Tier = "I"; + break; + case 1: + Tier = "II"; + break; + case 2: + Tier = "III"; + break; + case 3: + Tier = "IV"; + break; + case 4: + Tier = "V"; + break; + case 5: + Tier = "VI"; + break; + case 6: + Tier = "VII"; + break; + case 7: + Tier = "VIII"; + break; + case 8: + Tier = "IX"; + break; + case 9: + Tier = "X"; + break; + default: + Tier = "X"; + break; + } + + const profileImgUrl = user_discord.avatarURL() ?? user_discord.defaultAvatarURL + + // get historical statistics + + // get matches + let matches = await Match.find({where:{players:{user:{discordId}}}}) + + // sort by time + matches.sort((a, b) => {return -a.endTime + b.endTime}) + + // choose the latest 5 + let last_five_matches; + if (matches.length < 5){ + last_five_matches = matches + } + else { + last_five_matches = matches.slice(0,5) + } + + const historical_rating = [] + const historical_rating_delta =[] + const end_time = [] + // find players from the matches + for (let match of matches){ + let match_uuid = match.uuid; + let player = ensure(await Player.findOne({where:{match:{uuid:match_uuid},user:{discordId}},relations:{match:true}})) + console.log(player.rating); + historical_rating.push(player.rating); + historical_rating_delta.push(player.ratingDelta); + end_time.push(match.endTime); + } + + let fields = [{ + name: "Rank", + value: `\` ${rank} \`\u200B`, + inline: true, + }, + { + name: "Rating", + value: `\` ${playerStats.rating} \`\u200B`, + inline: true, + }, + { + name: "Matches", + value: `\` ${playerStats.numGames} \`\u200B`, + inline: true, + }, + { + name: "Winrate", + value: `\` ${winrate} \`\u200B`, + inline: true, + }, + { + name: "Tier", + value: `\` ${Tier} \`\u200B `, + inline: true, + }, + { + name: "W/L/S", + value: `\` ${playerStats.numWins}/${playerStats.numLosses}/${playerStats.streak} \`\u200B`, + inline: true, + },] + + if (historical_rating.length !== 0){ + fields.push( { + name: "Rating change", + value: historical_rating_delta.map(rating_change => `\` ${rating_change} \``).join("\n"), + inline: true, + }, + { + name: "Time", + value: end_time.map(time => ` `).join("\n"), + inline: true, + },) + } + + + + let messageEmbed = new MessageEmbed() + .setColor('#00ffff') + .setTitle(`__${username}__`) + .setColor("#ED2939") + .setThumbnail(profileImgUrl) + + messageEmbed.addFields(fields); + + return messageEmbed; + // return await playerStats.getPlayerStatsEmbed(guild!, channel); }, } as ICommand; \ No newline at end of file diff --git a/src/commands/rating/rating_reset.ts b/src/commands/rating/rating_reset.ts index d813d06..5313a26 100644 --- a/src/commands/rating/rating_reset.ts +++ b/src/commands/rating/rating_reset.ts @@ -1,31 +1,32 @@ +import {MessageActionRow, MessageButton, MessageComponentInteraction} from "discord.js"; import {ApplicationCommandOptionTypes} from "discord.js/typings/enums"; import {ICommand} from "wokcommands"; -import {ratingReset} from "../../abstract_commands/ratings/rating_reset"; +import {Leaderboard} from "../../entities/queues/Leaderboard"; +import {User} from "../../entities/User"; export default { - category: "Admin", - description: "Reset rating for a specific user/leaderboard", + category: "General", + description: "This command resets the ratings of all the users in the server back to the default 1000.", slash: true, testOnly: true, - guildOnly: true, options: [ { name: "user", - description: "The user to reset rating for", + description: "If specified, reset the ratings only for this user", type: ApplicationCommandOptionTypes.USER, required: false, }, { - name: "queue_uuid", - description: "The queue whose leaderboard to reset the rating for", - type: ApplicationCommandOptionTypes.STRING, + name: "leaderboard_uuid", + description: "If specified, reset the ratings only for this leaderboard.", + type: ApplicationCommandOptionTypes.INTEGER, required: false, }, ], - callback: async ({interaction}) => { + callback: async ({interaction, channel}) => { const {options, channelId, guildId} = interaction; // ensure that the command is being run in a server @@ -34,14 +35,99 @@ export default { } // get the command parameters - const user = options.getUser("user"); - const queueUUID = options.getString("queue_uuid") ?? ""; + const userAPI = options.getUser("user") ?? null; + let user:any; + if (userAPI !== null){ + user = await User.findOneBy({discordId:userAPI!.id}) + } + const leaderboard_uuid = options.getInteger("leaderboard_uuid") ?? null; + let leaderboard: any; - let discordId = ""; - if (user){ - discordId = user.id; + if (leaderboard_uuid !== null) { + leaderboard = await Leaderboard.findOneBy({uuid: leaderboard_uuid}); + if (leaderboard === null) { + return `Leaderboard with id ${leaderboard_uuid} does not exist`; + } } - return await ratingReset(discordId, queueUUID); - }, + // create embedded message for users to confirm their action + const row = new MessageActionRow() + .setComponents( + new MessageButton() + .setLabel('Cancel') + .setStyle('SECONDARY') + .setCustomId('cancel'), + new MessageButton() + .setLabel('Confirm') + .setStyle('DANGER') + .setCustomId('confirm'), + ) + const confirmMsg = await interaction.reply({ + content: "Are you sure you want to reset rating values?", + components: [row], + fetchReply: true + }) + + const filter = (i: MessageComponentInteraction) => { + return i.user.id === interaction.user.id + }; + + + let collector = channel.createMessageComponentCollector({filter, max: 1}); + + collector.on("collect", async (btnInt) => { + if (!btnInt) { + return; + } + await btnInt.deferUpdate(); + if (btnInt.customId === "cancel") { + return; + } else if (btnInt.customId === "confirm") { + // leaderboard uuid is not provided + if (!leaderboard) { + let leaderboards = await Leaderboard.find(); + // user is not provided + if (!user) { + for (let leaderboard of leaderboards) { + let playerStats = leaderboard.playerStats; + for (let playerStat of playerStats){ + playerStat.rating = 1000; + await playerStat.save(); + } + } + } + // otherwise + else { + for (let leaderboard of leaderboards) { + let playerStats = leaderboard.playerStats; + for (let playerStat of playerStats){ + if (playerStat.user === user){ + playerStat.rating = 1000; + await playerStat.save(); + } + } + } + } + } else { + let playerStats = leaderboard.playerStats; + if (!user){ + for (let playerStat of playerStats){ + playerStat.rating = 1000; + await playerStat.save(); + } + } + else { + for (let playerStat of playerStats){ + if (playerStat.user === user){ + playerStat.rating = 1000; + await playerStat.save(); + } + } + } + } + + await interaction.followUp(`The rating value has been set.`); + } + }) + } } as ICommand; diff --git a/src/commands/rating/rating_set.ts b/src/commands/rating/rating_set.ts index 84b63b5..a0c2fc6 100644 --- a/src/commands/rating/rating_set.ts +++ b/src/commands/rating/rating_set.ts @@ -1,39 +1,39 @@ +import {MessageActionRow, MessageButton, MessageComponentInteraction} from "discord.js"; import {ApplicationCommandOptionTypes} from "discord.js/typings/enums"; import {ICommand} from "wokcommands"; -import {ratingSet} from "../../abstract_commands/ratings/rating_set"; +import {Leaderboard} from "../../entities/queues/Leaderboard"; +import {User} from "../../entities/User"; import {ensure} from "../../utils/general"; - export default { - category: "Admin", - description: "Reset rating for a specific user/leaderboard", + category: "General", + description: "This command resets the ratings of all the users in the server back to the default 1000.", slash: true, testOnly: true, - guildOnly: true, options: [ { name: "rating", - description: "The new rating of the user.", - type: ApplicationCommandOptionTypes.STRING, + description: "The new rating of the user", + type: ApplicationCommandOptionTypes.INTEGER, required: true, }, { name: "user", - description: "The user to set rating for", + description: "If specified, reset the ratings only for this user", type: ApplicationCommandOptionTypes.USER, required: true, }, { - name: "queue_uuid", - description: "The leaderboard to reset the rating for", - type: ApplicationCommandOptionTypes.STRING, + name: "leaderboard_uuid", + description: "If specified, reset the ratings only for this leaderboard.", + type: ApplicationCommandOptionTypes.INTEGER, required: false, }, ], - callback: async ({interaction}) => { + callback: async ({interaction, channel}) => { const {options, channelId, guildId} = interaction; // ensure that the command is being run in a server @@ -42,15 +42,79 @@ export default { } // get the command parameters - const rating = ensure(options.getString("rating")); - const user = options.getUser("user"); - const queueUUID = options.getString("queue_uuid") ?? ""; + const rating = ensure(options.getInteger("rating")); + const userAPI = ensure(options.getUser("user")); + const user = await User.findOneBy({discordId:userAPI!.id}) + + const leaderboard_uuid = options.getInteger("leaderboard_uuid") ?? null; + let leaderboard: any; - let discordId = ""; - if (user){ - discordId = user.id; + if (leaderboard_uuid !== null) { + leaderboard = await Leaderboard.findOneBy({uuid: leaderboard_uuid}); + if (leaderboard === null) { + return `Leaderboard with id ${leaderboard_uuid} does not exist`; + } } - return await ratingSet(discordId, queueUUID, parseInt(rating)); - }, + // create embedded message for users to confirm their action + const row = new MessageActionRow() + .setComponents( + new MessageButton() + .setLabel('Cancel') + .setStyle('SECONDARY') + .setCustomId('cancel'), + new MessageButton() + .setLabel('Confirm') + .setStyle('DANGER') + .setCustomId('confirm'), + ) + const confirmMsg = await interaction.reply({ + content: `Are you sure you want to set rating values for ${userAPI.username}?`, + components: [row], + fetchReply: true + }) + + const filter = (i: MessageComponentInteraction) => { + return i.user.id === interaction.user.id + }; + + + let collector = channel.createMessageComponentCollector({filter, max: 1}); + + collector.on("collect", async (btnInt) => { + if (!btnInt) { + return; + } + await btnInt.deferUpdate(); + if (btnInt.customId === "cancel") { + return; + } else if (btnInt.customId === "confirm") { + // leaderboard uuid is not provided + if (!leaderboard) { + let leaderboards = await Leaderboard.find(); + + for (let leaderboard of leaderboards) { + let playerStats = leaderboard.playerStats; + for (let playerStat of playerStats){ + if (playerStat.user === user){ + playerStat.rating = rating; + await playerStat.save(); + } + } + } + } else { + let playerStats = leaderboard.playerStats; + for (let playerStat of playerStats){ + if (playerStat.user === user){ + playerStat.rating = rating; + await playerStat.save(); + } + } + + } + + await interaction.followUp(`The rating value has been set.`); + } + }) + } } as ICommand; diff --git a/src/features/expired-ban.ts b/src/features/expired-ban.ts new file mode 100644 index 0000000..1f7b1a7 --- /dev/null +++ b/src/features/expired-ban.ts @@ -0,0 +1,36 @@ +import {Client, Guild} from "discord.js"; +import {Ban} from "../entities/user_data/Ban"; +import {client} from "../main"; +import {User} from "../entities/User"; +import {LessThan} from "typeorm"; + +export default (client:Client) => { + const check = async () => { + // const results = await Ban.findBy({ + // until: LessThan(new Date().getTime()), + // }); + // let users = await User.find({relations:{guilds:true}}); + // console.log(users) + + // for (const result of results){ + // const userId = result.user?.discordId; + // const guildId = result.guild?.id; + // const guild = await client.guilds.fetch(guildId!).then(guild => { + // console.log(guild.); + // console.log(guild!.members); + // guild!.members.unban(userId!, "ban expired"); + // }); + // // console.log(guild); + // // console.log(guild!.members); + // // await guild!.members.unban(userId!, "ban expired"); + // } + setTimeout(check, 1000*60); + await Ban.delete({until: LessThan(new Date().getTime())}) + } + check(); +} + +export const config = { + dbName: "Ban", + displayName: "Banned users", +} \ No newline at end of file From 2eb2da38de93e4bc1e792d64030abd1071129af1 Mon Sep 17 00:00:00 2001 From: Alian713 Date: Thu, 11 Aug 2022 08:44:01 +0800 Subject: [PATCH 3/5] fixed merge conflicts 2 --- src/commands/rating/rating_reset.ts | 122 +--------------------------- src/commands/rating/rating_set.ts | 99 ++-------------------- 2 files changed, 9 insertions(+), 212 deletions(-) diff --git a/src/commands/rating/rating_reset.ts b/src/commands/rating/rating_reset.ts index 215c82f..9f3d22f 100644 --- a/src/commands/rating/rating_reset.ts +++ b/src/commands/rating/rating_reset.ts @@ -1,49 +1,31 @@ -import {MessageActionRow, MessageButton, MessageComponentInteraction} from "discord.js"; import {ApplicationCommandOptionTypes} from "discord.js/typings/enums"; import {ICommand} from "wokcommands"; -<<<<<<< HEAD -import {Leaderboard} from "../../entities/queues/Leaderboard"; -import {User} from "../../entities/User"; - -export default { - category: "General", - description: "This command resets the ratings of all the users in the server back to the default 1000.", -======= import {reset} from "../../abstract_commands/ratings/reset"; export default { category: "Admin", description: "Reset ratings for a user/queue", ->>>>>>> main slash: true, testOnly: true, + guildOnly: true, options: [ { name: "user", -<<<<<<< HEAD - description: "If specified, reset the ratings only for this user", -======= description: "The user to reset ratings for. If unspecified, resets the ratings of all users", ->>>>>>> main type: ApplicationCommandOptionTypes.USER, required: false, }, { -<<<<<<< HEAD - name: "leaderboard_uuid", - description: "If specified, reset the ratings only for this leaderboard.", -======= name: "queue_uuid", description: "The queue to reset the ratings for. If unspecified, resets the ratings in all queues", ->>>>>>> main type: ApplicationCommandOptionTypes.INTEGER, required: false, }, ], - callback: async ({interaction, channel}) => { + callback: async ({interaction}) => { const {options, channelId, guildId} = interaction; // ensure that the command is being run in a server @@ -52,107 +34,9 @@ export default { } // get the command parameters -<<<<<<< HEAD - const userAPI = options.getUser("user") ?? null; - let user:any; - if (userAPI !== null){ - user = await User.findOneBy({discordId:userAPI!.id}) - } - const leaderboard_uuid = options.getInteger("leaderboard_uuid") ?? null; - let leaderboard: any; - - if (leaderboard_uuid !== null) { - leaderboard = await Leaderboard.findOneBy({uuid: leaderboard_uuid}); - if (leaderboard === null) { - return `Leaderboard with id ${leaderboard_uuid} does not exist`; - } - } - - // create embedded message for users to confirm their action - const row = new MessageActionRow() - .setComponents( - new MessageButton() - .setLabel('Cancel') - .setStyle('SECONDARY') - .setCustomId('cancel'), - new MessageButton() - .setLabel('Confirm') - .setStyle('DANGER') - .setCustomId('confirm'), - ) - const confirmMsg = await interaction.reply({ - content: "Are you sure you want to reset rating values?", - components: [row], - fetchReply: true - }) - - const filter = (i: MessageComponentInteraction) => { - return i.user.id === interaction.user.id - }; - - - let collector = channel.createMessageComponentCollector({filter, max: 1}); - - collector.on("collect", async (btnInt) => { - if (!btnInt) { - return; - } - await btnInt.deferUpdate(); - if (btnInt.customId === "cancel") { - return; - } else if (btnInt.customId === "confirm") { - // leaderboard uuid is not provided - if (!leaderboard) { - let leaderboards = await Leaderboard.find(); - // user is not provided - if (!user) { - for (let leaderboard of leaderboards) { - let playerStats = leaderboard.playerStats; - for (let playerStat of playerStats){ - playerStat.rating = 1000; - await playerStat.save(); - } - } - } - // otherwise - else { - for (let leaderboard of leaderboards) { - let playerStats = leaderboard.playerStats; - for (let playerStat of playerStats){ - if (playerStat.user === user){ - playerStat.rating = 1000; - await playerStat.save(); - } - } - } - } - } else { - let playerStats = leaderboard.playerStats; - if (!user){ - for (let playerStat of playerStats){ - playerStat.rating = 1000; - await playerStat.save(); - } - } - else { - for (let playerStat of playerStats){ - if (playerStat.user === user){ - playerStat.rating = 1000; - await playerStat.save(); - } - } - } - } - - await interaction.followUp(`The rating value has been set.`); - } - }) - } -======= const discordId = options.getUser("user")?.id; const queueUuid = options.getInteger("queue_uuid") ?? undefined; return await reset(guildId, discordId, queueUuid, {rating: true}); }, ->>>>>>> main -} as ICommand; +} as ICommand; \ No newline at end of file diff --git a/src/commands/rating/rating_set.ts b/src/commands/rating/rating_set.ts index 01c30e1..a0b6efa 100644 --- a/src/commands/rating/rating_set.ts +++ b/src/commands/rating/rating_set.ts @@ -1,21 +1,16 @@ -import {MessageActionRow, MessageButton, MessageComponentInteraction} from "discord.js"; import {ApplicationCommandOptionTypes} from "discord.js/typings/enums"; import {ICommand} from "wokcommands"; -import {Leaderboard} from "../../entities/queues/Leaderboard"; -import {User} from "../../entities/User"; +import {ratingSet} from "../../abstract_commands/ratings/rating_set"; import {ensure} from "../../utils/general"; + export default { -<<<<<<< HEAD - category: "General", - description: "This command resets the ratings of all the users in the server back to the default 1000.", -======= category: "Admin", description: "Set the rating for a user for a specific queue", ->>>>>>> main slash: true, testOnly: true, + guildOnly: true, options: [ { @@ -26,24 +21,19 @@ export default { }, { name: "user", - description: "If specified, reset the ratings only for this user", + description: "The user to set rating for", type: ApplicationCommandOptionTypes.USER, required: true, }, { -<<<<<<< HEAD - name: "leaderboard_uuid", - description: "If specified, reset the ratings only for this leaderboard.", -======= name: "queue_uuid", description: "The queue to set the rating for", ->>>>>>> main type: ApplicationCommandOptionTypes.INTEGER, required: false, }, ], - callback: async ({interaction, channel}) => { + callback: async ({interaction}) => { const {options, channelId, guildId} = interaction; // ensure that the command is being run in a server @@ -53,86 +43,9 @@ export default { // get the command parameters const rating = ensure(options.getInteger("rating")); -<<<<<<< HEAD - const userAPI = ensure(options.getUser("user")); - const user = await User.findOneBy({discordId:userAPI!.id}) - - const leaderboard_uuid = options.getInteger("leaderboard_uuid") ?? null; - let leaderboard: any; - - if (leaderboard_uuid !== null) { - leaderboard = await Leaderboard.findOneBy({uuid: leaderboard_uuid}); - if (leaderboard === null) { - return `Leaderboard with id ${leaderboard_uuid} does not exist`; - } - } - - // create embedded message for users to confirm their action - const row = new MessageActionRow() - .setComponents( - new MessageButton() - .setLabel('Cancel') - .setStyle('SECONDARY') - .setCustomId('cancel'), - new MessageButton() - .setLabel('Confirm') - .setStyle('DANGER') - .setCustomId('confirm'), - ) - const confirmMsg = await interaction.reply({ - content: `Are you sure you want to set rating values for ${userAPI.username}?`, - components: [row], - fetchReply: true - }) - - const filter = (i: MessageComponentInteraction) => { - return i.user.id === interaction.user.id - }; - - - let collector = channel.createMessageComponentCollector({filter, max: 1}); - - collector.on("collect", async (btnInt) => { - if (!btnInt) { - return; - } - await btnInt.deferUpdate(); - if (btnInt.customId === "cancel") { - return; - } else if (btnInt.customId === "confirm") { - // leaderboard uuid is not provided - if (!leaderboard) { - let leaderboards = await Leaderboard.find(); - - for (let leaderboard of leaderboards) { - let playerStats = leaderboard.playerStats; - for (let playerStat of playerStats){ - if (playerStat.user === user){ - playerStat.rating = rating; - await playerStat.save(); - } - } - } - } else { - let playerStats = leaderboard.playerStats; - for (let playerStat of playerStats){ - if (playerStat.user === user){ - playerStat.rating = rating; - await playerStat.save(); - } - } - - } - - await interaction.followUp(`The rating value has been set.`); - } - }) - } -======= const discordId = ensure(options.getUser("user")?.id); const queueUuid = options.getInteger("queue_uuid") ?? undefined; return await ratingSet(discordId, rating, channelId, queueUuid); }, ->>>>>>> main -} as ICommand; +} as ICommand; \ No newline at end of file From 6ca25715c195369b848f1fc998d4a3e1e0028de0 Mon Sep 17 00:00:00 2001 From: Alian713 Date: Thu, 11 Aug 2022 08:49:53 +0800 Subject: [PATCH 4/5] fixed merge conflicts 3 --- package-lock.json | 2 +- src/commands/rating/rating_reset.ts | 2 +- src/commands/rating/rating_set.ts | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/package-lock.json b/package-lock.json index 06e11d1..0f55dd1 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9272,4 +9272,4 @@ "dev": true } } -} \ No newline at end of file +} diff --git a/src/commands/rating/rating_reset.ts b/src/commands/rating/rating_reset.ts index 9f3d22f..f59fa00 100644 --- a/src/commands/rating/rating_reset.ts +++ b/src/commands/rating/rating_reset.ts @@ -39,4 +39,4 @@ export default { return await reset(guildId, discordId, queueUuid, {rating: true}); }, -} as ICommand; \ No newline at end of file +} as ICommand; diff --git a/src/commands/rating/rating_set.ts b/src/commands/rating/rating_set.ts index a0b6efa..19d3d45 100644 --- a/src/commands/rating/rating_set.ts +++ b/src/commands/rating/rating_set.ts @@ -48,4 +48,4 @@ export default { return await ratingSet(discordId, rating, channelId, queueUuid); }, -} as ICommand; \ No newline at end of file +} as ICommand; From 6a55234c747217b9aa72baa20f8a454c2d953e34 Mon Sep 17 00:00:00 2001 From: Alian713 Date: Thu, 11 Aug 2022 08:54:51 +0800 Subject: [PATCH 5/5] removed unused files --- src/abstract_commands/draw_data.py | 26 --------------------- src/features/expired-ban.ts | 36 ------------------------------ 2 files changed, 62 deletions(-) delete mode 100644 src/abstract_commands/draw_data.py delete mode 100644 src/features/expired-ban.ts diff --git a/src/abstract_commands/draw_data.py b/src/abstract_commands/draw_data.py deleted file mode 100644 index 494b4cf..0000000 --- a/src/abstract_commands/draw_data.py +++ /dev/null @@ -1,26 +0,0 @@ -import matplotlib.pyplot as plt -import sys -import json -import ast - - -def draw_data(last_changes): - l = len(last_changes) - plt.plot(list(range(1,l+1)), last_changes, color="red", marker="o") - for a, b in zip(list(range(1,l+1)), last_changes): - plt.annotate(b, # this is the text - (a, b), # these are the coordinates to position the label - textcoords="offset points", # how to position the text - xytext=(0, 6), # distance from text to points (x,y) - ha='center') # horizontal alignment can be left, right or center - plt.title(f'rating changes in last {l} games') - plt.ylabel('rating change') - plt.xticks(range(1,l+1)) - plt.grid(True) - plt.savefig("saved_img") -# plt.show() - -input = ast.literal_eval(sys.argv[1]) -print("kkk") -draw_data(input) -sys.stdout.flush() \ No newline at end of file diff --git a/src/features/expired-ban.ts b/src/features/expired-ban.ts deleted file mode 100644 index 1f7b1a7..0000000 --- a/src/features/expired-ban.ts +++ /dev/null @@ -1,36 +0,0 @@ -import {Client, Guild} from "discord.js"; -import {Ban} from "../entities/user_data/Ban"; -import {client} from "../main"; -import {User} from "../entities/User"; -import {LessThan} from "typeorm"; - -export default (client:Client) => { - const check = async () => { - // const results = await Ban.findBy({ - // until: LessThan(new Date().getTime()), - // }); - // let users = await User.find({relations:{guilds:true}}); - // console.log(users) - - // for (const result of results){ - // const userId = result.user?.discordId; - // const guildId = result.guild?.id; - // const guild = await client.guilds.fetch(guildId!).then(guild => { - // console.log(guild.); - // console.log(guild!.members); - // guild!.members.unban(userId!, "ban expired"); - // }); - // // console.log(guild); - // // console.log(guild!.members); - // // await guild!.members.unban(userId!, "ban expired"); - // } - setTimeout(check, 1000*60); - await Ban.delete({until: LessThan(new Date().getTime())}) - } - check(); -} - -export const config = { - dbName: "Ban", - displayName: "Banned users", -} \ No newline at end of file