From 1107a6a1396380eafca5cc8592965771e8f96285 Mon Sep 17 00:00:00 2001 From: Each Chen Date: Tue, 27 Aug 2024 19:56:58 +0800 Subject: [PATCH 001/141] token move env --- .env.example | 14 +++++++- .gitignore | 3 ++ READMEtemp | 82 ---------------------------------------------- app.py | 43 ++++++++++++------------ cog/core/secret.py | 2 +- main.py | 11 +++---- token.json | 12 ------- 7 files changed, 43 insertions(+), 124 deletions(-) delete mode 100644 READMEtemp delete mode 100644 token.json diff --git a/.env.example b/.env.example index 2f78239..29f6b12 100644 --- a/.env.example +++ b/.env.example @@ -1,7 +1,19 @@ # 這是一個範例檔案,請複製一份 .env.example 並命名為 .env # 並將以下的設定值填入 +# Database configuration MYSQL_USER=資料庫使用者 MYSQL_PASSWORD=資料庫使用者密碼 MYSQL_PORT=資料庫連接埠 MYSQL_DATABASE=資料庫名稱 -HOST=資料庫主機位址 \ No newline at end of file +HOST=資料庫主機位址 + +# flask configuration +DISCORD_TOKEN=Disscord機器人Token +secret_key= 隨機字串,給 flask session 使用 +DISCORD_CLIENT_SECRET=DISCORD_CLIENT_SECRET,到 Discord Developer Portal 取得 +DISCORD_REDIRECT_URI=商店網址/callback +GITHUB_CLIENT_ID=GitHub Client ID,到 GitHub Developer 取得 +GITHUB_CLIENT_SECRET=GitHub Client Secret +GITHUB_REDIRECT_URI=GitHub OAuth Redirect URI +GITHUB_DISCORD_REDIRECT= +SEND_GIFT_ROLE=允許發送禮物的身分組ID,多個角色ID以逗號分隔 \ No newline at end of file diff --git a/.gitignore b/.gitignore index fa685a3..311b7d2 100644 --- a/.gitignore +++ b/.gitignore @@ -18,6 +18,9 @@ nohup.out pointLog.out ## Configuration files .env +# python 虛擬環境 +envuwu/ +env-uwu/ ### Ignore token ### 如果你的token.json已經被追蹤可以執行: ### 1. git rm --cached token.json diff --git a/READMEtemp b/READMEtemp deleted file mode 100644 index 5dba1b7..0000000 --- a/READMEtemp +++ /dev/null @@ -1,82 +0,0 @@ - - - -
-中電喵 SCAICT uwu - -# 中電喵 SCAICT uwu - -住在中電會 Discord 伺服器的貓咪 - -[![同步代辦事項至 Notion](https://github.com/SCAICT/SCAICT-uwu/actions/workflows/notion.yml/badge.svg?event=issues)](https://github.com/SCAICT/SCAICT-uwu/actions/workflows/notion.yml) -[![官方網站](https://img.shields.io/website?label=官方網站&&url=https%3A%2F%2Fscaict.org%2F)](https://scaict.org/) -[![中電商店](https://img.shields.io/website?label=中電商店&&url=https%3A%2F%2Fstore.scaict.org%2F)](https://store.scaict.org/) -[![加入 Discord 伺服器](https://img.shields.io/discord/959823904266944562?label=Discord&logo=discord&)](https://dc.scaict.org) -[![追蹤 Instagram](https://img.shields.io/badge/follow-%40scaict.tw-pink?&logo=instagram)](https://www.instagram.com/scaict.tw/) - -
- -> 這個專案目前處於開發階段,並且可能會有一些問題。如果您發現了任何問題或有任何建議,請透過提交 issue 來通知我們。 - -## 如何部署? - -1. clone 此儲存庫。 -2. 在 Python 3.11 中建立環境。 -3. 安裝必要的函式庫。 - - ```bash - pip install -r requirements.txt - ``` - -4. 在 `DataBase/server.config.json` 中設定頻道。 -5. 啟動 SQL 伺服器。 -6. 在 Breadcrumbs SCAICT-uwu 的 `cog/core/sql_acc.py` 中設定 SQL 伺服器。 -7. 執行 Flask。 - - ```bash - flask run - ``` - -8. 執行 `main.py`。 - - ```bash - python main.py - ``` - -## 檔案 - -* `main.py`:中電喵。 -* `app.py`:中電商店。 -* `generate_secrets.py`:為 `app.py` 產生密鑰,執行後儲存在 `token.json` 中。 -* 資料庫 MySQL:使用外部伺服器,相關設定在 `cog/core/secret.py` 中。 -* `token.json`: - - ```json - { - "discord_token": "", - "secret_key": "", - "discord_client_id": "", - "discord_client_secret": "", - "discord_redirect_uri": "http://127.0.0.1:5000/callback", - "github_client_id": "", - "github_client_secret": "", - "github_redirect_uri": "http://127.0.0.1:5000/github/callback", - "github_discord_redirect_uri": "http://127.0.0.1:5000/github/discord-callback" - } - ``` - -* `DataBase/slot.json`: - - 設定老虎機的中獎機率。 - - ```json - { - "element": [ percentage, reward ] - } - ``` - -> 更詳細的說明文件敘述可以參考[這裡](https://g.scaict.org/doc/) - -## 鳴謝 - -中電喵是由中電會和[貢獻者們](https://github.com/SCAICT/SCAICT-uwu/graphs/contributors)共同開發和維護的專案。角色設計由[毛哥 EM](https://elvismao.com/) 和[瑞樹](https://www.facebook.com/ruishuowo)創作,而部分圖示則選用了來自 [Freepik - Flaticon](https://www.flaticon.com/free-icons/slot-machine) 的設計素材。 diff --git a/app.py b/app.py index 53bdc41..62da604 100644 --- a/app.py +++ b/app.py @@ -16,7 +16,7 @@ jsonify, ) import requests - +from dotenv import load_dotenv # Local imports from cog.core.sql import write from cog.core.sql import read @@ -25,23 +25,24 @@ from cog.core.sql import user_id_exists app = Flask(__name__) - -# FILEPATH: /d:/GayHub/SCAICT-Discord-Bot/token.json -with open(f"{os.getcwd()}/token.json", encoding="utf-8") as token_file: - token_data = json.load(token_file) - -app.secret_key = token_data["secret_key"] -discord_client_id = token_data["discord_client_id"] -discord_client_secret = token_data["discord_client_secret"] -discord_redirect_uri = token_data["discord_redirect_uri"] -github_client_id = token_data["github_client_id"] -github_client_secret = token_data["github_client_secret"] -github_redirect_uri = token_data["github_redirect_uri"] -github_discord_redirect_uri = token_data["github_discord_redirect_uri"] -discord_token = token_data["discord_token"] -send_gift_role = token_data["send_gift_role"] - - +load_dotenv(f"{os.getcwd()}/.env",verbose=True, override=True) + +app.secret_key = os.getenv("SECRET_KEY") +discord_client_id = os.getenv("DISCORD_CLIENT_ID") +discord_client_secret = os.getenv("DISCORD_CLIENT_SECRET") +discord_redirect_uri = os.getenv("DISCORD_REDIRECT_URI") +github_client_id = os.getenv("GITHUB_CLIENT_ID") +github_client_secret = os.getenv("GITHUB_CLIENT_SECRET") +github_redirect_uri = os.getenv("GITHUB_REDIRECT_URI") +github_discord_redirect_uri = os.getenv("GITHUB_DISCORD_REDIRECT_URI") +discord_token = os.getenv("DISCORD_TOKEN") +send_gift_role = os.getenv("SEND_GIFT_ROLE") +guild_ID = os.getenv("GUILD_ID") +# 將字串轉換為列表 +if send_gift_role: + send_gift_role = [int(role_id) for role_id in send_gift_role.split(",")] +else: + send_gift_role_list = [] @app.errorhandler(404) def not_found_error(error): return render_template("404.html"), 404 @@ -81,7 +82,7 @@ def listt(): api_admin_id = api_admin.get("id") headers = {"Authorization": f"Bot {discord_token}"} url = ( - f"https://discord.com/api/v10/guilds/1203338928535379978/members/{api_admin_id}" + f"https://discord.com/api/v10/guilds/{guild_ID}/members/{api_admin_id}" ) response = requests.get(url, headers=headers, timeout=10) user_data = response.json() @@ -112,7 +113,7 @@ def send(target_user_id): api_admin_id = api_admin.get("id") api_admin_name = api_admin.get("name") headers = {"Authorization": f"Bot {discord_token}"} - url = f"https://discord.com/api/v10/guilds/1203338928535379978/members/{api_admin_id}" + url = f"https://discord.com/api/v10/guilds/{guild_ID}/members/{api_admin_id}" response = requests.get(url, headers=headers, timeout=10) user_data = response.json() if response.status_code != 200: @@ -133,7 +134,7 @@ def send(target_user_id): except ValueError: return jsonify({"result": "Invalid count value", "status": 400}) print(gift_type, count) - url = f"https://discord.com/api/v10/guilds/1203338928535379978/members/{target_user_id}" + url = f"https://discord.com/api/v10/guilds/{guild_ID}/members/{target_user_id}" response = requests.get(url, headers=headers, timeout=10) user_data = response.json() if response.status_code != 200: diff --git a/cog/core/secret.py b/cog/core/secret.py index 4b09446..f50b094 100644 --- a/cog/core/secret.py +++ b/cog/core/secret.py @@ -6,6 +6,7 @@ import mysql.connector +load_dotenv(f"{os.getcwd()}/.env") DB_USER = os.getenv("MYSQL_USER") DB_PASSWORD = os.getenv("MYSQL_PASSWORD") DB_NAME = os.getenv("MYSQL_DATABASE") @@ -14,7 +15,6 @@ def connect(): - load_dotenv(f"{os.getcwd()}/.env") return mysql.connector.connect( user=DB_USER, password=DB_PASSWORD, diff --git a/main.py b/main.py index 45316c5..735b90f 100644 --- a/main.py +++ b/main.py @@ -1,10 +1,9 @@ # Standard imports -import json import os # Third-party imports import discord - +from dotenv import load_dotenv # Local imports from channel_check import update_channel # update_channel程式從core目錄底下引入 from channel_check import change_status # update_channel程式從core目錄底下引入 @@ -14,10 +13,6 @@ intt.message_content = True bot = discord.Bot(intents=intt) -# 變更目前位置到專案根目錄(SCAICT-DISCORD-BOT 資料夾),再找檔案 -os.chdir("./") -with open(f"{os.getcwd()}/token.json", "r", encoding="utf-8") as file: - token = json.load(file) for filename in os.listdir(f"{os.getcwd()}/cog"): if filename.endswith(".py"): @@ -34,4 +29,6 @@ async def on_ready(): if __name__ == "__main__": - bot.run(token["discord_token"]) + load_dotenv(f"{os.getcwd()}/.env",verbose=True, override=True) + bot_token = os.getenv("DISCORD_TOKEN") + bot.run(bot_token) diff --git a/token.json b/token.json deleted file mode 100644 index dcbd62d..0000000 --- a/token.json +++ /dev/null @@ -1,12 +0,0 @@ -{ - "discord_token": "", - "secret_key": "", - "discord_client_id": "", - "discord_client_secret": "", - "discord_redirect_uri": "", - "github_client_id": "", - "github_client_secret": "", - "github_redirect_uri": "", - "github_discord_redirect_uri": "", - "send_gift_role":"" -} From 03095c556824749091f20d37898e038c6f170095 Mon Sep 17 00:00:00 2001 From: Each Chen Date: Tue, 27 Aug 2024 22:19:28 +0800 Subject: [PATCH 002/141] api in class --- app.py | 13 +++++-------- cog/api/api.py | 51 ++++++++++++++++++++++++++++++++++++++++++++++++++ test/api.py | 16 ++++++++++++++++ 3 files changed, 72 insertions(+), 8 deletions(-) create mode 100644 cog/api/api.py create mode 100644 test/api.py diff --git a/app.py b/app.py index 62da604..76bcde7 100644 --- a/app.py +++ b/app.py @@ -23,7 +23,7 @@ from cog.core.sql import link_sql from cog.core.sql import end from cog.core.sql import user_id_exists - +from cog.api.api import Apis app = Flask(__name__) load_dotenv(f"{os.getcwd()}/.env",verbose=True, override=True) @@ -112,15 +112,11 @@ def send(target_user_id): ) # {'avatar': 'https://cdn.discordapp.com/avatars/898141506588770334/a_c81acdd4a925993d053a6fe9ed990c14.png', 'id': '898141506588770334', 'name': 'iach526526'} api_admin_id = api_admin.get("id") api_admin_name = api_admin.get("name") + discord_api = Apis(discord_token, guild_ID) headers = {"Authorization": f"Bot {discord_token}"} url = f"https://discord.com/api/v10/guilds/{guild_ID}/members/{api_admin_id}" response = requests.get(url, headers=headers, timeout=10) - user_data = response.json() - if response.status_code != 200: - return ( - jsonify({"error": "Failed to fetch user information"}), - response.status_code, - ) + user_data = discord_api.get_user(api_admin_id) if send_gift_role not in user_data.get("roles", []): return jsonify( {"result": "You do not have permission to use this", "status": 403} @@ -133,7 +129,7 @@ def send(target_user_id): count = int(count) # 確保 count 是整數 except ValueError: return jsonify({"result": "Invalid count value", "status": 400}) - print(gift_type, count) + url = f"https://discord.com/api/v10/guilds/{guild_ID}/members/{target_user_id}" response = requests.get(url, headers=headers, timeout=10) user_data = response.json() @@ -228,6 +224,7 @@ def send(target_user_id): @app.route("/callback") + discord_api = Apis(discord_token, guild_ID) def callback(): code = request.args.get("code") redirurl = request.args.get("state") # 使用 state 作為重定向的目標 URL diff --git a/cog/api/api.py b/cog/api/api.py new file mode 100644 index 0000000..2a3fa32 --- /dev/null +++ b/cog/api/api.py @@ -0,0 +1,51 @@ +import requests +class Apis: + def __init__(self, api_key:str,guild_id:int): + self.api_key = api_key + self.guild_id = guild_id + self.headers = {"Authorization": f"Bot {self.api_key}","Content-Type": "application/json",} + def get_user(self, uid): + """API 回傳的資料格式範例,已經把一些敏感資料隱藏掉 + { + "avatar": null, + "banner": null, + "communication_disabled_until": null, + "flags": 0, + "joined_at": "", + "nick": null, + "pending": false, + "premium_since": null, + "roles": [ + "12348763", + "12448763", + "12548763" + ], + "unusual_dm_activity_until": null, + "user": { + "id": "", + "username": "", + "avatar": "", + "discriminator": "0", + "public_flags": 256, + "flags": 256, + "banner": "", + "accent_color": 2054367, + "global_name": "", + "avatar_decoration_data": { + "asset": "a_d3da36040163ee0f9176dfe7ced45cdc", + "sku_id": "1144058522808614923", + "expires_at": null + }, + "banner_color": "#1f58df", + "clan": null + }, + "mute": false, + "deaf": false + } + + """ + url = f"https://discord.com/api/v10/guilds/{self.guild_id}/members/{uid}" + response = requests.get(url, headers=self.headers,timeout=5) + if response.status_code != 200: + return [] + return response.json() \ No newline at end of file diff --git a/test/api.py b/test/api.py new file mode 100644 index 0000000..3704451 --- /dev/null +++ b/test/api.py @@ -0,0 +1,16 @@ +import os +import requests +from dotenv import load_dotenv +import json + +load_dotenv(f"{os.getcwd()}/.env",verbose=True, override=True) + +discord_token = os.getenv("DISCORD_TOKEN") +guild_ID = os.getenv("GUILD_ID") +uid=input("Enter the user ID: ") + +headers = {"Authorization": f"Bot {discord_token}"} +url = f"https://discord.com/api/v10/guilds/{guild_ID}/members/{uid}" +response = requests.get(url, headers=headers,timeout=5) +result = response.json() +print(json.dumps(result, indent=4)) # type: ignore From 58da1a4ac2341285969effa9cc0162cc9f960293 Mon Sep 17 00:00:00 2001 From: Each Chen Date: Wed, 28 Aug 2024 07:44:22 +0800 Subject: [PATCH 003/141] do not use! chore: Refactor API class and handle errors in get_user method --- app.py | 195 +++++++++++++++++++++++++------------------------ cog/api/api.py | 38 ++++++++-- 2 files changed, 132 insertions(+), 101 deletions(-) diff --git a/app.py b/app.py index 76bcde7..7e496fc 100644 --- a/app.py +++ b/app.py @@ -40,7 +40,7 @@ guild_ID = os.getenv("GUILD_ID") # 將字串轉換為列表 if send_gift_role: - send_gift_role = [int(role_id) for role_id in send_gift_role.split(",")] + send_gift_role = [str(role_id) for role_id in send_gift_role.split(",")] else: send_gift_role_list = [] @app.errorhandler(404) @@ -113,11 +113,19 @@ def send(target_user_id): api_admin_id = api_admin.get("id") api_admin_name = api_admin.get("name") discord_api = Apis(discord_token, guild_ID) - headers = {"Authorization": f"Bot {discord_token}"} - url = f"https://discord.com/api/v10/guilds/{guild_ID}/members/{api_admin_id}" - response = requests.get(url, headers=headers, timeout=10) - user_data = discord_api.get_user(api_admin_id) - if send_gift_role not in user_data.get("roles", []): + request_admin = discord_api.get_user(api_admin_id) + if "error" in request_admin: + # 如果有錯誤,返回錯誤訊息和詳細信息 + return jsonify( + { + "result": "Failed to fetch user information in admin id", + "status": 500, + "error_details": request_admin.get("details"), + } + ) + admin_roles =request_admin.get("roles", []) + # 確保發起人有權限發送禮物 + if set(send_gift_role) & set(admin_roles) == set(): return jsonify( {"result": "You do not have permission to use this", "status": 403} ) @@ -129,94 +137,94 @@ def send(target_user_id): count = int(count) # 確保 count 是整數 except ValueError: return jsonify({"result": "Invalid count value", "status": 400}) - - url = f"https://discord.com/api/v10/guilds/{guild_ID}/members/{target_user_id}" - response = requests.get(url, headers=headers, timeout=10) - user_data = response.json() - if response.status_code != 200: - # 確保 URL 的 target_user_id 在伺服器裡面 - return ( - jsonify({"error": "Failed to fetch user information in tg id"}), - response.status_code, - ) - # 送禮物 - try: - url = "https://discord.com/api/v10/users/@me/channels" - headers = { - "Authorization": f"Bot {discord_token}", - "Content-Type": "application/json", - } - json_data = {"recipient_id": target_user_id} - except requests.RequestException as e: - return jsonify( - {"result": "interal server error", "status": 500, "error": str(e)} - ) - except Exception as e: - return jsonify( - {"result": "interal server error", "status": 500, "error": str(e)} - ) - response = requests.post(url, headers=headers, json=json_data, timeout=10) - dm_channel = response.json() - dm_room = dm_channel["id"] - url = f"https://discord.com/api/v10/channels/{dm_room}/messages" - # 發送按鈕訊息 - headers = { - "Authorization": f"Bot {discord_token}", - "Content-Type": "application/json", - } - embed = { - "title": f"你收到了 {count} {gift_type}!", - "color": 3447003, # (藍色) - "description": ":gift:", - } - button = { - "type": 1, - "components": [ - { - "type": 2, - "label": "前往確認", - "style": 5, # `5` 表示 Link Button - "url": "https://store.scaict.org", # 要導向的連結 - } - ], - } - json_data = { - "embeds": [embed], - "components": [button], - "tts": False, # Text-to-speech, 默認為 False - } - try: - response = requests.post(url, headers=headers, json=json_data, timeout=10) - connect, cursor = link_sql() - message_id = response.json().get("id") - print(message_id) - if not user_id_exists(target_user_id, "user", cursor): - cursor.execute( - "INSERT INTO user (uid) VALUE(%s)", (target_user_id,) - ) # 這裡要調用 api 去抓使用者名稱和 Mail - cursor.execute( - "INSERT into gift (btnID,type,count,recipient,received,sender) VALUE(%s,%s,%s,%s,%s,%s)", - (message_id, gift_type, count, target_user_id, True, api_admin_name), - ) - gift_type = "point" if gift_type == "電電點" else "ticket" - query = f"update user set {gift_type}={gift_type}+%s where uid=%s" - cursor.execute(query, (count, target_user_id)) - end(connect, cursor) - except Exception as e: - return jsonify( - { - "result": "interal server error(SQL) when insert gift", - "status": 500, - "error": str(e), - } - ) - # 待辦:用戶端那裏也要提示 - response = requests.post(url, headers=headers, json=json_data, timeout=10) - if response.status_code != 200: - return jsonify( - {"error": "Failed to send message", "status": response.status_code} - ) return jsonify({"result": "success", "status": 200}) + # url = f"https://discord.com/api/v10/guilds/{guild_ID}/members/{target_user_id}" + # response = requests.get(url, headers=headers, timeout=10) + # user_data = discord_api.get_user(target_user_id) + # if response.status_code != 200: + # # 確保 URL 的 target_user_id 在伺服器裡面 + # return ( + # jsonify({"error": "Failed to fetch user information in tg id"}), + # response.status_code, + # ) + # # 送禮物 + # try: + # url = "https://discord.com/api/v10/users/@me/channels" + # headers = { + # "Authorization": f"Bot {discord_token}", + # "Content-Type": "application/json", + # } + # json_data = {"recipient_id": target_user_id} + # except requests.RequestException as e: + # return jsonify( + # {"result": "interal server error", "status": 500, "error": str(e)} + # ) + # except Exception as e: + # return jsonify( + # {"result": "interal server error", "status": 500, "error": str(e)} + # ) + # response = requests.post(url, headers=headers, json=json_data, timeout=10) + # dm_channel = response.json() + # dm_room = dm_channel["id"] + # url = f"https://discord.com/api/v10/channels/{dm_room}/messages" + # # 發送按鈕訊息 + # headers = { + # "Authorization": f"Bot {discord_token}", + # "Content-Type": "application/json", + # } + # embed = { + # "title": f"你收到了 {count} {gift_type}!", + # "color": 3447003, # (藍色) + # "description": ":gift:", + # } + # button = { + # "type": 1, + # "components": [ + # { + # "type": 2, + # "label": "前往確認", + # "style": 5, # `5` 表示 Link Button + # "url": "https://store.scaict.org", # 要導向的連結 + # } + # ], + # } + # json_data = { + # "embeds": [embed], + # "components": [button], + # "tts": False, # Text-to-speech, 默認為 False + # } + # try: + # response = requests.post(url, headers=headers, json=json_data, timeout=10) + # connect, cursor = link_sql() + # message_id = response.json().get("id") + # print(message_id) + # if not user_id_exists(target_user_id, "user", cursor): + # cursor.execute( + # "INSERT INTO user (uid) VALUE(%s)", (target_user_id,) + # ) # 這裡要調用 api 去抓使用者名稱和 Mail + # cursor.execute( + # "INSERT into gift (btnID,type,count,recipient,received,sender) VALUE(%s,%s,%s,%s,%s,%s)", + # (message_id, gift_type, count, target_user_id, True, api_admin_name), + # ) + # gift_type = "point" if gift_type == "電電點" else "ticket" + # query = f"update user set {gift_type}={gift_type}+%s where uid=%s" + # cursor.execute(query, (count, target_user_id)) + # end(connect, cursor) + # except Exception as e: + # return jsonify( + # { + # "result": "interal server error(SQL) when insert gift", + # "status": 500, + # "error": str(e), + # } + # ) + # # 待辦:用戶端那裏也要提示 + # response = requests.post(url, headers=headers, json=json_data, timeout=10) + # if response.status_code != 200: + # return jsonify( + # {"error": "Failed to send message", "status": response.status_code} + # ) + # return jsonify({"result": "success", "status": 200}) except Exception as e: return jsonify( {"result": "interal server error", "status": 500, "error": str(e)} @@ -224,7 +232,6 @@ def send(target_user_id): @app.route("/callback") - discord_api = Apis(discord_token, guild_ID) def callback(): code = request.args.get("code") redirurl = request.args.get("state") # 使用 state 作為重定向的目標 URL diff --git a/cog/api/api.py b/cog/api/api.py index 2a3fa32..c10ebd1 100644 --- a/cog/api/api.py +++ b/cog/api/api.py @@ -5,8 +5,9 @@ def __init__(self, api_key:str,guild_id:int): self.guild_id = guild_id self.headers = {"Authorization": f"Bot {self.api_key}","Content-Type": "application/json",} def get_user(self, uid): - """API 回傳的資料格式範例,已經把一些敏感資料隱藏掉 - { + """ + API 回傳的資料格式範例,已經把一些敏感資料隱藏掉 + { "avatar": null, "banner": null, "communication_disabled_until": null, @@ -44,8 +45,31 @@ def get_user(self, uid): } """ - url = f"https://discord.com/api/v10/guilds/{self.guild_id}/members/{uid}" - response = requests.get(url, headers=self.headers,timeout=5) - if response.status_code != 200: - return [] - return response.json() \ No newline at end of file + try: + url = f"https://discord.com/api/v10/guilds/{self.guild_id}/members/{uid}" + response = requests.get(url, headers=self.headers,timeout=5) + response.raise_for_status() # 檢查 HTTP 狀態碼 + return response.json() + except requests.exceptions.RequestException as e: + # 如果發生錯誤,返回一個包含錯誤訊息和詳細報錯的字典 + return {"error": "get_user error", "details": str(e)} + def create_dm_channel(self, target_user_id: str): + try: + url = "https://discord.com/api/v10/users/@me/channels" + json_data = {"recipient_id": target_user_id} + response = requests.post(url, headers=self.headers, json=json_data, timeout=10) + response.raise_for_status() # Raise an HTTPError for bad responses + dm_channel = response.json() + return dm_channel["id"] + except requests.RequestException as e: + return { + "result": "internal server error", + "status": 500, + "error": str(e), + } + except Exception as e: + return { + "result": "internal server error", + "status": 500, + "error": str(e), + } From d3ff30c85db98fc4d0b37644a94eacb7f6306fac Mon Sep 17 00:00:00 2001 From: Each Chen Date: Wed, 28 Aug 2024 08:08:32 +0800 Subject: [PATCH 004/141] resolve conflict ->force push --- .github/workflows/black.yml | 2 +- .pylintrc | 1 + cog/api/api.py | 18 +++++++++++++----- main.py | 3 ++- {src/scaict_uwu => scaict_uwu}/__init__.py | 0 {src/scaict_uwu => scaict_uwu}/bot/__init__.py | 0 .../bot/channels}/__init__.py | 0 .../emoji => scaict_uwu/bot/cog}/__init__.py | 0 .../bot/emoji}/__init__.py | 0 .../bot/users}/__init__.py | 0 .../cog => scaict_uwu/config}/__init__.py | 0 scaict_uwu/config/config.py | 7 +++++++ scaict_uwu/config/config_factory.py | 7 +++++++ .../i18n/course/zh-hant.json | 0 .../i18n/ctf/zh-hant.json | 0 .../i18n/daily_charge/zh-hant.json | 0 .../i18n/game_counting/zh-hant.json | 0 .../i18n/game_nice_color/zh-hant.json | 0 .../i18n/game_rps/zh-hant.json | 0 .../i18n/support_ticket/zh-hant.json | 0 .../i18n/version_info/zh-hant.json | 0 .../i18n/zh-hant.json | 0 .../installer}/__init__.py | 0 .../installer/cog}/__init__.py | 0 .../scripts => scaict_uwu/logging}/__init__.py | 0 .../maintenance}/__init__.py | 0 .../maintenance/data/tables.json | 0 .../maintenance/scripts}/__init__.py | 0 .../rdbms}/__init__.py | 0 .../user => scaict_uwu/stats}/__init__.py | 0 .../system_message}/__init__.py | 0 .../utils => scaict_uwu/user}/__init__.py | 0 .../website => scaict_uwu/utils}/__init__.py | 0 scaict_uwu/website/__init__.py | 0 34 files changed, 31 insertions(+), 7 deletions(-) rename {src/scaict_uwu => scaict_uwu}/__init__.py (100%) rename {src/scaict_uwu => scaict_uwu}/bot/__init__.py (100%) rename {src/scaict_uwu/bot/cog => scaict_uwu/bot/channels}/__init__.py (100%) rename {src/scaict_uwu/bot/emoji => scaict_uwu/bot/cog}/__init__.py (100%) rename {src/scaict_uwu/config => scaict_uwu/bot/emoji}/__init__.py (100%) rename {src/scaict_uwu/installer => scaict_uwu/bot/users}/__init__.py (100%) rename {src/scaict_uwu/installer/cog => scaict_uwu/config}/__init__.py (100%) create mode 100644 scaict_uwu/config/config.py create mode 100644 scaict_uwu/config/config_factory.py rename {src/scaict_uwu => scaict_uwu}/i18n/course/zh-hant.json (100%) rename {src/scaict_uwu => scaict_uwu}/i18n/ctf/zh-hant.json (100%) rename {src/scaict_uwu => scaict_uwu}/i18n/daily_charge/zh-hant.json (100%) rename {src/scaict_uwu => scaict_uwu}/i18n/game_counting/zh-hant.json (100%) rename {src/scaict_uwu => scaict_uwu}/i18n/game_nice_color/zh-hant.json (100%) rename {src/scaict_uwu => scaict_uwu}/i18n/game_rps/zh-hant.json (100%) rename {src/scaict_uwu => scaict_uwu}/i18n/support_ticket/zh-hant.json (100%) rename {src/scaict_uwu => scaict_uwu}/i18n/version_info/zh-hant.json (100%) rename {src/scaict_uwu => scaict_uwu}/i18n/zh-hant.json (100%) rename {src/scaict_uwu/logging => scaict_uwu/installer}/__init__.py (100%) rename {src/scaict_uwu/maintenance => scaict_uwu/installer/cog}/__init__.py (100%) rename {src/scaict_uwu/maintenance/scripts => scaict_uwu/logging}/__init__.py (100%) rename {src/scaict_uwu/rdbms => scaict_uwu/maintenance}/__init__.py (100%) rename {src/scaict_uwu => scaict_uwu}/maintenance/data/tables.json (100%) rename {src/scaict_uwu/stats => scaict_uwu/maintenance/scripts}/__init__.py (100%) rename {src/scaict_uwu/system_message => scaict_uwu/rdbms}/__init__.py (100%) rename {src/scaict_uwu/user => scaict_uwu/stats}/__init__.py (100%) rename {src/scaict_uwu/user/cog => scaict_uwu/system_message}/__init__.py (100%) rename {src/scaict_uwu/utils => scaict_uwu/user}/__init__.py (100%) rename {src/scaict_uwu/website => scaict_uwu/utils}/__init__.py (100%) create mode 100644 scaict_uwu/website/__init__.py diff --git a/.github/workflows/black.yml b/.github/workflows/black.yml index 29cd7a0..c658319 100644 --- a/.github/workflows/black.yml +++ b/.github/workflows/black.yml @@ -32,4 +32,4 @@ jobs: git config --local user.email "41898282+github-actions[bot]@users.noreply.github.com" git add * git diff-index --quiet HEAD || git commit -m "Format \"$(git show -s --format=%s)\" using Black" - git diff-index --quiet HEAD || git push + git push diff --git a/.pylintrc b/.pylintrc index 764eb8c..e26656c 100644 --- a/.pylintrc +++ b/.pylintrc @@ -448,6 +448,7 @@ disable=raw-checker-failed, line-too-long, duplicate-code, no-member, + too-few-public-methods, unused-argument, too-many-locals, too-many-arguments, diff --git a/cog/api/api.py b/cog/api/api.py index c10ebd1..6e67780 100644 --- a/cog/api/api.py +++ b/cog/api/api.py @@ -1,9 +1,15 @@ import requests + + class Apis: - def __init__(self, api_key:str,guild_id:int): + def __init__(self, api_key: str, guild_id: int): self.api_key = api_key self.guild_id = guild_id - self.headers = {"Authorization": f"Bot {self.api_key}","Content-Type": "application/json",} + self.headers = { + "Authorization": f"Bot {self.api_key}", + "Content-Type": "application/json", + } + def get_user(self, uid): """ API 回傳的資料格式範例,已經把一些敏感資料隱藏掉 @@ -43,21 +49,23 @@ def get_user(self, uid): "mute": false, "deaf": false } - """ try: url = f"https://discord.com/api/v10/guilds/{self.guild_id}/members/{uid}" - response = requests.get(url, headers=self.headers,timeout=5) + response = requests.get(url, headers=self.headers, timeout=5) response.raise_for_status() # 檢查 HTTP 狀態碼 return response.json() except requests.exceptions.RequestException as e: # 如果發生錯誤,返回一個包含錯誤訊息和詳細報錯的字典 return {"error": "get_user error", "details": str(e)} + def create_dm_channel(self, target_user_id: str): try: url = "https://discord.com/api/v10/users/@me/channels" json_data = {"recipient_id": target_user_id} - response = requests.post(url, headers=self.headers, json=json_data, timeout=10) + response = requests.post( + url, headers=self.headers, json=json_data, timeout=10 + ) response.raise_for_status() # Raise an HTTPError for bad responses dm_channel = response.json() return dm_channel["id"] diff --git a/main.py b/main.py index 735b90f..ef03506 100644 --- a/main.py +++ b/main.py @@ -4,6 +4,7 @@ # Third-party imports import discord from dotenv import load_dotenv + # Local imports from channel_check import update_channel # update_channel程式從core目錄底下引入 from channel_check import change_status # update_channel程式從core目錄底下引入 @@ -29,6 +30,6 @@ async def on_ready(): if __name__ == "__main__": - load_dotenv(f"{os.getcwd()}/.env",verbose=True, override=True) + load_dotenv(f"{os.getcwd()}/.env", verbose=True, override=True) bot_token = os.getenv("DISCORD_TOKEN") bot.run(bot_token) diff --git a/src/scaict_uwu/__init__.py b/scaict_uwu/__init__.py similarity index 100% rename from src/scaict_uwu/__init__.py rename to scaict_uwu/__init__.py diff --git a/src/scaict_uwu/bot/__init__.py b/scaict_uwu/bot/__init__.py similarity index 100% rename from src/scaict_uwu/bot/__init__.py rename to scaict_uwu/bot/__init__.py diff --git a/src/scaict_uwu/bot/cog/__init__.py b/scaict_uwu/bot/channels/__init__.py similarity index 100% rename from src/scaict_uwu/bot/cog/__init__.py rename to scaict_uwu/bot/channels/__init__.py diff --git a/src/scaict_uwu/bot/emoji/__init__.py b/scaict_uwu/bot/cog/__init__.py similarity index 100% rename from src/scaict_uwu/bot/emoji/__init__.py rename to scaict_uwu/bot/cog/__init__.py diff --git a/src/scaict_uwu/config/__init__.py b/scaict_uwu/bot/emoji/__init__.py similarity index 100% rename from src/scaict_uwu/config/__init__.py rename to scaict_uwu/bot/emoji/__init__.py diff --git a/src/scaict_uwu/installer/__init__.py b/scaict_uwu/bot/users/__init__.py similarity index 100% rename from src/scaict_uwu/installer/__init__.py rename to scaict_uwu/bot/users/__init__.py diff --git a/src/scaict_uwu/installer/cog/__init__.py b/scaict_uwu/config/__init__.py similarity index 100% rename from src/scaict_uwu/installer/cog/__init__.py rename to scaict_uwu/config/__init__.py diff --git a/scaict_uwu/config/config.py b/scaict_uwu/config/config.py new file mode 100644 index 0000000..d76a02c --- /dev/null +++ b/scaict_uwu/config/config.py @@ -0,0 +1,7 @@ +""" +Config +""" + + +class Config: + pass diff --git a/scaict_uwu/config/config_factory.py b/scaict_uwu/config/config_factory.py new file mode 100644 index 0000000..ca6ef1c --- /dev/null +++ b/scaict_uwu/config/config_factory.py @@ -0,0 +1,7 @@ +""" +Config factory +""" + + +class ConfigFactory: + pass diff --git a/src/scaict_uwu/i18n/course/zh-hant.json b/scaict_uwu/i18n/course/zh-hant.json similarity index 100% rename from src/scaict_uwu/i18n/course/zh-hant.json rename to scaict_uwu/i18n/course/zh-hant.json diff --git a/src/scaict_uwu/i18n/ctf/zh-hant.json b/scaict_uwu/i18n/ctf/zh-hant.json similarity index 100% rename from src/scaict_uwu/i18n/ctf/zh-hant.json rename to scaict_uwu/i18n/ctf/zh-hant.json diff --git a/src/scaict_uwu/i18n/daily_charge/zh-hant.json b/scaict_uwu/i18n/daily_charge/zh-hant.json similarity index 100% rename from src/scaict_uwu/i18n/daily_charge/zh-hant.json rename to scaict_uwu/i18n/daily_charge/zh-hant.json diff --git a/src/scaict_uwu/i18n/game_counting/zh-hant.json b/scaict_uwu/i18n/game_counting/zh-hant.json similarity index 100% rename from src/scaict_uwu/i18n/game_counting/zh-hant.json rename to scaict_uwu/i18n/game_counting/zh-hant.json diff --git a/src/scaict_uwu/i18n/game_nice_color/zh-hant.json b/scaict_uwu/i18n/game_nice_color/zh-hant.json similarity index 100% rename from src/scaict_uwu/i18n/game_nice_color/zh-hant.json rename to scaict_uwu/i18n/game_nice_color/zh-hant.json diff --git a/src/scaict_uwu/i18n/game_rps/zh-hant.json b/scaict_uwu/i18n/game_rps/zh-hant.json similarity index 100% rename from src/scaict_uwu/i18n/game_rps/zh-hant.json rename to scaict_uwu/i18n/game_rps/zh-hant.json diff --git a/src/scaict_uwu/i18n/support_ticket/zh-hant.json b/scaict_uwu/i18n/support_ticket/zh-hant.json similarity index 100% rename from src/scaict_uwu/i18n/support_ticket/zh-hant.json rename to scaict_uwu/i18n/support_ticket/zh-hant.json diff --git a/src/scaict_uwu/i18n/version_info/zh-hant.json b/scaict_uwu/i18n/version_info/zh-hant.json similarity index 100% rename from src/scaict_uwu/i18n/version_info/zh-hant.json rename to scaict_uwu/i18n/version_info/zh-hant.json diff --git a/src/scaict_uwu/i18n/zh-hant.json b/scaict_uwu/i18n/zh-hant.json similarity index 100% rename from src/scaict_uwu/i18n/zh-hant.json rename to scaict_uwu/i18n/zh-hant.json diff --git a/src/scaict_uwu/logging/__init__.py b/scaict_uwu/installer/__init__.py similarity index 100% rename from src/scaict_uwu/logging/__init__.py rename to scaict_uwu/installer/__init__.py diff --git a/src/scaict_uwu/maintenance/__init__.py b/scaict_uwu/installer/cog/__init__.py similarity index 100% rename from src/scaict_uwu/maintenance/__init__.py rename to scaict_uwu/installer/cog/__init__.py diff --git a/src/scaict_uwu/maintenance/scripts/__init__.py b/scaict_uwu/logging/__init__.py similarity index 100% rename from src/scaict_uwu/maintenance/scripts/__init__.py rename to scaict_uwu/logging/__init__.py diff --git a/src/scaict_uwu/rdbms/__init__.py b/scaict_uwu/maintenance/__init__.py similarity index 100% rename from src/scaict_uwu/rdbms/__init__.py rename to scaict_uwu/maintenance/__init__.py diff --git a/src/scaict_uwu/maintenance/data/tables.json b/scaict_uwu/maintenance/data/tables.json similarity index 100% rename from src/scaict_uwu/maintenance/data/tables.json rename to scaict_uwu/maintenance/data/tables.json diff --git a/src/scaict_uwu/stats/__init__.py b/scaict_uwu/maintenance/scripts/__init__.py similarity index 100% rename from src/scaict_uwu/stats/__init__.py rename to scaict_uwu/maintenance/scripts/__init__.py diff --git a/src/scaict_uwu/system_message/__init__.py b/scaict_uwu/rdbms/__init__.py similarity index 100% rename from src/scaict_uwu/system_message/__init__.py rename to scaict_uwu/rdbms/__init__.py diff --git a/src/scaict_uwu/user/__init__.py b/scaict_uwu/stats/__init__.py similarity index 100% rename from src/scaict_uwu/user/__init__.py rename to scaict_uwu/stats/__init__.py diff --git a/src/scaict_uwu/user/cog/__init__.py b/scaict_uwu/system_message/__init__.py similarity index 100% rename from src/scaict_uwu/user/cog/__init__.py rename to scaict_uwu/system_message/__init__.py diff --git a/src/scaict_uwu/utils/__init__.py b/scaict_uwu/user/__init__.py similarity index 100% rename from src/scaict_uwu/utils/__init__.py rename to scaict_uwu/user/__init__.py diff --git a/src/scaict_uwu/website/__init__.py b/scaict_uwu/utils/__init__.py similarity index 100% rename from src/scaict_uwu/website/__init__.py rename to scaict_uwu/utils/__init__.py diff --git a/scaict_uwu/website/__init__.py b/scaict_uwu/website/__init__.py new file mode 100644 index 0000000..e69de29 From 41af29652ee96a2ae077aa5c1a9158bc0429adbb Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Wed, 28 Aug 2024 00:09:00 +0000 Subject: [PATCH 005/141] Format "resolve conflict ->force push" using Black --- app.py | 12 +++++++----- test/api.py | 6 +++--- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/app.py b/app.py index 7e496fc..7949aa8 100644 --- a/app.py +++ b/app.py @@ -17,6 +17,7 @@ ) import requests from dotenv import load_dotenv + # Local imports from cog.core.sql import write from cog.core.sql import read @@ -24,8 +25,9 @@ from cog.core.sql import end from cog.core.sql import user_id_exists from cog.api.api import Apis + app = Flask(__name__) -load_dotenv(f"{os.getcwd()}/.env",verbose=True, override=True) +load_dotenv(f"{os.getcwd()}/.env", verbose=True, override=True) app.secret_key = os.getenv("SECRET_KEY") discord_client_id = os.getenv("DISCORD_CLIENT_ID") @@ -43,6 +45,8 @@ send_gift_role = [str(role_id) for role_id in send_gift_role.split(",")] else: send_gift_role_list = [] + + @app.errorhandler(404) def not_found_error(error): return render_template("404.html"), 404 @@ -81,9 +85,7 @@ def listt(): ) # {'avatar': 'https://cdn.discordapp.com/avatars/898141506588770334/a_c81acdd4a925993d053a6fe9ed990c14.png', 'id': '898141506588770334', 'name': 'iach526526'} api_admin_id = api_admin.get("id") headers = {"Authorization": f"Bot {discord_token}"} - url = ( - f"https://discord.com/api/v10/guilds/{guild_ID}/members/{api_admin_id}" - ) + url = f"https://discord.com/api/v10/guilds/{guild_ID}/members/{api_admin_id}" response = requests.get(url, headers=headers, timeout=10) user_data = response.json() if response.status_code != 200: @@ -123,7 +125,7 @@ def send(target_user_id): "error_details": request_admin.get("details"), } ) - admin_roles =request_admin.get("roles", []) + admin_roles = request_admin.get("roles", []) # 確保發起人有權限發送禮物 if set(send_gift_role) & set(admin_roles) == set(): return jsonify( diff --git a/test/api.py b/test/api.py index 3704451..f1de288 100644 --- a/test/api.py +++ b/test/api.py @@ -3,14 +3,14 @@ from dotenv import load_dotenv import json -load_dotenv(f"{os.getcwd()}/.env",verbose=True, override=True) +load_dotenv(f"{os.getcwd()}/.env", verbose=True, override=True) discord_token = os.getenv("DISCORD_TOKEN") guild_ID = os.getenv("GUILD_ID") -uid=input("Enter the user ID: ") +uid = input("Enter the user ID: ") headers = {"Authorization": f"Bot {discord_token}"} url = f"https://discord.com/api/v10/guilds/{guild_ID}/members/{uid}" -response = requests.get(url, headers=headers,timeout=5) +response = requests.get(url, headers=headers, timeout=5) result = response.json() print(json.dumps(result, indent=4)) # type: ignore From 2a3bce4f180f0888891aaede50c945dc766b7ad6 Mon Sep 17 00:00:00 2001 From: Each Chen Date: Wed, 28 Aug 2024 08:11:06 +0800 Subject: [PATCH 006/141] recover api change --- test/api.py | 89 ++++++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 74 insertions(+), 15 deletions(-) diff --git a/test/api.py b/test/api.py index 3704451..94c5cc3 100644 --- a/test/api.py +++ b/test/api.py @@ -1,16 +1,75 @@ -import os import requests -from dotenv import load_dotenv -import json - -load_dotenv(f"{os.getcwd()}/.env",verbose=True, override=True) - -discord_token = os.getenv("DISCORD_TOKEN") -guild_ID = os.getenv("GUILD_ID") -uid=input("Enter the user ID: ") - -headers = {"Authorization": f"Bot {discord_token}"} -url = f"https://discord.com/api/v10/guilds/{guild_ID}/members/{uid}" -response = requests.get(url, headers=headers,timeout=5) -result = response.json() -print(json.dumps(result, indent=4)) # type: ignore +class Apis: + def __init__(self, api_key:str,guild_id:int): + self.api_key = api_key + self.guild_id = guild_id + self.headers = {"Authorization": f"Bot {self.api_key}","Content-Type": "application/json",} + def get_user(self, uid): + """ + API 回傳的資料格式範例,已經把一些敏感資料隱藏掉 + { + "avatar": null, + "banner": null, + "communication_disabled_until": null, + "flags": 0, + "joined_at": "", + "nick": null, + "pending": false, + "premium_since": null, + "roles": [ + "12348763", + "12448763", + "12548763" + ], + "unusual_dm_activity_until": null, + "user": { + "id": "", + "username": "", + "avatar": "", + "discriminator": "0", + "public_flags": 256, + "flags": 256, + "banner": "", + "accent_color": 2054367, + "global_name": "", + "avatar_decoration_data": { + "asset": "a_d3da36040163ee0f9176dfe7ced45cdc", + "sku_id": "1144058522808614923", + "expires_at": null + }, + "banner_color": "#1f58df", + "clan": null + }, + "mute": false, + "deaf": false + } + + """ + try: + url = f"https://discord.com/api/v10/guilds/{self.guild_id}/members/{uid}" + response = requests.get(url, headers=self.headers,timeout=5) + response.raise_for_status() # 檢查 HTTP 狀態碼 + return response.json() + except requests.exceptions.RequestException as e: + # 如果發生錯誤,返回一個包含錯誤訊息和詳細報錯的字典 + return {"error": "get_user error", "details": str(e)} + def create_dm_channel(self, target_user_id: str): + try: + url = "https://discord.com/api/v10/users/@me/channels" + json_data = {"recipient_id": target_user_id} + response = requests.post(url, headers=self.headers, json=json_data, timeout=10) + response.raise_for_status() # Raise an HTTPError for bad responses + dm_channel = response.json() + return dm_channel["id"] + except requests.RequestException as e: + return { + "result": "internal server error", + "status": 500, + "error": str(e), + } + except Exception as e: + return { + "result": "internal server error", + "status": 500, + "error": str(e), + } \ No newline at end of file From e7d2c87a346227b89ee778c3a4866082ced79997 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Wed, 28 Aug 2024 00:12:21 +0000 Subject: [PATCH 007/141] Format "Merge branch" using Black --- test/api.py | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/test/api.py b/test/api.py index 94c5cc3..9546349 100644 --- a/test/api.py +++ b/test/api.py @@ -1,9 +1,15 @@ import requests + + class Apis: - def __init__(self, api_key:str,guild_id:int): + def __init__(self, api_key: str, guild_id: int): self.api_key = api_key self.guild_id = guild_id - self.headers = {"Authorization": f"Bot {self.api_key}","Content-Type": "application/json",} + self.headers = { + "Authorization": f"Bot {self.api_key}", + "Content-Type": "application/json", + } + def get_user(self, uid): """ API 回傳的資料格式範例,已經把一些敏感資料隱藏掉 @@ -43,21 +49,24 @@ def get_user(self, uid): "mute": false, "deaf": false } - + """ try: url = f"https://discord.com/api/v10/guilds/{self.guild_id}/members/{uid}" - response = requests.get(url, headers=self.headers,timeout=5) + response = requests.get(url, headers=self.headers, timeout=5) response.raise_for_status() # 檢查 HTTP 狀態碼 return response.json() except requests.exceptions.RequestException as e: # 如果發生錯誤,返回一個包含錯誤訊息和詳細報錯的字典 return {"error": "get_user error", "details": str(e)} + def create_dm_channel(self, target_user_id: str): try: url = "https://discord.com/api/v10/users/@me/channels" json_data = {"recipient_id": target_user_id} - response = requests.post(url, headers=self.headers, json=json_data, timeout=10) + response = requests.post( + url, headers=self.headers, json=json_data, timeout=10 + ) response.raise_for_status() # Raise an HTTPError for bad responses dm_channel = response.json() return dm_channel["id"] @@ -72,4 +81,4 @@ def create_dm_channel(self, target_user_id: str): "result": "internal server error", "status": 500, "error": str(e), - } \ No newline at end of file + } From 901e7a5538b6be82d4be3cb99f5f0cfbe2c5ac73 Mon Sep 17 00:00:00 2001 From: Each Chen Date: Wed, 28 Aug 2024 09:28:59 +0800 Subject: [PATCH 008/141] chore: Update Discord API endpoint for checking user membership in guild --- .env.example | 8 ++++++-- app.py | 4 +++- test/api.py | 11 +++++++++++ 3 files changed, 20 insertions(+), 3 deletions(-) diff --git a/.env.example b/.env.example index 29f6b12..af1ea94 100644 --- a/.env.example +++ b/.env.example @@ -7,10 +7,14 @@ MYSQL_PORT=資料庫連接埠 MYSQL_DATABASE=資料庫名稱 HOST=資料庫主機位址 -# flask configuration +# gobal configuration DISCORD_TOKEN=Disscord機器人Token -secret_key= 隨機字串,給 flask session 使用 +GUILD_ID=機器人所在伺服器ID + +# flask configuration +secret_key = 隨機字串,給 flask session 使用 DISCORD_CLIENT_SECRET=DISCORD_CLIENT_SECRET,到 Discord Developer Portal 取得 +DISCORD_CLIENT_ID=Disscord client ID DISCORD_REDIRECT_URI=商店網址/callback GITHUB_CLIENT_ID=GitHub Client ID,到 GitHub Developer 取得 GITHUB_CLIENT_SECRET=GitHub Client Secret diff --git a/app.py b/app.py index 7949aa8..be84236 100644 --- a/app.py +++ b/app.py @@ -105,6 +105,7 @@ def listt(): @app.route("/api/send/") +# api/send/{recipient}?gift_type={電電點|抽獎券}count={count} def send(target_user_id): if not session: return jsonify({"resulet": "you must loggin", "status": 403}) @@ -139,7 +140,8 @@ def send(target_user_id): count = int(count) # 確保 count 是整數 except ValueError: return jsonify({"result": "Invalid count value", "status": 400}) - return jsonify({"result": "success", "status": 200}) + # return jsonify({"result": "success", "status": 200}) + usr_in_guild = discord_api.in_guild(target_user_id) # url = f"https://discord.com/api/v10/guilds/{guild_ID}/members/{target_user_id}" # response = requests.get(url, headers=headers, timeout=10) # user_data = discord_api.get_user(target_user_id) diff --git a/test/api.py b/test/api.py index 94c5cc3..602464e 100644 --- a/test/api.py +++ b/test/api.py @@ -53,6 +53,17 @@ def get_user(self, uid): except requests.exceptions.RequestException as e: # 如果發生錯誤,返回一個包含錯誤訊息和詳細報錯的字典 return {"error": "get_user error", "details": str(e)} + def in_guild(self, uid): + # 檢查用戶是否在伺服器中 + try: + url = f"https://discord.com/api/v10/guilds/{self.guild_id}/members/{uid}" + response = requests.get(url, headers=self.headers,timeout=5) + response.raise_for_status() # 檢查 HTTP 狀態碼 + return response.json() + except requests.exceptions.RequestException as e: + # 如果發生錯誤,返回一個包含錯誤訊息和詳細報錯的字典 + return {"error": "in_guild", "details": str(e)} + def create_dm_channel(self, target_user_id: str): try: url = "https://discord.com/api/v10/users/@me/channels" From 291c285b87760d0405ca1c21c81663e06676f4f7 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Wed, 28 Aug 2024 01:30:33 +0000 Subject: [PATCH 009/141] Format "Merge branch development from GitHub action" using Black --- test/api.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/test/api.py b/test/api.py index 217f61e..4dc910b 100644 --- a/test/api.py +++ b/test/api.py @@ -59,11 +59,12 @@ def get_user(self, uid): except requests.exceptions.RequestException as e: # 如果發生錯誤,返回一個包含錯誤訊息和詳細報錯的字典 return {"error": "get_user error", "details": str(e)} + def in_guild(self, uid): # 檢查用戶是否在伺服器中 try: url = f"https://discord.com/api/v10/guilds/{self.guild_id}/members/{uid}" - response = requests.get(url, headers=self.headers,timeout=5) + response = requests.get(url, headers=self.headers, timeout=5) response.raise_for_status() # 檢查 HTTP 狀態碼 return response.json() except requests.exceptions.RequestException as e: From 82b070b9fbfdd4750dd8e8c320c14970309948f7 Mon Sep 17 00:00:00 2001 From: Each Chen Date: Wed, 28 Aug 2024 10:03:07 +0800 Subject: [PATCH 010/141] chore: Update Discord API --- app.py | 61 +++++++++++------------------ cog/api/api.py | 1 - test/api.py | 95 --------------------------------------------- test/api_request.py | 16 ++++++++ 4 files changed, 39 insertions(+), 134 deletions(-) delete mode 100644 test/api.py create mode 100644 test/api_request.py diff --git a/app.py b/app.py index be84236..5548061 100644 --- a/app.py +++ b/app.py @@ -25,6 +25,7 @@ from cog.core.sql import end from cog.core.sql import user_id_exists from cog.api.api import Apis +from cog.api.gift import Gift app = Flask(__name__) load_dotenv(f"{os.getcwd()}/.env", verbose=True, override=True) @@ -118,7 +119,7 @@ def send(target_user_id): discord_api = Apis(discord_token, guild_ID) request_admin = discord_api.get_user(api_admin_id) if "error" in request_admin: - # 如果有錯誤,返回錯誤訊息和詳細信息 + # 如果有錯誤,返回錯誤訊息和詳細報錯 return jsonify( { "result": "Failed to fetch user information in admin id", @@ -140,36 +141,20 @@ def send(target_user_id): count = int(count) # 確保 count 是整數 except ValueError: return jsonify({"result": "Invalid count value", "status": 400}) - # return jsonify({"result": "success", "status": 200}) - usr_in_guild = discord_api.in_guild(target_user_id) - # url = f"https://discord.com/api/v10/guilds/{guild_ID}/members/{target_user_id}" - # response = requests.get(url, headers=headers, timeout=10) - # user_data = discord_api.get_user(target_user_id) - # if response.status_code != 200: - # # 確保 URL 的 target_user_id 在伺服器裡面 - # return ( - # jsonify({"error": "Failed to fetch user information in tg id"}), - # response.status_code, - # ) + # 確保目標用戶存在 + user_data = discord_api.get_user(target_user_id) + if "error" in user_data: + # 如果有錯誤,返回錯誤訊息和詳細信息 + return jsonify( + { + "result": "Failed to fetch user information in target id(whitch is in url path)", + "status": 500, + "error_details": request_admin.get("details"), + } + ) # # 送禮物 - # try: - # url = "https://discord.com/api/v10/users/@me/channels" - # headers = { - # "Authorization": f"Bot {discord_token}", - # "Content-Type": "application/json", - # } - # json_data = {"recipient_id": target_user_id} - # except requests.RequestException as e: - # return jsonify( - # {"result": "interal server error", "status": 500, "error": str(e)} - # ) - # except Exception as e: - # return jsonify( - # {"result": "interal server error", "status": 500, "error": str(e)} - # ) - # response = requests.post(url, headers=headers, json=json_data, timeout=10) - # dm_channel = response.json() - # dm_room = dm_channel["id"] + try: + new_gift = Gift(discord_token, guild_ID) # url = f"https://discord.com/api/v10/channels/{dm_room}/messages" # # 發送按鈕訊息 # headers = { @@ -214,14 +199,14 @@ def send(target_user_id): # query = f"update user set {gift_type}={gift_type}+%s where uid=%s" # cursor.execute(query, (count, target_user_id)) # end(connect, cursor) - # except Exception as e: - # return jsonify( - # { - # "result": "interal server error(SQL) when insert gift", - # "status": 500, - # "error": str(e), - # } - # ) + except Exception as e: + return jsonify( + { + "result": "interal server error(SQL) when insert gift", + "status": 500, + "error": str(e), + } + ) # # 待辦:用戶端那裏也要提示 # response = requests.post(url, headers=headers, json=json_data, timeout=10) # if response.status_code != 200: diff --git a/cog/api/api.py b/cog/api/api.py index 6e67780..f85aab3 100644 --- a/cog/api/api.py +++ b/cog/api/api.py @@ -58,7 +58,6 @@ def get_user(self, uid): except requests.exceptions.RequestException as e: # 如果發生錯誤,返回一個包含錯誤訊息和詳細報錯的字典 return {"error": "get_user error", "details": str(e)} - def create_dm_channel(self, target_user_id: str): try: url = "https://discord.com/api/v10/users/@me/channels" diff --git a/test/api.py b/test/api.py deleted file mode 100644 index 4dc910b..0000000 --- a/test/api.py +++ /dev/null @@ -1,95 +0,0 @@ -import requests - - -class Apis: - def __init__(self, api_key: str, guild_id: int): - self.api_key = api_key - self.guild_id = guild_id - self.headers = { - "Authorization": f"Bot {self.api_key}", - "Content-Type": "application/json", - } - - def get_user(self, uid): - """ - API 回傳的資料格式範例,已經把一些敏感資料隱藏掉 - { - "avatar": null, - "banner": null, - "communication_disabled_until": null, - "flags": 0, - "joined_at": "", - "nick": null, - "pending": false, - "premium_since": null, - "roles": [ - "12348763", - "12448763", - "12548763" - ], - "unusual_dm_activity_until": null, - "user": { - "id": "", - "username": "", - "avatar": "", - "discriminator": "0", - "public_flags": 256, - "flags": 256, - "banner": "", - "accent_color": 2054367, - "global_name": "", - "avatar_decoration_data": { - "asset": "a_d3da36040163ee0f9176dfe7ced45cdc", - "sku_id": "1144058522808614923", - "expires_at": null - }, - "banner_color": "#1f58df", - "clan": null - }, - "mute": false, - "deaf": false - } - - """ - try: - url = f"https://discord.com/api/v10/guilds/{self.guild_id}/members/{uid}" - response = requests.get(url, headers=self.headers, timeout=5) - response.raise_for_status() # 檢查 HTTP 狀態碼 - return response.json() - except requests.exceptions.RequestException as e: - # 如果發生錯誤,返回一個包含錯誤訊息和詳細報錯的字典 - return {"error": "get_user error", "details": str(e)} - - def in_guild(self, uid): - # 檢查用戶是否在伺服器中 - try: - url = f"https://discord.com/api/v10/guilds/{self.guild_id}/members/{uid}" - response = requests.get(url, headers=self.headers, timeout=5) - response.raise_for_status() # 檢查 HTTP 狀態碼 - return response.json() - except requests.exceptions.RequestException as e: - # 如果發生錯誤,返回一個包含錯誤訊息和詳細報錯的字典 - return {"error": "in_guild", "details": str(e)} - - def create_dm_channel(self, target_user_id: str): - try: - url = "https://discord.com/api/v10/users/@me/channels" - json_data = {"recipient_id": target_user_id} - response = requests.post( - url, headers=self.headers, json=json_data, timeout=10 - ) - response.raise_for_status() # Raise an HTTPError for bad responses - dm_channel = response.json() - return dm_channel["id"] - except requests.RequestException as e: - return { - "result": "internal server error", - "status": 500, - "error": str(e), - } - except Exception as e: - return { - "result": "internal server error", - "status": 500, - "error": str(e), - } diff --git a/test/api_request.py b/test/api_request.py new file mode 100644 index 0000000..05643f1 --- /dev/null +++ b/test/api_request.py @@ -0,0 +1,16 @@ +import os +import requests +from dotenv import load_dotenv +import json +load_dotenv(f"{os.getcwd()}/.env", verbose=True, override=True) +guild_id = os.getenv("GUILD_ID") +api_key = os.getenv("DISCORD_TOKEN") +headers = { + "Authorization": f"Bot {api_key}", + "Content-Type": "application/json", + } +url = f"https://discord.com/api/v10/guilds/{guild_id}/members/898141506588770334" +response = requests.get(url, headers=headers,timeout=5) + +formatted_json = json.dumps(response.json(), indent=4) +print(formatted_json) \ No newline at end of file From dc03bf5bdf78efacffefcf810942c0208b9c3e72 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Wed, 28 Aug 2024 02:03:30 +0000 Subject: [PATCH 011/141] Format "chore: Update Discord API" using Black --- app.py | 92 ++++++++++++++++++++++----------------------- cog/api/api.py | 1 + test/api_request.py | 11 +++--- 3 files changed, 53 insertions(+), 51 deletions(-) diff --git a/app.py b/app.py index 5548061..0d4b643 100644 --- a/app.py +++ b/app.py @@ -152,53 +152,53 @@ def send(target_user_id): "error_details": request_admin.get("details"), } ) - # # 送禮物 + # # 送禮物 try: - new_gift = Gift(discord_token, guild_ID) - # url = f"https://discord.com/api/v10/channels/{dm_room}/messages" - # # 發送按鈕訊息 - # headers = { - # "Authorization": f"Bot {discord_token}", - # "Content-Type": "application/json", - # } - # embed = { - # "title": f"你收到了 {count} {gift_type}!", - # "color": 3447003, # (藍色) - # "description": ":gift:", - # } - # button = { - # "type": 1, - # "components": [ - # { - # "type": 2, - # "label": "前往確認", - # "style": 5, # `5` 表示 Link Button - # "url": "https://store.scaict.org", # 要導向的連結 - # } - # ], - # } - # json_data = { - # "embeds": [embed], - # "components": [button], - # "tts": False, # Text-to-speech, 默認為 False - # } - # try: - # response = requests.post(url, headers=headers, json=json_data, timeout=10) - # connect, cursor = link_sql() - # message_id = response.json().get("id") - # print(message_id) - # if not user_id_exists(target_user_id, "user", cursor): - # cursor.execute( - # "INSERT INTO user (uid) VALUE(%s)", (target_user_id,) - # ) # 這裡要調用 api 去抓使用者名稱和 Mail - # cursor.execute( - # "INSERT into gift (btnID,type,count,recipient,received,sender) VALUE(%s,%s,%s,%s,%s,%s)", - # (message_id, gift_type, count, target_user_id, True, api_admin_name), - # ) - # gift_type = "point" if gift_type == "電電點" else "ticket" - # query = f"update user set {gift_type}={gift_type}+%s where uid=%s" - # cursor.execute(query, (count, target_user_id)) - # end(connect, cursor) + new_gift = Gift(discord_token, guild_ID) + # url = f"https://discord.com/api/v10/channels/{dm_room}/messages" + # # 發送按鈕訊息 + # headers = { + # "Authorization": f"Bot {discord_token}", + # "Content-Type": "application/json", + # } + # embed = { + # "title": f"你收到了 {count} {gift_type}!", + # "color": 3447003, # (藍色) + # "description": ":gift:", + # } + # button = { + # "type": 1, + # "components": [ + # { + # "type": 2, + # "label": "前往確認", + # "style": 5, # `5` 表示 Link Button + # "url": "https://store.scaict.org", # 要導向的連結 + # } + # ], + # } + # json_data = { + # "embeds": [embed], + # "components": [button], + # "tts": False, # Text-to-speech, 默認為 False + # } + # try: + # response = requests.post(url, headers=headers, json=json_data, timeout=10) + # connect, cursor = link_sql() + # message_id = response.json().get("id") + # print(message_id) + # if not user_id_exists(target_user_id, "user", cursor): + # cursor.execute( + # "INSERT INTO user (uid) VALUE(%s)", (target_user_id,) + # ) # 這裡要調用 api 去抓使用者名稱和 Mail + # cursor.execute( + # "INSERT into gift (btnID,type,count,recipient,received,sender) VALUE(%s,%s,%s,%s,%s,%s)", + # (message_id, gift_type, count, target_user_id, True, api_admin_name), + # ) + # gift_type = "point" if gift_type == "電電點" else "ticket" + # query = f"update user set {gift_type}={gift_type}+%s where uid=%s" + # cursor.execute(query, (count, target_user_id)) + # end(connect, cursor) except Exception as e: return jsonify( { diff --git a/cog/api/api.py b/cog/api/api.py index f85aab3..6e67780 100644 --- a/cog/api/api.py +++ b/cog/api/api.py @@ -58,6 +58,7 @@ def get_user(self, uid): except requests.exceptions.RequestException as e: # 如果發生錯誤,返回一個包含錯誤訊息和詳細報錯的字典 return {"error": "get_user error", "details": str(e)} + def create_dm_channel(self, target_user_id: str): try: url = "https://discord.com/api/v10/users/@me/channels" diff --git a/test/api_request.py b/test/api_request.py index 05643f1..5a9b220 100644 --- a/test/api_request.py +++ b/test/api_request.py @@ -2,15 +2,16 @@ import requests from dotenv import load_dotenv import json + load_dotenv(f"{os.getcwd()}/.env", verbose=True, override=True) guild_id = os.getenv("GUILD_ID") api_key = os.getenv("DISCORD_TOKEN") headers = { - "Authorization": f"Bot {api_key}", - "Content-Type": "application/json", - } + "Authorization": f"Bot {api_key}", + "Content-Type": "application/json", +} url = f"https://discord.com/api/v10/guilds/{guild_id}/members/898141506588770334" -response = requests.get(url, headers=headers,timeout=5) +response = requests.get(url, headers=headers, timeout=5) formatted_json = json.dumps(response.json(), indent=4) -print(formatted_json) \ No newline at end of file +print(formatted_json) From ea5161b8965a9e1e9c4544a242be7d48d8a0c284 Mon Sep 17 00:00:00 2001 From: Each Chen Date: Wed, 28 Aug 2024 15:00:38 +0800 Subject: [PATCH 012/141] feat: Add new Gift class for sending gifts via Discord API --- app.py | 6 +++++- cog/api/gift.py | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+), 1 deletion(-) create mode 100644 cog/api/gift.py diff --git a/app.py b/app.py index 5548061..f76002f 100644 --- a/app.py +++ b/app.py @@ -154,7 +154,10 @@ def send(target_user_id): ) # # 送禮物 try: - new_gift = Gift(discord_token, guild_ID) + new_gift = Gift(discord_token, guild_ID,target_user_id) # create a new gift object + if new_gift.dm_room is None: + return jsonify({"result": "Failed to create DM channel", "status": 500, "error": new_gift.error_msg}) + return jsonify({"result": "success", "status": 200}) # url = f"https://discord.com/api/v10/channels/{dm_room}/messages" # # 發送按鈕訊息 # headers = { @@ -199,6 +202,7 @@ def send(target_user_id): # query = f"update user set {gift_type}={gift_type}+%s where uid=%s" # cursor.execute(query, (count, target_user_id)) # end(connect, cursor) + except Exception as e: return jsonify( { diff --git a/cog/api/gift.py b/cog/api/gift.py new file mode 100644 index 0000000..935570b --- /dev/null +++ b/cog/api/gift.py @@ -0,0 +1,36 @@ +import requests + +class Gift: + def __init__(self, api_key: str, guild_id: int,recipient_id:int): + self.api_key = api_key + self.guild_id = guild_id + self.error_msg = None + self.headers = { + "Authorization": f"Bot {self.api_key}", + "Content-Type": "application/json", + } + try: + fetch_usr = self.__new_dm(recipient_id)["id"] + if "id" in fetch_usr: + self.dm_room = fetch_usr["id"] + else: + self.dm_room = None + except Exception as e: + self.dm_room = None + self.error_msg = str(e) + print(self.dm_room) + def __new_dm(self, uid: int)->dict: + try: + url = f"https://discord.com/api/v10/users/@me/channels" + payload = { + "recipient_id": uid + } + #{'id': '', 'type': 1, 'last_message_id': '1276230139230814241', 'flags': 0, 'recipients': [{'id': '', 'username': '', 'avatar': '', 'discriminator': '0', 'public_flags': 256, 'flags': 256, 'banner': '', 'accent_color': 2054367, 'global_name': '', 'avatar_decoration_data': {'asset': '', 'sku_id': '1144058522808614923', 'expires_at': None}, 'banner_color': '#1f58df', 'clan': None}]} + response = requests.post(url, headers=self.headers, json=payload, timeout=5) + response.raise_for_status() + return response.json() + except requests.RequestException as e: + return {"result": "interal server error", "status": 500, "error": str(e)} + except Exception as e: + return {"result": "interal server error", "status": 500, "error": str(e)} + \ No newline at end of file From cafaa82c3642370b50c30f8ddeb7945a63b90195 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Wed, 28 Aug 2024 07:01:40 +0000 Subject: [PATCH 013/141] Format "Merge branch into development" using Black --- app.py | 102 ++++++++++++++++++++++++++---------------------- cog/api/gift.py | 13 +++--- 2 files changed, 61 insertions(+), 54 deletions(-) diff --git a/app.py b/app.py index 10d3f51..19b3eb1 100644 --- a/app.py +++ b/app.py @@ -154,55 +154,63 @@ def send(target_user_id): ) # # 送禮物 try: - new_gift = Gift(discord_token, guild_ID,target_user_id) # create a new gift object + new_gift = Gift( + discord_token, guild_ID, target_user_id + ) # create a new gift object if new_gift.dm_room is None: - return jsonify({"result": "Failed to create DM channel", "status": 500, "error": new_gift.error_msg}) + return jsonify( + { + "result": "Failed to create DM channel", + "status": 500, + "error": new_gift.error_msg, + } + ) return jsonify({"result": "success", "status": 200}) - # url = f"https://discord.com/api/v10/channels/{dm_room}/messages" - # # 發送按鈕訊息 - # headers = { - # "Authorization": f"Bot {discord_token}", - # "Content-Type": "application/json", - # } - # embed = { - # "title": f"你收到了 {count} {gift_type}!", - # "color": 3447003, # (藍色) - # "description": ":gift:", - # } - # button = { - # "type": 1, - # "components": [ - # { - # "type": 2, - # "label": "前往確認", - # "style": 5, # `5` 表示 Link Button - # "url": "https://store.scaict.org", # 要導向的連結 - # } - # ], - # } - # json_data = { - # "embeds": [embed], - # "components": [button], - # "tts": False, # Text-to-speech, 默認為 False - # } - # try: - # response = requests.post(url, headers=headers, json=json_data, timeout=10) - # connect, cursor = link_sql() - # message_id = response.json().get("id") - # print(message_id) - # if not user_id_exists(target_user_id, "user", cursor): - # cursor.execute( - # "INSERT INTO user (uid) VALUE(%s)", (target_user_id,) - # ) # 這裡要調用 api 去抓使用者名稱和 Mail - # cursor.execute( - # "INSERT into gift (btnID,type,count,recipient,received,sender) VALUE(%s,%s,%s,%s,%s,%s)", - # (message_id, gift_type, count, target_user_id, True, api_admin_name), - # ) - # gift_type = "point" if gift_type == "電電點" else "ticket" - # query = f"update user set {gift_type}={gift_type}+%s where uid=%s" - # cursor.execute(query, (count, target_user_id)) - # end(connect, cursor) - + # url = f"https://discord.com/api/v10/channels/{dm_room}/messages" + # # 發送按鈕訊息 + # headers = { + # "Authorization": f"Bot {discord_token}", + # "Content-Type": "application/json", + # } + # embed = { + # "title": f"你收到了 {count} {gift_type}!", + # "color": 3447003, # (藍色) + # "description": ":gift:", + # } + # button = { + # "type": 1, + # "components": [ + # { + # "type": 2, + # "label": "前往確認", + # "style": 5, # `5` 表示 Link Button + # "url": "https://store.scaict.org", # 要導向的連結 + # } + # ], + # } + # json_data = { + # "embeds": [embed], + # "components": [button], + # "tts": False, # Text-to-speech, 默認為 False + # } + # try: + # response = requests.post(url, headers=headers, json=json_data, timeout=10) + # connect, cursor = link_sql() + # message_id = response.json().get("id") + # print(message_id) + # if not user_id_exists(target_user_id, "user", cursor): + # cursor.execute( + # "INSERT INTO user (uid) VALUE(%s)", (target_user_id,) + # ) # 這裡要調用 api 去抓使用者名稱和 Mail + # cursor.execute( + # "INSERT into gift (btnID,type,count,recipient,received,sender) VALUE(%s,%s,%s,%s,%s,%s)", + # (message_id, gift_type, count, target_user_id, True, api_admin_name), + # ) + # gift_type = "point" if gift_type == "電電點" else "ticket" + # query = f"update user set {gift_type}={gift_type}+%s where uid=%s" + # cursor.execute(query, (count, target_user_id)) + # end(connect, cursor) + except Exception as e: return jsonify( { diff --git a/cog/api/gift.py b/cog/api/gift.py index 935570b..a682875 100644 --- a/cog/api/gift.py +++ b/cog/api/gift.py @@ -1,7 +1,8 @@ import requests + class Gift: - def __init__(self, api_key: str, guild_id: int,recipient_id:int): + def __init__(self, api_key: str, guild_id: int, recipient_id: int): self.api_key = api_key self.guild_id = guild_id self.error_msg = None @@ -19,13 +20,12 @@ def __init__(self, api_key: str, guild_id: int,recipient_id:int): self.dm_room = None self.error_msg = str(e) print(self.dm_room) - def __new_dm(self, uid: int)->dict: + + def __new_dm(self, uid: int) -> dict: try: url = f"https://discord.com/api/v10/users/@me/channels" - payload = { - "recipient_id": uid - } - #{'id': '', 'type': 1, 'last_message_id': '1276230139230814241', 'flags': 0, 'recipients': [{'id': '', 'username': '', 'avatar': '', 'discriminator': '0', 'public_flags': 256, 'flags': 256, 'banner': '', 'accent_color': 2054367, 'global_name': '', 'avatar_decoration_data': {'asset': '', 'sku_id': '1144058522808614923', 'expires_at': None}, 'banner_color': '#1f58df', 'clan': None}]} + payload = {"recipient_id": uid} + # {'id': '', 'type': 1, 'last_message_id': '1276230139230814241', 'flags': 0, 'recipients': [{'id': '', 'username': '', 'avatar': '', 'discriminator': '0', 'public_flags': 256, 'flags': 256, 'banner': '', 'accent_color': 2054367, 'global_name': '', 'avatar_decoration_data': {'asset': '', 'sku_id': '1144058522808614923', 'expires_at': None}, 'banner_color': '#1f58df', 'clan': None}]} response = requests.post(url, headers=self.headers, json=payload, timeout=5) response.raise_for_status() return response.json() @@ -33,4 +33,3 @@ def __new_dm(self, uid: int)->dict: return {"result": "interal server error", "status": 500, "error": str(e)} except Exception as e: return {"result": "interal server error", "status": 500, "error": str(e)} - \ No newline at end of file From 5a23a76160a946c431dd16bebac4853924c0c309 Mon Sep 17 00:00:00 2001 From: Each Chen Date: Wed, 28 Aug 2024 18:07:01 +0800 Subject: [PATCH 014/141] feat: Add gift_type and gift_amount parameters to send() function(not test yet) --- app.py | 66 +++++++++++++--------------------------------- cog/api/gift.py | 30 +++++++++++++++++++-- test/enumstruct.py | 11 ++++++++ 3 files changed, 57 insertions(+), 50 deletions(-) create mode 100644 test/enumstruct.py diff --git a/app.py b/app.py index 19b3eb1..768e4a4 100644 --- a/app.py +++ b/app.py @@ -118,6 +118,8 @@ def send(target_user_id): api_admin_name = api_admin.get("name") discord_api = Apis(discord_token, guild_ID) request_admin = discord_api.get_user(api_admin_id) + gift_type = request.args.get("gift_type", "電電點") # 預設為"電電點" + gift_amount = request.args.get("count", 1) # 預設數量為1 if "error" in request_admin: # 如果有錯誤,返回錯誤訊息和詳細報錯 return jsonify( @@ -133,12 +135,10 @@ def send(target_user_id): return jsonify( {"result": "You do not have permission to use this", "status": 403} ) - gift_type = request.args.get("gift_type", "電電點") # 預設為"電電點" if gift_type not in ["電電點", "抽獎券"]: return jsonify({"result": "Invalid gift type", "status": 400}) - count = request.args.get("count", 1) # 預設數量為1 try: - count = int(count) # 確保 count 是整數 + gift_amount = int(gift_amount) # 確保 count 是整數 except ValueError: return jsonify({"result": "Invalid count value", "status": 400}) # 確保目標用戶存在 @@ -165,51 +165,20 @@ def send(target_user_id): "error": new_gift.error_msg, } ) - return jsonify({"result": "success", "status": 200}) - # url = f"https://discord.com/api/v10/channels/{dm_room}/messages" - # # 發送按鈕訊息 - # headers = { - # "Authorization": f"Bot {discord_token}", - # "Content-Type": "application/json", - # } - # embed = { - # "title": f"你收到了 {count} {gift_type}!", - # "color": 3447003, # (藍色) - # "description": ":gift:", - # } - # button = { - # "type": 1, - # "components": [ - # { - # "type": 2, - # "label": "前往確認", - # "style": 5, # `5` 表示 Link Button - # "url": "https://store.scaict.org", # 要導向的連結 - # } - # ], - # } - # json_data = { - # "embeds": [embed], - # "components": [button], - # "tts": False, # Text-to-speech, 默認為 False - # } - # try: - # response = requests.post(url, headers=headers, json=json_data, timeout=10) - # connect, cursor = link_sql() - # message_id = response.json().get("id") - # print(message_id) - # if not user_id_exists(target_user_id, "user", cursor): - # cursor.execute( - # "INSERT INTO user (uid) VALUE(%s)", (target_user_id,) - # ) # 這裡要調用 api 去抓使用者名稱和 Mail - # cursor.execute( - # "INSERT into gift (btnID,type,count,recipient,received,sender) VALUE(%s,%s,%s,%s,%s,%s)", - # (message_id, gift_type, count, target_user_id, True, api_admin_name), - # ) - # gift_type = "point" if gift_type == "電電點" else "ticket" - # query = f"update user set {gift_type}={gift_type}+%s where uid=%s" - # cursor.execute(query, (count, target_user_id)) - # end(connect, cursor) + message_id = new_gift.send_gift(gift_type, gift_amount) + connect, cursor = link_sql() + if not user_id_exists(target_user_id, "user", cursor): + cursor.execute( + "INSERT INTO user (uid) VALUE(%s)", (target_user_id,) + ) # 這裡要調用 api 去抓使用者名稱和 Mail + cursor.execute( + "INSERT into gift (btnID,type,count,recipient,received,sender) VALUE(%s,%s,%s,%s,%s,%s)", + (message_id, gift_type, gift_amount, target_user_id, True, api_admin_name), + ) + gift_type = "point" if gift_type == "電電點" else "ticket" + query = f"update user set {gift_type}={gift_type}+%s where uid=%s" + cursor.execute(query, (gift_amount, target_user_id)) + end(connect, cursor) except Exception as e: return jsonify( @@ -219,6 +188,7 @@ def send(target_user_id): "error": str(e), } ) + return jsonify({"result": "success", "status": 200}) # # 待辦:用戶端那裏也要提示 # response = requests.post(url, headers=headers, json=json_data, timeout=10) # if response.status_code != 200: diff --git a/cog/api/gift.py b/cog/api/gift.py index a682875..032e67e 100644 --- a/cog/api/gift.py +++ b/cog/api/gift.py @@ -1,6 +1,5 @@ import requests - class Gift: def __init__(self, api_key: str, guild_id: int, recipient_id: int): self.api_key = api_key @@ -19,7 +18,6 @@ def __init__(self, api_key: str, guild_id: int, recipient_id: int): except Exception as e: self.dm_room = None self.error_msg = str(e) - print(self.dm_room) def __new_dm(self, uid: int) -> dict: try: @@ -33,3 +31,31 @@ def __new_dm(self, uid: int) -> dict: return {"result": "interal server error", "status": 500, "error": str(e)} except Exception as e: return {"result": "interal server error", "status": 500, "error": str(e)} + def _gen_msg(self, gift_type: str, gift_amount: int) -> str: + embed = { + "title": f"你收到了 {gift_amount} {gift_type}!", + "color": 3447003, # (藍色) + "description": ":gift:", + } + button = { + "type": 1, + "components": [ + { + "type": 2, + "label": "前往確認", + "style": 5, # `5` 表示 Link Button + "url": "https://store.scaict.org", # 要導向的連結 + } + ], + } + json_data = { + "embeds": [embed], + "components": [button], + "tts": False, # Text-to-speech, 默認為 False + } + return json_data + def send_gift(self, gift_type: str, gift_amount: int) -> str: + url = f"https://discord.com/api/v10/channels/{self.dm_room}/messages" + payload = self._gen_msg(gift_type, gift_amount) + response = requests.post(url, headers=self.headers, json=payload, timeout=5) + return response.json().get("id") \ No newline at end of file diff --git a/test/enumstruct.py b/test/enumstruct.py new file mode 100644 index 0000000..3291cbd --- /dev/null +++ b/test/enumstruct.py @@ -0,0 +1,11 @@ +# enume 測試 +from enum import Enum + +class GiftType(Enum): + point="電電點" + ticket="抽獎券" +for gt in GiftType:#eqaul to print(GiftType.{item}.name) + print(gt) +print(GiftType.point.name) + +print(GiftType.point.value) From f981ff34dd09e879d6687193b7558af615494694 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Wed, 28 Aug 2024 10:07:23 +0000 Subject: [PATCH 015/141] Format "feat: Add gift_type and gift_amount parameters to send() function(not test yet)" using Black --- app.py | 9 ++++++++- cog/api/gift.py | 29 ++++++++++++++++------------- test/enumstruct.py | 9 ++++++--- 3 files changed, 30 insertions(+), 17 deletions(-) diff --git a/app.py b/app.py index 768e4a4..a5aef2d 100644 --- a/app.py +++ b/app.py @@ -173,7 +173,14 @@ def send(target_user_id): ) # 這裡要調用 api 去抓使用者名稱和 Mail cursor.execute( "INSERT into gift (btnID,type,count,recipient,received,sender) VALUE(%s,%s,%s,%s,%s,%s)", - (message_id, gift_type, gift_amount, target_user_id, True, api_admin_name), + ( + message_id, + gift_type, + gift_amount, + target_user_id, + True, + api_admin_name, + ), ) gift_type = "point" if gift_type == "電電點" else "ticket" query = f"update user set {gift_type}={gift_type}+%s where uid=%s" diff --git a/cog/api/gift.py b/cog/api/gift.py index 032e67e..5998d2c 100644 --- a/cog/api/gift.py +++ b/cog/api/gift.py @@ -1,5 +1,6 @@ import requests + class Gift: def __init__(self, api_key: str, guild_id: int, recipient_id: int): self.api_key = api_key @@ -31,6 +32,7 @@ def __new_dm(self, uid: int) -> dict: return {"result": "interal server error", "status": 500, "error": str(e)} except Exception as e: return {"result": "interal server error", "status": 500, "error": str(e)} + def _gen_msg(self, gift_type: str, gift_amount: int) -> str: embed = { "title": f"你收到了 {gift_amount} {gift_type}!", @@ -38,24 +40,25 @@ def _gen_msg(self, gift_type: str, gift_amount: int) -> str: "description": ":gift:", } button = { - "type": 1, - "components": [ - { - "type": 2, - "label": "前往確認", - "style": 5, # `5` 表示 Link Button - "url": "https://store.scaict.org", # 要導向的連結 - } - ], + "type": 1, + "components": [ + { + "type": 2, + "label": "前往確認", + "style": 5, # `5` 表示 Link Button + "url": "https://store.scaict.org", # 要導向的連結 + } + ], } json_data = { - "embeds": [embed], - "components": [button], - "tts": False, # Text-to-speech, 默認為 False + "embeds": [embed], + "components": [button], + "tts": False, # Text-to-speech, 默認為 False } return json_data + def send_gift(self, gift_type: str, gift_amount: int) -> str: url = f"https://discord.com/api/v10/channels/{self.dm_room}/messages" payload = self._gen_msg(gift_type, gift_amount) response = requests.post(url, headers=self.headers, json=payload, timeout=5) - return response.json().get("id") \ No newline at end of file + return response.json().get("id") diff --git a/test/enumstruct.py b/test/enumstruct.py index 3291cbd..13be478 100644 --- a/test/enumstruct.py +++ b/test/enumstruct.py @@ -1,10 +1,13 @@ # enume 測試 from enum import Enum + class GiftType(Enum): - point="電電點" - ticket="抽獎券" -for gt in GiftType:#eqaul to print(GiftType.{item}.name) + point = "電電點" + ticket = "抽獎券" + + +for gt in GiftType: # eqaul to print(GiftType.{item}.name) print(gt) print(GiftType.point.name) From 9522153766b6e580b01cfe1b2a889de7947b549d Mon Sep 17 00:00:00 2001 From: Winston Sung Date: Wed, 28 Aug 2024 21:16:02 +0800 Subject: [PATCH 016/141] Add Merge CI Change-Id: I8926fc26ee263ce9446adccae7cf191330f9f593 --- .github/workflows/merge.yml | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 .github/workflows/merge.yml diff --git a/.github/workflows/merge.yml b/.github/workflows/merge.yml new file mode 100644 index 0000000..78f908d --- /dev/null +++ b/.github/workflows/merge.yml @@ -0,0 +1,37 @@ +name: Merge + +on: + pull_request_review: + types: [ submitted ] + +jobs: + merge: + permissions: + contents: write + pull-requests: write + if: # github.event.review.state == 'approved' && + ( + github.event.review.author_association == 'OWNER' || + github.event.review.author_association == 'MEMBER' || + github.event.review.author_association == 'COLLABORATOR' + ) + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + with: + fetch-depth: 0 + - name: Set Git config + run: | + git config --local user.name "github-actions[bot]" + git config --local user.email "41898282+github-actions[bot]@users.noreply.github.com" + - name: Rebase to target branch when needed in order to fast-forward merge + run: | + git fetch origin ${{ github.event.pull_request.base.ref }} + git rebase origin/${{ github.event.pull_request.base.ref }} + - name: Push back source branch (head) + run: | + git push "${{ github.event.pull_request.head.repo.clone_url }}" HEAD:${{ github.event.pull_request.head.ref }} --force + - name: Push to target branch (base) + run: | + # git push "${{ github.event.pull_request.base.repo.clone_url }}" ${{ github.event.pull_request.base.ref }} + git push origin HEAD:${{ github.event.pull_request.base.ref }} From 4faede023379bae35aaa7653a366c0548171d024 Mon Sep 17 00:00:00 2001 From: Winston Sung Date: Wed, 28 Aug 2024 21:51:49 +0800 Subject: [PATCH 017/141] Fix Black CI Change-Id: I4bcd6e7c3f13ae8a4211e275dc1723346161d913 --- .github/workflows/black.yml | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/.github/workflows/black.yml b/.github/workflows/black.yml index c658319..c961a4a 100644 --- a/.github/workflows/black.yml +++ b/.github/workflows/black.yml @@ -13,7 +13,12 @@ jobs: matrix: python-version: [ "3.11" ] steps: - - uses: actions/checkout@v4 + - if: github.event_name != 'pull_request' + uses: actions/checkout@v4 + - if: github.event_name == 'pull_request' && github.event.pull_request.head.repo.fork == true + uses: actions/checkout@v4 + with: + ref: ${{ github.event.pull_request.head.ref }} - name: Set up Python ${{ matrix.python-version }} uses: actions/setup-python@v5 with: @@ -26,10 +31,16 @@ jobs: - name: Formatting the code with Black run: | black $(git ls-files '*.py') - - name: Add, commit and push + - name: Git config run: | git config --local user.name "github-actions[bot]" git config --local user.email "41898282+github-actions[bot]@users.noreply.github.com" + - name: Git add + run: | git add * + - name: Git commit + run: | git diff-index --quiet HEAD || git commit -m "Format \"$(git show -s --format=%s)\" using Black" + - name: Git push + run: | git push From 1eca02534fca6536416a889a07fcb205aaec9830 Mon Sep 17 00:00:00 2001 From: Winston Sung Date: Wed, 28 Aug 2024 22:07:05 +0800 Subject: [PATCH 018/141] Fix lint issues Change-Id: Ib6dad0232b13b1e88ce3519f10b63e29aac2e905 --- cog/api/gift.py | 2 +- test/api_request.py | 7 +++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/cog/api/gift.py b/cog/api/gift.py index 5998d2c..1629626 100644 --- a/cog/api/gift.py +++ b/cog/api/gift.py @@ -22,7 +22,7 @@ def __init__(self, api_key: str, guild_id: int, recipient_id: int): def __new_dm(self, uid: int) -> dict: try: - url = f"https://discord.com/api/v10/users/@me/channels" + url = "https://discord.com/api/v10/users/@me/channels" payload = {"recipient_id": uid} # {'id': '', 'type': 1, 'last_message_id': '1276230139230814241', 'flags': 0, 'recipients': [{'id': '', 'username': '', 'avatar': '', 'discriminator': '0', 'public_flags': 256, 'flags': 256, 'banner': '', 'accent_color': 2054367, 'global_name': '', 'avatar_decoration_data': {'asset': '', 'sku_id': '1144058522808614923', 'expires_at': None}, 'banner_color': '#1f58df', 'clan': None}]} response = requests.post(url, headers=self.headers, json=payload, timeout=5) diff --git a/test/api_request.py b/test/api_request.py index 5a9b220..d330a92 100644 --- a/test/api_request.py +++ b/test/api_request.py @@ -1,7 +1,10 @@ +# Standard imports +import json import os -import requests + +# Third-party imports from dotenv import load_dotenv -import json +import requests load_dotenv(f"{os.getcwd()}/.env", verbose=True, override=True) guild_id = os.getenv("GUILD_ID") From ecff2207ca05a858e3fe4fafc115697ea8c3f35d Mon Sep 17 00:00:00 2001 From: Winston Sung Date: Wed, 28 Aug 2024 21:44:37 +0800 Subject: [PATCH 019/141] Introduce maintenance scripts Bug: #51 Change-Id: If695821600dfeccc9f9e91548a5b6237a323812c --- scaict_uwu/bot_pycord.py | 5 ++ scaict_uwu/maintenance.py | 5 ++ scaict_uwu/maintenance/maintenance.py | 77 ++++++++++++++++++++++++ scaict_uwu/maintenance/parameters.py | 56 +++++++++++++++++ scaict_uwu/maintenance/scripts/update.py | 21 +++++++ scaict_uwu/website_flask.py | 5 ++ 6 files changed, 169 insertions(+) create mode 100644 scaict_uwu/bot_pycord.py create mode 100644 scaict_uwu/maintenance.py create mode 100644 scaict_uwu/maintenance/maintenance.py create mode 100644 scaict_uwu/maintenance/parameters.py create mode 100644 scaict_uwu/maintenance/scripts/update.py create mode 100644 scaict_uwu/website_flask.py diff --git a/scaict_uwu/bot_pycord.py b/scaict_uwu/bot_pycord.py new file mode 100644 index 0000000..da0bf6c --- /dev/null +++ b/scaict_uwu/bot_pycord.py @@ -0,0 +1,5 @@ +""" +Entry point for Discord bot using Pycord. + +TODO: Complete this +""" diff --git a/scaict_uwu/maintenance.py b/scaict_uwu/maintenance.py new file mode 100644 index 0000000..c61880f --- /dev/null +++ b/scaict_uwu/maintenance.py @@ -0,0 +1,5 @@ +""" +Entry point for all maintenance scripts. + +TODO: Complete this +""" diff --git a/scaict_uwu/maintenance/maintenance.py b/scaict_uwu/maintenance/maintenance.py new file mode 100644 index 0000000..35b64c5 --- /dev/null +++ b/scaict_uwu/maintenance/maintenance.py @@ -0,0 +1,77 @@ +""" +This is the module for the abstract class for all maintenance scripts. +""" + +# Local imports +from scaict_uwu.maintenance.parameters import MaintenanceParameters + + +class Maintenance: + """ + Abstract class for all maintenance scripts. + """ + + _parameters: MaintenanceParameters + """ + _parameters (MaintenanceParameters) + """ + + def __init__(self) -> None: + """ + Default constructor. Child classes should call this *first* if + implementing their own constructors. + """ + self._parameters = MaintenanceParameters() + self.add_default_params() + + def add_description(self, description: str) -> None: + """ + Set description for maintenance scription. + + Parameters: + description (str): The description to set. + """ + self.get_parameters().set_description(description) + + def get_parameters(self) -> MaintenanceParameters: + """ + Returns: + MaintenanceParameters + """ + return self._parameters + + def add_default_params(self) -> None: + """ + TODO + """ + + def can_execute_without_config(self) -> bool: + """ + Whether this script can run without config. + + Scripts that need to be able to run before installed should override\ + this to return true. + + Scripts that return true from this method will fail with a fatal error + if attempt to access the database. + + Subclasses that override this method to return true should also\ + override get_db_type() to return self::DB_NONE. + """ + return False + + def execute(self) -> bool: + """ + Do the actual work. All child classes will need to implement this. + + Returns: + bool: True for success, false for failure. + Returning false for failure will cause\ + do_maintenance.py to exit the process with a non-zero exit\ + status. + + Raises: + NotImplementedError: The method must be implemented in subclass. + """ + # Abstract + raise NotImplementedError diff --git a/scaict_uwu/maintenance/parameters.py b/scaict_uwu/maintenance/parameters.py new file mode 100644 index 0000000..82993f0 --- /dev/null +++ b/scaict_uwu/maintenance/parameters.py @@ -0,0 +1,56 @@ +""" +Module parameters for class MaintenanceParameters. +""" + + +class MaintenanceParameters: + """ + Command line parameter handler for maintenance scripts. + """ + + __description: str + """ + __description (str): Short description of what the script does. + """ + + def has_description(self) -> bool: + """ + Check whether the script has description. + + Returns: + bool + """ + return self.__description != "" + + def get_description(self) -> str: + """ + Get the short description of what the script does. + + Returns: + str: The short description + """ + return self.__description + + def set_description(self, text: str) -> None: + """ + Set a short description of what the script does. + + Parameters: + text (str) + """ + self.__description = text + + def get_help(self) -> str: + """ + Get help text. + + Returns: + str + """ + output: list = [] + + # Description + if self.has_description(): + output.append("") + + return "".join(output) diff --git a/scaict_uwu/maintenance/scripts/update.py b/scaict_uwu/maintenance/scripts/update.py new file mode 100644 index 0000000..42696d0 --- /dev/null +++ b/scaict_uwu/maintenance/scripts/update.py @@ -0,0 +1,21 @@ +""" +Run all updaters. + +This is used when the database schema is modified and we need to apply patches. +""" + +# Local imports +from scaict_uwu.maintenance.maintenance import Maintenance + + +class UpdateMaintenance(Maintenance): + """ + Maintenance script to run database schema updates. + """ + + def __init__(self) -> None: + super().__init__() + self.add_description("Database updater.") + + def execute(self) -> bool: + return True diff --git a/scaict_uwu/website_flask.py b/scaict_uwu/website_flask.py new file mode 100644 index 0000000..0001c01 --- /dev/null +++ b/scaict_uwu/website_flask.py @@ -0,0 +1,5 @@ +""" +Entry point for the SCAICT shop website using Flask run. + +TODO: Complete this +""" From 64f30148e7696c9fac49d3580b3dd7e59b8eb348 Mon Sep 17 00:00:00 2001 From: Winston Sung Date: Wed, 28 Aug 2024 22:22:51 +0800 Subject: [PATCH 020/141] Packaging: Move to src/ Change-Id: Id9cd8d4ce8fc949c51679b38f158f1bfc740a8f0 --- .github/workflows/black.yml | 1 + .github/workflows/pylint.yml | 1 + {scaict_uwu => src/scaict_uwu}/__init__.py | 0 {scaict_uwu => src/scaict_uwu}/bot/__init__.py | 0 {scaict_uwu => src/scaict_uwu}/bot/channels/__init__.py | 0 {scaict_uwu => src/scaict_uwu}/bot/cog/__init__.py | 0 {scaict_uwu => src/scaict_uwu}/bot/emoji/__init__.py | 0 {scaict_uwu => src/scaict_uwu}/bot/users/__init__.py | 0 {scaict_uwu => src/scaict_uwu}/bot_pycord.py | 0 {scaict_uwu => src/scaict_uwu}/config/__init__.py | 0 {scaict_uwu => src/scaict_uwu}/config/config.py | 0 {scaict_uwu => src/scaict_uwu}/config/config_factory.py | 0 {scaict_uwu => src/scaict_uwu}/i18n/course/zh-hant.json | 0 {scaict_uwu => src/scaict_uwu}/i18n/ctf/zh-hant.json | 0 {scaict_uwu => src/scaict_uwu}/i18n/daily_charge/zh-hant.json | 0 {scaict_uwu => src/scaict_uwu}/i18n/game_counting/zh-hant.json | 0 .../scaict_uwu}/i18n/game_nice_color/zh-hant.json | 0 {scaict_uwu => src/scaict_uwu}/i18n/game_rps/zh-hant.json | 0 .../scaict_uwu}/i18n/support_ticket/zh-hant.json | 0 {scaict_uwu => src/scaict_uwu}/i18n/version_info/zh-hant.json | 0 {scaict_uwu => src/scaict_uwu}/i18n/zh-hant.json | 0 {scaict_uwu => src/scaict_uwu}/installer/__init__.py | 0 {scaict_uwu => src/scaict_uwu}/installer/cog/__init__.py | 0 {scaict_uwu => src/scaict_uwu}/logging/__init__.py | 0 {scaict_uwu => src/scaict_uwu}/maintenance.py | 0 {scaict_uwu => src/scaict_uwu}/maintenance/__init__.py | 0 {scaict_uwu => src/scaict_uwu}/maintenance/data/tables.json | 0 {scaict_uwu => src/scaict_uwu}/maintenance/maintenance.py | 3 ++- {scaict_uwu => src/scaict_uwu}/maintenance/parameters.py | 0 {scaict_uwu => src/scaict_uwu}/maintenance/scripts/__init__.py | 0 {scaict_uwu => src/scaict_uwu}/maintenance/scripts/update.py | 3 ++- {scaict_uwu => src/scaict_uwu}/rdbms/__init__.py | 0 {scaict_uwu => src/scaict_uwu}/stats/__init__.py | 0 {scaict_uwu => src/scaict_uwu}/system_message/__init__.py | 0 {scaict_uwu => src/scaict_uwu}/user/__init__.py | 0 {scaict_uwu => src/scaict_uwu}/utils/__init__.py | 0 {scaict_uwu => src/scaict_uwu}/website/__init__.py | 0 {scaict_uwu => src/scaict_uwu}/website_flask.py | 0 38 files changed, 6 insertions(+), 2 deletions(-) rename {scaict_uwu => src/scaict_uwu}/__init__.py (100%) rename {scaict_uwu => src/scaict_uwu}/bot/__init__.py (100%) rename {scaict_uwu => src/scaict_uwu}/bot/channels/__init__.py (100%) rename {scaict_uwu => src/scaict_uwu}/bot/cog/__init__.py (100%) rename {scaict_uwu => src/scaict_uwu}/bot/emoji/__init__.py (100%) rename {scaict_uwu => src/scaict_uwu}/bot/users/__init__.py (100%) rename {scaict_uwu => src/scaict_uwu}/bot_pycord.py (100%) rename {scaict_uwu => src/scaict_uwu}/config/__init__.py (100%) rename {scaict_uwu => src/scaict_uwu}/config/config.py (100%) rename {scaict_uwu => src/scaict_uwu}/config/config_factory.py (100%) rename {scaict_uwu => src/scaict_uwu}/i18n/course/zh-hant.json (100%) rename {scaict_uwu => src/scaict_uwu}/i18n/ctf/zh-hant.json (100%) rename {scaict_uwu => src/scaict_uwu}/i18n/daily_charge/zh-hant.json (100%) rename {scaict_uwu => src/scaict_uwu}/i18n/game_counting/zh-hant.json (100%) rename {scaict_uwu => src/scaict_uwu}/i18n/game_nice_color/zh-hant.json (100%) rename {scaict_uwu => src/scaict_uwu}/i18n/game_rps/zh-hant.json (100%) rename {scaict_uwu => src/scaict_uwu}/i18n/support_ticket/zh-hant.json (100%) rename {scaict_uwu => src/scaict_uwu}/i18n/version_info/zh-hant.json (100%) rename {scaict_uwu => src/scaict_uwu}/i18n/zh-hant.json (100%) rename {scaict_uwu => src/scaict_uwu}/installer/__init__.py (100%) rename {scaict_uwu => src/scaict_uwu}/installer/cog/__init__.py (100%) rename {scaict_uwu => src/scaict_uwu}/logging/__init__.py (100%) rename {scaict_uwu => src/scaict_uwu}/maintenance.py (100%) rename {scaict_uwu => src/scaict_uwu}/maintenance/__init__.py (100%) rename {scaict_uwu => src/scaict_uwu}/maintenance/data/tables.json (100%) rename {scaict_uwu => src/scaict_uwu}/maintenance/maintenance.py (96%) rename {scaict_uwu => src/scaict_uwu}/maintenance/parameters.py (100%) rename {scaict_uwu => src/scaict_uwu}/maintenance/scripts/__init__.py (100%) rename {scaict_uwu => src/scaict_uwu}/maintenance/scripts/update.py (84%) rename {scaict_uwu => src/scaict_uwu}/rdbms/__init__.py (100%) rename {scaict_uwu => src/scaict_uwu}/stats/__init__.py (100%) rename {scaict_uwu => src/scaict_uwu}/system_message/__init__.py (100%) rename {scaict_uwu => src/scaict_uwu}/user/__init__.py (100%) rename {scaict_uwu => src/scaict_uwu}/utils/__init__.py (100%) rename {scaict_uwu => src/scaict_uwu}/website/__init__.py (100%) rename {scaict_uwu => src/scaict_uwu}/website_flask.py (100%) diff --git a/.github/workflows/black.yml b/.github/workflows/black.yml index c961a4a..bcf3fb6 100644 --- a/.github/workflows/black.yml +++ b/.github/workflows/black.yml @@ -28,6 +28,7 @@ jobs: python -m pip install --upgrade pip pip install -r requirements.txt pip install -r requirements_dev.txt + pip install -e .[dev] - name: Formatting the code with Black run: | black $(git ls-files '*.py') diff --git a/.github/workflows/pylint.yml b/.github/workflows/pylint.yml index dfaab50..9f5abc7 100644 --- a/.github/workflows/pylint.yml +++ b/.github/workflows/pylint.yml @@ -22,6 +22,7 @@ jobs: python -m pip install --upgrade pip pip install -r requirements.txt pip install -r requirements_dev.txt + pip install -e .[dev] - name: Analysing the code with Pylint run: | pylint $(git ls-files '*.py') diff --git a/scaict_uwu/__init__.py b/src/scaict_uwu/__init__.py similarity index 100% rename from scaict_uwu/__init__.py rename to src/scaict_uwu/__init__.py diff --git a/scaict_uwu/bot/__init__.py b/src/scaict_uwu/bot/__init__.py similarity index 100% rename from scaict_uwu/bot/__init__.py rename to src/scaict_uwu/bot/__init__.py diff --git a/scaict_uwu/bot/channels/__init__.py b/src/scaict_uwu/bot/channels/__init__.py similarity index 100% rename from scaict_uwu/bot/channels/__init__.py rename to src/scaict_uwu/bot/channels/__init__.py diff --git a/scaict_uwu/bot/cog/__init__.py b/src/scaict_uwu/bot/cog/__init__.py similarity index 100% rename from scaict_uwu/bot/cog/__init__.py rename to src/scaict_uwu/bot/cog/__init__.py diff --git a/scaict_uwu/bot/emoji/__init__.py b/src/scaict_uwu/bot/emoji/__init__.py similarity index 100% rename from scaict_uwu/bot/emoji/__init__.py rename to src/scaict_uwu/bot/emoji/__init__.py diff --git a/scaict_uwu/bot/users/__init__.py b/src/scaict_uwu/bot/users/__init__.py similarity index 100% rename from scaict_uwu/bot/users/__init__.py rename to src/scaict_uwu/bot/users/__init__.py diff --git a/scaict_uwu/bot_pycord.py b/src/scaict_uwu/bot_pycord.py similarity index 100% rename from scaict_uwu/bot_pycord.py rename to src/scaict_uwu/bot_pycord.py diff --git a/scaict_uwu/config/__init__.py b/src/scaict_uwu/config/__init__.py similarity index 100% rename from scaict_uwu/config/__init__.py rename to src/scaict_uwu/config/__init__.py diff --git a/scaict_uwu/config/config.py b/src/scaict_uwu/config/config.py similarity index 100% rename from scaict_uwu/config/config.py rename to src/scaict_uwu/config/config.py diff --git a/scaict_uwu/config/config_factory.py b/src/scaict_uwu/config/config_factory.py similarity index 100% rename from scaict_uwu/config/config_factory.py rename to src/scaict_uwu/config/config_factory.py diff --git a/scaict_uwu/i18n/course/zh-hant.json b/src/scaict_uwu/i18n/course/zh-hant.json similarity index 100% rename from scaict_uwu/i18n/course/zh-hant.json rename to src/scaict_uwu/i18n/course/zh-hant.json diff --git a/scaict_uwu/i18n/ctf/zh-hant.json b/src/scaict_uwu/i18n/ctf/zh-hant.json similarity index 100% rename from scaict_uwu/i18n/ctf/zh-hant.json rename to src/scaict_uwu/i18n/ctf/zh-hant.json diff --git a/scaict_uwu/i18n/daily_charge/zh-hant.json b/src/scaict_uwu/i18n/daily_charge/zh-hant.json similarity index 100% rename from scaict_uwu/i18n/daily_charge/zh-hant.json rename to src/scaict_uwu/i18n/daily_charge/zh-hant.json diff --git a/scaict_uwu/i18n/game_counting/zh-hant.json b/src/scaict_uwu/i18n/game_counting/zh-hant.json similarity index 100% rename from scaict_uwu/i18n/game_counting/zh-hant.json rename to src/scaict_uwu/i18n/game_counting/zh-hant.json diff --git a/scaict_uwu/i18n/game_nice_color/zh-hant.json b/src/scaict_uwu/i18n/game_nice_color/zh-hant.json similarity index 100% rename from scaict_uwu/i18n/game_nice_color/zh-hant.json rename to src/scaict_uwu/i18n/game_nice_color/zh-hant.json diff --git a/scaict_uwu/i18n/game_rps/zh-hant.json b/src/scaict_uwu/i18n/game_rps/zh-hant.json similarity index 100% rename from scaict_uwu/i18n/game_rps/zh-hant.json rename to src/scaict_uwu/i18n/game_rps/zh-hant.json diff --git a/scaict_uwu/i18n/support_ticket/zh-hant.json b/src/scaict_uwu/i18n/support_ticket/zh-hant.json similarity index 100% rename from scaict_uwu/i18n/support_ticket/zh-hant.json rename to src/scaict_uwu/i18n/support_ticket/zh-hant.json diff --git a/scaict_uwu/i18n/version_info/zh-hant.json b/src/scaict_uwu/i18n/version_info/zh-hant.json similarity index 100% rename from scaict_uwu/i18n/version_info/zh-hant.json rename to src/scaict_uwu/i18n/version_info/zh-hant.json diff --git a/scaict_uwu/i18n/zh-hant.json b/src/scaict_uwu/i18n/zh-hant.json similarity index 100% rename from scaict_uwu/i18n/zh-hant.json rename to src/scaict_uwu/i18n/zh-hant.json diff --git a/scaict_uwu/installer/__init__.py b/src/scaict_uwu/installer/__init__.py similarity index 100% rename from scaict_uwu/installer/__init__.py rename to src/scaict_uwu/installer/__init__.py diff --git a/scaict_uwu/installer/cog/__init__.py b/src/scaict_uwu/installer/cog/__init__.py similarity index 100% rename from scaict_uwu/installer/cog/__init__.py rename to src/scaict_uwu/installer/cog/__init__.py diff --git a/scaict_uwu/logging/__init__.py b/src/scaict_uwu/logging/__init__.py similarity index 100% rename from scaict_uwu/logging/__init__.py rename to src/scaict_uwu/logging/__init__.py diff --git a/scaict_uwu/maintenance.py b/src/scaict_uwu/maintenance.py similarity index 100% rename from scaict_uwu/maintenance.py rename to src/scaict_uwu/maintenance.py diff --git a/scaict_uwu/maintenance/__init__.py b/src/scaict_uwu/maintenance/__init__.py similarity index 100% rename from scaict_uwu/maintenance/__init__.py rename to src/scaict_uwu/maintenance/__init__.py diff --git a/scaict_uwu/maintenance/data/tables.json b/src/scaict_uwu/maintenance/data/tables.json similarity index 100% rename from scaict_uwu/maintenance/data/tables.json rename to src/scaict_uwu/maintenance/data/tables.json diff --git a/scaict_uwu/maintenance/maintenance.py b/src/scaict_uwu/maintenance/maintenance.py similarity index 96% rename from scaict_uwu/maintenance/maintenance.py rename to src/scaict_uwu/maintenance/maintenance.py index 35b64c5..a6e2a22 100644 --- a/scaict_uwu/maintenance/maintenance.py +++ b/src/scaict_uwu/maintenance/maintenance.py @@ -3,7 +3,8 @@ """ # Local imports -from scaict_uwu.maintenance.parameters import MaintenanceParameters +# scaict_uwu.maintenance.parameters +from .parameters import MaintenanceParameters class Maintenance: diff --git a/scaict_uwu/maintenance/parameters.py b/src/scaict_uwu/maintenance/parameters.py similarity index 100% rename from scaict_uwu/maintenance/parameters.py rename to src/scaict_uwu/maintenance/parameters.py diff --git a/scaict_uwu/maintenance/scripts/__init__.py b/src/scaict_uwu/maintenance/scripts/__init__.py similarity index 100% rename from scaict_uwu/maintenance/scripts/__init__.py rename to src/scaict_uwu/maintenance/scripts/__init__.py diff --git a/scaict_uwu/maintenance/scripts/update.py b/src/scaict_uwu/maintenance/scripts/update.py similarity index 84% rename from scaict_uwu/maintenance/scripts/update.py rename to src/scaict_uwu/maintenance/scripts/update.py index 42696d0..12a6760 100644 --- a/scaict_uwu/maintenance/scripts/update.py +++ b/src/scaict_uwu/maintenance/scripts/update.py @@ -5,7 +5,8 @@ """ # Local imports -from scaict_uwu.maintenance.maintenance import Maintenance +# scaict_uwu.maintenance.maintenance +from ..maintenance import Maintenance class UpdateMaintenance(Maintenance): diff --git a/scaict_uwu/rdbms/__init__.py b/src/scaict_uwu/rdbms/__init__.py similarity index 100% rename from scaict_uwu/rdbms/__init__.py rename to src/scaict_uwu/rdbms/__init__.py diff --git a/scaict_uwu/stats/__init__.py b/src/scaict_uwu/stats/__init__.py similarity index 100% rename from scaict_uwu/stats/__init__.py rename to src/scaict_uwu/stats/__init__.py diff --git a/scaict_uwu/system_message/__init__.py b/src/scaict_uwu/system_message/__init__.py similarity index 100% rename from scaict_uwu/system_message/__init__.py rename to src/scaict_uwu/system_message/__init__.py diff --git a/scaict_uwu/user/__init__.py b/src/scaict_uwu/user/__init__.py similarity index 100% rename from scaict_uwu/user/__init__.py rename to src/scaict_uwu/user/__init__.py diff --git a/scaict_uwu/utils/__init__.py b/src/scaict_uwu/utils/__init__.py similarity index 100% rename from scaict_uwu/utils/__init__.py rename to src/scaict_uwu/utils/__init__.py diff --git a/scaict_uwu/website/__init__.py b/src/scaict_uwu/website/__init__.py similarity index 100% rename from scaict_uwu/website/__init__.py rename to src/scaict_uwu/website/__init__.py diff --git a/scaict_uwu/website_flask.py b/src/scaict_uwu/website_flask.py similarity index 100% rename from scaict_uwu/website_flask.py rename to src/scaict_uwu/website_flask.py From 76c8a8f73afe168d66fbabebad41e25402faf109 Mon Sep 17 00:00:00 2001 From: Winston Sung Date: Wed, 28 Aug 2024 23:04:59 +0800 Subject: [PATCH 021/141] Add build/lib/ to .gitignore Change-Id: I27770b2ff249842ab8bfbc8f7905e1213fb7c9fb --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 311b7d2..d994783 100644 --- a/.gitignore +++ b/.gitignore @@ -12,6 +12,7 @@ ## Python **/__pycache__ *.egg-info/ +build/lib/ ## Linux flakLog.out nohup.out From 1666a6fa884b9dce0e3d596c61f7298eb9f40e68 Mon Sep 17 00:00:00 2001 From: Winston Sung Date: Wed, 28 Aug 2024 23:13:47 +0800 Subject: [PATCH 022/141] Update Black CI Change-Id: I15b6a1fd2595151c0454d6c1f9fe23f89de17d1e --- .github/workflows/black.yml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/workflows/black.yml b/.github/workflows/black.yml index bcf3fb6..540c963 100644 --- a/.github/workflows/black.yml +++ b/.github/workflows/black.yml @@ -36,12 +36,12 @@ jobs: run: | git config --local user.name "github-actions[bot]" git config --local user.email "41898282+github-actions[bot]@users.noreply.github.com" + - name: Git diff + run: | + git diff-index --quiet HEAD - name: Git add run: | git add * - - name: Git commit - run: | - git diff-index --quiet HEAD || git commit -m "Format \"$(git show -s --format=%s)\" using Black" - - name: Git push + - name: Git commit & push run: | - git push + git diff-index --quiet HEAD || ( git commit -m "Format \"$(git show -s --format=%s)\" using Black" && git push ) From 9995f0b2f914a15e7b361279f7f0e8c80916d445 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 28 Aug 2024 15:17:53 +0000 Subject: [PATCH 023/141] Bump idna from 3.7 to 3.8 Bumps [idna](https://github.com/kjd/idna) from 3.7 to 3.8. - [Release notes](https://github.com/kjd/idna/releases) - [Changelog](https://github.com/kjd/idna/blob/master/HISTORY.rst) - [Commits](https://github.com/kjd/idna/compare/v3.7...v3.8) --- updated-dependencies: - dependency-name: idna dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index b643953..97cdf70 100644 --- a/requirements.txt +++ b/requirements.txt @@ -9,7 +9,7 @@ click == 8.1.7 colorama == 0.4.6 flask == 3.0.3 frozenlist == 1.4.1 -idna == 3.7 +idna == 3.8 itsdangerous == 2.2.0 jinja2 == 3.1.4 markupsafe == 2.1.5 From e86e0efe345931f673f811058f82d4cc8af380de Mon Sep 17 00:00:00 2001 From: Winston Sung Date: Tue, 13 Aug 2024 23:38:48 +0800 Subject: [PATCH 024/141] Add support for system messages Change-Id: I14c9859111c02d2f330a02767a9be826db7f9444 --- src/scaict_uwu/system_message/message.py | 43 ++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 src/scaict_uwu/system_message/message.py diff --git a/src/scaict_uwu/system_message/message.py b/src/scaict_uwu/system_message/message.py new file mode 100644 index 0000000..b4f3b4a --- /dev/null +++ b/src/scaict_uwu/system_message/message.py @@ -0,0 +1,43 @@ +""" +This is the module for the class for all system messages. +""" + + +class Message: + """ + The Message class deals with fetching and processing of system messages. + """ + + __use_lang: str = "zh-hant" + """ + __use_lang (str): The language tag of the language for the system message\ + to use. + """ + + __in_lang: str = "zh-hant" + """ + __in_lang (str): The language tag of the language that the system message\ + actually used. + """ + + def set_lang(self, lang_tag: str) -> None: + """ + Set the language tag of the language that the message expected to use. + + Parameters: + lang_tag (str): The language tag of the language that the message\ + expected to use. + """ + + self.__use_lang = lang_tag + + def get_lang(self) -> str: + """ + Get the final language tag of the language that the message used or\ + falls back to. + + Returns: + str: Description of return value. + """ + + return self.__use_lang or self.__in_lang From 4f6062e71f6b1978209a3265715bb57186a90238 Mon Sep 17 00:00:00 2001 From: Each Chen Date: Thu, 29 Aug 2024 14:25:39 +0800 Subject: [PATCH 025/141] now :gift command :MySQL server has gone away. flask is ok --- app.py | 16 +++++----------- cog/admin_gift.py | 15 +++++++++++---- cog/api/api.py | 7 ++++--- cog/api/gift.py | 2 +- main.py | 5 ++--- 5 files changed, 23 insertions(+), 22 deletions(-) diff --git a/app.py b/app.py index a5aef2d..24e0fcb 100644 --- a/app.py +++ b/app.py @@ -3,7 +3,7 @@ import os import random from urllib.parse import urlencode - +import traceback # Third-party imports from flask import ( Flask, @@ -26,7 +26,6 @@ from cog.core.sql import user_id_exists from cog.api.api import Apis from cog.api.gift import Gift - app = Flask(__name__) load_dotenv(f"{os.getcwd()}/.env", verbose=True, override=True) @@ -152,7 +151,8 @@ def send(target_user_id): "error_details": request_admin.get("details"), } ) - # # 送禮物 + # 送禮物 + user_name = user_data["user"]["username"] try: new_gift = Gift( discord_token, guild_ID, target_user_id @@ -177,7 +177,7 @@ def send(target_user_id): message_id, gift_type, gift_amount, - target_user_id, + user_name, True, api_admin_name, ), @@ -196,14 +196,8 @@ def send(target_user_id): } ) return jsonify({"result": "success", "status": 200}) - # # 待辦:用戶端那裏也要提示 - # response = requests.post(url, headers=headers, json=json_data, timeout=10) - # if response.status_code != 200: - # return jsonify( - # {"error": "Failed to send message", "status": response.status_code} - # ) - # return jsonify({"result": "success", "status": 200}) except Exception as e: + traceback.print_exc() return jsonify( {"result": "interal server error", "status": 500, "error": str(e)} ) diff --git a/cog/admin_gift.py b/cog/admin_gift.py index 4ce8907..9b98c1f 100644 --- a/cog/admin_gift.py +++ b/cog/admin_gift.py @@ -1,5 +1,6 @@ # Standard imports from datetime import datetime +import traceback # Third-party imports import discord @@ -75,7 +76,9 @@ async def get_gift(self, button: discord.ui.Button, ctx) -> None: button.label = "已領取" # Change the button's label to "已領取" button.disabled = True # 關閉按鈕,避免重複點擊 await ctx.response.edit_message(view=self) - + def cache_users_by_name(self): + # 將所有使用者名稱和對應的使用者物件存入字典 + return {user.name: user for user in self.bot.users} @discord.slash_command(name="發送禮物", description="dm_gift") async def send_dm_gift( self, @@ -89,6 +92,7 @@ async def send_dm_gift( if not ctx.author.guild_permissions.administrator: await ctx.respond("你沒有權限使用這個指令!", ephemeral=True) return + SendGift.user_cache = self.cache_users_by_name() try: await ctx.defer() # 確保機器人請求不會超時 # 不能發送負數 @@ -99,11 +103,14 @@ async def send_dm_gift( print(type(manager)) target_usernames = target_str.split(",") target_users = [] - async def fetch_user_by_name(name): user_obj = discord.utils.find(lambda u: u.name == name, self.bot.users) if user_obj: - return await self.bot.fetch_user(user_obj.id) + try: + return await self.bot.fetch_user(user_obj.id) + except Exception as e: + print(f"Failed to fetch user with ID {user_obj.id}: {str(e)}") + return None for username in target_usernames: username = username.strip() @@ -113,7 +120,6 @@ async def fetch_user_by_name(name): except (ValueError, Exception) as e: await ctx.respond(f"找不到使用者 : {username}{e}", ephemeral=True) return - # DM 一個 Embed 和領取按鈕 for target_user in target_users: await send_gift_button( @@ -124,6 +130,7 @@ async def fetch_user_by_name(name): f"{manager} 已發送 {count} {gift_type} 給 {', '.join([user.name for user in target_users])}" ) except Exception as e: + traceback.print_exc() await ctx.respond(f"伺服器內部出現錯誤:{e}", ephemeral=True) diff --git a/cog/api/api.py b/cog/api/api.py index 6e67780..8da63a3 100644 --- a/cog/api/api.py +++ b/cog/api/api.py @@ -1,4 +1,5 @@ import requests +import json class Apis: @@ -52,9 +53,9 @@ def get_user(self, uid): """ try: url = f"https://discord.com/api/v10/guilds/{self.guild_id}/members/{uid}" - response = requests.get(url, headers=self.headers, timeout=5) - response.raise_for_status() # 檢查 HTTP 狀態碼 - return response.json() + usr = requests.get(url, headers=self.headers, timeout=5) + usr.raise_for_status() # 檢查 HTTP 狀態碼 + return usr.json() except requests.exceptions.RequestException as e: # 如果發生錯誤,返回一個包含錯誤訊息和詳細報錯的字典 return {"error": "get_user error", "details": str(e)} diff --git a/cog/api/gift.py b/cog/api/gift.py index 1629626..e6cd98a 100644 --- a/cog/api/gift.py +++ b/cog/api/gift.py @@ -11,7 +11,7 @@ def __init__(self, api_key: str, guild_id: int, recipient_id: int): "Content-Type": "application/json", } try: - fetch_usr = self.__new_dm(recipient_id)["id"] + fetch_usr = self.__new_dm(recipient_id) if "id" in fetch_usr: self.dm_room = fetch_usr["id"] else: diff --git a/main.py b/main.py index ef03506..2b31543 100644 --- a/main.py +++ b/main.py @@ -4,7 +4,6 @@ # Third-party imports import discord from dotenv import load_dotenv - # Local imports from channel_check import update_channel # update_channel程式從core目錄底下引入 from channel_check import change_status # update_channel程式從core目錄底下引入 @@ -30,6 +29,6 @@ async def on_ready(): if __name__ == "__main__": - load_dotenv(f"{os.getcwd()}/.env", verbose=True, override=True) + load_dotenv(f"{os.getcwd()}/.env",verbose=True, override=True) bot_token = os.getenv("DISCORD_TOKEN") - bot.run(bot_token) + bot.run(bot_token) \ No newline at end of file From 9f84b738bf2e8a51f999f54763825ac46e9ff45a Mon Sep 17 00:00:00 2001 From: Each Chen Date: Thu, 29 Aug 2024 16:05:16 +0800 Subject: [PATCH 026/141] send gift ok and oop reload --- app.py | 6 ------ cog/admin.py | 24 ++++++++++++++++++++++++ cog/admin_gift.py | 5 ++--- cog/core/sendgift.py | 3 +-- main.py | 9 ++++++++- 5 files changed, 35 insertions(+), 12 deletions(-) create mode 100644 cog/admin.py diff --git a/app.py b/app.py index 24e0fcb..5e464ba 100644 --- a/app.py +++ b/app.py @@ -66,7 +66,6 @@ def login(): params["state"] = redirurl # 將參數進行 URL 編碼並組合成最終的 URL urlencoded = urlencode(params) - print(f"{base_url}?\n\n{urlencoded}") return redirect(f"{base_url}?{urlencoded}") @@ -279,7 +278,6 @@ def discord_callback(): response = requests.post( "https://discord.com/api/oauth2/token", data=data, headers=headers ) - print(response.json()) access_token = response.json()["access_token"] headers = {"Authorization": f"Bearer {access_token}"} # pylint: disable-next = missing-timeout @@ -478,7 +476,6 @@ def github_callback(): } # pylint: disable-next = missing-timeout response = requests.post(token_url, headers=headers, data=data) - print(response.json()) session["access_token"] = response.json()["access_token"] return redirect(url_for("star_uwu")) @@ -504,7 +501,6 @@ def insert_user(user_id, table, cursor): # 初始化(新增)傳入該ID的 headers = {"Authorization": f"token {session['access_token']}"} # pylint: disable-next = missing-timeout user_response = requests.get(user_url, headers=headers) - print(user_response.json()) github_username = user_response.json()["login"] github_email = user_response.json()["email"] connection, cursor = link_sql() # SQL 會話 @@ -517,11 +513,9 @@ def insert_user(user_id, table, cursor): # 初始化(新增)傳入該ID的 repo_name = "SCAICT-uwu" star_url = f"https://api.github.com/user/starred/{repo_owner}/{repo_name}" headers = {"Authorization": f"token {session['access_token']}"} - print(session["access_token"]) # Sending a PUT request to star the repository # pylint: disable-next = missing-timeout response = requests.put(star_url, headers=headers) - print(response.text) # Checking the response status and returning an appropriate message if response.ok: print(f"Successfully starred {repo_owner}/{repo_name}! {response}") diff --git a/cog/admin.py b/cog/admin.py new file mode 100644 index 0000000..c56191d --- /dev/null +++ b/cog/admin.py @@ -0,0 +1,24 @@ +# Standard imports +# import csv +# from datetime import datetime, timedelta +# import json +# import os + +# Third-party imports +import discord +from build.build import Build +# Local imports + + +class ManagerCommand(Build): + @discord.slash_command(name="reload", description="你是管理員才讓你用") + async def reload(self, ctx,package): + if not ctx.author.guild_permissions.administrator: + await ctx.respond("你沒有權限使用這個指令!", ephemeral=True) + return + self.bot.reload_extension(f"cog.{package}") + await ctx.respond(f"🔄 {package} reloaded" ) + + +def setup(bot): + bot.add_cog(ManagerCommand(bot)) diff --git a/cog/admin_gift.py b/cog/admin_gift.py index 9b98c1f..6bff833 100644 --- a/cog/admin_gift.py +++ b/cog/admin_gift.py @@ -100,7 +100,6 @@ async def send_dm_gift( await ctx.respond("不能發送 0 以下個禮物!", ephemeral=True) return manager = ctx.author # return - print(type(manager)) target_usernames = target_str.split(",") target_users = [] async def fetch_user_by_name(name): @@ -114,6 +113,8 @@ async def fetch_user_by_name(name): for username in target_usernames: username = username.strip() + if username not in SendGift.user_cache: + continue try: user = await fetch_user_by_name(username) target_users.append(user) @@ -132,7 +133,5 @@ async def fetch_user_by_name(name): except Exception as e: traceback.print_exc() await ctx.respond(f"伺服器內部出現錯誤:{e}", ephemeral=True) - - def setup(bot): bot.add_cog(SendGift(bot)) diff --git a/cog/core/sendgift.py b/cog/core/sendgift.py index d98f6cf..a26d714 100644 --- a/cog/core/sendgift.py +++ b/cog/core/sendgift.py @@ -36,9 +36,8 @@ async def record_db( ) end(connection, cursor) except Exception as e: - raise DBError("無法成功插入禮物資料進資料庫") from e - finally: end(connection, cursor) + raise DBError("無法成功插入禮物資料進資料庫") from e try: await target_user.send(embed=embed) diff --git a/main.py b/main.py index 2b31543..6b329b5 100644 --- a/main.py +++ b/main.py @@ -19,7 +19,14 @@ bot.load_extension(f"cog.{filename[:-3]}") print(f"📖 {filename} loaded") # test - +@bot.command() +async def load(ctx, extension): + bot.load_extension(f"cog.{extension}") + await ctx.send(f"📖 {extension} loaded") +@bot.command() +async def unload(ctx, extension): + bot.unload_extension(f"cog.{extension}") + await ctx.send(f"📖 {extension} unloaded") @bot.event async def on_ready(): print(f"✅ {bot.user} is online") From 28e949b3776a937545b00b3c4b4ad1cabc03d232 Mon Sep 17 00:00:00 2001 From: Winston Sung Date: Fri, 30 Aug 2024 21:51:21 +0800 Subject: [PATCH 027/141] Fix Black CI https: //stackoverflow.com/questions/38578140 Change-Id: I7fa990bed428ee5d8b923396c787ed4a61ffec72 --- .github/workflows/black.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/black.yml b/.github/workflows/black.yml index 540c963..1890e5c 100644 --- a/.github/workflows/black.yml +++ b/.github/workflows/black.yml @@ -38,7 +38,7 @@ jobs: git config --local user.email "41898282+github-actions[bot]@users.noreply.github.com" - name: Git diff run: | - git diff-index --quiet HEAD + git diff-index --quiet HEAD || true - name: Git add run: | git add * From b49e5acc99e7f46de23264d21776bd79d52c7566 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Fri, 30 Aug 2024 13:52:09 +0000 Subject: [PATCH 028/141] Format "Fix Black CI" using Black --- app.py | 2 ++ cog/admin.py | 5 +++-- cog/admin_gift.py | 5 +++++ main.py | 10 ++++++++-- 4 files changed, 18 insertions(+), 4 deletions(-) diff --git a/app.py b/app.py index 5e464ba..7cd68c4 100644 --- a/app.py +++ b/app.py @@ -4,6 +4,7 @@ import random from urllib.parse import urlencode import traceback + # Third-party imports from flask import ( Flask, @@ -26,6 +27,7 @@ from cog.core.sql import user_id_exists from cog.api.api import Apis from cog.api.gift import Gift + app = Flask(__name__) load_dotenv(f"{os.getcwd()}/.env", verbose=True, override=True) diff --git a/cog/admin.py b/cog/admin.py index c56191d..8833f5a 100644 --- a/cog/admin.py +++ b/cog/admin.py @@ -7,17 +7,18 @@ # Third-party imports import discord from build.build import Build + # Local imports class ManagerCommand(Build): @discord.slash_command(name="reload", description="你是管理員才讓你用") - async def reload(self, ctx,package): + async def reload(self, ctx, package): if not ctx.author.guild_permissions.administrator: await ctx.respond("你沒有權限使用這個指令!", ephemeral=True) return self.bot.reload_extension(f"cog.{package}") - await ctx.respond(f"🔄 {package} reloaded" ) + await ctx.respond(f"🔄 {package} reloaded") def setup(bot): diff --git a/cog/admin_gift.py b/cog/admin_gift.py index 6bff833..b784c3f 100644 --- a/cog/admin_gift.py +++ b/cog/admin_gift.py @@ -76,9 +76,11 @@ async def get_gift(self, button: discord.ui.Button, ctx) -> None: button.label = "已領取" # Change the button's label to "已領取" button.disabled = True # 關閉按鈕,避免重複點擊 await ctx.response.edit_message(view=self) + def cache_users_by_name(self): # 將所有使用者名稱和對應的使用者物件存入字典 return {user.name: user for user in self.bot.users} + @discord.slash_command(name="發送禮物", description="dm_gift") async def send_dm_gift( self, @@ -102,6 +104,7 @@ async def send_dm_gift( manager = ctx.author # return target_usernames = target_str.split(",") target_users = [] + async def fetch_user_by_name(name): user_obj = discord.utils.find(lambda u: u.name == name, self.bot.users) if user_obj: @@ -133,5 +136,7 @@ async def fetch_user_by_name(name): except Exception as e: traceback.print_exc() await ctx.respond(f"伺服器內部出現錯誤:{e}", ephemeral=True) + + def setup(bot): bot.add_cog(SendGift(bot)) diff --git a/main.py b/main.py index 6b329b5..942d6af 100644 --- a/main.py +++ b/main.py @@ -4,6 +4,7 @@ # Third-party imports import discord from dotenv import load_dotenv + # Local imports from channel_check import update_channel # update_channel程式從core目錄底下引入 from channel_check import change_status # update_channel程式從core目錄底下引入 @@ -19,14 +20,19 @@ bot.load_extension(f"cog.{filename[:-3]}") print(f"📖 {filename} loaded") # test + @bot.command() async def load(ctx, extension): bot.load_extension(f"cog.{extension}") await ctx.send(f"📖 {extension} loaded") + + @bot.command() async def unload(ctx, extension): bot.unload_extension(f"cog.{extension}") await ctx.send(f"📖 {extension} unloaded") + + @bot.event async def on_ready(): print(f"✅ {bot.user} is online") @@ -36,6 +42,6 @@ async def on_ready(): if __name__ == "__main__": - load_dotenv(f"{os.getcwd()}/.env",verbose=True, override=True) + load_dotenv(f"{os.getcwd()}/.env", verbose=True, override=True) bot_token = os.getenv("DISCORD_TOKEN") - bot.run(bot_token) \ No newline at end of file + bot.run(bot_token) From cb243f738a16bbc133d00389e6e1f2f5b950b161 Mon Sep 17 00:00:00 2001 From: Winston Sung Date: Fri, 30 Aug 2024 21:56:04 +0800 Subject: [PATCH 029/141] Fix Black CI Change-Id: I44bab4375c3cf1ba794e1bf92b9ec1fbc997ce68 --- .github/workflows/black.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/black.yml b/.github/workflows/black.yml index 1890e5c..8e67b68 100644 --- a/.github/workflows/black.yml +++ b/.github/workflows/black.yml @@ -38,7 +38,7 @@ jobs: git config --local user.email "41898282+github-actions[bot]@users.noreply.github.com" - name: Git diff run: | - git diff-index --quiet HEAD || true + git diff HEAD || true - name: Git add run: | git add * From 3416f96ff18e9d78878d6e1af7eed1049e8034a1 Mon Sep 17 00:00:00 2001 From: Winston Sung Date: Fri, 30 Aug 2024 22:29:58 +0800 Subject: [PATCH 030/141] Fix lint issues Change-Id: Idef63cd778262f7d197e89427dfc08758308a7d4 --- cog/api/api.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/cog/api/api.py b/cog/api/api.py index 8da63a3..cffa02b 100644 --- a/cog/api/api.py +++ b/cog/api/api.py @@ -1,5 +1,8 @@ +# Standard imports +# import json + +# Third-party imports import requests -import json class Apis: From 8be7454955121bf5929890083586510f4d65d378 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 2 Sep 2024 01:58:32 +0000 Subject: [PATCH 031/141] Bump yarl from 1.9.4 to 1.9.7 Bumps [yarl](https://github.com/aio-libs/yarl) from 1.9.4 to 1.9.7. - [Release notes](https://github.com/aio-libs/yarl/releases) - [Changelog](https://github.com/aio-libs/yarl/blob/master/CHANGES.rst) - [Commits](https://github.com/aio-libs/yarl/compare/v1.9.4...v1.9.7) --- updated-dependencies: - dependency-name: yarl dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index 97cdf70..cc05a3e 100644 --- a/requirements.txt +++ b/requirements.txt @@ -20,4 +20,4 @@ python-dotenv == 1.0.1 requests == 2.32.3 urllib3 == 2.2.2 werkzeug == 3.0.4 -yarl == 1.9.4 +yarl == 1.9.7 From 35830706d352a22587603fbb0701a2c8a8f7e8c6 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 2 Sep 2024 04:29:45 +0000 Subject: [PATCH 032/141] Bump certifi from 2024.7.4 to 2024.8.30 Bumps [certifi](https://github.com/certifi/python-certifi) from 2024.7.4 to 2024.8.30. - [Commits](https://github.com/certifi/python-certifi/compare/2024.07.04...2024.08.30) --- updated-dependencies: - dependency-name: certifi dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index cc05a3e..bd9b3dc 100644 --- a/requirements.txt +++ b/requirements.txt @@ -3,7 +3,7 @@ aiohttp == 3.10.5 aiosignal == 1.3.1 attrs == 24.2.0 blinker == 1.8.2 -certifi == 2024.7.4 +certifi == 2024.8.30 charset-normalizer == 3.3.2 click == 8.1.7 colorama == 0.4.6 From e74365b95f0454105d06e3ce4e8a8491e0e82f6f Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 2 Sep 2024 04:33:10 +0000 Subject: [PATCH 033/141] Bump pylint from 3.2.6 to 3.2.7 Bumps [pylint](https://github.com/pylint-dev/pylint) from 3.2.6 to 3.2.7. - [Release notes](https://github.com/pylint-dev/pylint/releases) - [Commits](https://github.com/pylint-dev/pylint/compare/v3.2.6...v3.2.7) --- updated-dependencies: - dependency-name: pylint dependency-type: direct:development update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- pyproject.toml | 2 +- requirements_dev.txt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 9f6e61d..94f6800 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -37,6 +37,6 @@ dependencies = [ # Lock file: requirements_dev.txt optional-dependencies.dev = [ "black == 24.8.0", - "pylint == 3.2.6", + "pylint == 3.2.7", "pytest == 8.3.2", ] diff --git a/requirements_dev.txt b/requirements_dev.txt index 391a504..1a53148 100644 --- a/requirements_dev.txt +++ b/requirements_dev.txt @@ -11,6 +11,6 @@ packaging == 24.1 pathspec == 0.12.1 platformdirs == 4.2.2 pluggy == 1.5.0 -pylint == 3.2.6 +pylint == 3.2.7 pytest == 8.3.2 tomlkit == 0.13.2 From 63690700138dabeb7bf0c088b15c70a645df3861 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 5 Sep 2024 01:40:00 +0000 Subject: [PATCH 034/141] Bump yarl from 1.9.7 to 1.9.10 Bumps [yarl](https://github.com/aio-libs/yarl) from 1.9.7 to 1.9.10. - [Release notes](https://github.com/aio-libs/yarl/releases) - [Changelog](https://github.com/aio-libs/yarl/blob/v1.9.10/CHANGES.rst) - [Commits](https://github.com/aio-libs/yarl/compare/v1.9.7...v1.9.10) --- updated-dependencies: - dependency-name: yarl dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index bd9b3dc..704e1bc 100644 --- a/requirements.txt +++ b/requirements.txt @@ -20,4 +20,4 @@ python-dotenv == 1.0.1 requests == 2.32.3 urllib3 == 2.2.2 werkzeug == 3.0.4 -yarl == 1.9.7 +yarl == 1.9.10 From 19e87d38f44dd475ec391433bae4cf3cf40f511e Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 9 Sep 2024 01:34:49 +0000 Subject: [PATCH 035/141] Bump platformdirs from 4.2.2 to 4.3.2 Bumps [platformdirs](https://github.com/platformdirs/platformdirs) from 4.2.2 to 4.3.2. - [Release notes](https://github.com/platformdirs/platformdirs/releases) - [Changelog](https://github.com/tox-dev/platformdirs/blob/main/CHANGES.rst) - [Commits](https://github.com/platformdirs/platformdirs/compare/4.2.2...4.3.2) --- updated-dependencies: - dependency-name: platformdirs dependency-type: direct:development update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- requirements_dev.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements_dev.txt b/requirements_dev.txt index 1a53148..3b654dc 100644 --- a/requirements_dev.txt +++ b/requirements_dev.txt @@ -9,7 +9,7 @@ mccabe == 0.7.0 mypy-extensions == 1.0.0 packaging == 24.1 pathspec == 0.12.1 -platformdirs == 4.2.2 +platformdirs == 4.3.2 pluggy == 1.5.0 pylint == 3.2.7 pytest == 8.3.2 From 559d50fbb2b03cb00ddeb434715eedf8122a5359 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 9 Sep 2024 11:20:40 +0000 Subject: [PATCH 036/141] Bump yarl from 1.9.10 to 1.11.0 Bumps [yarl](https://github.com/aio-libs/yarl) from 1.9.10 to 1.11.0. - [Release notes](https://github.com/aio-libs/yarl/releases) - [Changelog](https://github.com/aio-libs/yarl/blob/master/CHANGES.rst) - [Commits](https://github.com/aio-libs/yarl/compare/v1.9.10...v1.11.0) --- updated-dependencies: - dependency-name: yarl dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index 704e1bc..ef01ed5 100644 --- a/requirements.txt +++ b/requirements.txt @@ -20,4 +20,4 @@ python-dotenv == 1.0.1 requests == 2.32.3 urllib3 == 2.2.2 werkzeug == 3.0.4 -yarl == 1.9.10 +yarl == 1.11.0 From 417319cd6a8393ed51868f5501754256beb8535d Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 10 Sep 2024 01:55:27 +0000 Subject: [PATCH 037/141] Bump multidict from 6.0.5 to 6.1.0 Bumps [multidict](https://github.com/aio-libs/multidict) from 6.0.5 to 6.1.0. - [Release notes](https://github.com/aio-libs/multidict/releases) - [Changelog](https://github.com/aio-libs/multidict/blob/master/CHANGES.rst) - [Commits](https://github.com/aio-libs/multidict/compare/v6.0.5...v6.1.0) --- updated-dependencies: - dependency-name: multidict dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index ef01ed5..1fdfbff 100644 --- a/requirements.txt +++ b/requirements.txt @@ -13,7 +13,7 @@ idna == 3.8 itsdangerous == 2.2.0 jinja2 == 3.1.4 markupsafe == 2.1.5 -multidict == 6.0.5 +multidict == 6.1.0 mysql-connector-python == 8.4.0 py-cord == 2.6.0 python-dotenv == 1.0.1 From 10fa7e9c4a5bfde36b13958ac83e0f22342eaddb Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 10 Sep 2024 04:43:48 +0000 Subject: [PATCH 038/141] Bump yarl from 1.11.0 to 1.11.1 Bumps [yarl](https://github.com/aio-libs/yarl) from 1.11.0 to 1.11.1. - [Release notes](https://github.com/aio-libs/yarl/releases) - [Changelog](https://github.com/aio-libs/yarl/blob/master/CHANGES.rst) - [Commits](https://github.com/aio-libs/yarl/compare/v1.11.0...v1.11.1) --- updated-dependencies: - dependency-name: yarl dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index 1fdfbff..fbed878 100644 --- a/requirements.txt +++ b/requirements.txt @@ -20,4 +20,4 @@ python-dotenv == 1.0.1 requests == 2.32.3 urllib3 == 2.2.2 werkzeug == 3.0.4 -yarl == 1.11.0 +yarl == 1.11.1 From 3d5ce916f6420cc895ca9f46c421ac2c7773c58a Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 11 Sep 2024 02:06:08 +0000 Subject: [PATCH 039/141] Bump pytest from 8.3.2 to 8.3.3 Bumps [pytest](https://github.com/pytest-dev/pytest) from 8.3.2 to 8.3.3. - [Release notes](https://github.com/pytest-dev/pytest/releases) - [Changelog](https://github.com/pytest-dev/pytest/blob/main/CHANGELOG.rst) - [Commits](https://github.com/pytest-dev/pytest/compare/8.3.2...8.3.3) --- updated-dependencies: - dependency-name: pytest dependency-type: direct:development update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- pyproject.toml | 2 +- requirements_dev.txt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 94f6800..8e36e67 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -38,5 +38,5 @@ dependencies = [ optional-dependencies.dev = [ "black == 24.8.0", "pylint == 3.2.7", - "pytest == 8.3.2", + "pytest == 8.3.3", ] diff --git a/requirements_dev.txt b/requirements_dev.txt index 3b654dc..e269f09 100644 --- a/requirements_dev.txt +++ b/requirements_dev.txt @@ -12,5 +12,5 @@ pathspec == 0.12.1 platformdirs == 4.3.2 pluggy == 1.5.0 pylint == 3.2.7 -pytest == 8.3.2 +pytest == 8.3.3 tomlkit == 0.13.2 From 101280e26dca777fcac6fad2368017366565c331 Mon Sep 17 00:00:00 2001 From: Winston Sung Date: Wed, 11 Sep 2024 13:40:22 +0800 Subject: [PATCH 040/141] Add draft of RELEASE-NOTES-0.1 Change-Id: Ief532791cc7b742c82db38ea6dad25939ec782bf --- RELEASE-NOTES-0.1.md | 562 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 562 insertions(+) create mode 100644 RELEASE-NOTES-0.1.md diff --git a/RELEASE-NOTES-0.1.md b/RELEASE-NOTES-0.1.md new file mode 100644 index 0000000..1473c6e --- /dev/null +++ b/RELEASE-NOTES-0.1.md @@ -0,0 +1,562 @@ +# SCAICT-uwu 0.1 + +## SCAICT-uwu 0.1 development branch + +THIS IS NOT A RELEASE YET + +The `development` branch is an beta-quality development branch. Use it at your +own risk! + +### Configuration changes for system administrators + +#### New configuration + +* … + +#### Changed configuration + +* … + +#### Removed configuration + +* … + +### New user-facing features + +* … + +### New features for sysadmins + +* … + +### New developer features + +* … + +### Bug fixes + +* … + +### API changes + +* … + +### API internal changes + +* … + +### Languages updated + +SCAICT-uwu now supports 1 language. Many localisations are updated regularly. + +Below only new and removed languages are listed. + +* … + +### Breaking changes + +* … + +### Deprecations + +* … + +### Other changes + +* … + +## SCAICT-uwu 0.1.7 + +This is a maintenance release of SCAICT-uwu 0.1 version. + +### Configuration changes for system administrators in 0.1.7 + +#### New configuration in 0.1.7 + +* … + +#### Changed configuration in 0.1.7 + +* … + +#### Removed configuration in 0.1.7 + +* … + +### New user-facing features in 0.1.7 + +* … + +### New features for sysadmins in 0.1.7 + +* … + +### New developer features in 0.1.7 + +* … + +### Bug fixes in 0.1.7 + +* … + +### API changes in 0.1.7 + +* … + +### API internal changes in 0.1.7 + +* … + +### Languages updated in 0.1.7 + +SCAICT-uwu now supports 1 language. Many localisations are updated regularly. + +Below only new and removed languages are listed. + +* … + +### Breaking changes in 0.1.7 + +* … + +### Deprecations in 0.1.7 + +* … + +### Other changes in 0.1.7 + +* … + +## SCAICT-uwu 0.1.6 + +This is a maintenance release of SCAICT-uwu 0.1 version. + +### Configuration changes for system administrators in 0.1.6 + +#### New configuration in 0.1.6 + +* … + +#### Changed configuration in 0.1.6 + +* … + +#### Removed configuration in 0.1.6 + +* … + +### New user-facing features in 0.1.6 + +* … + +### New features for sysadmins in 0.1.6 + +* … + +### New developer features in 0.1.6 + +* … + +### Bug fixes in 0.1.6 + +* … + +### API changes in 0.1.6 + +* … + +### API internal changes in 0.1.6 + +* … + +### Languages updated in 0.1.6 + +SCAICT-uwu now supports 1 language. Many localisations are updated regularly. + +Below only new and removed languages are listed. + +* … + +### Breaking changes in 0.1.6 + +* … + +### Deprecations in 0.1.6 + +* … + +### Other changes in 0.1.6 + +* … + +## SCAICT-uwu 0.1.5 + +This is a maintenance release of SCAICT-uwu 0.1 version. + +### Configuration changes for system administrators in 0.1.5 + +#### New configuration in 0.1.5 + +* … + +#### Changed configuration in 0.1.5 + +* … + +#### Removed configuration in 0.1.5 + +* … + +### New user-facing features in 0.1.5 + +* … + +### New features for sysadmins in 0.1.5 + +* … + +### New developer features in 0.1.5 + +* … + +### Bug fixes in 0.1.5 + +* … + +### API changes in 0.1.5 + +* … + +### API internal changes in 0.1.5 + +* … + +### Languages updated in 0.1.5 + +SCAICT-uwu now supports 1 language. Many localisations are updated regularly. + +Below only new and removed languages are listed. + +* … + +### Breaking changes in 0.1.5 + +* … + +### Deprecations in 0.1.5 + +* … + +### Other changes in 0.1.5 + +* … + +## SCAICT-uwu 0.1.4 + +This is a maintenance release of SCAICT-uwu 0.1 version. + +### Configuration changes for system administrators in 0.1.4 + +#### New configuration in 0.1.4 + +* … + +#### Changed configuration in 0.1.4 + +* … + +#### Removed configuration in 0.1.4 + +* … + +### New user-facing features in 0.1.4 + +* … + +### New features for sysadmins in 0.1.4 + +* … + +### New developer features in 0.1.4 + +* … + +### Bug fixes in 0.1.4 + +* … + +### API changes in 0.1.4 + +* … + +### API internal changes in 0.1.4 + +* … + +### Languages updated in 0.1.4 + +SCAICT-uwu now supports 1 language. Many localisations are updated regularly. + +Below only new and removed languages are listed. + +* … + +### Breaking changes in 0.1.4 + +* … + +### Deprecations in 0.1.4 + +* … + +### Other changes in 0.1.4 + +* … + +## SCAICT-uwu 0.1.3 + +This is a maintenance release of SCAICT-uwu 0.1 version. + +### Configuration changes for system administrators in 0.1.3 + +#### New configuration in 0.1.3 + +* … + +#### Changed configuration in 0.1.3 + +* … + +#### Removed configuration in 0.1.3 + +* … + +### New user-facing features in 0.1.3 + +* … + +### New features for sysadmins in 0.1.3 + +* … + +### New developer features in 0.1.3 + +* … + +### Bug fixes in 0.1.3 + +* … + +### API changes in 0.1.3 + +* … + +### API internal changes in 0.1.3 + +* … + +### Languages updated in 0.1.3 + +SCAICT-uwu now supports 1 language. Many localisations are updated regularly. + +Below only new and removed languages are listed. + +* … + +### Breaking changes in 0.1.3 + +* … + +### Deprecations in 0.1.3 + +* … + +### Other changes in 0.1.3 + +* … + +## SCAICT-uwu 0.1.2 + +This is a maintenance release of SCAICT-uwu 0.1 version. + +### Configuration changes for system administrators in 0.1.2 + +#### New configuration in 0.1.2 + +* … + +#### Changed configuration in 0.1.2 + +* … + +#### Removed configuration in 0.1.2 + +* … + +### New user-facing features in 0.1.2 + +* … + +### New features for sysadmins in 0.1.2 + +* … + +### New developer features in 0.1.2 + +* … + +### Bug fixes in 0.1.2 + +* … + +### API changes in 0.1.2 + +* … + +### API internal changes in 0.1.2 + +* … + +### Languages updated in 0.1.2 + +SCAICT-uwu now supports 1 language. Many localisations are updated regularly. + +Below only new and removed languages are listed. + +* … + +### Breaking changes in 0.1.2 + +* … + +### Deprecations in 0.1.2 + +* … + +### Other changes in 0.1.2 + +* … + +## SCAICT-uwu 0.1.1 + +This is a maintenance release of SCAICT-uwu 0.1 version. + +### Configuration changes for system administrators in 0.1.1 + +#### New configuration in 0.1.1 + +* … + +#### Changed configuration in 0.1.1 + +* … + +#### Removed configuration in 0.1.1 + +* … + +### New user-facing features in 0.1.1 + +* … + +### New features for sysadmins in 0.1.1 + +* … + +### New developer features in 0.1.1 + +* … + +### Bug fixes in 0.1.1 + +* … + +### API changes in 0.1.1 + +* … + +### API internal changes in 0.1.1 + +* … + +### Languages updated in 0.1.1 + +SCAICT-uwu now supports 1 language. Many localisations are updated regularly. + +Below only new and removed languages are listed. + +* … + +### Breaking changes in 0.1.1 + +* … + +### Deprecations in 0.1.1 + +* … + +### Other changes in 0.1.1 + +* … + +## SCAICT-uwu 0.1.0 + +This is the initial release of SCAICT-uwu 0.1 version. + +### Configuration changes for system administrators in 0.1.0 + +#### New configuration in 0.1.0 + +* … + +#### Changed configuration in 0.1.0 + +* … + +#### Removed configuration in 0.1.0 + +* … + +### New user-facing features in 0.1.0 + +* … + +### New features for sysadmins in 0.1.0 + +* … + +### New developer features in 0.1.0 + +* … + +### Bug fixes in 0.1.0 + +* … + +### API changes in 0.1.0 + +* … + +### API internal changes in 0.1.0 + +* … + +### Languages updated in 0.1.0 + +SCAICT-uwu now supports 1 language. Many localisations are updated regularly. + +Below only new and removed languages are listed. + +* … + +### Breaking changes in 0.1.0 + +* … + +### Deprecations in 0.1.0 + +* … + +### Other changes in 0.1.0 + +* … From 53af08f0f33175ba6f6c37a9a5946e894f62361d Mon Sep 17 00:00:00 2001 From: Winston Sung Date: Wed, 11 Sep 2024 13:46:30 +0800 Subject: [PATCH 041/141] Complete release notes for 0.1.0 Change-Id: I009549147d4d955762759b559e51caf346aab812 --- RELEASE-NOTES-0.1.md | 60 +++----------------------------------------- 1 file changed, 4 insertions(+), 56 deletions(-) diff --git a/RELEASE-NOTES-0.1.md b/RELEASE-NOTES-0.1.md index 1473c6e..80aa673 100644 --- a/RELEASE-NOTES-0.1.md +++ b/RELEASE-NOTES-0.1.md @@ -503,60 +503,8 @@ Below only new and removed languages are listed. This is the initial release of SCAICT-uwu 0.1 version. -### Configuration changes for system administrators in 0.1.0 +### Changes in 0.1.0 -#### New configuration in 0.1.0 - -* … - -#### Changed configuration in 0.1.0 - -* … - -#### Removed configuration in 0.1.0 - -* … - -### New user-facing features in 0.1.0 - -* … - -### New features for sysadmins in 0.1.0 - -* … - -### New developer features in 0.1.0 - -* … - -### Bug fixes in 0.1.0 - -* … - -### API changes in 0.1.0 - -* … - -### API internal changes in 0.1.0 - -* … - -### Languages updated in 0.1.0 - -SCAICT-uwu now supports 1 language. Many localisations are updated regularly. - -Below only new and removed languages are listed. - -* … - -### Breaking changes in 0.1.0 - -* … - -### Deprecations in 0.1.0 - -* … - -### Other changes in 0.1.0 - -* … +* Initial commit. + * Added `LICENSE`, using Apache License Version 2.0, January 2004. + * Added `README.md`. From a9474ec163a6d5a5641c1400e9c804da2cf65c84 Mon Sep 17 00:00:00 2001 From: Winston Sung Date: Wed, 11 Sep 2024 14:37:08 +0800 Subject: [PATCH 042/141] Added draft of release notes for 0.1.1 Change-Id: I8b652a5c88e8f4d620be683bbea2373de5167fe9 --- RELEASE-NOTES-0.1.md | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/RELEASE-NOTES-0.1.md b/RELEASE-NOTES-0.1.md index 80aa673..620c991 100644 --- a/RELEASE-NOTES-0.1.md +++ b/RELEASE-NOTES-0.1.md @@ -497,6 +497,41 @@ Below only new and removed languages are listed. ### Other changes in 0.1.1 +* Added dynamic voice channel and support ticket feature. +* Added `.gitignore` to ignore token files. +* Added `.gitignore` to ignore cache files. +* Added channel member display. +* Added CTF features. +* self problem. +* Updated CTF features wip (can create and list). +* independent update channel. +* Passing bot attributes. +* Added comment, check_point and daily_charge Python modules. +* Added JSON file as initial database. +* Added user Python module. +* Migrated use of user functions to user Python module. +* Rewrote the daily charge feature. +* Completed CTF features. +* Fixed counting error, only replyer sees message. +* Added initial website using Flask. +* Completed course role features. +* Updated design of SCAICT Store. +* Updated to use JSON file to get CTF maker role ID. +* Updated the support ticket embed description. +* Updated to limit the usage of daily change command to specific channel. +* Completed SCAICT Store. +* Added lottery slot feature in SCAICT Store. +* Added SQL database. +* Migrated user.json to SQL database. +* Added exception handling for data not found issues. +* Renamed SQL column name from `user_id` to `uid`. +* Added support for bot status/presence. +* Added zap emoji. +* Added Google Analytics. +* Added total point status display. +* Dropped support for `user.json`, use SQL database instead. +* Fixed issue caused by users without avatar set. +* Updated CTF features. * … ## SCAICT-uwu 0.1.0 From df05ba9693d31eeedffcc99d689d4db95a2cb847 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 13 Sep 2024 01:35:35 +0000 Subject: [PATCH 043/141] Bump urllib3 from 2.2.2 to 2.2.3 Bumps [urllib3](https://github.com/urllib3/urllib3) from 2.2.2 to 2.2.3. - [Release notes](https://github.com/urllib3/urllib3/releases) - [Changelog](https://github.com/urllib3/urllib3/blob/main/CHANGES.rst) - [Commits](https://github.com/urllib3/urllib3/compare/2.2.2...2.2.3) --- updated-dependencies: - dependency-name: urllib3 dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index fbed878..1534c65 100644 --- a/requirements.txt +++ b/requirements.txt @@ -18,6 +18,6 @@ mysql-connector-python == 8.4.0 py-cord == 2.6.0 python-dotenv == 1.0.1 requests == 2.32.3 -urllib3 == 2.2.2 +urllib3 == 2.2.3 werkzeug == 3.0.4 yarl == 1.11.1 From bef06d8d0d784cb0c62adcedc7d7968ce6f37f6e Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 16 Sep 2024 01:54:13 +0000 Subject: [PATCH 044/141] Bump idna from 3.8 to 3.10 Bumps [idna](https://github.com/kjd/idna) from 3.8 to 3.10. - [Release notes](https://github.com/kjd/idna/releases) - [Changelog](https://github.com/kjd/idna/blob/master/HISTORY.rst) - [Commits](https://github.com/kjd/idna/compare/v3.8...v3.10) --- updated-dependencies: - dependency-name: idna dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index 1534c65..e90ceff 100644 --- a/requirements.txt +++ b/requirements.txt @@ -9,7 +9,7 @@ click == 8.1.7 colorama == 0.4.6 flask == 3.0.3 frozenlist == 1.4.1 -idna == 3.8 +idna == 3.10 itsdangerous == 2.2.0 jinja2 == 3.1.4 markupsafe == 2.1.5 From d30362ecd2a855ad56e55dea32532968b2883182 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 16 Sep 2024 03:35:46 +0000 Subject: [PATCH 045/141] Bump py-cord from 2.6.0 to 2.6.1 Bumps [py-cord](https://github.com/Pycord-Development/pycord) from 2.6.0 to 2.6.1. - [Release notes](https://github.com/Pycord-Development/pycord/releases) - [Changelog](https://github.com/Pycord-Development/pycord/blob/master/CHANGELOG.md) - [Commits](https://github.com/Pycord-Development/pycord/compare/v2.6.0...v2.6.1) --- updated-dependencies: - dependency-name: py-cord dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- pyproject.toml | 2 +- requirements.txt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 8e36e67..661cd1d 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -30,7 +30,7 @@ urls.issues = "https://github.com/SCAICT/SCAICT-uwu/issues" dependencies = [ "flask == 3.0.3", "mysql-connector-python == 8.4.0", - "py-cord == 2.6.0", + "py-cord == 2.6.1", "python-dotenv == 1.0.1", "requests == 2.32.3", ] diff --git a/requirements.txt b/requirements.txt index e90ceff..9aa80f1 100644 --- a/requirements.txt +++ b/requirements.txt @@ -15,7 +15,7 @@ jinja2 == 3.1.4 markupsafe == 2.1.5 multidict == 6.1.0 mysql-connector-python == 8.4.0 -py-cord == 2.6.0 +py-cord == 2.6.1 python-dotenv == 1.0.1 requests == 2.32.3 urllib3 == 2.2.3 From fef4eefa538e96b53910654c615388ccbca01b22 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 16 Sep 2024 03:38:36 +0000 Subject: [PATCH 046/141] Bump platformdirs from 4.3.2 to 4.3.3 Bumps [platformdirs](https://github.com/tox-dev/platformdirs) from 4.3.2 to 4.3.3. - [Release notes](https://github.com/tox-dev/platformdirs/releases) - [Changelog](https://github.com/tox-dev/platformdirs/blob/main/CHANGES.rst) - [Commits](https://github.com/tox-dev/platformdirs/compare/4.3.2...4.3.3) --- updated-dependencies: - dependency-name: platformdirs dependency-type: direct:development update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- requirements_dev.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements_dev.txt b/requirements_dev.txt index e269f09..5373773 100644 --- a/requirements_dev.txt +++ b/requirements_dev.txt @@ -9,7 +9,7 @@ mccabe == 0.7.0 mypy-extensions == 1.0.0 packaging == 24.1 pathspec == 0.12.1 -platformdirs == 4.3.2 +platformdirs == 4.3.3 pluggy == 1.5.0 pylint == 3.2.7 pytest == 8.3.3 From b15750be03957ddad676d8fcf79fc9f86e441fe3 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 18 Sep 2024 01:32:55 +0000 Subject: [PATCH 047/141] Bump platformdirs from 4.3.3 to 4.3.6 Bumps [platformdirs](https://github.com/tox-dev/platformdirs) from 4.3.3 to 4.3.6. - [Release notes](https://github.com/tox-dev/platformdirs/releases) - [Changelog](https://github.com/tox-dev/platformdirs/blob/main/CHANGES.rst) - [Commits](https://github.com/tox-dev/platformdirs/compare/4.3.3...4.3.6) --- updated-dependencies: - dependency-name: platformdirs dependency-type: direct:development update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- requirements_dev.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements_dev.txt b/requirements_dev.txt index 5373773..78ee85e 100644 --- a/requirements_dev.txt +++ b/requirements_dev.txt @@ -9,7 +9,7 @@ mccabe == 0.7.0 mypy-extensions == 1.0.0 packaging == 24.1 pathspec == 0.12.1 -platformdirs == 4.3.3 +platformdirs == 4.3.6 pluggy == 1.5.0 pylint == 3.2.7 pytest == 8.3.3 From 11302f7804d3b88e22651305c093ddef4c9a1b61 Mon Sep 17 00:00:00 2001 From: Winston Sung Date: Fri, 20 Sep 2024 14:42:07 +0800 Subject: [PATCH 048/141] Fix README formatting Change-Id: I3f29971c19d22bfe2ceec70d11f0550d1b292e09 --- README.md | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index f6fae6b..fe8d93c 100644 --- a/README.md +++ b/README.md @@ -5,17 +5,18 @@ 中電喵 SCAICT uwu # 中電喵 SCAICT uwu -[![同步代辦事項至 Notion](https://github.com/SCAICT/SCAICT-uwu/actions/workflows/notion.yml/badge.svg?event=issues)](https://github.com/SCAICT/SCAICT-uwu/actions/workflows/notion.yml) -[![website](https://img.shields.io/website?label=website&&url=https%3A%2F%2Fscaict.org%2F)](https://scaict.org/) -[![SCAICT store](https://img.shields.io/website?label=SCAICT-store&&url=https%3A%2F%2Fstore.scaict.org%2F)](https://store.scaict.org/) -[![document](https://img.shields.io/website?label=Document&&url=https%3A%2F%2Fstore.scaict.org%2F)](https://g.scaict.org/doc/) -[![Join Discord](https://img.shields.io/discord/959823904266944562?label=Discord&logo=discord&)](https://dc.scaict.org) -[![follow Instagram](https://img.shields.io/badge/follow-%40scaict.tw-pink?&logo=instagram)](https://www.instagram.com/scaict.tw/) - +[![Sync issues to Notion](https://github.com/SCAICT/SCAICT-uwu/actions/workflows/notion.yml/badge.svg?event=issues)](https://github.com/SCAICT/SCAICT-uwu/actions/workflows/notion.yml) +[![Website](https://img.shields.io/website?label=Website&&url=https%3A%2F%2Fscaict.org%2F)](https://scaict.org/) +[![SCAICT store](https://img.shields.io/website?label=SCAICT+store&&url=https%3A%2F%2Fstore.scaict.org%2F)](https://store.scaict.org/) +[![Documentation](https://img.shields.io/website?label=Documentation&&url=https%3A%2F%2Fstore.scaict.org%2F)](https://g.scaict.org/doc/) +[![Join Discord server](https://img.shields.io/discord/959823904266944562?label=Discord&logo=discord&)](https://dc.scaict.org) +[![Follow Instagram](https://img.shields.io/badge/Follow-%40scaict.tw-pink?&logo=instagram)](https://www.instagram.com/scaict.tw/) + # SCAICT-uwu + SCAICT-uwu is a playful and interactive Discord bot that resides in the SCAICT Discord community. Designed to bring fun and utility to its users, SCAICT-uwu loves to sing, dance, code, and do math, making it an engaging companion for the community members. ## Overview @@ -23,6 +24,7 @@ SCAICT-uwu is a playful and interactive Discord bot that resides in the SCAICT D SCAICT-uwu offers a range of interactive features, from daily activities to coding challenges. Whether you want to play games, solve puzzles, or simply chat, SCAICT-uwu is always ready to respond to your commands. ### About SCAICT + SCAICT, the Student Club Information Association of Central Taiwan, is an electronic engineering club composed of schools from central Taiwan. By combining the resources of the Central District, we actively organize educational events, activities, and competitions related to information technology, with the goal of facilitating the flow of technology and knowledge. ## Features @@ -41,8 +43,11 @@ Interact with SCAICT-uwu using slash commands in any channel where the bot is ac Some interactions with SCAICT-uwu occur within dedicated channels, allowing for more focused activities such as guessing colors or counting. ![color guess](https://raw.githubusercontent.com/SCAICT/doc/main/static/img/color-demo.gif) + ### Store + #### Buy somthing + You can buy some products like our stickers or USB drives using Electric Points. Note that the products currently can only be exchanged during in-person events. We will soon offer shipping options and more virtual rewards for redemption.
@@ -52,6 +57,7 @@ You can buy some products like our stickers or USB drives using Electric Points.
#### Play slot + Get some tickets, and you can play the slot machine to earn Electric Points. Just long press to start the slot.
@@ -60,12 +66,11 @@ Get some tickets, and you can play the slot machine to earn Electric Points. Jus
## Getting Started -1. **Join the Server** - Start by joining the SCAICT Discord community using this [link](https://dc.scaict.org). +1. **Join the Server** + Start by joining the SCAICT Discord community using this [link](https://dc.scaict.org). 2. **Earn Your First Electric Points** Visit the `#daily-charge` channel and use the `/charge` command to receive your first set of Electric Points, the primary currency used within the bot's ecosystem. - 3. **Enjoy in Services** Explore the various commands and interactions SCAICT-uwu offers, and enjoy the space within the server, engaging and connecting with everyone. @@ -129,9 +134,8 @@ Get some tickets, and you can play the slot machine to earn Electric Points. Jus "element": [ percentage, reward ] } ``` -> For more detailed documentation, please refer to [this link](https://g.scaict.org/doc/docs/category/%E9%96%8B%E7%99%BC%E8%80%85%E5%B0%88%E5%8D%80) - +> For more detailed documentation, please refer to [this link](https://g.scaict.org/doc/docs/category/%E9%96%8B%E7%99%BC%E8%80%85%E5%B0%88%E5%8D%80) ## Acknowledgements From d38a29033a26e8b06dfd960a3379ae4040dbfd67 Mon Sep 17 00:00:00 2001 From: Winston Sung Date: Fri, 20 Sep 2024 15:29:16 +0800 Subject: [PATCH 049/141] docs: Update database schema Based on table_struct.sql generated on 2024-08-20 19:32:15 Change-Id: I3bcb7c22022dc741352bfedfc845f626d42f2d3c --- docs/abstract_schema_table.json | 10 +- src/scaict_uwu/maintenance/data/tables.json | 294 +++++++++++++++++++- 2 files changed, 301 insertions(+), 3 deletions(-) diff --git a/docs/abstract_schema_table.json b/docs/abstract_schema_table.json index 0544acb..c53a91f 100644 --- a/docs/abstract_schema_table.json +++ b/docs/abstract_schema_table.json @@ -1,7 +1,7 @@ { "$schema": "https://json-schema.org/schema#", "description": "Abstract description of a scaict-uwu database table, derived from MediaWiki database table schema", - "type": "object", + "type": "array", "additionalProperties": false, "properties": { "name": { @@ -41,6 +41,7 @@ "datetime", "datetimetz", "decimal", + "enum", "float", "integer", "smallint", @@ -79,6 +80,13 @@ "default": null, "minimum": 0 }, + "enum": { + "type": "array", + "items": { + "type": "string" + }, + "uniqueItems": true + }, "notnull": { "type": "boolean", "description": "Indicates whether the column is nullable or not", diff --git a/src/scaict_uwu/maintenance/data/tables.json b/src/scaict_uwu/maintenance/data/tables.json index 4f5049f..566b2de 100644 --- a/src/scaict_uwu/maintenance/data/tables.json +++ b/src/scaict_uwu/maintenance/data/tables.json @@ -3,6 +3,15 @@ "name": "user", "comment": "The user table contains basic user information, user properties, etc.", "columns": [ + { + "name": "DCname", + "comment": "", + "type": "string", + "options": { + "length": 32, + "default": null + } + }, { "name": "uid", "comment": "Primary key", @@ -11,6 +20,33 @@ "notnull": true } }, + { + "name": "DCMail", + "comment": "", + "type": "string", + "options": { + "length": 320, + "default": null + } + }, + { + "name": "githubName", + "comment": "", + "type": "string", + "options": { + "length": 39, + "default": null + } + }, + { + "name": "githubMail", + "comment": "", + "type": "string", + "options": { + "length": 320, + "default": null + } + }, { "name": "loveuwu", "comment": "", @@ -36,7 +72,7 @@ "type": "integer", "options": { "notnull": true, - "default": 0 + "default": 1 } }, { @@ -99,7 +135,8 @@ "comment": "Primary key", "type": "integer", "options": { - "autoincrement": true + "autoincrement": true, + "notnull": true } }, { @@ -133,5 +170,258 @@ "pk": [ "seq" ] + }, + { + "name": "game", + "comment": "", + "columns": [ + { + "name": "seq", + "comment": "", + "type": "bigint", + "options": { + "notnull": true, + "default": 0 + } + }, + { + "name": "lastID", + "comment": "", + "type": "bigint", + "options": { + "default": 0 + } + }, + { + "name": "niceColor", + "comment": "", + "type": "string", + "options": { + "length": 3, + "notnull": true, + "default": "FFF" + } + }, + { + "name": "nicecolorround", + "comment": "", + "type": "integer", + "options": { + "default": null + } + }, + { + "name": "niceColorCount", + "comment": "", + "type": "bigint", + "options": { + "default": 0 + } + } + ], + "indexes": [], + "pk": [] + }, + { + "name": "gift", + "comment": "", + "columns": [ + { + "name": "btnID", + "comment": "Primary key", + "type": "bigint", + "options": { + "notnull": true + } + }, + { + "name": "type", + "comment": "", + "type": "enum", + "options": { + "enum": [ + "電電點", + "抽獎券" + ], + "default": null + } + }, + { + "name": "count", + "comment": "", + "type": "integer", + "options": { + "default": null + } + }, + { + "name": "recipient", + "comment": "", + "type": "string", + "options": { + "length": 32, + "default": null + } + }, + { + "name": "received", + "comment": "", + "type": "tinyint", + "options": { + "length": 1, + "default": 0 + } + }, + { + "name": "sender", + "comment": "", + "type": "string", + "options": { + "length": 32, + "default": "admin" + } + } + ], + "indexes": [], + "pk": [ + "btnID" + ] + }, + { + "name": "ctf_data", + "comment": "", + "columns": [ + { + "name": "id", + "comment": "Primary key", + "type": "bigint", + "options": { + "notnull": true + } + }, + { + "name": "flags", + "comment": "", + "type": "string", + "options": { + "length": 255, + "default": null + } + }, + { + "name": "score", + "comment": "", + "type": "integer", + "options": { + "default": null + } + }, + { + "name": "restrictions", + "comment": "", + "type": "string", + "options": { + "length": 255, + "default": null + } + }, + { + "name": "message_id", + "comment": "", + "type": "bigint", + "options": { + "default": null + } + }, + { + "name": "case_status", + "comment": "", + "type": "tinyint", + "options": { + "length": 1, + "default": null + } + }, + { + "name": "start_time", + "comment": "", + "type": "datetime", + "options": { + "default": null + } + }, + { + "name": "end_time", + "comment": "", + "type": "string", + "options": { + "length": 255, + "default": null + } + }, + { + "name": "title", + "comment": "", + "type": "string", + "options": { + "length": 255, + "default": null + } + }, + { + "name": "tried", + "comment": "", + "type": "integer", + "options": { + "default": null + } + } + ], + "indexes": [], + "pk": [ + "seq" + ] + }, + { + "name": "ctf_history", + "comment": "", + "columns": [ + { + "name": "data_id", + "comment": "Foreign key", + "type": "bigint", + "options": { + "default": null + } + }, + { + "name": "uid", + "comment": "", + "type": "bigint", + "options": { + "default": null + } + }, + { + "name": "count", + "comment": "", + "type": "integer", + "options": { + "default": null + } + }, + { + "name": "solved", + "comment": "", + "type": "tinyint", + "options": { + "length": 1, + "notnull": true, + "default": 0 + } + } + ], + "indexes": [], + "pk": [] } ] From fa775bce23c47127822f7ebcd5c781ae5fa4eb5a Mon Sep 17 00:00:00 2001 From: Winston Sung Date: Fri, 20 Sep 2024 15:41:58 +0800 Subject: [PATCH 050/141] docs: Create tables_diagram_layout.json Change-Id: I0313c240f51365f737c8b70fe16c30fa8266783d --- .../data/tables_diagram_layout.json | 38 +++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 src/scaict_uwu/maintenance/data/tables_diagram_layout.json diff --git a/src/scaict_uwu/maintenance/data/tables_diagram_layout.json b/src/scaict_uwu/maintenance/data/tables_diagram_layout.json new file mode 100644 index 0000000..a720fb0 --- /dev/null +++ b/src/scaict_uwu/maintenance/data/tables_diagram_layout.json @@ -0,0 +1,38 @@ +[ + { + "title": "User", + "color": "#dafdd5", + "tables": [ + [ "user" ] + ] + }, + { + "title": "Comment points", + "color": "#eaf3ff", + "tables": [ + [ "comment_points" ] + ] + }, + { + "title": "Game", + "color": "#eaf3ff", + "tables": [ + [ "game" ] + ] + }, + { + "title": "Gift", + "color": "#eaf3ff", + "tables": [ + [ "gift" ] + ] + }, + { + "title": "CTF", + "color": "#fef6e7", + "tables": [ + [ "ctf_data" ], + [ "ctf_history" ] + ] + } +] From 61d225b29623b495e6f6366329f0669f9e5ad460 Mon Sep 17 00:00:00 2001 From: Winston Sung Date: Fri, 20 Sep 2024 16:04:32 +0800 Subject: [PATCH 051/141] docs: Add database_layout.html Change-Id: I79e775a373b1467557928c078e74f4c8777fce38 --- docs/database_layout.html | 335 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 335 insertions(+) create mode 100644 docs/database_layout.html diff --git a/docs/database_layout.html b/docs/database_layout.html new file mode 100644 index 0000000..2f9759a --- /dev/null +++ b/docs/database_layout.html @@ -0,0 +1,335 @@ + + + + +SCAICT-uwu database table layout diagram + + + +
+
+

Database schema of SCAICT-uwu.

+
+
+
+
+

User

+
+ + + + + + +
+
+
+

user

+
+
    +
  • DCname STRING(32)
  • +
  • uid BIGINT
  • +
  • DCMail STRING(320)
  • +
  • githubName STRING(39)
  • +
  • githubMail STRING(320)
  • +
  • loveuwu TINYINT(1)
  • +
  • point INT
  • +
  • ticket INT
  • +
  • charge_combo INT
  • +
  • next_lottery INT
  • +
  • last_charge DATETIME
  • +
  • last_comment DATE
  • +
  • today_comments INT
  • +
+
+
+
+
+
+

Comment points

+
+ + + + + + +
+
+
+

comment_points

+
+
    +
  • + seq INT
  • +
  • uid BIGINT
  • +
  • times INT
  • +
  • next_reward INT
  • +
+
+
+
+
+
+

Game

+
+ + + + + + +
+
+
+

game

+
+
    +
  • + seq BIGINT
  • +
  • lastID BIGINT
  • +
  • niceColor STRING(3)
  • +
  • nicecolorround INT
  • +
  • niceColorCount BIGINT
  • +
+
+
+
+
+
+

Gift

+
+ + + + + + +
+
+
+

gift

+
+
    +
  • + btnID BIGINT
  • +
  • type ENUM
  • +
  • count INT
  • +
  • recipient STRING(32)
  • +
  • received TINYINT(1)
  • +
  • sender STRING(32)
  • +
+
+
+
+
+
+

CTF

+
+ + + + + + + +
+
+
+

ctf_data

+
+
    +
  • + id BIGINT
  • +
  • flags STRING(255)
  • +
  • score INT
  • +
  • restrictions STRING(255)
  • +
  • message_id BIGINT
  • +
  • case_status TINYINT(1)
  • +
  • start_time DATETIME
  • +
  • end_time STRING(255)
  • +
  • title STRING(255)
  • +
  • tried INT
  • +
+
+
+
+
+

ctf_history

+
+
    +
  • + data_id BIGINT
  • +
  • uid BIGINT
  • +
  • count INT
  • +
  • solved TINYINT(1)
  • +
+
+
+
+
+

+
+ + From 2ae86dc30dec12d7748bdc796d1f1f85dd479ea7 Mon Sep 17 00:00:00 2001 From: Winston Sung Date: Sat, 21 Sep 2024 20:56:39 +0800 Subject: [PATCH 052/141] docs: Update database_layout.html Change-Id: I4fd9d8ee9f71d3b3c1d9e0e36cb0c92c51a227d4 --- docs/database_layout.html | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/docs/database_layout.html b/docs/database_layout.html index 2f9759a..5feb469 100644 --- a/docs/database_layout.html +++ b/docs/database_layout.html @@ -185,11 +185,11 @@

User

user

    -
  • DCname STRING(32)
  • +
  • DCname VARCHAR(32)
  • uid BIGINT
  • -
  • DCMail STRING(320)
  • -
  • githubName STRING(39)
  • -
  • githubMail STRING(320)
  • +
  • DCMail VARCHAR(320)
  • +
  • githubName VARCHAR(39)
  • +
  • githubMail VARCHAR(320)
  • loveuwu TINYINT(1)
  • point INT
  • ticket INT
  • @@ -246,7 +246,7 @@

    game

  • seq BIGINT
  • lastID BIGINT
  • -
  • niceColor STRING(3)
  • +
  • niceColor VARCHAR(3)
  • nicecolorround INT
  • niceColorCount BIGINT
@@ -271,11 +271,11 @@

gift

  • btnID BIGINT
  • -
  • type ENUM
  • +
  • type ENUM(…)
  • count INT
  • -
  • recipient STRING(32)
  • +
  • recipient VARCHAR(32)
  • received TINYINT(1)
  • -
  • sender STRING(32)
  • +
  • sender VARCHAR(32)
@@ -298,14 +298,14 @@

ctf_data

  • id BIGINT
  • -
  • flags STRING(255)
  • +
  • flags VARCHAR(255)
  • score INT
  • -
  • restrictions STRING(255)
  • +
  • restrictions VARCHAR(255)
  • message_id BIGINT
  • case_status TINYINT(1)
  • start_time DATETIME
  • -
  • end_time STRING(255)
  • -
  • title STRING(255)
  • +
  • end_time VARCHAR(255)
  • +
  • title VARCHAR(255)
  • tried INT
From aec6521a3525f7bd7887f963472c6432069861a4 Mon Sep 17 00:00:00 2001 From: Winston Sung Date: Sat, 21 Sep 2024 21:02:10 +0800 Subject: [PATCH 053/141] docs: Update README Change-Id: Ib8ebd00068a9a7510cd6d606aef66f292f24d663 --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index fe8d93c..f4866bd 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,7 @@ [![Sync issues to Notion](https://github.com/SCAICT/SCAICT-uwu/actions/workflows/notion.yml/badge.svg?event=issues)](https://github.com/SCAICT/SCAICT-uwu/actions/workflows/notion.yml) [![Website](https://img.shields.io/website?label=Website&&url=https%3A%2F%2Fscaict.org%2F)](https://scaict.org/) -[![SCAICT store](https://img.shields.io/website?label=SCAICT+store&&url=https%3A%2F%2Fstore.scaict.org%2F)](https://store.scaict.org/) +[![SCAICT Store](https://img.shields.io/website?label=SCAICT+store&&url=https%3A%2F%2Fstore.scaict.org%2F)](https://store.scaict.org/) [![Documentation](https://img.shields.io/website?label=Documentation&&url=https%3A%2F%2Fstore.scaict.org%2F)](https://g.scaict.org/doc/) [![Join Discord server](https://img.shields.io/discord/959823904266944562?label=Discord&logo=discord&)](https://dc.scaict.org) [![Follow Instagram](https://img.shields.io/badge/Follow-%40scaict.tw-pink?&logo=instagram)](https://www.instagram.com/scaict.tw/) From aedb576779139d2987de3f2d1c43baab0c6dccce Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 23 Sep 2024 01:35:37 +0000 Subject: [PATCH 054/141] Bump pylint from 3.2.7 to 3.3.0, astroid from 3.2.4 to 3.3.3 Bumps [pylint](https://github.com/pylint-dev/pylint) from 3.2.7 to 3.3.0. - [Release notes](https://github.com/pylint-dev/pylint/releases) - [Commits](https://github.com/pylint-dev/pylint/compare/v3.2.7...v3.3.0) Bumps [astroid](https://github.com/pylint-dev/astroid) from 3.2.4 to 3.3.3. - [Release notes](https://github.com/pylint-dev/astroid/releases) - [Changelog](https://github.com/pylint-dev/astroid/blob/main/ChangeLog) - [Commits](https://github.com/pylint-dev/astroid/compare/v3.2.4...v3.3.3) --- updated-dependencies: - dependency-name: pylint dependency-type: direct:development update-type: version-update:semver-minor ... - dependency-name: astroid dependency-type: direct:development update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- pyproject.toml | 2 +- requirements_dev.txt | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 661cd1d..e33c701 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -37,6 +37,6 @@ dependencies = [ # Lock file: requirements_dev.txt optional-dependencies.dev = [ "black == 24.8.0", - "pylint == 3.2.7", + "pylint == 3.3.0", "pytest == 8.3.3", ] diff --git a/requirements_dev.txt b/requirements_dev.txt index 78ee85e..1b12fee 100644 --- a/requirements_dev.txt +++ b/requirements_dev.txt @@ -1,4 +1,4 @@ -astroid == 3.2.4 +astroid == 3.3.3 black == 24.8.0 click == 8.1.7 colorama == 0.4.6 @@ -11,6 +11,6 @@ packaging == 24.1 pathspec == 0.12.1 platformdirs == 4.3.6 pluggy == 1.5.0 -pylint == 3.2.7 +pylint == 3.3.0 pytest == 8.3.3 tomlkit == 0.13.2 From 04782b50317326071e20d46291ee2601bc2c87f0 Mon Sep 17 00:00:00 2001 From: Winston Sung Date: Mon, 23 Sep 2024 14:38:32 +0800 Subject: [PATCH 055/141] Disable Pylint too-many-positional-arguments for slash_command - class_role - ctf Change-Id: Ifa3f67639c771ee8f84c9b3caa5c5224a9f16309 --- cog/class_role.py | 2 +- cog/ctf.py | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/cog/class_role.py b/cog/class_role.py index 14de07d..df71b41 100644 --- a/cog/class_role.py +++ b/cog/class_role.py @@ -124,7 +124,7 @@ async def send_modal(self, ctx): await ctx.send(embed=embed, view=self.TokenVerifyButton()) @discord.slash_command(description="新增主題課程") - # pylint: disable-next = too-many-arguments + # pylint: disable-next = too-many-arguments, too-many-positional-arguments async def add_class( self, ctx, class_code: str, name: str, theme: str, teacher: str, time: str ): diff --git a/cog/ctf.py b/cog/ctf.py index dff0416..1dd2826 100644 --- a/cog/ctf.py +++ b/cog/ctf.py @@ -279,6 +279,7 @@ async def callback(self, interaction: discord.Interaction) -> None: @ctf_commands.command(name="create", description="新題目") # 新增題目 + # pylint: disable-next = too-many-positional-arguments async def create( self, ctx, From a372437f3151ea0c3ecf7536c96367b3b985b70b Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 24 Sep 2024 01:34:50 +0000 Subject: [PATCH 056/141] Bump yarl from 1.11.1 to 1.12.1 Bumps [yarl](https://github.com/aio-libs/yarl) from 1.11.1 to 1.12.1. - [Release notes](https://github.com/aio-libs/yarl/releases) - [Changelog](https://github.com/aio-libs/yarl/blob/master/CHANGES.rst) - [Commits](https://github.com/aio-libs/yarl/compare/v1.11.1...v1.12.1) --- updated-dependencies: - dependency-name: yarl dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index 9aa80f1..4431e43 100644 --- a/requirements.txt +++ b/requirements.txt @@ -20,4 +20,4 @@ python-dotenv == 1.0.1 requests == 2.32.3 urllib3 == 2.2.3 werkzeug == 3.0.4 -yarl == 1.11.1 +yarl == 1.12.1 From b1507d93c770d50e1b720bc52088f072903238c0 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 24 Sep 2024 02:59:34 +0000 Subject: [PATCH 057/141] Bump astroid from 3.3.3 to 3.3.4 Bumps [astroid](https://github.com/pylint-dev/astroid) from 3.3.3 to 3.3.4. - [Release notes](https://github.com/pylint-dev/astroid/releases) - [Changelog](https://github.com/pylint-dev/astroid/blob/main/ChangeLog) - [Commits](https://github.com/pylint-dev/astroid/compare/v3.3.3...v3.3.4) --- updated-dependencies: - dependency-name: astroid dependency-type: direct:development update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- requirements_dev.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements_dev.txt b/requirements_dev.txt index 1b12fee..e5844c7 100644 --- a/requirements_dev.txt +++ b/requirements_dev.txt @@ -1,4 +1,4 @@ -astroid == 3.3.3 +astroid == 3.3.4 black == 24.8.0 click == 8.1.7 colorama == 0.4.6 From 8ba6cedc4cebc3f0e56b602b0d4da8e686983c37 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 25 Sep 2024 01:41:31 +0000 Subject: [PATCH 058/141] Bump pylint from 3.3.0 to 3.3.1 Bumps [pylint](https://github.com/pylint-dev/pylint) from 3.3.0 to 3.3.1. - [Release notes](https://github.com/pylint-dev/pylint/releases) - [Commits](https://github.com/pylint-dev/pylint/compare/v3.3.0...v3.3.1) --- updated-dependencies: - dependency-name: pylint dependency-type: direct:development update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- pyproject.toml | 2 +- requirements_dev.txt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index e33c701..64ded98 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -37,6 +37,6 @@ dependencies = [ # Lock file: requirements_dev.txt optional-dependencies.dev = [ "black == 24.8.0", - "pylint == 3.3.0", + "pylint == 3.3.1", "pytest == 8.3.3", ] diff --git a/requirements_dev.txt b/requirements_dev.txt index e5844c7..a77ff49 100644 --- a/requirements_dev.txt +++ b/requirements_dev.txt @@ -11,6 +11,6 @@ packaging == 24.1 pathspec == 0.12.1 platformdirs == 4.3.6 pluggy == 1.5.0 -pylint == 3.3.0 +pylint == 3.3.1 pytest == 8.3.3 tomlkit == 0.13.2 From 206276c4eee98e21fee30ab0b39e694eac20fff5 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 25 Sep 2024 12:19:38 +0000 Subject: [PATCH 059/141] Bump aiohttp from 3.10.5 to 3.10.6 Bumps [aiohttp](https://github.com/aio-libs/aiohttp) from 3.10.5 to 3.10.6. - [Release notes](https://github.com/aio-libs/aiohttp/releases) - [Changelog](https://github.com/aio-libs/aiohttp/blob/master/CHANGES.rst) - [Commits](https://github.com/aio-libs/aiohttp/compare/v3.10.5...v3.10.6) --- updated-dependencies: - dependency-name: aiohttp dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index 4431e43..55893a1 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,5 +1,5 @@ aiohappyeyeballs == 2.4.0 -aiohttp == 3.10.5 +aiohttp == 3.10.6 aiosignal == 1.3.1 attrs == 24.2.0 blinker == 1.8.2 From f3617174a95126b9e3ff612f6a2b7a7d16afdc1f Mon Sep 17 00:00:00 2001 From: Winston Sung Date: Wed, 25 Sep 2024 20:18:21 +0800 Subject: [PATCH 060/141] Packaging: Prepare src layout migration Change-Id: I32db111a9784e876b191d0242273fb029dba6af7 --- src/scaict_uwu/bot/{cog => cogs}/__init__.py | 0 src/scaict_uwu/bot/slash_commands/__init__.py | 0 2 files changed, 0 insertions(+), 0 deletions(-) rename src/scaict_uwu/bot/{cog => cogs}/__init__.py (100%) create mode 100644 src/scaict_uwu/bot/slash_commands/__init__.py diff --git a/src/scaict_uwu/bot/cog/__init__.py b/src/scaict_uwu/bot/cogs/__init__.py similarity index 100% rename from src/scaict_uwu/bot/cog/__init__.py rename to src/scaict_uwu/bot/cogs/__init__.py diff --git a/src/scaict_uwu/bot/slash_commands/__init__.py b/src/scaict_uwu/bot/slash_commands/__init__.py new file mode 100644 index 0000000..e69de29 From 6ac096120b6ce0aece037c54ec8ca1e1f6867a0b Mon Sep 17 00:00:00 2001 From: Winston Sung Date: Wed, 25 Sep 2024 20:25:47 +0800 Subject: [PATCH 061/141] docs: Update RELEASE-NOTES-0.1 Change-Id: I422f7aec4193785b95ac39059c4bc6d934086ed7 --- RELEASE-NOTES-0.1.md | 28 ---------------------------- 1 file changed, 28 deletions(-) diff --git a/RELEASE-NOTES-0.1.md b/RELEASE-NOTES-0.1.md index 620c991..a458e4b 100644 --- a/RELEASE-NOTES-0.1.md +++ b/RELEASE-NOTES-0.1.md @@ -111,10 +111,6 @@ This is a maintenance release of SCAICT-uwu 0.1 version. SCAICT-uwu now supports 1 language. Many localisations are updated regularly. -Below only new and removed languages are listed. - -* … - ### Breaking changes in 0.1.7 * … @@ -173,10 +169,6 @@ This is a maintenance release of SCAICT-uwu 0.1 version. SCAICT-uwu now supports 1 language. Many localisations are updated regularly. -Below only new and removed languages are listed. - -* … - ### Breaking changes in 0.1.6 * … @@ -235,10 +227,6 @@ This is a maintenance release of SCAICT-uwu 0.1 version. SCAICT-uwu now supports 1 language. Many localisations are updated regularly. -Below only new and removed languages are listed. - -* … - ### Breaking changes in 0.1.5 * … @@ -297,10 +285,6 @@ This is a maintenance release of SCAICT-uwu 0.1 version. SCAICT-uwu now supports 1 language. Many localisations are updated regularly. -Below only new and removed languages are listed. - -* … - ### Breaking changes in 0.1.4 * … @@ -359,10 +343,6 @@ This is a maintenance release of SCAICT-uwu 0.1 version. SCAICT-uwu now supports 1 language. Many localisations are updated regularly. -Below only new and removed languages are listed. - -* … - ### Breaking changes in 0.1.3 * … @@ -421,10 +401,6 @@ This is a maintenance release of SCAICT-uwu 0.1 version. SCAICT-uwu now supports 1 language. Many localisations are updated regularly. -Below only new and removed languages are listed. - -* … - ### Breaking changes in 0.1.2 * … @@ -483,10 +459,6 @@ This is a maintenance release of SCAICT-uwu 0.1 version. SCAICT-uwu now supports 1 language. Many localisations are updated regularly. -Below only new and removed languages are listed. - -* … - ### Breaking changes in 0.1.1 * … From 84f9b234e733a4ea41483f6856376b87b0b31721 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 27 Sep 2024 01:40:43 +0000 Subject: [PATCH 062/141] Bump aiohappyeyeballs from 2.4.0 to 2.4.2 Bumps [aiohappyeyeballs](https://github.com/aio-libs/aiohappyeyeballs) from 2.4.0 to 2.4.2. - [Release notes](https://github.com/aio-libs/aiohappyeyeballs/releases) - [Changelog](https://github.com/aio-libs/aiohappyeyeballs/blob/main/CHANGELOG.md) - [Commits](https://github.com/aio-libs/aiohappyeyeballs/compare/v2.4.0...v2.4.2) --- updated-dependencies: - dependency-name: aiohappyeyeballs dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index 55893a1..bb2019c 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,4 @@ -aiohappyeyeballs == 2.4.0 +aiohappyeyeballs == 2.4.2 aiohttp == 3.10.6 aiosignal == 1.3.1 attrs == 24.2.0 From 6b179fba1aa9c9554c8f667864f5da6b059a5c3a Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 27 Sep 2024 13:13:14 +0000 Subject: [PATCH 063/141] Bump yarl from 1.12.1 to 1.13.0 Bumps [yarl](https://github.com/aio-libs/yarl) from 1.12.1 to 1.13.0. - [Release notes](https://github.com/aio-libs/yarl/releases) - [Changelog](https://github.com/aio-libs/yarl/blob/master/CHANGES.rst) - [Commits](https://github.com/aio-libs/yarl/compare/v1.12.1...v1.13.0) --- updated-dependencies: - dependency-name: yarl dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index bb2019c..4723021 100644 --- a/requirements.txt +++ b/requirements.txt @@ -20,4 +20,4 @@ python-dotenv == 1.0.1 requests == 2.32.3 urllib3 == 2.2.3 werkzeug == 3.0.4 -yarl == 1.12.1 +yarl == 1.13.0 From 3755a08ccb6419d07f606fb92528a3887161f452 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 30 Sep 2024 01:29:28 +0000 Subject: [PATCH 064/141] Bump dill from 0.3.8 to 0.3.9 Bumps [dill](https://github.com/uqfoundation/dill) from 0.3.8 to 0.3.9. - [Release notes](https://github.com/uqfoundation/dill/releases) - [Commits](https://github.com/uqfoundation/dill/compare/0.3.8...0.3.9) --- updated-dependencies: - dependency-name: dill dependency-type: direct:development update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- requirements_dev.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements_dev.txt b/requirements_dev.txt index a77ff49..50257c0 100644 --- a/requirements_dev.txt +++ b/requirements_dev.txt @@ -2,7 +2,7 @@ astroid == 3.3.4 black == 24.8.0 click == 8.1.7 colorama == 0.4.6 -dill == 0.3.8 +dill == 0.3.9 iniconfig == 2.0.0 isort == 5.13.2 mccabe == 0.7.0 From 475bebfe1fd544d944730b97a9828028ba9fb44f Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 30 Sep 2024 01:29:37 +0000 Subject: [PATCH 065/141] Bump aiohttp from 3.10.6 to 3.10.8 Bumps [aiohttp](https://github.com/aio-libs/aiohttp) from 3.10.6 to 3.10.8. - [Release notes](https://github.com/aio-libs/aiohttp/releases) - [Changelog](https://github.com/aio-libs/aiohttp/blob/master/CHANGES.rst) - [Commits](https://github.com/aio-libs/aiohttp/compare/v3.10.6...v3.10.8) --- updated-dependencies: - dependency-name: aiohttp dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index 4723021..e91fb9b 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,5 +1,5 @@ aiohappyeyeballs == 2.4.2 -aiohttp == 3.10.6 +aiohttp == 3.10.8 aiosignal == 1.3.1 attrs == 24.2.0 blinker == 1.8.2 From 3fe9a15fb0ec85c0a32eef6cadd9c667aa750274 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 30 Sep 2024 01:29:48 +0000 Subject: [PATCH 066/141] Bump yarl from 1.13.0 to 1.13.1 Bumps [yarl](https://github.com/aio-libs/yarl) from 1.13.0 to 1.13.1. - [Release notes](https://github.com/aio-libs/yarl/releases) - [Changelog](https://github.com/aio-libs/yarl/blob/master/CHANGES.rst) - [Commits](https://github.com/aio-libs/yarl/compare/v1.13.0...v1.13.1) --- updated-dependencies: - dependency-name: yarl dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index e91fb9b..cb7d892 100644 --- a/requirements.txt +++ b/requirements.txt @@ -20,4 +20,4 @@ python-dotenv == 1.0.1 requests == 2.32.3 urllib3 == 2.2.3 werkzeug == 3.0.4 -yarl == 1.13.0 +yarl == 1.13.1 From 6bebb6e13f28ad14cfd30000e81c5cea3b6957cc Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Sun, 6 Oct 2024 14:09:28 +0000 Subject: [PATCH 067/141] Bump aiohappyeyeballs from 2.4.2 to 2.4.3 Bumps [aiohappyeyeballs](https://github.com/aio-libs/aiohappyeyeballs) from 2.4.2 to 2.4.3. - [Release notes](https://github.com/aio-libs/aiohappyeyeballs/releases) - [Changelog](https://github.com/aio-libs/aiohappyeyeballs/blob/main/CHANGELOG.md) - [Commits](https://github.com/aio-libs/aiohappyeyeballs/compare/v2.4.2...v2.4.3) --- updated-dependencies: - dependency-name: aiohappyeyeballs dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index cb7d892..96db258 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,4 @@ -aiohappyeyeballs == 2.4.2 +aiohappyeyeballs == 2.4.3 aiohttp == 3.10.8 aiosignal == 1.3.1 attrs == 24.2.0 From cad7850311f36f1cc409ed2f2b8141967cadfc30 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 7 Oct 2024 01:44:26 +0000 Subject: [PATCH 068/141] Bump astroid from 3.3.4 to 3.3.5 Bumps [astroid](https://github.com/pylint-dev/astroid) from 3.3.4 to 3.3.5. - [Release notes](https://github.com/pylint-dev/astroid/releases) - [Changelog](https://github.com/pylint-dev/astroid/blob/main/ChangeLog) - [Commits](https://github.com/pylint-dev/astroid/compare/v3.3.4...v3.3.5) --- updated-dependencies: - dependency-name: astroid dependency-type: direct:development update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- requirements_dev.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements_dev.txt b/requirements_dev.txt index 50257c0..1530998 100644 --- a/requirements_dev.txt +++ b/requirements_dev.txt @@ -1,4 +1,4 @@ -astroid == 3.3.4 +astroid == 3.3.5 black == 24.8.0 click == 8.1.7 colorama == 0.4.6 From 6b424931458a719a158a0ec08216a78272ab96e1 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 7 Oct 2024 10:11:06 +0000 Subject: [PATCH 069/141] Bump aiohttp from 3.10.8 to 3.10.9 Bumps [aiohttp](https://github.com/aio-libs/aiohttp) from 3.10.8 to 3.10.9. - [Release notes](https://github.com/aio-libs/aiohttp/releases) - [Changelog](https://github.com/aio-libs/aiohttp/blob/master/CHANGES.rst) - [Commits](https://github.com/aio-libs/aiohttp/compare/v3.10.8...v3.10.9) --- updated-dependencies: - dependency-name: aiohttp dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index 96db258..1c12b56 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,5 +1,5 @@ aiohappyeyeballs == 2.4.3 -aiohttp == 3.10.8 +aiohttp == 3.10.9 aiosignal == 1.3.1 attrs == 24.2.0 blinker == 1.8.2 From 0403762b3c5ea8ae7aa220f6b1b448b51c891ade Mon Sep 17 00:00:00 2001 From: Winston Sung Date: Tue, 8 Oct 2024 00:12:52 +0800 Subject: [PATCH 070/141] Packaging: Prepare src layout migration - language - system_message Change-Id: Ied7b8182e3564269c17c59aef78e2c9e2972ca76 --- src/scaict_uwu/language/__init__.py | 0 src/scaict_uwu/language/language.py | 42 +++++++++++++++++++++++ src/scaict_uwu/language/language_utils.py | 9 +++++ src/scaict_uwu/system_message/message.py | 33 ++++++++++++++---- 4 files changed, 77 insertions(+), 7 deletions(-) create mode 100644 src/scaict_uwu/language/__init__.py create mode 100644 src/scaict_uwu/language/language.py create mode 100644 src/scaict_uwu/language/language_utils.py diff --git a/src/scaict_uwu/language/__init__.py b/src/scaict_uwu/language/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/src/scaict_uwu/language/language.py b/src/scaict_uwu/language/language.py new file mode 100644 index 0000000..9852656 --- /dev/null +++ b/src/scaict_uwu/language/language.py @@ -0,0 +1,42 @@ +""" +This is the module for the class for all languages. +""" + + +class Language: + """ + The Language class deals with language data. + """ + + def get_bcp_47_lang_tag(self) -> str | None: + pass + + def get_bcp_47_lang_subtag(self) -> str | None: + pass + + def get_iso_639_lang_code(self) -> str | None: + pass + + def get_bcp_47_script_subtag(self) -> str | None: + pass + + def get_bcp_47_region_subtag(self) -> str | None: + pass + + def get_bcp_47_variant_subtags(self) -> list | None: + pass + + def get_bcp_47_private_subtags(self) -> list | None: + pass + + def get_writing_mode(self) -> str | None: + pass + + def get_writing_mode_dir(self) -> str | None: + pass + + def get_writing_mode_prop(self) -> str | None: + pass + + def get_lang_fallbacks(self) -> list | None: + pass diff --git a/src/scaict_uwu/language/language_utils.py b/src/scaict_uwu/language/language_utils.py new file mode 100644 index 0000000..183cf68 --- /dev/null +++ b/src/scaict_uwu/language/language_utils.py @@ -0,0 +1,9 @@ +""" +This is the module for the class for language utilities. +""" + + +class LanguageUtils: + """ + The LanguageUtils class deals with language utilities. + """ diff --git a/src/scaict_uwu/system_message/message.py b/src/scaict_uwu/system_message/message.py index b4f3b4a..96744fe 100644 --- a/src/scaict_uwu/system_message/message.py +++ b/src/scaict_uwu/system_message/message.py @@ -2,24 +2,43 @@ This is the module for the class for all system messages. """ +# Local imports +from ..language.language import Language + class Message: """ The Message class deals with fetching and processing of system messages. """ - __use_lang: str = "zh-hant" + __use_lang: str | None = None """ - __use_lang (str): The language tag of the language for the system message\ - to use. + __use_lang (str|None): The language tag of the language for the system\ + message to use. """ - __in_lang: str = "zh-hant" + __in_lang: str | None = None """ - __in_lang (str): The language tag of the language that the system message\ - actually used. + __in_lang (str|None): The language tag of the language that the system\ + message actually used. """ + def __init__( + self, + key: str, + params: list, + use_lang: Language | None, + ) -> None: + """ + Set the language tag of the language that the message expected to use. + + Parameters: + key (str): Message key. + params (list): Message parameters. + use_lang: (Language|None): Language to use (None: defaults to\ + current user language). + """ + def set_lang(self, lang_tag: str) -> None: """ Set the language tag of the language that the message expected to use. @@ -40,4 +59,4 @@ def get_lang(self) -> str: str: Description of return value. """ - return self.__use_lang or self.__in_lang + return self.__use_lang or self.__in_lang or "" From 1fce2e4fa1555ee358c3bba111193a9005694d54 Mon Sep 17 00:00:00 2001 From: Winston Sung Date: Tue, 8 Oct 2024 00:43:06 +0800 Subject: [PATCH 071/141] i18n: Add course system messages Change-Id: I506404173b815a7052016019fcb1aaca50bf1461 --- src/scaict_uwu/i18n/course/zh-hant.json | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/src/scaict_uwu/i18n/course/zh-hant.json b/src/scaict_uwu/i18n/course/zh-hant.json index 0967ef4..e10816f 100644 --- a/src/scaict_uwu/i18n/course/zh-hant.json +++ b/src/scaict_uwu/i18n/course/zh-hant.json @@ -1 +1,18 @@ -{} +{ + "course-token-redeem-button-label": "請輸入課程代碼", + "course-token-modal-title": "請輸入課程代碼", + "course-token-modal-input-text-label": "請輸入課程代碼", + "course-token-modal-redeemed-role": "已領取{0}身分組", + "course-token-modal-redeemed-course-theme": "課程主題:{0}", + "course-token-modal-redeemed-user": "使用者:{0}", + "course-token-modal-redeemed-lecturer": "講師:{0}", + "course-token-modal-redeemed-course-time": "課程時間:{0}", + "course-token-modal-failed": "領取失敗", + "course-token-modal-failed-user": "使用者:{0}", + "course-token-modal-failed-hint": "請重新確認課程代碼", + "course-send-redeem-embed-command-desc": "傳送課程代碼兌換鈕", + "course-redeem-embed-enter-token": "點下方按鈕輸入token", + "course-redeem-embed-redeem-role": "領取課程身分組!", + "course-create-theme-course-command-desc": "新增主題課程", + "course-create-theme-course-created": "已將{0}新增至 JSON;主題:{1},講師:{2},時間:{3}" +} From f4c5f69639bba429f82b2eaff7af2cc8a803f0e5 Mon Sep 17 00:00:00 2001 From: Winston Sung Date: Tue, 8 Oct 2024 00:56:21 +0800 Subject: [PATCH 072/141] Fix typo: "SCAICT Store" instead of "SCAICT Shop" Change-Id: I703d067a1b0348480ac8045896bbea13a1ecc069 --- src/scaict_uwu/website_flask.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/scaict_uwu/website_flask.py b/src/scaict_uwu/website_flask.py index 0001c01..f6926dc 100644 --- a/src/scaict_uwu/website_flask.py +++ b/src/scaict_uwu/website_flask.py @@ -1,5 +1,5 @@ """ -Entry point for the SCAICT shop website using Flask run. +Entry point for the SCAICT store website using Flask run. TODO: Complete this """ From cf7fd07b85398710bd403682f7f6bf77df49a890 Mon Sep 17 00:00:00 2001 From: Winston Sung Date: Tue, 8 Oct 2024 01:06:14 +0800 Subject: [PATCH 073/141] i18n: Add @metadata.authors to course messages Change-Id: Ibd7c837026a460170dafbc99780c32e37d06d71a --- src/scaict_uwu/i18n/course/zh-hant.json | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/scaict_uwu/i18n/course/zh-hant.json b/src/scaict_uwu/i18n/course/zh-hant.json index e10816f..5b2335b 100644 --- a/src/scaict_uwu/i18n/course/zh-hant.json +++ b/src/scaict_uwu/i18n/course/zh-hant.json @@ -1,4 +1,11 @@ { + "@metadata": { + "authors": [ + "Each Chen", + "os24", + "Winston Sung" + ] + }, "course-token-redeem-button-label": "請輸入課程代碼", "course-token-modal-title": "請輸入課程代碼", "course-token-modal-input-text-label": "請輸入課程代碼", From fcada002842dcceca1dede0ae7c512718681eb9a Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 8 Oct 2024 09:32:34 +0000 Subject: [PATCH 074/141] Bump black from 24.8.0 to 24.10.0 Bumps [black](https://github.com/psf/black) from 24.8.0 to 24.10.0. - [Release notes](https://github.com/psf/black/releases) - [Changelog](https://github.com/psf/black/blob/main/CHANGES.md) - [Commits](https://github.com/psf/black/compare/24.8.0...24.10.0) --- updated-dependencies: - dependency-name: black dependency-type: direct:development update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- pyproject.toml | 2 +- requirements_dev.txt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 64ded98..63544d1 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -36,7 +36,7 @@ dependencies = [ ] # Lock file: requirements_dev.txt optional-dependencies.dev = [ - "black == 24.8.0", + "black == 24.10.0", "pylint == 3.3.1", "pytest == 8.3.3", ] diff --git a/requirements_dev.txt b/requirements_dev.txt index 1530998..53db936 100644 --- a/requirements_dev.txt +++ b/requirements_dev.txt @@ -1,5 +1,5 @@ astroid == 3.3.5 -black == 24.8.0 +black == 24.10.0 click == 8.1.7 colorama == 0.4.6 dill == 0.3.9 From fd6247eadc974a10ef2be06e435a34d1a035dc92 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 8 Oct 2024 09:38:24 +0000 Subject: [PATCH 075/141] Bump markupsafe from 2.1.5 to 3.0.0 Bumps [markupsafe](https://github.com/pallets/markupsafe) from 2.1.5 to 3.0.0. - [Release notes](https://github.com/pallets/markupsafe/releases) - [Changelog](https://github.com/pallets/markupsafe/blob/main/CHANGES.rst) - [Commits](https://github.com/pallets/markupsafe/compare/2.1.5...3.0.0) --- updated-dependencies: - dependency-name: markupsafe dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index 1c12b56..1e19f3a 100644 --- a/requirements.txt +++ b/requirements.txt @@ -12,7 +12,7 @@ frozenlist == 1.4.1 idna == 3.10 itsdangerous == 2.2.0 jinja2 == 3.1.4 -markupsafe == 2.1.5 +markupsafe == 3.0.0 multidict == 6.1.0 mysql-connector-python == 8.4.0 py-cord == 2.6.1 From ebbe9ad76abfff32ba3f7bdec681a130a3b33ead Mon Sep 17 00:00:00 2001 From: Winston Sung Date: Tue, 8 Oct 2024 19:40:13 +0800 Subject: [PATCH 076/141] Complete release notes for 0.1.1 Change-Id: I9d96245bfd0e8dd04ccb4dcddf9e037258b8fe4582b --- RELEASE-NOTES-0.1.md | 99 +++++++++++++++----------------------------- 1 file changed, 34 insertions(+), 65 deletions(-) diff --git a/RELEASE-NOTES-0.1.md b/RELEASE-NOTES-0.1.md index a458e4b..6cecda7 100644 --- a/RELEASE-NOTES-0.1.md +++ b/RELEASE-NOTES-0.1.md @@ -4,7 +4,7 @@ THIS IS NOT A RELEASE YET -The `development` branch is an beta-quality development branch. Use it at your +The `development` branch is a beta-quality development branch. Use it at your own risk! ### Configuration changes for system administrators @@ -417,94 +417,63 @@ SCAICT-uwu now supports 1 language. Many localisations are updated regularly. This is a maintenance release of SCAICT-uwu 0.1 version. -### Configuration changes for system administrators in 0.1.1 - -#### New configuration in 0.1.1 - -* … - -#### Changed configuration in 0.1.1 - -* … - -#### Removed configuration in 0.1.1 - -* … - ### New user-facing features in 0.1.1 -* … +* Added dynamic voice channel and support ticket feature. +* Added channel member display. +* Added CTF features. +* Updated CTF features (WIP, can create and list). +* Added independent update channels. +* Rewrote the daily charge feature. +* Completed CTF features. +* Added initial website using Flask. +* Completed course role features. +* Updated design of SCAICT Store. +* Updated the support ticket embed description. +* Updated to limit the usage of daily change command to specific channel. +* Completed SCAICT Store. +* Added lottery slot feature in SCAICT Store. +* Added support for bot status/presence. +* Added zap emoji. +* Added total point status display. +* Updated CTF features. ### New features for sysadmins in 0.1.1 -* … - -### New developer features in 0.1.1 - -* … +* Added Google Analytics. ### Bug fixes in 0.1.1 -* … - -### API changes in 0.1.1 - -* … - -### API internal changes in 0.1.1 - -* … +* Fixed the problem of bot responding to self messages. +* Fixed counting error, only the user replied would see the message. +* Added exception handling for data not found issues. +* Fixed issue caused by users without avatar set. -### Languages updated in 0.1.1 +### Languages in 0.1.1 SCAICT-uwu now supports 1 language. Many localisations are updated regularly. -### Breaking changes in 0.1.1 +Below only new and removed languages are listed. -* … +* Added language support for Mandarin - Traditional Han script (`zh-hant`). -### Deprecations in 0.1.1 +### Breaking changes and deprecations in 0.1.1 -* … +* Added JSON file as initial database. +* Updated to use JSON file to get CTF maker role ID. +* Added SQL database. +* Migrated user.json to SQL database. +* Renamed SQL column name from `user_id` to `uid`. +* Dropped support for `user.json`, use SQL database instead. ### Other changes in 0.1.1 -* Added dynamic voice channel and support ticket feature. * Added `.gitignore` to ignore token files. * Added `.gitignore` to ignore cache files. -* Added channel member display. -* Added CTF features. -* self problem. -* Updated CTF features wip (can create and list). -* independent update channel. * Passing bot attributes. * Added comment, check_point and daily_charge Python modules. -* Added JSON file as initial database. * Added user Python module. * Migrated use of user functions to user Python module. -* Rewrote the daily charge feature. -* Completed CTF features. -* Fixed counting error, only replyer sees message. -* Added initial website using Flask. -* Completed course role features. -* Updated design of SCAICT Store. -* Updated to use JSON file to get CTF maker role ID. -* Updated the support ticket embed description. -* Updated to limit the usage of daily change command to specific channel. -* Completed SCAICT Store. -* Added lottery slot feature in SCAICT Store. -* Added SQL database. -* Migrated user.json to SQL database. -* Added exception handling for data not found issues. -* Renamed SQL column name from `user_id` to `uid`. -* Added support for bot status/presence. -* Added zap emoji. -* Added Google Analytics. -* Added total point status display. -* Dropped support for `user.json`, use SQL database instead. -* Fixed issue caused by users without avatar set. -* Updated CTF features. -* … ## SCAICT-uwu 0.1.0 From 9a99211f8a70cc4ac8980cb058927f828d32742e Mon Sep 17 00:00:00 2001 From: YuevUwU <96368079+YuevUwU@users.noreply.github.com> Date: Tue, 8 Oct 2024 21:23:46 +0800 Subject: [PATCH 077/141] fix: style, typo (including code strings) --- .env.example | 14 +++++++------- CONTRIBUTING.md | 2 +- README.md | 10 +++++----- app.py | 20 ++++++++++---------- cog/api/gift.py | 4 ++-- cog/comment.py | 6 +++--- cog/game.py | 2 +- docs/abstract_schema_table.json | 2 +- static/switch-btn.js | 2 +- templates/home.html | 2 +- test/enumstruct.py | 4 ++-- 11 files changed, 34 insertions(+), 34 deletions(-) diff --git a/.env.example b/.env.example index af1ea94..78006c3 100644 --- a/.env.example +++ b/.env.example @@ -7,17 +7,17 @@ MYSQL_PORT=資料庫連接埠 MYSQL_DATABASE=資料庫名稱 HOST=資料庫主機位址 -# gobal configuration -DISCORD_TOKEN=Disscord機器人Token +# Global configuration +DISCORD_TOKEN=Discord機器人Token GUILD_ID=機器人所在伺服器ID -# flask configuration -secret_key = 隨機字串,給 flask session 使用 -DISCORD_CLIENT_SECRET=DISCORD_CLIENT_SECRET,到 Discord Developer Portal 取得 -DISCORD_CLIENT_ID=Disscord client ID +# Flask configuration +secret_key=隨機字串,給 flask session 使用 +DISCORD_CLIENT_SECRET=Discord Client Secret,到 Discord Developer Portal 取得 +DISCORD_CLIENT_ID=Discord Client ID DISCORD_REDIRECT_URI=商店網址/callback GITHUB_CLIENT_ID=GitHub Client ID,到 GitHub Developer 取得 GITHUB_CLIENT_SECRET=GitHub Client Secret GITHUB_REDIRECT_URI=GitHub OAuth Redirect URI GITHUB_DISCORD_REDIRECT= -SEND_GIFT_ROLE=允許發送禮物的身分組ID,多個角色ID以逗號分隔 \ No newline at end of file +SEND_GIFT_ROLE=允許發送禮物的身分組ID,多個身分組ID以逗號分隔 \ No newline at end of file diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index aa0d15e..0314237 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -189,7 +189,7 @@ for further information. MySQL/MariaDB. * Column names should be unique, i.e., same column name should not exist in different tables. -* Column names should be prefixed with table names or abbrieviations. +* Column names should be prefixed with table names or abbreviations. * For example, `user_id` in `user`, `ug_user` in `user_groups`. Examples: diff --git a/README.md b/README.md index f4866bd..7289457 100644 --- a/README.md +++ b/README.md @@ -25,7 +25,7 @@ SCAICT-uwu offers a range of interactive features, from daily activities to codi ### About SCAICT -SCAICT, the Student Club Information Association of Central Taiwan, is an electronic engineering club composed of schools from central Taiwan. By combining the resources of the Central District, we actively organize educational events, activities, and competitions related to information technology, with the goal of facilitating the flow of technology and knowledge. +SCAICT, Student Club's Association of Information in Central Taiwan, is an electronic engineering club composed of schools from Central Taiwan. By combining the resources of the Central Region, we actively organize educational events, activities, and competitions related to information technology, with the goal of facilitating the flow of technology and knowledge. ## Features @@ -46,7 +46,7 @@ Some interactions with SCAICT-uwu occur within dedicated channels, allowing for ### Store -#### Buy somthing +#### Buy something You can buy some products like our stickers or USB drives using Electric Points. Note that the products currently can only be exchanged during in-person events. We will soon offer shipping options and more virtual rewards for redemption. @@ -61,7 +61,7 @@ You can buy some products like our stickers or USB drives using Electric Points. Get some tickets, and you can play the slot machine to earn Electric Points. Just long press to start the slot.
-![solt demo](https://raw.githubusercontent.com/SCAICT/doc/main/static/img/slot-demo.gif) +![slot demo](https://raw.githubusercontent.com/SCAICT/doc/main/static/img/slot-demo.gif)
@@ -70,7 +70,7 @@ Get some tickets, and you can play the slot machine to earn Electric Points. Jus 1. **Join the Server** Start by joining the SCAICT Discord community using this [link](https://dc.scaict.org). 2. **Earn Your First Electric Points** - Visit the `#daily-charge` channel and use the `/charge` command to receive your first set of Electric Points, the primary currency used within the bot's ecosystem. + Visit the `#🔌每日充電` (`everyDayCharge`) channel and use the `/charge` command to receive your first set of Electric Points, the primary currency used within the bot's ecosystem. 3. **Enjoy in Services** Explore the various commands and interactions SCAICT-uwu offers, and enjoy the space within the server, engaging and connecting with everyone. @@ -139,4 +139,4 @@ Get some tickets, and you can play the slot machine to earn Electric Points. Jus ## Acknowledgements -SCAICT-uww is a project jointly developed and maintained by SCAICT and [contributors](https://github.com/SCAICT/SCAICT-uwu/graphs/contributors). The character design was created by [毛哥 EM](https://elvismao.com/) and [瑞樹](https://www.facebook.com/ruishuowo), while some icons were sourced from [Freepik - Flaticon](https://www.flaticon.com/free-icons/slot-machine). +SCAICT-uwu is a project jointly developed and maintained by SCAICT and [contributors](https://github.com/SCAICT/SCAICT-uwu/graphs/contributors). The character design was created by [毛哥 EM](https://elvismao.com/) and [瑞樹](https://www.facebook.com/ruishuowo), while some icons were sourced from [Freepik - Flaticon](https://www.flaticon.com/free-icons/slot-machine). diff --git a/app.py b/app.py index 7cd68c4..299b297 100644 --- a/app.py +++ b/app.py @@ -80,7 +80,7 @@ def logout(): @app.route("/api/mlist") def listt(): if not session: - return jsonify({"resulet": "you must loggin", "status": 403}) + return jsonify({"result": "you must login", "status": 403}) api_admin = session.get( "user" ) # {'avatar': 'https://cdn.discordapp.com/avatars/898141506588770334/a_c81acdd4a925993d053a6fe9ed990c14.png', 'id': '898141506588770334', 'name': 'iach526526'} @@ -109,7 +109,7 @@ def listt(): # api/send/{recipient}?gift_type={電電點|抽獎券}count={count} def send(target_user_id): if not session: - return jsonify({"resulet": "you must loggin", "status": 403}) + return jsonify({"result": "you must login", "status": 403}) try: api_admin = session.get( "user" @@ -147,7 +147,7 @@ def send(target_user_id): # 如果有錯誤,返回錯誤訊息和詳細信息 return jsonify( { - "result": "Failed to fetch user information in target id(whitch is in url path)", + "result": "Failed to fetch user information in target id (which is in url path)", "status": 500, "error_details": request_admin.get("details"), } @@ -191,7 +191,7 @@ def send(target_user_id): except Exception as e: return jsonify( { - "result": "interal server error(SQL) when insert gift", + "result": "internal server error(SQL) when insert gift", "status": 500, "error": str(e), } @@ -200,7 +200,7 @@ def send(target_user_id): except Exception as e: traceback.print_exc() return jsonify( - {"result": "interal server error", "status": 500, "error": str(e)} + {"result": "internal server error", "status": 500, "error": str(e)} ) @@ -293,7 +293,7 @@ def discord_callback(): return redirect(url_for("star_uwu")) -# make filder static in templates/static static +# make filter static in templates/static static @app.route("/static/") def staticfiles(path): return send_from_directory("static", path) @@ -367,7 +367,7 @@ def product_list(): @app.route("/buyProduct", methods=["POST"]) def buy_product(): - # Recieve POST request, get product id and check if logged in + # Receive POST request, get product id and check if logged in discord_user = session.get("user") if not discord_user: return "請重新登入" @@ -491,7 +491,7 @@ def insert_user(user_id, table, cursor): # 初始化(新增)傳入該ID的 if "access_token" not in session: print("GitHub access token not found!") return redirect(url_for("github_login")) - # if dc not loggin + # if dc not login discord_user = session.get("user") if not discord_user: # pylint: disable-next = line-too-long @@ -524,9 +524,9 @@ def insert_user(user_id, table, cursor): # 初始化(新增)傳入該ID的 connection, cursor = link_sql() # SQL 會話 if not user_id_exists( discord_user["id"], "user", cursor - ): # 該 uesr id 不在user表格內,插入該筆使用者資料 + ): # 該 user id 不在user表格內,插入該筆使用者資料 insert_user(discord_user["id"], "user", cursor) - # if already starred. liveuwu is 1 + # if already starred. loveuwu is 1 if read(discord_user["id"], "loveuwu", cursor): end(connection, cursor) return render_template("already.html") diff --git a/cog/api/gift.py b/cog/api/gift.py index e6cd98a..0510f6e 100644 --- a/cog/api/gift.py +++ b/cog/api/gift.py @@ -29,9 +29,9 @@ def __new_dm(self, uid: int) -> dict: response.raise_for_status() return response.json() except requests.RequestException as e: - return {"result": "interal server error", "status": 500, "error": str(e)} + return {"result": "internal server error", "status": 500, "error": str(e)} except Exception as e: - return {"result": "interal server error", "status": 500, "error": str(e)} + return {"result": "internal server error", "status": 500, "error": str(e)} def _gen_msg(self, gift_type: str, gift_amount: int) -> str: embed = { diff --git a/cog/comment.py b/cog/comment.py index a27956c..acf38c7 100644 --- a/cog/comment.py +++ b/cog/comment.py @@ -141,7 +141,7 @@ def today_comment(user_id, message, cursor): try: # 新增該user的資料表 if not user_id_exists(user_id, "user", cursor): - # 該 uesr id 不在user資料表內,插入該筆使用者資料 + # 該 user id 不在user資料表內,插入該筆使用者資料 insert_user(user_id, "user", cursor) if not user_id_exists(user_id, "comment_points", cursor): insert_user(user_id, "comment_points", cursor) @@ -187,7 +187,7 @@ async def count(message): # Allow both plain and monospace formatting based_number = re.sub("^`([^\n]+)`$", "\\1", raw_content) - # If is valid 4-digit whitespace delimeter format + # If is valid 4-digit whitespace delimiter format # (with/without base), then strip whitespace characters. # # Test cases: @@ -209,7 +209,7 @@ async def count(message): based_number, ): based_number = based_number.replace(" ", "") - # If is valid 3-digit comma delimeter format + # If is valid 3-digit comma delimiter format # (10-based, without base) elif counting_base == 10 and re.match( "^([0-9]{1,3}(,[0-9]{3})*)$", based_number diff --git a/cog/game.py b/cog/game.py index 9e2dfba..941191d 100644 --- a/cog/game.py +++ b/cog/game.py @@ -37,7 +37,7 @@ def get_channels(): class Game(commands.Cog): # User can use this command to play ✊-🤚-✌️ with the bot in the command channel @discord.slash_command(name="rock_paper_scissors", description="玩剪刀石頭布") - # useser can choose ✊, 🤚, or ✌️ in their command + # user can choose ✊, 🤚, or ✌️ in their command async def rock_paper_scissors( self, interaction, choice: discord.Option(str, choices=["✊", "🤚", "✌️"]) ): diff --git a/docs/abstract_schema_table.json b/docs/abstract_schema_table.json index c53a91f..ea2502f 100644 --- a/docs/abstract_schema_table.json +++ b/docs/abstract_schema_table.json @@ -129,7 +129,7 @@ }, "enum_values": { "type": "array", - "description": "Values to use with type 'mwenum'", + "description": "Values to use with type 'enum'", "additionalItems": false, "items": { "type": "string" diff --git a/static/switch-btn.js b/static/switch-btn.js index 1281f50..5dd038b 100644 --- a/static/switch-btn.js +++ b/static/switch-btn.js @@ -39,7 +39,7 @@ function switchRight(){//右邊,10連 activeSwitch.style.left = '50%'; numDraws.value=10; changeMachine('#FF0000', '#FF4500', '#B22222', '#8B0000'); - achine('#FFD700', '#FFA500', '#FF6347', '#d76a1d'); + achine('#FFD700', '#FFA500', '#FF6347', '#d76a1d');// Suspected Redundant Code } switchBtnLeft.addEventListener('click', function(){ diff --git a/templates/home.html b/templates/home.html index 5882e08..fe8b5e6 100644 --- a/templates/home.html +++ b/templates/home.html @@ -156,7 +156,7 @@

${product.name}

}, body: JSON.stringify({ id: selected.id }), }) - //alert recieved text + //alert received text .then(res => res.text()) .then(text => { // if response is html then show it in new page diff --git a/test/enumstruct.py b/test/enumstruct.py index 13be478..24fe787 100644 --- a/test/enumstruct.py +++ b/test/enumstruct.py @@ -1,4 +1,4 @@ -# enume 測試 +# enum 測試 from enum import Enum @@ -7,7 +7,7 @@ class GiftType(Enum): ticket = "抽獎券" -for gt in GiftType: # eqaul to print(GiftType.{item}.name) +for gt in GiftType: # equal to print(GiftType.{item}.name) print(gt) print(GiftType.point.name) From cd7ee64947e28dfb869110c6fe4854519750ade8 Mon Sep 17 00:00:00 2001 From: YuevUwU <96368079+YuevUwU@users.noreply.github.com> Date: Tue, 8 Oct 2024 21:37:42 +0800 Subject: [PATCH 078/141] fix: avoid case sensibility of environment variable --- .env.example | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.env.example b/.env.example index 78006c3..bb015a4 100644 --- a/.env.example +++ b/.env.example @@ -12,7 +12,7 @@ DISCORD_TOKEN=Discord機器人Token GUILD_ID=機器人所在伺服器ID # Flask configuration -secret_key=隨機字串,給 flask session 使用 +SECRET_KEY=隨機字串,給 flask session 使用 DISCORD_CLIENT_SECRET=Discord Client Secret,到 Discord Developer Portal 取得 DISCORD_CLIENT_ID=Discord Client ID DISCORD_REDIRECT_URI=商店網址/callback From 189878ea60c69f817235dcae5b796248935a4aba Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 9 Oct 2024 07:37:53 +0000 Subject: [PATCH 079/141] Bump yarl from 1.13.1 to 1.14.0 Bumps [yarl](https://github.com/aio-libs/yarl) from 1.13.1 to 1.14.0. - [Release notes](https://github.com/aio-libs/yarl/releases) - [Changelog](https://github.com/aio-libs/yarl/blob/master/CHANGES.rst) - [Commits](https://github.com/aio-libs/yarl/compare/v1.13.1...v1.14.0) --- updated-dependencies: - dependency-name: yarl dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index 1e19f3a..dfb984a 100644 --- a/requirements.txt +++ b/requirements.txt @@ -20,4 +20,4 @@ python-dotenv == 1.0.1 requests == 2.32.3 urllib3 == 2.2.3 werkzeug == 3.0.4 -yarl == 1.13.1 +yarl == 1.14.0 From e5c03eb5902e1ffbf0c1ae8b83a3a026189ee2ae Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 9 Oct 2024 07:40:03 +0000 Subject: [PATCH 080/141] Bump markupsafe from 3.0.0 to 3.0.1 Bumps [markupsafe](https://github.com/pallets/markupsafe) from 3.0.0 to 3.0.1. - [Release notes](https://github.com/pallets/markupsafe/releases) - [Changelog](https://github.com/pallets/markupsafe/blob/main/CHANGES.rst) - [Commits](https://github.com/pallets/markupsafe/compare/3.0.0...3.0.1) --- updated-dependencies: - dependency-name: markupsafe dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index dfb984a..1373ce4 100644 --- a/requirements.txt +++ b/requirements.txt @@ -12,7 +12,7 @@ frozenlist == 1.4.1 idna == 3.10 itsdangerous == 2.2.0 jinja2 == 3.1.4 -markupsafe == 3.0.0 +markupsafe == 3.0.1 multidict == 6.1.0 mysql-connector-python == 8.4.0 py-cord == 2.6.1 From d1d5bd24e1264db6fc8c43a5314ca46f2612f86a Mon Sep 17 00:00:00 2001 From: Winston Sung Date: Wed, 9 Oct 2024 15:45:55 +0800 Subject: [PATCH 081/141] Update CONTRIBUTING, .env.example Change-Id: I74cac543ce87b64c897880a654ac05cac2d635c3 --- .env.example | 5 +++-- CONTRIBUTING.md | 4 +++- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/.env.example b/.env.example index bb015a4..67ef289 100644 --- a/.env.example +++ b/.env.example @@ -1,5 +1,6 @@ # 這是一個範例檔案,請複製一份 .env.example 並命名為 .env # 並將以下的設定值填入 + # Database configuration MYSQL_USER=資料庫使用者 MYSQL_PASSWORD=資料庫使用者密碼 @@ -8,7 +9,7 @@ MYSQL_DATABASE=資料庫名稱 HOST=資料庫主機位址 # Global configuration -DISCORD_TOKEN=Discord機器人Token +DISCORD_TOKEN=Discord機器人token GUILD_ID=機器人所在伺服器ID # Flask configuration @@ -20,4 +21,4 @@ GITHUB_CLIENT_ID=GitHub Client ID,到 GitHub Developer 取得 GITHUB_CLIENT_SECRET=GitHub Client Secret GITHUB_REDIRECT_URI=GitHub OAuth Redirect URI GITHUB_DISCORD_REDIRECT= -SEND_GIFT_ROLE=允許發送禮物的身分組ID,多個身分組ID以逗號分隔 \ No newline at end of file +SEND_GIFT_ROLE=允許發送禮物的身分組ID,多個身分組ID以逗號分隔 diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 0314237..01e55f8 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -190,7 +190,8 @@ for further information. * Column names should be unique, i.e., same column name should not exist in different tables. * Column names should be prefixed with table names or abbreviations. - * For example, `user_id` in `user`, `ug_user` in `user_groups`. + * For example, `user_id` column in `user` table, `ug_user` column in + `user_groups` table. Examples: @@ -212,5 +213,6 @@ UPDATE game SET game_seq = game_seq + 1 ### Development dependencies +* black: * pylint: * pytest: From 397b979aa3086f098e11ec10bcdd2c7297a79d76 Mon Sep 17 00:00:00 2001 From: Winston Sung Date: Thu, 10 Oct 2024 00:35:03 +0800 Subject: [PATCH 082/141] Fix Merge CI Change-Id: I28b155b7f08b8cf7ea10c2889e117ae8c4d45eb7 --- .github/workflows/merge.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/merge.yml b/.github/workflows/merge.yml index 78f908d..45bdefc 100644 --- a/.github/workflows/merge.yml +++ b/.github/workflows/merge.yml @@ -9,7 +9,8 @@ jobs: permissions: contents: write pull-requests: write - if: # github.event.review.state == 'approved' && + if: + github.event.review.state == 'approved' && ( github.event.review.author_association == 'OWNER' || github.event.review.author_association == 'MEMBER' || From 63074eda5398536de04c18f6fc51e8079e52a04c Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 10 Oct 2024 01:51:45 +0000 Subject: [PATCH 083/141] Bump charset-normalizer from 3.3.2 to 3.4.0 Bumps [charset-normalizer](https://github.com/Ousret/charset_normalizer) from 3.3.2 to 3.4.0. - [Release notes](https://github.com/Ousret/charset_normalizer/releases) - [Changelog](https://github.com/jawah/charset_normalizer/blob/master/CHANGELOG.md) - [Commits](https://github.com/Ousret/charset_normalizer/compare/3.3.2...3.4.0) --- updated-dependencies: - dependency-name: charset-normalizer dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index 1373ce4..38f39cd 100644 --- a/requirements.txt +++ b/requirements.txt @@ -4,7 +4,7 @@ aiosignal == 1.3.1 attrs == 24.2.0 blinker == 1.8.2 certifi == 2024.8.30 -charset-normalizer == 3.3.2 +charset-normalizer == 3.4.0 click == 8.1.7 colorama == 0.4.6 flask == 3.0.3 From 374acf544535a67a7b1195faae5c228a53edd7bf Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 11 Oct 2024 01:52:01 +0000 Subject: [PATCH 084/141] Bump aiohttp from 3.10.9 to 3.10.10 Bumps [aiohttp](https://github.com/aio-libs/aiohttp) from 3.10.9 to 3.10.10. - [Release notes](https://github.com/aio-libs/aiohttp/releases) - [Changelog](https://github.com/aio-libs/aiohttp/blob/master/CHANGES.rst) - [Commits](https://github.com/aio-libs/aiohttp/compare/v3.10.9...v3.10.10) --- updated-dependencies: - dependency-name: aiohttp dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index 38f39cd..e9aab43 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,5 +1,5 @@ aiohappyeyeballs == 2.4.3 -aiohttp == 3.10.9 +aiohttp == 3.10.10 aiosignal == 1.3.1 attrs == 24.2.0 blinker == 1.8.2 From efe0f483400e095b153538e6a500b43878f96e01 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 14 Oct 2024 01:28:24 +0000 Subject: [PATCH 085/141] Bump yarl from 1.14.0 to 1.15.2 Bumps [yarl](https://github.com/aio-libs/yarl) from 1.14.0 to 1.15.2. - [Release notes](https://github.com/aio-libs/yarl/releases) - [Changelog](https://github.com/aio-libs/yarl/blob/master/CHANGES.rst) - [Commits](https://github.com/aio-libs/yarl/compare/v1.14.0...v1.15.2) --- updated-dependencies: - dependency-name: yarl dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index e9aab43..ab93ca2 100644 --- a/requirements.txt +++ b/requirements.txt @@ -20,4 +20,4 @@ python-dotenv == 1.0.1 requests == 2.32.3 urllib3 == 2.2.3 werkzeug == 3.0.4 -yarl == 1.14.0 +yarl == 1.15.2 From c72e4417693e438a89c8baa3f4d5781e09e401f7 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 24 Oct 2024 15:29:14 +0000 Subject: [PATCH 086/141] Bump markupsafe from 3.0.1 to 3.0.2 Bumps [markupsafe](https://github.com/pallets/markupsafe) from 3.0.1 to 3.0.2. - [Release notes](https://github.com/pallets/markupsafe/releases) - [Changelog](https://github.com/pallets/markupsafe/blob/main/CHANGES.rst) - [Commits](https://github.com/pallets/markupsafe/compare/3.0.1...3.0.2) --- updated-dependencies: - dependency-name: markupsafe dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index ab93ca2..ab82331 100644 --- a/requirements.txt +++ b/requirements.txt @@ -12,7 +12,7 @@ frozenlist == 1.4.1 idna == 3.10 itsdangerous == 2.2.0 jinja2 == 3.1.4 -markupsafe == 3.0.1 +markupsafe == 3.0.2 multidict == 6.1.0 mysql-connector-python == 8.4.0 py-cord == 2.6.1 From b45e04290161601c75f61df4e73ea1d558f5859b Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 24 Oct 2024 15:31:09 +0000 Subject: [PATCH 087/141] Bump yarl from 1.15.2 to 1.16.0 Bumps [yarl](https://github.com/aio-libs/yarl) from 1.15.2 to 1.16.0. - [Release notes](https://github.com/aio-libs/yarl/releases) - [Changelog](https://github.com/aio-libs/yarl/blob/master/CHANGES.rst) - [Commits](https://github.com/aio-libs/yarl/compare/v1.15.2...v1.16.0) --- updated-dependencies: - dependency-name: yarl dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index ab82331..7cc35ea 100644 --- a/requirements.txt +++ b/requirements.txt @@ -20,4 +20,4 @@ python-dotenv == 1.0.1 requests == 2.32.3 urllib3 == 2.2.3 werkzeug == 3.0.4 -yarl == 1.15.2 +yarl == 1.16.0 From 75b177ebbdbe02a29bd225f451b35ea175873b4d Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 24 Oct 2024 15:34:09 +0000 Subject: [PATCH 088/141] Bump frozenlist from 1.4.1 to 1.5.0 Bumps [frozenlist](https://github.com/aio-libs/frozenlist) from 1.4.1 to 1.5.0. - [Release notes](https://github.com/aio-libs/frozenlist/releases) - [Changelog](https://github.com/aio-libs/frozenlist/blob/master/CHANGES.rst) - [Commits](https://github.com/aio-libs/frozenlist/compare/v1.4.1...v1.5.0) --- updated-dependencies: - dependency-name: frozenlist dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index 7cc35ea..577f013 100644 --- a/requirements.txt +++ b/requirements.txt @@ -8,7 +8,7 @@ charset-normalizer == 3.4.0 click == 8.1.7 colorama == 0.4.6 flask == 3.0.3 -frozenlist == 1.4.1 +frozenlist == 1.5.0 idna == 3.10 itsdangerous == 2.2.0 jinja2 == 3.1.4 From 578f7344a04e25aa01caabcad32e0f7ea7dd950e Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 29 Oct 2024 05:24:46 +0000 Subject: [PATCH 089/141] Bump werkzeug from 3.0.4 to 3.0.6 Bumps [werkzeug](https://github.com/pallets/werkzeug) from 3.0.4 to 3.0.6. - [Release notes](https://github.com/pallets/werkzeug/releases) - [Changelog](https://github.com/pallets/werkzeug/blob/main/CHANGES.rst) - [Commits](https://github.com/pallets/werkzeug/compare/3.0.4...3.0.6) --- updated-dependencies: - dependency-name: werkzeug dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index 577f013..451f109 100644 --- a/requirements.txt +++ b/requirements.txt @@ -19,5 +19,5 @@ py-cord == 2.6.1 python-dotenv == 1.0.1 requests == 2.32.3 urllib3 == 2.2.3 -werkzeug == 3.0.4 +werkzeug == 3.0.6 yarl == 1.16.0 From 4252d0fd4374fc06c9d98a44f445f91e5008ac59 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 29 Oct 2024 05:26:47 +0000 Subject: [PATCH 090/141] Bump yarl from 1.16.0 to 1.17.0 Bumps [yarl](https://github.com/aio-libs/yarl) from 1.16.0 to 1.17.0. - [Release notes](https://github.com/aio-libs/yarl/releases) - [Changelog](https://github.com/aio-libs/yarl/blob/master/CHANGES.rst) - [Commits](https://github.com/aio-libs/yarl/compare/v1.16.0...v1.17.0) --- updated-dependencies: - dependency-name: yarl dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index 451f109..7bbe78d 100644 --- a/requirements.txt +++ b/requirements.txt @@ -20,4 +20,4 @@ python-dotenv == 1.0.1 requests == 2.32.3 urllib3 == 2.2.3 werkzeug == 3.0.6 -yarl == 1.16.0 +yarl == 1.17.0 From e3642ef0e20f01525f1873927446ff5fd6d6ac39 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Sat, 2 Nov 2024 11:13:54 +0000 Subject: [PATCH 091/141] Bump mysql-connector-python from 8.4.0 to 9.1.0 Bumps [mysql-connector-python](https://github.com/mysql/mysql-connector-python) from 8.4.0 to 9.1.0. - [Changelog](https://github.com/mysql/mysql-connector-python/blob/trunk/CHANGES.txt) - [Commits](https://github.com/mysql/mysql-connector-python/compare/8.4.0...9.1.0) --- updated-dependencies: - dependency-name: mysql-connector-python dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] --- pyproject.toml | 2 +- requirements.txt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 63544d1..476bacc 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -29,7 +29,7 @@ urls.issues = "https://github.com/SCAICT/SCAICT-uwu/issues" # Lock file: requirements.txt dependencies = [ "flask == 3.0.3", - "mysql-connector-python == 8.4.0", + "mysql-connector-python == 9.1.0", "py-cord == 2.6.1", "python-dotenv == 1.0.1", "requests == 2.32.3", diff --git a/requirements.txt b/requirements.txt index 7bbe78d..549be93 100644 --- a/requirements.txt +++ b/requirements.txt @@ -14,7 +14,7 @@ itsdangerous == 2.2.0 jinja2 == 3.1.4 markupsafe == 3.0.2 multidict == 6.1.0 -mysql-connector-python == 8.4.0 +mysql-connector-python == 9.1.0 py-cord == 2.6.1 python-dotenv == 1.0.1 requests == 2.32.3 From 8fca4b201097c8d6595049cde7c96de3d6f99d74 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Sat, 2 Nov 2024 11:17:02 +0000 Subject: [PATCH 092/141] Bump yarl from 1.17.0 to 1.17.1 Bumps [yarl](https://github.com/aio-libs/yarl) from 1.17.0 to 1.17.1. - [Release notes](https://github.com/aio-libs/yarl/releases) - [Changelog](https://github.com/aio-libs/yarl/blob/master/CHANGES.rst) - [Commits](https://github.com/aio-libs/yarl/compare/v1.17.0...v1.17.1) --- updated-dependencies: - dependency-name: yarl dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index 549be93..f88e731 100644 --- a/requirements.txt +++ b/requirements.txt @@ -20,4 +20,4 @@ python-dotenv == 1.0.1 requests == 2.32.3 urllib3 == 2.2.3 werkzeug == 3.0.6 -yarl == 1.17.0 +yarl == 1.17.1 From 15cdfc37db6641e5fa6b164b98bc4fc6bf60be1d Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Sat, 2 Nov 2024 11:21:28 +0000 Subject: [PATCH 093/141] Bump werkzeug from 3.0.6 to 3.1.1 Bumps [werkzeug](https://github.com/pallets/werkzeug) from 3.0.6 to 3.1.1. - [Release notes](https://github.com/pallets/werkzeug/releases) - [Changelog](https://github.com/pallets/werkzeug/blob/main/CHANGES.rst) - [Commits](https://github.com/pallets/werkzeug/compare/3.0.6...3.1.1) --- updated-dependencies: - dependency-name: werkzeug dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index f88e731..2131acd 100644 --- a/requirements.txt +++ b/requirements.txt @@ -19,5 +19,5 @@ py-cord == 2.6.1 python-dotenv == 1.0.1 requests == 2.32.3 urllib3 == 2.2.3 -werkzeug == 3.0.6 +werkzeug == 3.1.1 yarl == 1.17.1 From c4281abc8e1297fe47e4c01b0c81e4d8f96a93cc Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 20 Nov 2024 15:37:33 +0000 Subject: [PATCH 094/141] Bump packaging from 24.1 to 24.2 Bumps [packaging](https://github.com/pypa/packaging) from 24.1 to 24.2. - [Release notes](https://github.com/pypa/packaging/releases) - [Changelog](https://github.com/pypa/packaging/blob/main/CHANGELOG.rst) - [Commits](https://github.com/pypa/packaging/compare/24.1...24.2) --- updated-dependencies: - dependency-name: packaging dependency-type: direct:development update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- requirements_dev.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements_dev.txt b/requirements_dev.txt index 53db936..8f9cbdc 100644 --- a/requirements_dev.txt +++ b/requirements_dev.txt @@ -7,7 +7,7 @@ iniconfig == 2.0.0 isort == 5.13.2 mccabe == 0.7.0 mypy-extensions == 1.0.0 -packaging == 24.1 +packaging == 24.2 pathspec == 0.12.1 platformdirs == 4.3.6 pluggy == 1.5.0 From 42553e24f25a641f9fed80d89868836112a9d849 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 20 Nov 2024 15:39:37 +0000 Subject: [PATCH 095/141] Bump blinker from 1.8.2 to 1.9.0 Bumps [blinker](https://github.com/pallets-eco/blinker) from 1.8.2 to 1.9.0. - [Release notes](https://github.com/pallets-eco/blinker/releases) - [Changelog](https://github.com/pallets-eco/blinker/blob/main/CHANGES.rst) - [Commits](https://github.com/pallets-eco/blinker/compare/1.8.2...1.9.0) --- updated-dependencies: - dependency-name: blinker dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index 2131acd..58b059c 100644 --- a/requirements.txt +++ b/requirements.txt @@ -2,7 +2,7 @@ aiohappyeyeballs == 2.4.3 aiohttp == 3.10.10 aiosignal == 1.3.1 attrs == 24.2.0 -blinker == 1.8.2 +blinker == 1.9.0 certifi == 2024.8.30 charset-normalizer == 3.4.0 click == 8.1.7 From 5ce1879d4a55b5c7e1e10fa70c0643df932277b1 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 20 Nov 2024 15:42:19 +0000 Subject: [PATCH 096/141] Bump werkzeug from 3.1.1 to 3.1.3 Bumps [werkzeug](https://github.com/pallets/werkzeug) from 3.1.1 to 3.1.3. - [Release notes](https://github.com/pallets/werkzeug/releases) - [Changelog](https://github.com/pallets/werkzeug/blob/main/CHANGES.rst) - [Commits](https://github.com/pallets/werkzeug/compare/3.1.1...3.1.3) --- updated-dependencies: - dependency-name: werkzeug dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index 58b059c..aeaa85e 100644 --- a/requirements.txt +++ b/requirements.txt @@ -19,5 +19,5 @@ py-cord == 2.6.1 python-dotenv == 1.0.1 requests == 2.32.3 urllib3 == 2.2.3 -werkzeug == 3.1.1 +werkzeug == 3.1.3 yarl == 1.17.1 From ef8c0a847b621dff70adfc601187a7fbebe624a8 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 20 Nov 2024 15:45:17 +0000 Subject: [PATCH 097/141] Bump flask from 3.0.3 to 3.1.0 Bumps [flask](https://github.com/pallets/flask) from 3.0.3 to 3.1.0. - [Release notes](https://github.com/pallets/flask/releases) - [Changelog](https://github.com/pallets/flask/blob/main/CHANGES.rst) - [Commits](https://github.com/pallets/flask/compare/3.0.3...3.1.0) --- updated-dependencies: - dependency-name: flask dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- pyproject.toml | 2 +- requirements.txt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 476bacc..13aa567 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -28,7 +28,7 @@ urls.repository = "https://github.com/SCAICT/SCAICT-uwu.git" urls.issues = "https://github.com/SCAICT/SCAICT-uwu/issues" # Lock file: requirements.txt dependencies = [ - "flask == 3.0.3", + "flask == 3.1.0", "mysql-connector-python == 9.1.0", "py-cord == 2.6.1", "python-dotenv == 1.0.1", diff --git a/requirements.txt b/requirements.txt index aeaa85e..edd1c60 100644 --- a/requirements.txt +++ b/requirements.txt @@ -7,7 +7,7 @@ certifi == 2024.8.30 charset-normalizer == 3.4.0 click == 8.1.7 colorama == 0.4.6 -flask == 3.0.3 +flask == 3.1.0 frozenlist == 1.5.0 idna == 3.10 itsdangerous == 2.2.0 From 45801f347ec52d73e4dd64d7a22c44e6d9d83d24 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 20 Nov 2024 15:47:56 +0000 Subject: [PATCH 098/141] Bump yarl from 1.17.1 to 1.17.2 Bumps [yarl](https://github.com/aio-libs/yarl) from 1.17.1 to 1.17.2. - [Release notes](https://github.com/aio-libs/yarl/releases) - [Changelog](https://github.com/aio-libs/yarl/blob/master/CHANGES.rst) - [Commits](https://github.com/aio-libs/yarl/compare/v1.17.1...v1.17.2) --- updated-dependencies: - dependency-name: yarl dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index edd1c60..320df8c 100644 --- a/requirements.txt +++ b/requirements.txt @@ -20,4 +20,4 @@ python-dotenv == 1.0.1 requests == 2.32.3 urllib3 == 2.2.3 werkzeug == 3.1.3 -yarl == 1.17.1 +yarl == 1.17.2 From 691d1401674c8d3579aa76501fcbea7307ac8495 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 20 Nov 2024 15:51:36 +0000 Subject: [PATCH 099/141] Bump aiohttp from 3.10.10 to 3.11.6 Bumps [aiohttp](https://github.com/aio-libs/aiohttp) from 3.10.10 to 3.11.6. - [Release notes](https://github.com/aio-libs/aiohttp/releases) - [Changelog](https://github.com/aio-libs/aiohttp/blob/master/CHANGES.rst) - [Commits](https://github.com/aio-libs/aiohttp/compare/v3.10.10...v3.11.6) --- updated-dependencies: - dependency-name: aiohttp dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index 320df8c..9dd025b 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,5 +1,5 @@ aiohappyeyeballs == 2.4.3 -aiohttp == 3.10.10 +aiohttp == 3.11.6 aiosignal == 1.3.1 attrs == 24.2.0 blinker == 1.9.0 From 4d463b9a5dd4ca38edf8a6d8c885c0f4f8090736 Mon Sep 17 00:00:00 2001 From: YuevUwU <96368079+YuevUwU@users.noreply.github.com> Date: Thu, 21 Nov 2024 05:54:59 +0800 Subject: [PATCH 100/141] fix: Unmatched name of GITHUB_DISCORD_REDIRECT_URI and order --- .env.example | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.env.example b/.env.example index 67ef289..0cff0b3 100644 --- a/.env.example +++ b/.env.example @@ -14,11 +14,11 @@ GUILD_ID=機器人所在伺服器ID # Flask configuration SECRET_KEY=隨機字串,給 flask session 使用 -DISCORD_CLIENT_SECRET=Discord Client Secret,到 Discord Developer Portal 取得 DISCORD_CLIENT_ID=Discord Client ID +DISCORD_CLIENT_SECRET=Discord Client Secret,到 Discord Developer Portal 取得 DISCORD_REDIRECT_URI=商店網址/callback GITHUB_CLIENT_ID=GitHub Client ID,到 GitHub Developer 取得 GITHUB_CLIENT_SECRET=GitHub Client Secret GITHUB_REDIRECT_URI=GitHub OAuth Redirect URI -GITHUB_DISCORD_REDIRECT= +GITHUB_DISCORD_REDIRECT_URI= SEND_GIFT_ROLE=允許發送禮物的身分組ID,多個身分組ID以逗號分隔 From 752f766a73044a01d7e7dd31eb27654bfee730ec Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 22 Nov 2024 18:07:46 +0000 Subject: [PATCH 101/141] Bump yarl from 1.17.2 to 1.18.0 Bumps [yarl](https://github.com/aio-libs/yarl) from 1.17.2 to 1.18.0. - [Release notes](https://github.com/aio-libs/yarl/releases) - [Changelog](https://github.com/aio-libs/yarl/blob/master/CHANGES.rst) - [Commits](https://github.com/aio-libs/yarl/compare/v1.17.2...v1.18.0) --- updated-dependencies: - dependency-name: yarl dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index 9dd025b..bf2aee8 100644 --- a/requirements.txt +++ b/requirements.txt @@ -20,4 +20,4 @@ python-dotenv == 1.0.1 requests == 2.32.3 urllib3 == 2.2.3 werkzeug == 3.1.3 -yarl == 1.17.2 +yarl == 1.18.0 From 61f2816c74f789eddbfe9f633be72b9df54bc71c Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 22 Nov 2024 18:10:14 +0000 Subject: [PATCH 102/141] Bump aiohttp from 3.11.6 to 3.11.7 Bumps [aiohttp](https://github.com/aio-libs/aiohttp) from 3.11.6 to 3.11.7. - [Release notes](https://github.com/aio-libs/aiohttp/releases) - [Changelog](https://github.com/aio-libs/aiohttp/blob/master/CHANGES.rst) - [Commits](https://github.com/aio-libs/aiohttp/compare/v3.11.6...v3.11.7) --- updated-dependencies: - dependency-name: aiohttp dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index bf2aee8..2e73afc 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,5 +1,5 @@ aiohappyeyeballs == 2.4.3 -aiohttp == 3.11.6 +aiohttp == 3.11.7 aiosignal == 1.3.1 attrs == 24.2.0 blinker == 1.9.0 From e8d363221cd4b6e11a7c07cd5b2c96a5d1b70787 Mon Sep 17 00:00:00 2001 From: Winston Sung Date: Sat, 23 Nov 2024 02:18:51 +0800 Subject: [PATCH 103/141] Fix Pylint CI duplicated runs Change-Id: I57595cf06fea9f2fba30bf355a8c291a4cddfd6c --- .github/workflows/pylint.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/pylint.yml b/.github/workflows/pylint.yml index 9f5abc7..d873bc1 100644 --- a/.github/workflows/pylint.yml +++ b/.github/workflows/pylint.yml @@ -7,6 +7,7 @@ on: jobs: build: + if: github.event_name != 'pull_request' || github.event.pull_request.head.repo.fork == true runs-on: ubuntu-latest strategy: matrix: From 20517c1bb816b07b3f1520b81c22c1f33dd204a5 Mon Sep 17 00:00:00 2001 From: Winston Sung Date: Thu, 28 Nov 2024 02:17:38 +0800 Subject: [PATCH 104/141] Packaging: Prepare src layout migration - Dependency injection - Service container - Service wiring Change-Id: I058ef5706b803d8a415ab088559f893288ab7c48 --- src/scaict_uwu/language/language.py | 42 --------- src/scaict_uwu/language/language_tag.py | 26 ++++++ .../language/language_tag_factory.py | 26 ++++++ src/scaict_uwu/service_container.py | 91 +++++++++++++++++++ src/scaict_uwu/service_wiring.py | 16 ++++ src/scaict_uwu/system_message/message.py | 4 +- 6 files changed, 161 insertions(+), 44 deletions(-) delete mode 100644 src/scaict_uwu/language/language.py create mode 100644 src/scaict_uwu/language/language_tag.py create mode 100644 src/scaict_uwu/language/language_tag_factory.py create mode 100644 src/scaict_uwu/service_container.py create mode 100644 src/scaict_uwu/service_wiring.py diff --git a/src/scaict_uwu/language/language.py b/src/scaict_uwu/language/language.py deleted file mode 100644 index 9852656..0000000 --- a/src/scaict_uwu/language/language.py +++ /dev/null @@ -1,42 +0,0 @@ -""" -This is the module for the class for all languages. -""" - - -class Language: - """ - The Language class deals with language data. - """ - - def get_bcp_47_lang_tag(self) -> str | None: - pass - - def get_bcp_47_lang_subtag(self) -> str | None: - pass - - def get_iso_639_lang_code(self) -> str | None: - pass - - def get_bcp_47_script_subtag(self) -> str | None: - pass - - def get_bcp_47_region_subtag(self) -> str | None: - pass - - def get_bcp_47_variant_subtags(self) -> list | None: - pass - - def get_bcp_47_private_subtags(self) -> list | None: - pass - - def get_writing_mode(self) -> str | None: - pass - - def get_writing_mode_dir(self) -> str | None: - pass - - def get_writing_mode_prop(self) -> str | None: - pass - - def get_lang_fallbacks(self) -> list | None: - pass diff --git a/src/scaict_uwu/language/language_tag.py b/src/scaict_uwu/language/language_tag.py new file mode 100644 index 0000000..bf8eb89 --- /dev/null +++ b/src/scaict_uwu/language/language_tag.py @@ -0,0 +1,26 @@ +""" +This is the module for the class for all languages. +""" + + +class LanguageTag: + """ + The LanguageTag class deals with language data. + """ + + _tag: str + """ + _tag (str): The BCP 47 language subtag of the LanguageTag object. + """ + + def __init__(self, language_tag) -> None: + pass + + def get_bcp_47_tag(self) -> str | None: + pass + + def get_discord_code(self) -> str | None: + pass + + def get_fallbacks(self) -> list | None: + pass diff --git a/src/scaict_uwu/language/language_tag_factory.py b/src/scaict_uwu/language/language_tag_factory.py new file mode 100644 index 0000000..ee04888 --- /dev/null +++ b/src/scaict_uwu/language/language_tag_factory.py @@ -0,0 +1,26 @@ +""" +This is the module for creating the objects for all languages. +""" + +# Local imports +from .language_tag import LanguageTag + + +class LanguageTagFactory: + """ + The LanguageTagFactory class deals with LanguageTag object creations. + """ + + _tags: dict = {} + """ + _tags (dict): The LanguageTag objects. + """ + + def __init__(self) -> None: + pass + + def get_tag(self) -> LanguageTag | None: + pass + + def get_tag_by_discord_code(self) -> LanguageTag | None: + pass diff --git a/src/scaict_uwu/service_container.py b/src/scaict_uwu/service_container.py new file mode 100644 index 0000000..740c709 --- /dev/null +++ b/src/scaict_uwu/service_container.py @@ -0,0 +1,91 @@ +""" +Module for SCAICT-uwu service locator. +""" + +# Standard imports +import importlib +import sys + + +class ServiceContainer: + """ + Service locator for SCAICT-uwu core services. + + Refer to service_wiring.py for the default implementations. + """ + + _services: dict = {} + """ + """ + + _service_instantiators: dict = {} + """ + """ + + _services_being_created: dict = {} + """ + """ + + def load_wiring_files(self, wiring_modules: list) -> None: + for module_name in wiring_modules: + module = importlib.import_module(module_name) + self.apply_wiring(module.get_wiring()) + + def apply_wiring(self, service_instantiators) -> None: + for name, instantiator in service_instantiators: + self.define_service(name, instantiator) + + def get_service_names(self) -> list: + # Convert dict_keys to list + return list(self._service_instantiators.keys()) + + def has_service(self, name: str) -> bool: + return name in self._service_instantiators + + def define_service(self, name: str, instantiator) -> None: + if self.has_service(name): + sys.exit("ServiceAlreadyDefinedException $name") + + self._service_instantiators[name] = instantiator + + def redefine_service(self, name: str, instantiator) -> None: + if not self.has_service(name): + sys.exit("NoSuchServiceException $name") + + if name in self._services: + sys.exit("CannotReplaceActiveServiceException $name") + + self._service_instantiators[name] = instantiator + + def create_service(self, name: str): + if not self.has_service(name): + sys.exit("NoSuchServiceException $name") + + if not name in self._services_being_created: + sys.exit( + "RecursiveServiceDependencyException " + + "Circular dependency when creating service!" + ) + + self._services_being_created[name] = True + + service = self._service_instantiators[name](self) + + return service + + def get_service(self, name: str): + if not name in self._services: + self._services[name] = self.create_service(name) + + return self._services[name] + + # Service helper functions + + def get_config(self): + return self.get_service("Config") + + def get_language_tag(self): + return self.get_service("LanguageTag") + + def get_language_tag_factory(self): + return self.get_service("LanguageTagFactory") diff --git a/src/scaict_uwu/service_wiring.py b/src/scaict_uwu/service_wiring.py new file mode 100644 index 0000000..f885323 --- /dev/null +++ b/src/scaict_uwu/service_wiring.py @@ -0,0 +1,16 @@ +""" +Module for SCAICT-uwu default service implementations. +""" + +from .service_container import ServiceContainer + + +def get_wiring() -> dict: + """ + Get the service implementation functions. + """ + return {"Config": get_config} + + +def get_config(service_container: ServiceContainer): + pass diff --git a/src/scaict_uwu/system_message/message.py b/src/scaict_uwu/system_message/message.py index 96744fe..4466053 100644 --- a/src/scaict_uwu/system_message/message.py +++ b/src/scaict_uwu/system_message/message.py @@ -3,7 +3,7 @@ """ # Local imports -from ..language.language import Language +from ..language.language_tag import LanguageTag class Message: @@ -27,7 +27,7 @@ def __init__( self, key: str, params: list, - use_lang: Language | None, + use_lang: LanguageTag | None, ) -> None: """ Set the language tag of the language that the message expected to use. From b3f016acf37a06906ac99c323497ae7d314c8c8a Mon Sep 17 00:00:00 2001 From: Winston Sung Date: Mon, 2 Dec 2024 04:09:12 +0800 Subject: [PATCH 105/141] Packaging: Prepare src layout migration - LanguageTag - LanguageTagFactory - LanguageUtils Change-Id: I4ae5e5d1f07f316d3bcf3c9da0d8985890a22128 --- src/scaict_uwu/bot.py | 9 ++ src/scaict_uwu/bot_pycord.py | 5 - src/scaict_uwu/config/config_names.py | 7 ++ src/scaict_uwu/config/config_schema.py | 7 ++ src/scaict_uwu/language/language_tag.py | 55 ++++++++-- .../language/language_tag_factory.py | 39 ++++++- src/scaict_uwu/language/language_utils.py | 100 ++++++++++++++++++ .../{website_flask.py => website.py} | 8 +- 8 files changed, 211 insertions(+), 19 deletions(-) create mode 100644 src/scaict_uwu/bot.py delete mode 100644 src/scaict_uwu/bot_pycord.py create mode 100644 src/scaict_uwu/config/config_names.py create mode 100644 src/scaict_uwu/config/config_schema.py rename src/scaict_uwu/{website_flask.py => website.py} (52%) diff --git a/src/scaict_uwu/bot.py b/src/scaict_uwu/bot.py new file mode 100644 index 0000000..5a24462 --- /dev/null +++ b/src/scaict_uwu/bot.py @@ -0,0 +1,9 @@ +""" +Entry point for Discord bot using Pycord. +""" + + +def run() -> None: + """ + TODO: Complete this + """ diff --git a/src/scaict_uwu/bot_pycord.py b/src/scaict_uwu/bot_pycord.py deleted file mode 100644 index da0bf6c..0000000 --- a/src/scaict_uwu/bot_pycord.py +++ /dev/null @@ -1,5 +0,0 @@ -""" -Entry point for Discord bot using Pycord. - -TODO: Complete this -""" diff --git a/src/scaict_uwu/config/config_names.py b/src/scaict_uwu/config/config_names.py new file mode 100644 index 0000000..5145bc1 --- /dev/null +++ b/src/scaict_uwu/config/config_names.py @@ -0,0 +1,7 @@ +""" +Config names +""" + + +class ConfigNames: + pass diff --git a/src/scaict_uwu/config/config_schema.py b/src/scaict_uwu/config/config_schema.py new file mode 100644 index 0000000..602704d --- /dev/null +++ b/src/scaict_uwu/config/config_schema.py @@ -0,0 +1,7 @@ +""" +Config schema +""" + + +class ConfigSchema: + pass diff --git a/src/scaict_uwu/language/language_tag.py b/src/scaict_uwu/language/language_tag.py index bf8eb89..7ce4985 100644 --- a/src/scaict_uwu/language/language_tag.py +++ b/src/scaict_uwu/language/language_tag.py @@ -2,6 +2,8 @@ This is the module for the class for all languages. """ +from .language_utils import LanguageUtils + class LanguageTag: """ @@ -13,14 +15,53 @@ class LanguageTag: _tag (str): The BCP 47 language subtag of the LanguageTag object. """ - def __init__(self, language_tag) -> None: - pass + def __init__(self, language_tag: str) -> None: + """ + Parameters: + language_tag (str): BCP 47 language tag. + """ + + self._tag = language_tag + + def get_bcp_47_tag(self) -> str: + """ + Get the BCP 47 language tag of the LanguageTag object. + + Returns: + str: The BCP 47 language tag. + """ + + return self._tag + + def get_system_message_tag(self) -> str: + """ + Get the system message language tag of the LanguageTag object. - def get_bcp_47_tag(self) -> str | None: - pass + Returns: + str: The system message language tag. + """ + + return self._tag.lower() def get_discord_code(self) -> str | None: - pass + """ + Get the Discord locale code of the LanguageTag object. + + See + + Returns: + str: The Discord locale code. + """ + + return LanguageUtils.get_discord_code(self._tag) + + def get_fallbacks(self) -> list: + """ + Get the language fallback chain of the LanguageTag object. + + Returns: + list: The list containing BCP 47 language tags of the language\ + fallback chain. + """ - def get_fallbacks(self) -> list | None: - pass + return [] diff --git a/src/scaict_uwu/language/language_tag_factory.py b/src/scaict_uwu/language/language_tag_factory.py index ee04888..b81f905 100644 --- a/src/scaict_uwu/language/language_tag_factory.py +++ b/src/scaict_uwu/language/language_tag_factory.py @@ -4,6 +4,7 @@ # Local imports from .language_tag import LanguageTag +from .language_utils import LanguageUtils class LanguageTagFactory: @@ -11,7 +12,7 @@ class LanguageTagFactory: The LanguageTagFactory class deals with LanguageTag object creations. """ - _tags: dict = {} + _tags: dict[str, LanguageTag] = {} """ _tags (dict): The LanguageTag objects. """ @@ -19,8 +20,36 @@ class LanguageTagFactory: def __init__(self) -> None: pass - def get_tag(self) -> LanguageTag | None: - pass + def get_tag(self, tag) -> LanguageTag: + """ + Get LanguageTag object by BCP 47 language tag. - def get_tag_by_discord_code(self) -> LanguageTag | None: - pass + Returns: + LanguageTag: The LanguageTag object to the responding BCP 47\ + language tag. + """ + + if not tag in self._tags: + self._tags[tag] = LanguageTag(tag) + + return self._tags[tag] + + def get_tag_by_discord_code(self, code) -> LanguageTag | None: + """ + Get LanguageTag object by BCP 47 language tag. + + Returns: + (LanguageTag | None): The LanguageTag object to the responding\ + Discord locale code. Return None when is not a supported\ + Discord locale code. + """ + + if not code in LanguageUtils.get_supported_discord_codes(): + return None + + tag = LanguageUtils.get_bcp_47_from_discord_code(code) + + if not tag in self._tags: + self._tags[tag] = LanguageTag(tag) + + return self._tags[tag] diff --git a/src/scaict_uwu/language/language_utils.py b/src/scaict_uwu/language/language_utils.py index 183cf68..f1ddd47 100644 --- a/src/scaict_uwu/language/language_utils.py +++ b/src/scaict_uwu/language/language_utils.py @@ -7,3 +7,103 @@ class LanguageUtils: """ The LanguageUtils class deals with language utilities. """ + + @staticmethod + def get_supported_discord_codes() -> list: + """ + Get the Discord locale codes supported by Discord. + + See Pycord discord.commands.core valid_locales (not public) + See + + Returns: + list: The list of Discord locale codes supported by Discord. + """ + + return [ + "bg", + "cs", + "da", + "de", + "el", + "en-GB", + "en-US", + # 'es-419' was missing from Pycord + "es-419", + "es-ES", + "fi", + "fr", + "hi", + "hr", + "hu", + # 'id' was missing from Pycord + "id", + "it", + "ja", + "ko", + "lt", + "nl", + "no", + "pl", + "pt-BR", + "ro", + "ru", + "sv-SE", + "th", + "tr", + "uk", + "vi", + "zh-CN", + "zh-TW", + ] + + @staticmethod + def get_discord_code_mapping() -> dict: + """ + Get the mapping of BCP 47 language tag to Discord locale code. + + Returns: + dict: The mapping of BCP 47 language tag to Discord locale code. + """ + + return { + "en": "en-US", + "es": "es-ES", + "nb": "no", + "sv": "sv-SE", + "zh-Hans": "zh-CN", + "zh-Hant": "zh-TW", + } + + @classmethod + def get_discord_code_to_bcp_47_mapping(cls) -> dict: + """ + Get the mapping of Discord locale code to BCP 47 language tag. + + Returns: + dict: The mapping of Discord locale code to BCP 47 language tag. + """ + + return {v: k for k, v in cls.get_discord_code_mapping()} + + @classmethod + def get_discord_code(cls, code) -> str: + """ + Get the BCP 47 language tag from Discord locale code. + + Returns: + str: the mapping of Discord locale code to BCP 47 language tag. + """ + + return cls.get_discord_code_mapping().get(code, code) + + @classmethod + def get_bcp_47_from_discord_code(cls, code) -> str: + """ + Get the BCP 47 language tag from Discord locale code. + + Returns: + str: the mapping of Discord locale code to BCP 47 language tag. + """ + + return cls.get_discord_code_to_bcp_47_mapping().get(code, code) diff --git a/src/scaict_uwu/website_flask.py b/src/scaict_uwu/website.py similarity index 52% rename from src/scaict_uwu/website_flask.py rename to src/scaict_uwu/website.py index f6926dc..6dd86bc 100644 --- a/src/scaict_uwu/website_flask.py +++ b/src/scaict_uwu/website.py @@ -1,5 +1,9 @@ """ Entry point for the SCAICT store website using Flask run. - -TODO: Complete this """ + + +def run() -> None: + """ + TODO: Complete this + """ From 684e21fb1dfcdf737c79631479b5ebbc134c55b3 Mon Sep 17 00:00:00 2001 From: Winston Sung Date: Mon, 2 Dec 2024 04:23:51 +0800 Subject: [PATCH 106/141] Packaging: Prepare src layout migration Rearrange modules to prevent folder name conflict with module name Change-Id: I81a80d9bd60a78599cb78e4206da386186a4ea63 --- src/scaict_uwu/{bot => core}/__init__.py | 0 src/scaict_uwu/{bot/channels => core/bot}/__init__.py | 0 src/scaict_uwu/{bot/cogs => core/bot/channels}/__init__.py | 0 src/scaict_uwu/{bot/emoji => core/bot/cogs}/__init__.py | 0 src/scaict_uwu/{bot/slash_commands => core/bot/emoji}/__init__.py | 0 src/scaict_uwu/{bot/users => core/bot/slash_commands}/__init__.py | 0 src/scaict_uwu/{config => core/bot/users}/__init__.py | 0 src/scaict_uwu/{installer => core/config}/__init__.py | 0 src/scaict_uwu/{ => core}/config/config.py | 0 src/scaict_uwu/{ => core}/config/config_factory.py | 0 src/scaict_uwu/{ => core}/config/config_names.py | 0 src/scaict_uwu/{ => core}/config/config_schema.py | 0 src/scaict_uwu/{installer/cog => core/maintenance}/__init__.py | 0 src/scaict_uwu/{ => core}/maintenance/data/tables.json | 0 .../{ => core}/maintenance/data/tables_diagram_layout.json | 0 src/scaict_uwu/{ => core}/maintenance/maintenance.py | 0 src/scaict_uwu/{ => core}/maintenance/parameters.py | 0 src/scaict_uwu/{language => core/maintenance/scripts}/__init__.py | 0 src/scaict_uwu/{ => core}/maintenance/scripts/update.py | 0 src/scaict_uwu/{logging => core/stats}/__init__.py | 0 src/scaict_uwu/{maintenance => core/user}/__init__.py | 0 src/scaict_uwu/{maintenance/scripts => core/utils}/__init__.py | 0 src/scaict_uwu/{rdbms => core/website}/__init__.py | 0 src/scaict_uwu/{stats => libs}/__init__.py | 0 src/scaict_uwu/{system_message => libs/language}/__init__.py | 0 src/scaict_uwu/{ => libs}/language/language_tag.py | 0 src/scaict_uwu/{ => libs}/language/language_tag_factory.py | 0 src/scaict_uwu/{ => libs}/language/language_utils.py | 0 src/scaict_uwu/{user => libs/logging}/__init__.py | 0 src/scaict_uwu/{utils => libs/rdbms}/__init__.py | 0 src/scaict_uwu/{website => libs/system_message}/__init__.py | 0 src/scaict_uwu/{ => libs}/system_message/message.py | 0 32 files changed, 0 insertions(+), 0 deletions(-) rename src/scaict_uwu/{bot => core}/__init__.py (100%) rename src/scaict_uwu/{bot/channels => core/bot}/__init__.py (100%) rename src/scaict_uwu/{bot/cogs => core/bot/channels}/__init__.py (100%) rename src/scaict_uwu/{bot/emoji => core/bot/cogs}/__init__.py (100%) rename src/scaict_uwu/{bot/slash_commands => core/bot/emoji}/__init__.py (100%) rename src/scaict_uwu/{bot/users => core/bot/slash_commands}/__init__.py (100%) rename src/scaict_uwu/{config => core/bot/users}/__init__.py (100%) rename src/scaict_uwu/{installer => core/config}/__init__.py (100%) rename src/scaict_uwu/{ => core}/config/config.py (100%) rename src/scaict_uwu/{ => core}/config/config_factory.py (100%) rename src/scaict_uwu/{ => core}/config/config_names.py (100%) rename src/scaict_uwu/{ => core}/config/config_schema.py (100%) rename src/scaict_uwu/{installer/cog => core/maintenance}/__init__.py (100%) rename src/scaict_uwu/{ => core}/maintenance/data/tables.json (100%) rename src/scaict_uwu/{ => core}/maintenance/data/tables_diagram_layout.json (100%) rename src/scaict_uwu/{ => core}/maintenance/maintenance.py (100%) rename src/scaict_uwu/{ => core}/maintenance/parameters.py (100%) rename src/scaict_uwu/{language => core/maintenance/scripts}/__init__.py (100%) rename src/scaict_uwu/{ => core}/maintenance/scripts/update.py (100%) rename src/scaict_uwu/{logging => core/stats}/__init__.py (100%) rename src/scaict_uwu/{maintenance => core/user}/__init__.py (100%) rename src/scaict_uwu/{maintenance/scripts => core/utils}/__init__.py (100%) rename src/scaict_uwu/{rdbms => core/website}/__init__.py (100%) rename src/scaict_uwu/{stats => libs}/__init__.py (100%) rename src/scaict_uwu/{system_message => libs/language}/__init__.py (100%) rename src/scaict_uwu/{ => libs}/language/language_tag.py (100%) rename src/scaict_uwu/{ => libs}/language/language_tag_factory.py (100%) rename src/scaict_uwu/{ => libs}/language/language_utils.py (100%) rename src/scaict_uwu/{user => libs/logging}/__init__.py (100%) rename src/scaict_uwu/{utils => libs/rdbms}/__init__.py (100%) rename src/scaict_uwu/{website => libs/system_message}/__init__.py (100%) rename src/scaict_uwu/{ => libs}/system_message/message.py (100%) diff --git a/src/scaict_uwu/bot/__init__.py b/src/scaict_uwu/core/__init__.py similarity index 100% rename from src/scaict_uwu/bot/__init__.py rename to src/scaict_uwu/core/__init__.py diff --git a/src/scaict_uwu/bot/channels/__init__.py b/src/scaict_uwu/core/bot/__init__.py similarity index 100% rename from src/scaict_uwu/bot/channels/__init__.py rename to src/scaict_uwu/core/bot/__init__.py diff --git a/src/scaict_uwu/bot/cogs/__init__.py b/src/scaict_uwu/core/bot/channels/__init__.py similarity index 100% rename from src/scaict_uwu/bot/cogs/__init__.py rename to src/scaict_uwu/core/bot/channels/__init__.py diff --git a/src/scaict_uwu/bot/emoji/__init__.py b/src/scaict_uwu/core/bot/cogs/__init__.py similarity index 100% rename from src/scaict_uwu/bot/emoji/__init__.py rename to src/scaict_uwu/core/bot/cogs/__init__.py diff --git a/src/scaict_uwu/bot/slash_commands/__init__.py b/src/scaict_uwu/core/bot/emoji/__init__.py similarity index 100% rename from src/scaict_uwu/bot/slash_commands/__init__.py rename to src/scaict_uwu/core/bot/emoji/__init__.py diff --git a/src/scaict_uwu/bot/users/__init__.py b/src/scaict_uwu/core/bot/slash_commands/__init__.py similarity index 100% rename from src/scaict_uwu/bot/users/__init__.py rename to src/scaict_uwu/core/bot/slash_commands/__init__.py diff --git a/src/scaict_uwu/config/__init__.py b/src/scaict_uwu/core/bot/users/__init__.py similarity index 100% rename from src/scaict_uwu/config/__init__.py rename to src/scaict_uwu/core/bot/users/__init__.py diff --git a/src/scaict_uwu/installer/__init__.py b/src/scaict_uwu/core/config/__init__.py similarity index 100% rename from src/scaict_uwu/installer/__init__.py rename to src/scaict_uwu/core/config/__init__.py diff --git a/src/scaict_uwu/config/config.py b/src/scaict_uwu/core/config/config.py similarity index 100% rename from src/scaict_uwu/config/config.py rename to src/scaict_uwu/core/config/config.py diff --git a/src/scaict_uwu/config/config_factory.py b/src/scaict_uwu/core/config/config_factory.py similarity index 100% rename from src/scaict_uwu/config/config_factory.py rename to src/scaict_uwu/core/config/config_factory.py diff --git a/src/scaict_uwu/config/config_names.py b/src/scaict_uwu/core/config/config_names.py similarity index 100% rename from src/scaict_uwu/config/config_names.py rename to src/scaict_uwu/core/config/config_names.py diff --git a/src/scaict_uwu/config/config_schema.py b/src/scaict_uwu/core/config/config_schema.py similarity index 100% rename from src/scaict_uwu/config/config_schema.py rename to src/scaict_uwu/core/config/config_schema.py diff --git a/src/scaict_uwu/installer/cog/__init__.py b/src/scaict_uwu/core/maintenance/__init__.py similarity index 100% rename from src/scaict_uwu/installer/cog/__init__.py rename to src/scaict_uwu/core/maintenance/__init__.py diff --git a/src/scaict_uwu/maintenance/data/tables.json b/src/scaict_uwu/core/maintenance/data/tables.json similarity index 100% rename from src/scaict_uwu/maintenance/data/tables.json rename to src/scaict_uwu/core/maintenance/data/tables.json diff --git a/src/scaict_uwu/maintenance/data/tables_diagram_layout.json b/src/scaict_uwu/core/maintenance/data/tables_diagram_layout.json similarity index 100% rename from src/scaict_uwu/maintenance/data/tables_diagram_layout.json rename to src/scaict_uwu/core/maintenance/data/tables_diagram_layout.json diff --git a/src/scaict_uwu/maintenance/maintenance.py b/src/scaict_uwu/core/maintenance/maintenance.py similarity index 100% rename from src/scaict_uwu/maintenance/maintenance.py rename to src/scaict_uwu/core/maintenance/maintenance.py diff --git a/src/scaict_uwu/maintenance/parameters.py b/src/scaict_uwu/core/maintenance/parameters.py similarity index 100% rename from src/scaict_uwu/maintenance/parameters.py rename to src/scaict_uwu/core/maintenance/parameters.py diff --git a/src/scaict_uwu/language/__init__.py b/src/scaict_uwu/core/maintenance/scripts/__init__.py similarity index 100% rename from src/scaict_uwu/language/__init__.py rename to src/scaict_uwu/core/maintenance/scripts/__init__.py diff --git a/src/scaict_uwu/maintenance/scripts/update.py b/src/scaict_uwu/core/maintenance/scripts/update.py similarity index 100% rename from src/scaict_uwu/maintenance/scripts/update.py rename to src/scaict_uwu/core/maintenance/scripts/update.py diff --git a/src/scaict_uwu/logging/__init__.py b/src/scaict_uwu/core/stats/__init__.py similarity index 100% rename from src/scaict_uwu/logging/__init__.py rename to src/scaict_uwu/core/stats/__init__.py diff --git a/src/scaict_uwu/maintenance/__init__.py b/src/scaict_uwu/core/user/__init__.py similarity index 100% rename from src/scaict_uwu/maintenance/__init__.py rename to src/scaict_uwu/core/user/__init__.py diff --git a/src/scaict_uwu/maintenance/scripts/__init__.py b/src/scaict_uwu/core/utils/__init__.py similarity index 100% rename from src/scaict_uwu/maintenance/scripts/__init__.py rename to src/scaict_uwu/core/utils/__init__.py diff --git a/src/scaict_uwu/rdbms/__init__.py b/src/scaict_uwu/core/website/__init__.py similarity index 100% rename from src/scaict_uwu/rdbms/__init__.py rename to src/scaict_uwu/core/website/__init__.py diff --git a/src/scaict_uwu/stats/__init__.py b/src/scaict_uwu/libs/__init__.py similarity index 100% rename from src/scaict_uwu/stats/__init__.py rename to src/scaict_uwu/libs/__init__.py diff --git a/src/scaict_uwu/system_message/__init__.py b/src/scaict_uwu/libs/language/__init__.py similarity index 100% rename from src/scaict_uwu/system_message/__init__.py rename to src/scaict_uwu/libs/language/__init__.py diff --git a/src/scaict_uwu/language/language_tag.py b/src/scaict_uwu/libs/language/language_tag.py similarity index 100% rename from src/scaict_uwu/language/language_tag.py rename to src/scaict_uwu/libs/language/language_tag.py diff --git a/src/scaict_uwu/language/language_tag_factory.py b/src/scaict_uwu/libs/language/language_tag_factory.py similarity index 100% rename from src/scaict_uwu/language/language_tag_factory.py rename to src/scaict_uwu/libs/language/language_tag_factory.py diff --git a/src/scaict_uwu/language/language_utils.py b/src/scaict_uwu/libs/language/language_utils.py similarity index 100% rename from src/scaict_uwu/language/language_utils.py rename to src/scaict_uwu/libs/language/language_utils.py diff --git a/src/scaict_uwu/user/__init__.py b/src/scaict_uwu/libs/logging/__init__.py similarity index 100% rename from src/scaict_uwu/user/__init__.py rename to src/scaict_uwu/libs/logging/__init__.py diff --git a/src/scaict_uwu/utils/__init__.py b/src/scaict_uwu/libs/rdbms/__init__.py similarity index 100% rename from src/scaict_uwu/utils/__init__.py rename to src/scaict_uwu/libs/rdbms/__init__.py diff --git a/src/scaict_uwu/website/__init__.py b/src/scaict_uwu/libs/system_message/__init__.py similarity index 100% rename from src/scaict_uwu/website/__init__.py rename to src/scaict_uwu/libs/system_message/__init__.py diff --git a/src/scaict_uwu/system_message/message.py b/src/scaict_uwu/libs/system_message/message.py similarity index 100% rename from src/scaict_uwu/system_message/message.py rename to src/scaict_uwu/libs/system_message/message.py From c0f0a90534c9d5aa77dc326c315cf9ccd3a126bc Mon Sep 17 00:00:00 2001 From: Winston Sung Date: Mon, 2 Dec 2024 15:17:31 +0800 Subject: [PATCH 107/141] Packaging: Prepare src layout migration Change-Id: I03f566f159ea56a57b005110d9140d961ef15333 --- src/scaict_uwu/core/config/config.py | 12 ++++- src/scaict_uwu/core/config/config_factory.py | 6 ++- .../{core/maintenance => }/data/tables.json | 0 .../data/tables_diagram_layout.json | 0 src/scaict_uwu/libs/exceptions/__init__.py | 0 src/scaict_uwu/libs/language/language_tag.py | 22 ++++++--- .../libs/language/language_tag_factory.py | 28 ++++++----- .../libs/language/language_utils.py | 49 ++++++++++++++----- src/scaict_uwu/libs/system_message/message.py | 12 ++--- src/scaict_uwu/service_container.py | 38 ++++++++------ src/scaict_uwu/service_wiring.py | 37 ++++++++++++-- 11 files changed, 148 insertions(+), 56 deletions(-) rename src/scaict_uwu/{core/maintenance => }/data/tables.json (100%) rename src/scaict_uwu/{core/maintenance => }/data/tables_diagram_layout.json (100%) create mode 100644 src/scaict_uwu/libs/exceptions/__init__.py diff --git a/src/scaict_uwu/core/config/config.py b/src/scaict_uwu/core/config/config.py index d76a02c..1ae2e48 100644 --- a/src/scaict_uwu/core/config/config.py +++ b/src/scaict_uwu/core/config/config.py @@ -2,6 +2,16 @@ Config """ +# Standard imports +import sys +from typing import ClassVar + class Config: - pass + options: ClassVar[dict] + + def get_option(self, name: str): + if name in self.options: + return self.options[name] + + sys.exit("NoSuchOptionExpection") diff --git a/src/scaict_uwu/core/config/config_factory.py b/src/scaict_uwu/core/config/config_factory.py index ca6ef1c..e91dff2 100644 --- a/src/scaict_uwu/core/config/config_factory.py +++ b/src/scaict_uwu/core/config/config_factory.py @@ -2,6 +2,10 @@ Config factory """ +# Local imports +from .config import Config + class ConfigFactory: - pass + def get(self) -> Config: + return Config() diff --git a/src/scaict_uwu/core/maintenance/data/tables.json b/src/scaict_uwu/data/tables.json similarity index 100% rename from src/scaict_uwu/core/maintenance/data/tables.json rename to src/scaict_uwu/data/tables.json diff --git a/src/scaict_uwu/core/maintenance/data/tables_diagram_layout.json b/src/scaict_uwu/data/tables_diagram_layout.json similarity index 100% rename from src/scaict_uwu/core/maintenance/data/tables_diagram_layout.json rename to src/scaict_uwu/data/tables_diagram_layout.json diff --git a/src/scaict_uwu/libs/exceptions/__init__.py b/src/scaict_uwu/libs/exceptions/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/src/scaict_uwu/libs/language/language_tag.py b/src/scaict_uwu/libs/language/language_tag.py index 7ce4985..d667584 100644 --- a/src/scaict_uwu/libs/language/language_tag.py +++ b/src/scaict_uwu/libs/language/language_tag.py @@ -8,6 +8,15 @@ class LanguageTag: """ The LanguageTag class deals with language data. + + Note: + This class is designed to be instantiated through LanguageTagFactory\ + rather than directly. + + Example: + language_tag_factory = LanguageTagFactory() + tag = language_tag_factory.get("zh-Hant") + tag = language_tag_factory.get_by_discord_code("zh-TW") """ _tag: str @@ -15,13 +24,13 @@ class LanguageTag: _tag (str): The BCP 47 language subtag of the LanguageTag object. """ - def __init__(self, language_tag: str) -> None: + def __init__(self, tag: str) -> None: """ Parameters: - language_tag (str): BCP 47 language tag. + tag (str): BCP 47 language tag. """ - self._tag = language_tag + self._tag = tag def get_bcp_47_tag(self) -> str: """ @@ -50,17 +59,18 @@ def get_discord_code(self) -> str | None: See Returns: - str: The Discord locale code. + (str | None): The Discord locale code. Return None when there is no\ + corresponding supported Discord locale code. """ return LanguageUtils.get_discord_code(self._tag) - def get_fallbacks(self) -> list: + def get_fallbacks(self) -> list[str]: """ Get the language fallback chain of the LanguageTag object. Returns: - list: The list containing BCP 47 language tags of the language\ + list[str]: The list containing BCP 47 language tags of the language\ fallback chain. """ diff --git a/src/scaict_uwu/libs/language/language_tag_factory.py b/src/scaict_uwu/libs/language/language_tag_factory.py index b81f905..2033760 100644 --- a/src/scaict_uwu/libs/language/language_tag_factory.py +++ b/src/scaict_uwu/libs/language/language_tag_factory.py @@ -2,6 +2,9 @@ This is the module for creating the objects for all languages. """ +# Standard imports +from typing import ClassVar + # Local imports from .language_tag import LanguageTag from .language_utils import LanguageUtils @@ -12,44 +15,47 @@ class LanguageTagFactory: The LanguageTagFactory class deals with LanguageTag object creations. """ - _tags: dict[str, LanguageTag] = {} + _tags: ClassVar[dict[str, LanguageTag]] = {} """ _tags (dict): The LanguageTag objects. """ - def __init__(self) -> None: - pass - - def get_tag(self, tag) -> LanguageTag: + def get(self, tag: str) -> LanguageTag: """ Get LanguageTag object by BCP 47 language tag. + Parameters: + tag (str): BCP 47 language tag. + Returns: LanguageTag: The LanguageTag object to the responding BCP 47\ language tag. """ - if not tag in self._tags: + if tag not in self._tags: self._tags[tag] = LanguageTag(tag) return self._tags[tag] - def get_tag_by_discord_code(self, code) -> LanguageTag | None: + def get_by_discord_code(self, code: str) -> LanguageTag | None: """ - Get LanguageTag object by BCP 47 language tag. + Get LanguageTag object by Discord locale code. + + Parameters: + code (str): Discord locale code. Returns: - (LanguageTag | None): The LanguageTag object to the responding\ + (LanguageTag | None): The LanguageTag object of the responding\ Discord locale code. Return None when is not a supported\ Discord locale code. """ - if not code in LanguageUtils.get_supported_discord_codes(): + if code not in LanguageUtils.get_supported_discord_codes(): return None tag = LanguageUtils.get_bcp_47_from_discord_code(code) - if not tag in self._tags: + if tag not in self._tags: self._tags[tag] = LanguageTag(tag) return self._tags[tag] diff --git a/src/scaict_uwu/libs/language/language_utils.py b/src/scaict_uwu/libs/language/language_utils.py index f1ddd47..06dd3a9 100644 --- a/src/scaict_uwu/libs/language/language_utils.py +++ b/src/scaict_uwu/libs/language/language_utils.py @@ -9,7 +9,7 @@ class LanguageUtils: """ @staticmethod - def get_supported_discord_codes() -> list: + def get_supported_discord_codes() -> list[str]: """ Get the Discord locale codes supported by Discord. @@ -17,7 +17,7 @@ def get_supported_discord_codes() -> list: See Returns: - list: The list of Discord locale codes supported by Discord. + list[str]: The list of Discord locale codes supported by Discord. """ return [ @@ -58,12 +58,12 @@ def get_supported_discord_codes() -> list: ] @staticmethod - def get_discord_code_mapping() -> dict: + def get_discord_code_mapping() -> dict[str, str]: """ Get the mapping of BCP 47 language tag to Discord locale code. Returns: - dict: The mapping of BCP 47 language tag to Discord locale code. + dict[str, str]: The mapping of BCP 47 language tag to Discord locale code. """ return { @@ -84,26 +84,53 @@ def get_discord_code_to_bcp_47_mapping(cls) -> dict: dict: The mapping of Discord locale code to BCP 47 language tag. """ - return {v: k for k, v in cls.get_discord_code_mapping()} + return {v: k for k, v in cls.get_discord_code_mapping().items()} @classmethod - def get_discord_code(cls, code) -> str: + def is_supported_discord_code(cls, code: str) -> bool: """ - Get the BCP 47 language tag from Discord locale code. + Check if the given code is a supported Discord locale code. + + Parameters: + code (str): Discord locale code. Returns: - str: the mapping of Discord locale code to BCP 47 language tag. + bool: Whether the given code is a supported Discord locale code. """ - return cls.get_discord_code_mapping().get(code, code) + return code in cls.get_supported_discord_codes() @classmethod - def get_bcp_47_from_discord_code(cls, code) -> str: + def get_discord_code(cls, tag: str) -> str | None: + """ + Get the Discord locale code from BCP 47 language tag. + + Parameters: + tag (str): BCP 47 language tag. + + Returns: + (str | None): the Discord locale code of the BCP 47 language tag.\ + Return None when there's no corresponding supported Discord\ + locale code. + """ + + code = cls.get_discord_code_mapping().get(tag, tag) + + if cls.is_supported_discord_code(code): + return code + + return None + + @classmethod + def get_bcp_47_from_discord_code(cls, code: str) -> str: """ Get the BCP 47 language tag from Discord locale code. + Parameters: + code (str): Discord locale code. + Returns: - str: the mapping of Discord locale code to BCP 47 language tag. + str: the BCP 47 language tag of the Discord locale code. """ return cls.get_discord_code_to_bcp_47_mapping().get(code, code) diff --git a/src/scaict_uwu/libs/system_message/message.py b/src/scaict_uwu/libs/system_message/message.py index 4466053..4d372fd 100644 --- a/src/scaict_uwu/libs/system_message/message.py +++ b/src/scaict_uwu/libs/system_message/message.py @@ -11,15 +11,15 @@ class Message: The Message class deals with fetching and processing of system messages. """ - __use_lang: str | None = None + _use_lang: str | None = None """ - __use_lang (str|None): The language tag of the language for the system\ + _use_lang (str|None): The language tag of the language for the system\ message to use. """ - __in_lang: str | None = None + _in_lang: str | None = None """ - __in_lang (str|None): The language tag of the language that the system\ + _in_lang (str|None): The language tag of the language that the system\ message actually used. """ @@ -48,7 +48,7 @@ def set_lang(self, lang_tag: str) -> None: expected to use. """ - self.__use_lang = lang_tag + self._use_lang = lang_tag def get_lang(self) -> str: """ @@ -59,4 +59,4 @@ def get_lang(self) -> str: str: Description of return value. """ - return self.__use_lang or self.__in_lang or "" + return self._use_lang or self._in_lang or "" diff --git a/src/scaict_uwu/service_container.py b/src/scaict_uwu/service_container.py index 740c709..1311689 100644 --- a/src/scaict_uwu/service_container.py +++ b/src/scaict_uwu/service_container.py @@ -3,8 +3,13 @@ """ # Standard imports -import importlib import sys +from typing import Callable + +# Local imports +from .core.config.config import Config +from .core.config.config_factory import ConfigFactory +from .libs.language.language_tag_factory import LanguageTagFactory class ServiceContainer: @@ -26,10 +31,15 @@ class ServiceContainer: """ """ - def load_wiring_files(self, wiring_modules: list) -> None: - for module_name in wiring_modules: - module = importlib.import_module(module_name) + def load_wiring_module(self, module) -> None: + try: self.apply_wiring(module.get_wiring()) + except AttributeError: + sys.exit("InvalidWiringModuleException") + + def load_wiring_modules(self, modules: list) -> None: + for module in modules: + self.load_wiring_module(module) def apply_wiring(self, service_instantiators) -> None: for name, instantiator in service_instantiators: @@ -42,13 +52,13 @@ def get_service_names(self) -> list: def has_service(self, name: str) -> bool: return name in self._service_instantiators - def define_service(self, name: str, instantiator) -> None: + def define_service(self, name: str, instantiator: Callable) -> None: if self.has_service(name): sys.exit("ServiceAlreadyDefinedException $name") self._service_instantiators[name] = instantiator - def redefine_service(self, name: str, instantiator) -> None: + def redefine_service(self, name: str, instantiator: Callable) -> None: if not self.has_service(name): sys.exit("NoSuchServiceException $name") @@ -61,7 +71,7 @@ def create_service(self, name: str): if not self.has_service(name): sys.exit("NoSuchServiceException $name") - if not name in self._services_being_created: + if name in self._services_being_created: sys.exit( "RecursiveServiceDependencyException " + "Circular dependency when creating service!" @@ -69,23 +79,21 @@ def create_service(self, name: str): self._services_being_created[name] = True - service = self._service_instantiators[name](self) - - return service + return self._service_instantiators[name](self) def get_service(self, name: str): - if not name in self._services: + if name not in self._services: self._services[name] = self.create_service(name) return self._services[name] # Service helper functions - def get_config(self): + def get_config(self) -> Config: return self.get_service("Config") - def get_language_tag(self): - return self.get_service("LanguageTag") + def get_config_factory(self) -> ConfigFactory: + return self.get_service("ConfigFactory") - def get_language_tag_factory(self): + def get_language_tag_factory(self) -> LanguageTagFactory: return self.get_service("LanguageTagFactory") diff --git a/src/scaict_uwu/service_wiring.py b/src/scaict_uwu/service_wiring.py index f885323..7cb23f8 100644 --- a/src/scaict_uwu/service_wiring.py +++ b/src/scaict_uwu/service_wiring.py @@ -2,15 +2,42 @@ Module for SCAICT-uwu default service implementations. """ +# Standard imports +from typing import Callable + +# Local imports +from .core.config.config import Config +from .core.config.config_factory import ConfigFactory +from .libs.language.language_tag_factory import LanguageTagFactory from .service_container import ServiceContainer -def get_wiring() -> dict: +def get_wiring() -> dict[str, Callable]: """ - Get the service implementation functions. + Get the service instantiator functions. + + Returns: + dict: A mapping of service names to their instantiator functions. + Format: {"service_name": instantiator_function} """ - return {"Config": get_config} + return { + "Config": get_config, + "ConfigFactory": get_config_factory, + "LanguageTagFactory": get_language_tag_factory, + } + +def get_config( + service_container: ServiceContainer +) -> Config: + return service_container.get_config_factory().get() + +def get_config_factory( + service_container: ServiceContainer +) -> ConfigFactory: + return ConfigFactory() -def get_config(service_container: ServiceContainer): - pass +def get_language_tag_factory( + service_container: ServiceContainer +) -> LanguageTagFactory: + return LanguageTagFactory() From e44f966c47a552c80484b12e83de68c0c96fe4f7 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Mon, 2 Dec 2024 07:26:07 +0000 Subject: [PATCH 108/141] Format "Packaging: Prepare src layout migration" using Black --- src/scaict_uwu/service_container.py | 2 +- src/scaict_uwu/service_wiring.py | 15 ++++++--------- 2 files changed, 7 insertions(+), 10 deletions(-) diff --git a/src/scaict_uwu/service_container.py b/src/scaict_uwu/service_container.py index 1311689..14c6225 100644 --- a/src/scaict_uwu/service_container.py +++ b/src/scaict_uwu/service_container.py @@ -82,7 +82,7 @@ def create_service(self, name: str): return self._service_instantiators[name](self) def get_service(self, name: str): - if name not in self._services: + if name not in self._services: self._services[name] = self.create_service(name) return self._services[name] diff --git a/src/scaict_uwu/service_wiring.py b/src/scaict_uwu/service_wiring.py index 7cb23f8..5a5f197 100644 --- a/src/scaict_uwu/service_wiring.py +++ b/src/scaict_uwu/service_wiring.py @@ -27,17 +27,14 @@ def get_wiring() -> dict[str, Callable]: "LanguageTagFactory": get_language_tag_factory, } -def get_config( - service_container: ServiceContainer -) -> Config: + +def get_config(service_container: ServiceContainer) -> Config: return service_container.get_config_factory().get() -def get_config_factory( - service_container: ServiceContainer -) -> ConfigFactory: + +def get_config_factory(service_container: ServiceContainer) -> ConfigFactory: return ConfigFactory() -def get_language_tag_factory( - service_container: ServiceContainer -) -> LanguageTagFactory: + +def get_language_tag_factory(service_container: ServiceContainer) -> LanguageTagFactory: return LanguageTagFactory() From 7b242fca7586847139609c96679912fc0ca4d0c3 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 2 Dec 2024 07:27:02 +0000 Subject: [PATCH 109/141] Bump pytest from 8.3.3 to 8.3.4 Bumps [pytest](https://github.com/pytest-dev/pytest) from 8.3.3 to 8.3.4. - [Release notes](https://github.com/pytest-dev/pytest/releases) - [Changelog](https://github.com/pytest-dev/pytest/blob/main/CHANGELOG.rst) - [Commits](https://github.com/pytest-dev/pytest/compare/8.3.3...8.3.4) --- updated-dependencies: - dependency-name: pytest dependency-type: direct:development update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- pyproject.toml | 2 +- requirements_dev.txt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 13aa567..def83cd 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -38,5 +38,5 @@ dependencies = [ optional-dependencies.dev = [ "black == 24.10.0", "pylint == 3.3.1", - "pytest == 8.3.3", + "pytest == 8.3.4", ] diff --git a/requirements_dev.txt b/requirements_dev.txt index 8f9cbdc..4feee13 100644 --- a/requirements_dev.txt +++ b/requirements_dev.txt @@ -12,5 +12,5 @@ pathspec == 0.12.1 platformdirs == 4.3.6 pluggy == 1.5.0 pylint == 3.3.1 -pytest == 8.3.3 +pytest == 8.3.4 tomlkit == 0.13.2 From 6e0b85b64ccd42ccafa8aef8de5da558d4be221b Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 2 Dec 2024 07:29:42 +0000 Subject: [PATCH 110/141] Bump aiohttp from 3.11.7 to 3.11.9 Bumps [aiohttp](https://github.com/aio-libs/aiohttp) from 3.11.7 to 3.11.9. - [Release notes](https://github.com/aio-libs/aiohttp/releases) - [Changelog](https://github.com/aio-libs/aiohttp/blob/master/CHANGES.rst) - [Commits](https://github.com/aio-libs/aiohttp/compare/v3.11.7...v3.11.9) --- updated-dependencies: - dependency-name: aiohttp dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index 2e73afc..45cbb91 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,5 +1,5 @@ aiohappyeyeballs == 2.4.3 -aiohttp == 3.11.7 +aiohttp == 3.11.9 aiosignal == 1.3.1 attrs == 24.2.0 blinker == 1.9.0 From 2cf61ce470cf8f75b4289975c019981d03a27f87 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 2 Dec 2024 07:32:28 +0000 Subject: [PATCH 111/141] Bump pylint from 3.3.1 to 3.3.2 Bumps [pylint](https://github.com/pylint-dev/pylint) from 3.3.1 to 3.3.2. - [Release notes](https://github.com/pylint-dev/pylint/releases) - [Commits](https://github.com/pylint-dev/pylint/compare/v3.3.1...v3.3.2) --- updated-dependencies: - dependency-name: pylint dependency-type: direct:development update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- pyproject.toml | 2 +- requirements_dev.txt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index def83cd..4a94659 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -37,6 +37,6 @@ dependencies = [ # Lock file: requirements_dev.txt optional-dependencies.dev = [ "black == 24.10.0", - "pylint == 3.3.1", + "pylint == 3.3.2", "pytest == 8.3.4", ] diff --git a/requirements_dev.txt b/requirements_dev.txt index 4feee13..8a416ee 100644 --- a/requirements_dev.txt +++ b/requirements_dev.txt @@ -11,6 +11,6 @@ packaging == 24.2 pathspec == 0.12.1 platformdirs == 4.3.6 pluggy == 1.5.0 -pylint == 3.3.1 +pylint == 3.3.2 pytest == 8.3.4 tomlkit == 0.13.2 From 38515ec748712071d7f3e8af7784374478cb8231 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 2 Dec 2024 07:39:07 +0000 Subject: [PATCH 112/141] Bump aiohappyeyeballs from 2.4.3 to 2.4.4 Bumps [aiohappyeyeballs](https://github.com/aio-libs/aiohappyeyeballs) from 2.4.3 to 2.4.4. - [Release notes](https://github.com/aio-libs/aiohappyeyeballs/releases) - [Changelog](https://github.com/aio-libs/aiohappyeyeballs/blob/main/CHANGELOG.md) - [Commits](https://github.com/aio-libs/aiohappyeyeballs/compare/v2.4.3...v2.4.4) --- updated-dependencies: - dependency-name: aiohappyeyeballs dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index 45cbb91..6ceae31 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,4 @@ -aiohappyeyeballs == 2.4.3 +aiohappyeyeballs == 2.4.4 aiohttp == 3.11.9 aiosignal == 1.3.1 attrs == 24.2.0 From 8a4a15d094ef3ccba71b89dcf4773def37abb64c Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 2 Dec 2024 08:30:15 +0000 Subject: [PATCH 113/141] Bump yarl from 1.18.0 to 1.18.3 Bumps [yarl](https://github.com/aio-libs/yarl) from 1.18.0 to 1.18.3. - [Release notes](https://github.com/aio-libs/yarl/releases) - [Changelog](https://github.com/aio-libs/yarl/blob/master/CHANGES.rst) - [Commits](https://github.com/aio-libs/yarl/compare/v1.18.0...v1.18.3) --- updated-dependencies: - dependency-name: yarl dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index 6ceae31..ac36e88 100644 --- a/requirements.txt +++ b/requirements.txt @@ -20,4 +20,4 @@ python-dotenv == 1.0.1 requests == 2.32.3 urllib3 == 2.2.3 werkzeug == 3.1.3 -yarl == 1.18.0 +yarl == 1.18.3 From 8bdc6fa468043c68033a5f33a2e70e78f2ffd989 Mon Sep 17 00:00:00 2001 From: Winston Sung Date: Mon, 2 Dec 2024 16:37:19 +0800 Subject: [PATCH 114/141] Packaging: Prepare src layout migration Change-Id: I5b5c4bcc07ac9a54356f21e1a8d7781aff73f368 --- .../libs/{exceptions => errors}/__init__.py | 0 .../libs/language/language_utils.py | 2 +- src/scaict_uwu/service_container.py | 28 +++++++++---------- src/scaict_uwu/service_wiring.py | 8 +++--- 4 files changed, 19 insertions(+), 19 deletions(-) rename src/scaict_uwu/libs/{exceptions => errors}/__init__.py (100%) diff --git a/src/scaict_uwu/libs/exceptions/__init__.py b/src/scaict_uwu/libs/errors/__init__.py similarity index 100% rename from src/scaict_uwu/libs/exceptions/__init__.py rename to src/scaict_uwu/libs/errors/__init__.py diff --git a/src/scaict_uwu/libs/language/language_utils.py b/src/scaict_uwu/libs/language/language_utils.py index 06dd3a9..523fe60 100644 --- a/src/scaict_uwu/libs/language/language_utils.py +++ b/src/scaict_uwu/libs/language/language_utils.py @@ -122,7 +122,7 @@ def get_discord_code(cls, tag: str) -> str | None: return None @classmethod - def get_bcp_47_from_discord_code(cls, code: str) -> str: + def get_from_discord_code(cls, code: str) -> str: """ Get the BCP 47 language tag from Discord locale code. diff --git a/src/scaict_uwu/service_container.py b/src/scaict_uwu/service_container.py index 14c6225..2533a62 100644 --- a/src/scaict_uwu/service_container.py +++ b/src/scaict_uwu/service_container.py @@ -43,23 +43,23 @@ def load_wiring_modules(self, modules: list) -> None: def apply_wiring(self, service_instantiators) -> None: for name, instantiator in service_instantiators: - self.define_service(name, instantiator) + self.define(name, instantiator) - def get_service_names(self) -> list: + def get_names(self) -> list: # Convert dict_keys to list return list(self._service_instantiators.keys()) - def has_service(self, name: str) -> bool: + def has(self, name: str) -> bool: return name in self._service_instantiators - def define_service(self, name: str, instantiator: Callable) -> None: - if self.has_service(name): + def define(self, name: str, instantiator: Callable) -> None: + if self.has(name): sys.exit("ServiceAlreadyDefinedException $name") self._service_instantiators[name] = instantiator - def redefine_service(self, name: str, instantiator: Callable) -> None: - if not self.has_service(name): + def redefine(self, name: str, instantiator: Callable) -> None: + if not self.has(name): sys.exit("NoSuchServiceException $name") if name in self._services: @@ -67,8 +67,8 @@ def redefine_service(self, name: str, instantiator: Callable) -> None: self._service_instantiators[name] = instantiator - def create_service(self, name: str): - if not self.has_service(name): + def create(self, name: str): + if not self.has(name): sys.exit("NoSuchServiceException $name") if name in self._services_being_created: @@ -81,19 +81,19 @@ def create_service(self, name: str): return self._service_instantiators[name](self) - def get_service(self, name: str): + def get(self, name: str): if name not in self._services: - self._services[name] = self.create_service(name) + self._services[name] = self.create(name) return self._services[name] # Service helper functions def get_config(self) -> Config: - return self.get_service("Config") + return self.get("Config") def get_config_factory(self) -> ConfigFactory: - return self.get_service("ConfigFactory") + return self.get("ConfigFactory") def get_language_tag_factory(self) -> LanguageTagFactory: - return self.get_service("LanguageTagFactory") + return self.get("LanguageTagFactory") diff --git a/src/scaict_uwu/service_wiring.py b/src/scaict_uwu/service_wiring.py index 5a5f197..05a0304 100644 --- a/src/scaict_uwu/service_wiring.py +++ b/src/scaict_uwu/service_wiring.py @@ -28,13 +28,13 @@ def get_wiring() -> dict[str, Callable]: } -def get_config(service_container: ServiceContainer) -> Config: - return service_container.get_config_factory().get() +def get_config(services: ServiceContainer) -> Config: + return services.get_config_factory().get() -def get_config_factory(service_container: ServiceContainer) -> ConfigFactory: +def get_config_factory(services: ServiceContainer) -> ConfigFactory: return ConfigFactory() -def get_language_tag_factory(service_container: ServiceContainer) -> LanguageTagFactory: +def get_language_tag_factory(services: ServiceContainer) -> LanguageTagFactory: return LanguageTagFactory() From 72c90632bf473e44589fede1958b786be58fc731 Mon Sep 17 00:00:00 2001 From: Winston Sung Date: Mon, 2 Dec 2024 18:31:28 +0800 Subject: [PATCH 115/141] Introduce unit tests using unittest and pytest Bug: #76 Change-Id: I6c8f39b2e0ccc238cbe55a7009e8ecb397123dae --- .github/workflows/pytest.yml | 29 ++++++++++++++ .github/workflows/unittest.yml | 29 ++++++++++++++ .../libs/language/language_tag_factory.py | 6 +-- src/scaict_uwu/service_container.py | 2 +- tests/__init__.py | 0 tests/pytest/__init__.py | 0 tests/pytest/test_service_wiring.py | 17 ++++++++ tests/unittest/__init__.py | 0 tests/unittest/test_language_tag_factory.py | 39 +++++++++++++++++++ 9 files changed, 118 insertions(+), 4 deletions(-) create mode 100644 .github/workflows/pytest.yml create mode 100644 .github/workflows/unittest.yml create mode 100644 tests/__init__.py create mode 100644 tests/pytest/__init__.py create mode 100644 tests/pytest/test_service_wiring.py create mode 100644 tests/unittest/__init__.py create mode 100644 tests/unittest/test_language_tag_factory.py diff --git a/.github/workflows/pytest.yml b/.github/workflows/pytest.yml new file mode 100644 index 0000000..c532b5f --- /dev/null +++ b/.github/workflows/pytest.yml @@ -0,0 +1,29 @@ +name: Pytest + +on: + pull_request: + push: + workflow_dispatch: + +jobs: + build: + if: github.event_name != 'pull_request' || github.event.pull_request.head.repo.fork == true + runs-on: ubuntu-latest + strategy: + matrix: + python-version: [ "3.11" ] + steps: + - uses: actions/checkout@v4 + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v5 + with: + python-version: ${{ matrix.python-version }} + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install -r requirements.txt + pip install -r requirements_dev.txt + pip install -e .[dev] + - name: Analysing the code with Pylint + run: | + pytest tests/pytest/ diff --git a/.github/workflows/unittest.yml b/.github/workflows/unittest.yml new file mode 100644 index 0000000..f8f0040 --- /dev/null +++ b/.github/workflows/unittest.yml @@ -0,0 +1,29 @@ +name: Python unittest + +on: + pull_request: + push: + workflow_dispatch: + +jobs: + build: + if: github.event_name != 'pull_request' || github.event.pull_request.head.repo.fork == true + runs-on: ubuntu-latest + strategy: + matrix: + python-version: [ "3.11" ] + steps: + - uses: actions/checkout@v4 + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v5 + with: + python-version: ${{ matrix.python-version }} + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install -r requirements.txt + pip install -r requirements_dev.txt + pip install -e .[dev] + - name: Analysing the code with Pylint + run: | + python -m unittest $(git ls-files 'tests/unittest/*.py') diff --git a/src/scaict_uwu/libs/language/language_tag_factory.py b/src/scaict_uwu/libs/language/language_tag_factory.py index 2033760..865ea8c 100644 --- a/src/scaict_uwu/libs/language/language_tag_factory.py +++ b/src/scaict_uwu/libs/language/language_tag_factory.py @@ -28,7 +28,7 @@ def get(self, tag: str) -> LanguageTag: tag (str): BCP 47 language tag. Returns: - LanguageTag: The LanguageTag object to the responding BCP 47\ + LanguageTag: The LanguageTag object to the corresponding BCP 47\ language tag. """ @@ -45,7 +45,7 @@ def get_by_discord_code(self, code: str) -> LanguageTag | None: code (str): Discord locale code. Returns: - (LanguageTag | None): The LanguageTag object of the responding\ + (LanguageTag | None): The LanguageTag object of the corresponding\ Discord locale code. Return None when is not a supported\ Discord locale code. """ @@ -53,7 +53,7 @@ def get_by_discord_code(self, code: str) -> LanguageTag | None: if code not in LanguageUtils.get_supported_discord_codes(): return None - tag = LanguageUtils.get_bcp_47_from_discord_code(code) + tag = LanguageUtils.get_from_discord_code(code) if tag not in self._tags: self._tags[tag] = LanguageTag(tag) diff --git a/src/scaict_uwu/service_container.py b/src/scaict_uwu/service_container.py index 2533a62..1ccccc8 100644 --- a/src/scaict_uwu/service_container.py +++ b/src/scaict_uwu/service_container.py @@ -33,7 +33,7 @@ class ServiceContainer: def load_wiring_module(self, module) -> None: try: - self.apply_wiring(module.get_wiring()) + self.apply_wiring(module.get_wiring().items()) except AttributeError: sys.exit("InvalidWiringModuleException") diff --git a/tests/__init__.py b/tests/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/tests/pytest/__init__.py b/tests/pytest/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/tests/pytest/test_service_wiring.py b/tests/pytest/test_service_wiring.py new file mode 100644 index 0000000..d1beae1 --- /dev/null +++ b/tests/pytest/test_service_wiring.py @@ -0,0 +1,17 @@ +""" +Unit test for using Pytest. +""" + +# Standard imports +from typing import Callable + +# Local imports +from scaict_uwu import service_wiring + + +def test_get_wiring() -> None: + service_instantiators = service_wiring.get_wiring() + + for name, instantiator in service_instantiators.items(): + assert isinstance(name, str) + assert isinstance(instantiator, Callable) diff --git a/tests/unittest/__init__.py b/tests/unittest/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/tests/unittest/test_language_tag_factory.py b/tests/unittest/test_language_tag_factory.py new file mode 100644 index 0000000..98e5321 --- /dev/null +++ b/tests/unittest/test_language_tag_factory.py @@ -0,0 +1,39 @@ +""" +Unit test for LanguageTagFactory using unittest. +""" + +# Standard imports +import unittest + +# Local imports +from scaict_uwu.libs.language.language_tag import LanguageTag +from scaict_uwu.libs.language.language_tag_factory import LanguageTagFactory + + +class TestLanguageTagFactory(unittest.TestCase): + language_tag_factory: LanguageTagFactory | None + + def setUp(self) -> None: + self.language_tag_factory = LanguageTagFactory() + + def tearDown(self) -> None: + self.language_tag_factory = None + + def test_get(self) -> None: + language_tag: LanguageTag = self.language_tag_factory.get("zh-Hant") + + self.assertEqual(language_tag.get_bcp_47_tag(), "zh-Hant") + self.assertEqual(language_tag.get_discord_code(), "zh-TW") + + def test_get_by_discord_code(self) -> None: + language_tag: LanguageTag | None = ( + self.language_tag_factory.get_by_discord_code("zh-TW") + ) + + self.assertIsNotNone(language_tag) + self.assertEqual(language_tag.get_bcp_47_tag(), "zh-Hant") + self.assertEqual(language_tag.get_discord_code(), "zh-TW") + + +if __name__ == "__main__": + unittest.main() From 07d7821ab85bbc72e2122c15b77be56dce2476db Mon Sep 17 00:00:00 2001 From: Winston Sung Date: Mon, 2 Dec 2024 21:13:33 +0800 Subject: [PATCH 116/141] Fix YAML formatting Change-Id: I5cbf1b5a106bff43b87509b3348a731f258071ac --- .github/workflows/black.yml | 66 +++++++++++++++++----------------- .github/workflows/merge.yml | 38 ++++++++++---------- .github/workflows/notion.yml | 2 +- .github/workflows/pylint.yml | 30 ++++++++-------- .github/workflows/pytest.yml | 30 ++++++++-------- .github/workflows/unittest.yml | 32 ++++++++--------- 6 files changed, 99 insertions(+), 99 deletions(-) diff --git a/.github/workflows/black.yml b/.github/workflows/black.yml index 8e67b68..c11abdc 100644 --- a/.github/workflows/black.yml +++ b/.github/workflows/black.yml @@ -11,37 +11,37 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - python-version: [ "3.11" ] + python-version: ["3.11"] steps: - - if: github.event_name != 'pull_request' - uses: actions/checkout@v4 - - if: github.event_name == 'pull_request' && github.event.pull_request.head.repo.fork == true - uses: actions/checkout@v4 - with: - ref: ${{ github.event.pull_request.head.ref }} - - name: Set up Python ${{ matrix.python-version }} - uses: actions/setup-python@v5 - with: - python-version: ${{ matrix.python-version }} - - name: Install dependencies - run: | - python -m pip install --upgrade pip - pip install -r requirements.txt - pip install -r requirements_dev.txt - pip install -e .[dev] - - name: Formatting the code with Black - run: | - black $(git ls-files '*.py') - - name: Git config - run: | - git config --local user.name "github-actions[bot]" - git config --local user.email "41898282+github-actions[bot]@users.noreply.github.com" - - name: Git diff - run: | - git diff HEAD || true - - name: Git add - run: | - git add * - - name: Git commit & push - run: | - git diff-index --quiet HEAD || ( git commit -m "Format \"$(git show -s --format=%s)\" using Black" && git push ) + - if: github.event_name != 'pull_request' + uses: actions/checkout@v4 + - if: github.event_name == 'pull_request' && github.event.pull_request.head.repo.fork == true + uses: actions/checkout@v4 + with: + ref: ${{ github.event.pull_request.head.ref }} + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v5 + with: + python-version: ${{ matrix.python-version }} + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install -r requirements.txt + pip install -r requirements_dev.txt + pip install -e .[dev] + - name: Formatting the code with Black + run: | + black $(git ls-files '*.py') + - name: Git config + run: | + git config --local user.name "github-actions[bot]" + git config --local user.email "41898282+github-actions[bot]@users.noreply.github.com" + - name: Git diff + run: | + git diff HEAD || true + - name: Git add + run: | + git add * + - name: Git commit & push + run: | + git diff-index --quiet HEAD || ( git commit -m "Format \"$(git show -s --format=%s)\" using Black" && git push ) diff --git a/.github/workflows/merge.yml b/.github/workflows/merge.yml index 45bdefc..1b910ca 100644 --- a/.github/workflows/merge.yml +++ b/.github/workflows/merge.yml @@ -2,7 +2,7 @@ name: Merge on: pull_request_review: - types: [ submitted ] + types: [submitted] jobs: merge: @@ -18,21 +18,21 @@ jobs: ) runs-on: ubuntu-latest steps: - - uses: actions/checkout@v4 - with: - fetch-depth: 0 - - name: Set Git config - run: | - git config --local user.name "github-actions[bot]" - git config --local user.email "41898282+github-actions[bot]@users.noreply.github.com" - - name: Rebase to target branch when needed in order to fast-forward merge - run: | - git fetch origin ${{ github.event.pull_request.base.ref }} - git rebase origin/${{ github.event.pull_request.base.ref }} - - name: Push back source branch (head) - run: | - git push "${{ github.event.pull_request.head.repo.clone_url }}" HEAD:${{ github.event.pull_request.head.ref }} --force - - name: Push to target branch (base) - run: | - # git push "${{ github.event.pull_request.base.repo.clone_url }}" ${{ github.event.pull_request.base.ref }} - git push origin HEAD:${{ github.event.pull_request.base.ref }} + - uses: actions/checkout@v4 + with: + fetch-depth: 0 + - name: Set Git config + run: | + git config --local user.name "github-actions[bot]" + git config --local user.email "41898282+github-actions[bot]@users.noreply.github.com" + - name: Rebase to target branch when needed in order to fast-forward merge + run: | + git fetch origin ${{ github.event.pull_request.base.ref }} + git rebase origin/${{ github.event.pull_request.base.ref }} + - name: Push back source branch (head) + run: | + git push "${{ github.event.pull_request.head.repo.clone_url }}" HEAD:${{ github.event.pull_request.head.ref }} --force + - name: Push to target branch (base) + run: | + # git push "${{ github.event.pull_request.base.repo.clone_url }}" ${{ github.event.pull_request.base.ref }} + git push origin HEAD:${{ github.event.pull_request.base.ref }} diff --git a/.github/workflows/notion.yml b/.github/workflows/notion.yml index 2b63a87..44fb095 100644 --- a/.github/workflows/notion.yml +++ b/.github/workflows/notion.yml @@ -2,7 +2,7 @@ name: Sync issues to Notion on: issues: - types: [ opened, edited, deleted, reopened, closed ] + types: [opened, edited, deleted, reopened, closed] workflow_dispatch: jobs: diff --git a/.github/workflows/pylint.yml b/.github/workflows/pylint.yml index d873bc1..18d7a6e 100644 --- a/.github/workflows/pylint.yml +++ b/.github/workflows/pylint.yml @@ -11,19 +11,19 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - python-version: [ "3.11" ] + python-version: ["3.11"] steps: - - uses: actions/checkout@v4 - - name: Set up Python ${{ matrix.python-version }} - uses: actions/setup-python@v5 - with: - python-version: ${{ matrix.python-version }} - - name: Install dependencies - run: | - python -m pip install --upgrade pip - pip install -r requirements.txt - pip install -r requirements_dev.txt - pip install -e .[dev] - - name: Analysing the code with Pylint - run: | - pylint $(git ls-files '*.py') + - uses: actions/checkout@v4 + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v5 + with: + python-version: ${{ matrix.python-version }} + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install -r requirements.txt + pip install -r requirements_dev.txt + pip install -e .[dev] + - name: Analysing the code with Pylint + run: | + pylint $(git ls-files '*.py') diff --git a/.github/workflows/pytest.yml b/.github/workflows/pytest.yml index c532b5f..9300f34 100644 --- a/.github/workflows/pytest.yml +++ b/.github/workflows/pytest.yml @@ -11,19 +11,19 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - python-version: [ "3.11" ] + python-version: ["3.11"] steps: - - uses: actions/checkout@v4 - - name: Set up Python ${{ matrix.python-version }} - uses: actions/setup-python@v5 - with: - python-version: ${{ matrix.python-version }} - - name: Install dependencies - run: | - python -m pip install --upgrade pip - pip install -r requirements.txt - pip install -r requirements_dev.txt - pip install -e .[dev] - - name: Analysing the code with Pylint - run: | - pytest tests/pytest/ + - uses: actions/checkout@v4 + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v5 + with: + python-version: ${{ matrix.python-version }} + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install -r requirements.txt + pip install -r requirements_dev.txt + pip install -e .[dev] + - name: Analysing the code with Pylint + run: | + pytest tests/pytest/ diff --git a/.github/workflows/unittest.yml b/.github/workflows/unittest.yml index f8f0040..5f22567 100644 --- a/.github/workflows/unittest.yml +++ b/.github/workflows/unittest.yml @@ -7,23 +7,23 @@ on: jobs: build: - if: github.event_name != 'pull_request' || github.event.pull_request.head.repo.fork == true + if: (github.event_name != 'pull_request' || github.event.pull_request.head.repo.fork == true) runs-on: ubuntu-latest strategy: matrix: - python-version: [ "3.11" ] + python-version: ["3.11"] steps: - - uses: actions/checkout@v4 - - name: Set up Python ${{ matrix.python-version }} - uses: actions/setup-python@v5 - with: - python-version: ${{ matrix.python-version }} - - name: Install dependencies - run: | - python -m pip install --upgrade pip - pip install -r requirements.txt - pip install -r requirements_dev.txt - pip install -e .[dev] - - name: Analysing the code with Pylint - run: | - python -m unittest $(git ls-files 'tests/unittest/*.py') + - uses: actions/checkout@v4 + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v5 + with: + python-version: ${{ matrix.python-version }} + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install -r requirements.txt + pip install -r requirements_dev.txt + pip install -e .[dev] + - name: Analysing the code with Pylint + run: | + python -m unittest $(git ls-files 'tests/unittest/*.py') From 2ece78a98320224cd021266888d43e2515946fc7 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 16 Jan 2025 11:05:37 +0000 Subject: [PATCH 117/141] Bump certifi from 2024.8.30 to 2024.12.14 Bumps [certifi](https://github.com/certifi/python-certifi) from 2024.8.30 to 2024.12.14. - [Commits](https://github.com/certifi/python-certifi/compare/2024.08.30...2024.12.14) --- updated-dependencies: - dependency-name: certifi dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index ac36e88..4f34c16 100644 --- a/requirements.txt +++ b/requirements.txt @@ -3,7 +3,7 @@ aiohttp == 3.11.9 aiosignal == 1.3.1 attrs == 24.2.0 blinker == 1.9.0 -certifi == 2024.8.30 +certifi == 2024.12.14 charset-normalizer == 3.4.0 click == 8.1.7 colorama == 0.4.6 From 9dc1c35b58fb66a71d70faeeb1a806e19d7cd49f Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 16 Jan 2025 11:08:06 +0000 Subject: [PATCH 118/141] Bump aiosignal from 1.3.1 to 1.3.2 Bumps [aiosignal](https://github.com/aio-libs/aiosignal) from 1.3.1 to 1.3.2. - [Release notes](https://github.com/aio-libs/aiosignal/releases) - [Changelog](https://github.com/aio-libs/aiosignal/blob/master/CHANGES.rst) - [Commits](https://github.com/aio-libs/aiosignal/compare/v1.3.1...v1.3.2) --- updated-dependencies: - dependency-name: aiosignal dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index 4f34c16..e16290d 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,6 +1,6 @@ aiohappyeyeballs == 2.4.4 aiohttp == 3.11.9 -aiosignal == 1.3.1 +aiosignal == 1.3.2 attrs == 24.2.0 blinker == 1.9.0 certifi == 2024.12.14 From 5c6eed4ea362c4ed42b1fe8db8ac1532466825d7 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 16 Jan 2025 11:10:47 +0000 Subject: [PATCH 119/141] Bump attrs from 24.2.0 to 24.3.0 Bumps [attrs](https://github.com/sponsors/hynek) from 24.2.0 to 24.3.0. - [Commits](https://github.com/sponsors/hynek/commits) --- updated-dependencies: - dependency-name: attrs dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index e16290d..93874b8 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,7 +1,7 @@ aiohappyeyeballs == 2.4.4 aiohttp == 3.11.9 aiosignal == 1.3.2 -attrs == 24.2.0 +attrs == 24.3.0 blinker == 1.9.0 certifi == 2024.12.14 charset-normalizer == 3.4.0 From d0c358e95c8b691949597bf8b995eeaaf415dbac Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 16 Jan 2025 11:16:26 +0000 Subject: [PATCH 120/141] Bump aiohttp from 3.11.9 to 3.11.11 --- updated-dependencies: - dependency-name: aiohttp dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index 93874b8..d72a858 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,5 +1,5 @@ aiohappyeyeballs == 2.4.4 -aiohttp == 3.11.9 +aiohttp == 3.11.11 aiosignal == 1.3.2 attrs == 24.3.0 blinker == 1.9.0 From 7da7120413f1d23e67d8f6a78d5cffb43fe8b4bd Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 16 Jan 2025 11:30:05 +0000 Subject: [PATCH 121/141] Bump urllib3 from 2.2.3 to 2.3.0 Bumps [urllib3](https://github.com/urllib3/urllib3) from 2.2.3 to 2.3.0. - [Release notes](https://github.com/urllib3/urllib3/releases) - [Changelog](https://github.com/urllib3/urllib3/blob/main/CHANGES.rst) - [Commits](https://github.com/urllib3/urllib3/compare/2.2.3...2.3.0) --- updated-dependencies: - dependency-name: urllib3 dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index d72a858..4d3fb73 100644 --- a/requirements.txt +++ b/requirements.txt @@ -18,6 +18,6 @@ mysql-connector-python == 9.1.0 py-cord == 2.6.1 python-dotenv == 1.0.1 requests == 2.32.3 -urllib3 == 2.2.3 +urllib3 == 2.3.0 werkzeug == 3.1.3 yarl == 1.18.3 From accbc560369fa9cb36bb780f3f0bedef4a43a5cd Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 16 Jan 2025 11:41:04 +0000 Subject: [PATCH 122/141] Bump click from 8.1.7 to 8.1.8 Bumps [click](https://github.com/pallets/click) from 8.1.7 to 8.1.8. - [Release notes](https://github.com/pallets/click/releases) - [Changelog](https://github.com/pallets/click/blob/main/CHANGES.rst) - [Commits](https://github.com/pallets/click/compare/8.1.7...8.1.8) --- updated-dependencies: - dependency-name: click dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- requirements.txt | 2 +- requirements_dev.txt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/requirements.txt b/requirements.txt index 4d3fb73..b70ddcf 100644 --- a/requirements.txt +++ b/requirements.txt @@ -5,7 +5,7 @@ attrs == 24.3.0 blinker == 1.9.0 certifi == 2024.12.14 charset-normalizer == 3.4.0 -click == 8.1.7 +click == 8.1.8 colorama == 0.4.6 flask == 3.1.0 frozenlist == 1.5.0 diff --git a/requirements_dev.txt b/requirements_dev.txt index 8a416ee..f858d7a 100644 --- a/requirements_dev.txt +++ b/requirements_dev.txt @@ -1,6 +1,6 @@ astroid == 3.3.5 black == 24.10.0 -click == 8.1.7 +click == 8.1.8 colorama == 0.4.6 dill == 0.3.9 iniconfig == 2.0.0 From dac673ca6339d17ab9ece0aae4653d0afa61b563 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 16 Jan 2025 11:53:56 +0000 Subject: [PATCH 123/141] Bump jinja2 from 3.1.4 to 3.1.5 Bumps [jinja2](https://github.com/pallets/jinja) from 3.1.4 to 3.1.5. - [Release notes](https://github.com/pallets/jinja/releases) - [Changelog](https://github.com/pallets/jinja/blob/main/CHANGES.rst) - [Commits](https://github.com/pallets/jinja/compare/3.1.4...3.1.5) --- updated-dependencies: - dependency-name: jinja2 dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index b70ddcf..c633013 100644 --- a/requirements.txt +++ b/requirements.txt @@ -11,7 +11,7 @@ flask == 3.1.0 frozenlist == 1.5.0 idna == 3.10 itsdangerous == 2.2.0 -jinja2 == 3.1.4 +jinja2 == 3.1.5 markupsafe == 3.0.2 multidict == 6.1.0 mysql-connector-python == 9.1.0 From 48aac3130d5f68aa4cf4ce2b25ef4f588178792c Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 16 Jan 2025 11:57:13 +0000 Subject: [PATCH 124/141] Bump astroid from 3.3.5 to 3.3.8 Bumps [astroid](https://github.com/pylint-dev/astroid) from 3.3.5 to 3.3.8. - [Release notes](https://github.com/pylint-dev/astroid/releases) - [Changelog](https://github.com/pylint-dev/astroid/blob/main/ChangeLog) - [Commits](https://github.com/pylint-dev/astroid/compare/v3.3.5...v3.3.8) --- updated-dependencies: - dependency-name: astroid dependency-type: direct:development update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- requirements_dev.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements_dev.txt b/requirements_dev.txt index f858d7a..26450ff 100644 --- a/requirements_dev.txt +++ b/requirements_dev.txt @@ -1,4 +1,4 @@ -astroid == 3.3.5 +astroid == 3.3.8 black == 24.10.0 click == 8.1.8 colorama == 0.4.6 From ddbbe9fd268e68b0c507d6e75b536784df3fa806 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 16 Jan 2025 12:03:23 +0000 Subject: [PATCH 125/141] Bump pylint from 3.3.2 to 3.3.3 Bumps [pylint](https://github.com/pylint-dev/pylint) from 3.3.2 to 3.3.3. - [Release notes](https://github.com/pylint-dev/pylint/releases) - [Commits](https://github.com/pylint-dev/pylint/compare/v3.3.2...v3.3.3) --- updated-dependencies: - dependency-name: pylint dependency-type: direct:development update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- pyproject.toml | 2 +- requirements_dev.txt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 4a94659..33772cc 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -37,6 +37,6 @@ dependencies = [ # Lock file: requirements_dev.txt optional-dependencies.dev = [ "black == 24.10.0", - "pylint == 3.3.2", + "pylint == 3.3.3", "pytest == 8.3.4", ] diff --git a/requirements_dev.txt b/requirements_dev.txt index 26450ff..98e99c1 100644 --- a/requirements_dev.txt +++ b/requirements_dev.txt @@ -11,6 +11,6 @@ packaging == 24.2 pathspec == 0.12.1 platformdirs == 4.3.6 pluggy == 1.5.0 -pylint == 3.3.2 +pylint == 3.3.3 pytest == 8.3.4 tomlkit == 0.13.2 From 463f7bdf411c0594fbb2c929627b17c724665179 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 16 Jan 2025 12:10:15 +0000 Subject: [PATCH 126/141] Bump charset-normalizer from 3.4.0 to 3.4.1 Bumps [charset-normalizer](https://github.com/jawah/charset_normalizer) from 3.4.0 to 3.4.1. - [Release notes](https://github.com/jawah/charset_normalizer/releases) - [Changelog](https://github.com/jawah/charset_normalizer/blob/master/CHANGELOG.md) - [Commits](https://github.com/jawah/charset_normalizer/compare/3.4.0...3.4.1) --- updated-dependencies: - dependency-name: charset-normalizer dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index c633013..e64ee21 100644 --- a/requirements.txt +++ b/requirements.txt @@ -4,7 +4,7 @@ aiosignal == 1.3.2 attrs == 24.3.0 blinker == 1.9.0 certifi == 2024.12.14 -charset-normalizer == 3.4.0 +charset-normalizer == 3.4.1 click == 8.1.8 colorama == 0.4.6 flask == 3.1.0 From 862cad73493927bed22f14842169e8c048971c83 Mon Sep 17 00:00:00 2001 From: Winston Sung Date: Thu, 16 Jan 2025 21:49:18 +0800 Subject: [PATCH 127/141] Update .gitignore Change-Id: I1f1b09d0b0846423c641d4a673dd4f8f0aa4fb2c --- .gitignore | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.gitignore b/.gitignore index d994783..3d17a4b 100644 --- a/.gitignore +++ b/.gitignore @@ -20,8 +20,12 @@ pointLog.out ## Configuration files .env # python 虛擬環境 +bin/ envuwu/ env-uwu/ +lib/ +lib64 +pyvenv.cfg ### Ignore token ### 如果你的token.json已經被追蹤可以執行: ### 1. git rm --cached token.json From a8e948580a5a8a493897cf50c2a795b863d2db39 Mon Sep 17 00:00:00 2001 From: Winston Sung Date: Thu, 16 Jan 2025 21:50:46 +0800 Subject: [PATCH 128/141] Add py-cord dep. propcache 0.2.1 to lock file Change-Id: I7e8ddecc2ed30925defb3ecc0d17661119bb5b97 --- requirements.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/requirements.txt b/requirements.txt index e64ee21..d183b88 100644 --- a/requirements.txt +++ b/requirements.txt @@ -15,6 +15,7 @@ jinja2 == 3.1.5 markupsafe == 3.0.2 multidict == 6.1.0 mysql-connector-python == 9.1.0 +propcache == 0.2.1 py-cord == 2.6.1 python-dotenv == 1.0.1 requests == 2.32.3 From 9c8f11ed5106de4292e5f81205bc03c9e9954d70 Mon Sep 17 00:00:00 2001 From: Winston Sung Date: Thu, 16 Jan 2025 21:51:02 +0800 Subject: [PATCH 129/141] Update release notes Change-Id: Ie6a048cb4962897a3b1af972f5925f4e4aa6c21e --- RELEASE-NOTES-0.1.md | 174 ++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 162 insertions(+), 12 deletions(-) diff --git a/RELEASE-NOTES-0.1.md b/RELEASE-NOTES-0.1.md index 6cecda7..8606dbd 100644 --- a/RELEASE-NOTES-0.1.md +++ b/RELEASE-NOTES-0.1.md @@ -33,6 +33,28 @@ own risk! * … +### External dependency changes + +#### New external dependencies + +* … + +#### New development-only external dependencies + +* … + +#### Changed external dependencies + +* … + +#### Changed development-only external dependencies + +* … + +#### Removed external dependencies + +* … + ### Bug fixes * … @@ -47,11 +69,7 @@ own risk! ### Languages updated -SCAICT-uwu now supports 1 language. Many localisations are updated regularly. - -Below only new and removed languages are listed. - -* … +SCAICT-uwu now supports 1 language. ### Breaking changes @@ -95,6 +113,28 @@ This is a maintenance release of SCAICT-uwu 0.1 version. * … +### External dependency changes in 0.1.7 + +#### New external dependencies in 0.1.7 + +* … + +#### New development-only external dependencies in 0.1.7 + +* … + +#### Changed external dependencies in 0.1.7 + +* … + +#### Changed development-only external dependencies in 0.1.7 + +* … + +#### Removed external dependencies in 0.1.7 + +* … + ### Bug fixes in 0.1.7 * … @@ -109,7 +149,7 @@ This is a maintenance release of SCAICT-uwu 0.1 version. ### Languages updated in 0.1.7 -SCAICT-uwu now supports 1 language. Many localisations are updated regularly. +SCAICT-uwu now supports 1 language. ### Breaking changes in 0.1.7 @@ -153,6 +193,28 @@ This is a maintenance release of SCAICT-uwu 0.1 version. * … +### External dependency changes in 0.1.6 + +#### New external dependencies in 0.1.6 + +* … + +#### New development-only external dependencies in 0.1.6 + +* … + +#### Changed external dependencies in 0.1.6 + +* … + +#### Changed development-only external dependencies in 0.1.6 + +* … + +#### Removed external dependencies in 0.1.6 + +* … + ### Bug fixes in 0.1.6 * … @@ -167,7 +229,7 @@ This is a maintenance release of SCAICT-uwu 0.1 version. ### Languages updated in 0.1.6 -SCAICT-uwu now supports 1 language. Many localisations are updated regularly. +SCAICT-uwu now supports 1 language. ### Breaking changes in 0.1.6 @@ -211,6 +273,28 @@ This is a maintenance release of SCAICT-uwu 0.1 version. * … +### External dependency changes in 0.1.5 + +#### New external dependencies in 0.1.5 + +* … + +#### New development-only external dependencies in 0.1.5 + +* … + +#### Changed external dependencies in 0.1.5 + +* … + +#### Changed development-only external dependencies in 0.1.5 + +* … + +#### Removed external dependencies in 0.1.5 + +* … + ### Bug fixes in 0.1.5 * … @@ -225,7 +309,7 @@ This is a maintenance release of SCAICT-uwu 0.1 version. ### Languages updated in 0.1.5 -SCAICT-uwu now supports 1 language. Many localisations are updated regularly. +SCAICT-uwu now supports 1 language. ### Breaking changes in 0.1.5 @@ -269,6 +353,28 @@ This is a maintenance release of SCAICT-uwu 0.1 version. * … +### External dependency changes in 0.1.4 + +#### New external dependencies in 0.1.4 + +* … + +#### New development-only external dependencies in 0.1.4 + +* … + +#### Changed external dependencies in 0.1.4 + +* … + +#### Changed development-only external dependencies in 0.1.4 + +* … + +#### Removed external dependencies in 0.1.4 + +* … + ### Bug fixes in 0.1.4 * … @@ -283,7 +389,7 @@ This is a maintenance release of SCAICT-uwu 0.1 version. ### Languages updated in 0.1.4 -SCAICT-uwu now supports 1 language. Many localisations are updated regularly. +SCAICT-uwu now supports 1 language. ### Breaking changes in 0.1.4 @@ -327,6 +433,28 @@ This is a maintenance release of SCAICT-uwu 0.1 version. * … +### External dependency changes in 0.1.3 + +#### New external dependencies in 0.1.3 + +* … + +#### New development-only external dependencies in 0.1.3 + +* … + +#### Changed external dependencies in 0.1.3 + +* … + +#### Changed development-only external dependencies in 0.1.3 + +* … + +#### Removed external dependencies in 0.1.3 + +* … + ### Bug fixes in 0.1.3 * … @@ -341,7 +469,7 @@ This is a maintenance release of SCAICT-uwu 0.1 version. ### Languages updated in 0.1.3 -SCAICT-uwu now supports 1 language. Many localisations are updated regularly. +SCAICT-uwu now supports 1 language. ### Breaking changes in 0.1.3 @@ -385,6 +513,28 @@ This is a maintenance release of SCAICT-uwu 0.1 version. * … +### External dependency changes in 0.1.2 + +#### New external dependencies in 0.1.2 + +* … + +#### New development-only external dependencies in 0.1.2 + +* … + +#### Changed external dependencies in 0.1.2 + +* … + +#### Changed development-only external dependencies in 0.1.2 + +* … + +#### Removed external dependencies in 0.1.2 + +* … + ### Bug fixes in 0.1.2 * … @@ -399,7 +549,7 @@ This is a maintenance release of SCAICT-uwu 0.1 version. ### Languages updated in 0.1.2 -SCAICT-uwu now supports 1 language. Many localisations are updated regularly. +SCAICT-uwu now supports 1 language. ### Breaking changes in 0.1.2 @@ -451,7 +601,7 @@ This is a maintenance release of SCAICT-uwu 0.1 version. ### Languages in 0.1.1 -SCAICT-uwu now supports 1 language. Many localisations are updated regularly. +SCAICT-uwu now supports 1 language. Below only new and removed languages are listed. From b3e13178a7f5826d1688afef42bf752bd0a50448 Mon Sep 17 00:00:00 2001 From: Winston Sung Date: Thu, 16 Jan 2025 22:01:55 +0800 Subject: [PATCH 130/141] Update release notes Change-Id: Id4f370144a0cc2b47d8a2d3a37d7b6b1e39ce0d6 --- RELEASE-NOTES-0.1.md | 83 ------------------------------ RELEASE-NOTES-0.2.md | 118 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 118 insertions(+), 83 deletions(-) create mode 100644 RELEASE-NOTES-0.2.md diff --git a/RELEASE-NOTES-0.1.md b/RELEASE-NOTES-0.1.md index 8606dbd..b42e84d 100644 --- a/RELEASE-NOTES-0.1.md +++ b/RELEASE-NOTES-0.1.md @@ -1,88 +1,5 @@ # SCAICT-uwu 0.1 -## SCAICT-uwu 0.1 development branch - -THIS IS NOT A RELEASE YET - -The `development` branch is a beta-quality development branch. Use it at your -own risk! - -### Configuration changes for system administrators - -#### New configuration - -* … - -#### Changed configuration - -* … - -#### Removed configuration - -* … - -### New user-facing features - -* … - -### New features for sysadmins - -* … - -### New developer features - -* … - -### External dependency changes - -#### New external dependencies - -* … - -#### New development-only external dependencies - -* … - -#### Changed external dependencies - -* … - -#### Changed development-only external dependencies - -* … - -#### Removed external dependencies - -* … - -### Bug fixes - -* … - -### API changes - -* … - -### API internal changes - -* … - -### Languages updated - -SCAICT-uwu now supports 1 language. - -### Breaking changes - -* … - -### Deprecations - -* … - -### Other changes - -* … - ## SCAICT-uwu 0.1.7 This is a maintenance release of SCAICT-uwu 0.1 version. diff --git a/RELEASE-NOTES-0.2.md b/RELEASE-NOTES-0.2.md new file mode 100644 index 0000000..d75ad9e --- /dev/null +++ b/RELEASE-NOTES-0.2.md @@ -0,0 +1,118 @@ +# SCAICT-uwu 0.2 + +## SCAICT-uwu 0.2 development branch + +THIS IS NOT A RELEASE YET + +The `development` branch is a beta-quality development branch. Use it at your +own risk! + +### Configuration changes for system administrators + +#### New configuration + +* … + +#### Changed configuration + +* … + +#### Removed configuration + +* … + +### New user-facing features + +* … + +### New features for sysadmins + +* … + +### New developer features + +* … + +### External dependency changes + +#### New external dependencies + +* Added py-cord dependency. + * Added propcache 0.2.1. + +#### New development-only external dependencies + +* … + +#### Changed external dependencies + +* Updated flask from 3.0.3 to 3.1.0. + * Updated blinker from 1.8.2 to 1.9.0 + * Updated click from 8.1.7 to 8.1.8. + * Updated jinja2 from 3.1.4 to 3.1.5. + * Updated markupsafe from 2.1.5 to 3.0.2. + * Updated werkzeug from 3.0.4 to 3.1.3. +* Updated mysql-connector-python from 8.4.0 to 9.1.0. +* Updated py-cord from 2.6.0 to 2.6.1. + * Updated aiohappyeyeballs from 2.4.0 to 2.4.4. + * Updated aiohttp from 3.10.5 to 3.11.11. + * Updated aiosignal from 1.3.1 to 1.3.2. + * Updated attrs from 24.2.0 to 24.3.0. + * Updated frozenlist from 1.4.1 to 1.5.0. + * Updated idna from 3.7 to 3.10. + * Updated multidict from 6.0.5 to 6.1.0. + * Updated yarl from 1.9.4 to 1.18.3. +* Updated requests dependencies. + * Updated certifi from 2024.7.4 to 2024.12.14. + * Updated charset-normalizer from 3.3.2 to 3.4.1. + * Updated idna from 3.7 to 3.10. + * Updated urllib3 from 2.2.2 to 2.3.0. + +#### Changed development-only external dependencies + +* Updated black from 24.8.0 to 24.10.0. + * Updated click from 8.1.7 to 8.1.8. + * Updated packaging from 24.1 to 24.2. + * Updated platformdirs from 4.2.2 to 4.3.6. +* Updated pylint from 3.2.6 to 3.3.3. + * Updated astroid from 3.2.4 to 3.3.8. + * Updated dill from 0.3.8 to 0.3.9. + * Updated platformdirs from 4.2.2 to 4.3.6. +* Updated pytest from 8.3.2 to 8.3.4. + * Updated packaging from 24.1 to 24.2. + +#### Removed external dependencies + +* … + +### Bug fixes + +* … + +### API changes + +* … + +### API internal changes + +* … + +### Languages updated + +SCAICT-uwu now supports 1 language. Localisations are updated regularly. + +Below only new and removed languages are listed. + +* … + +### Breaking changes + +* … + +### Deprecations + +* … + +### Other changes + +* … From 66eacf45c71c41fd5bff1b5a6f00f2b1cddc62ec Mon Sep 17 00:00:00 2001 From: Winston Sung Date: Thu, 16 Jan 2025 22:02:27 +0800 Subject: [PATCH 131/141] Update release notes Change-Id: If1eb47626bffb27314b2b9248c063c45843332cc --- RELEASE-NOTES-0.1.md => HISTORY.md | 4 ++++ 1 file changed, 4 insertions(+) rename RELEASE-NOTES-0.1.md => HISTORY.md (98%) diff --git a/RELEASE-NOTES-0.1.md b/HISTORY.md similarity index 98% rename from RELEASE-NOTES-0.1.md rename to HISTORY.md index b42e84d..c8cf6f9 100644 --- a/RELEASE-NOTES-0.1.md +++ b/HISTORY.md @@ -1,3 +1,7 @@ +# History + +Change notes from older releases. For current info, see RELEASE-NOTES-0.2. + # SCAICT-uwu 0.1 ## SCAICT-uwu 0.1.7 From 3dcc8266cef7ee3d456afdc77ded110137ba28ce Mon Sep 17 00:00:00 2001 From: Winston Sung Date: Thu, 16 Jan 2025 22:15:34 +0800 Subject: [PATCH 132/141] Remove deprecated redundant code in switch-btn.js Change-Id: I6bb5dd1cc73186f5f2c056fd21b13608ae408822 --- static/switch-btn.js | 31 +++++++++++++++++++------------ 1 file changed, 19 insertions(+), 12 deletions(-) diff --git a/static/switch-btn.js b/static/switch-btn.js index 5dd038b..971f200 100644 --- a/static/switch-btn.js +++ b/static/switch-btn.js @@ -4,49 +4,56 @@ var switchButton = document.querySelector('.switch-button'); var switchBtnRight = document.querySelector('.switch-button-case.right'); var switchBtnLeft = document.querySelector('.switch-button-case.left'); var activeSwitch = document.querySelector('.active'); -var numDraws = document.getElementById('numDraws');//決定要抽幾抽的表單 -//抓轉蛋機外觀元素,用來調整轉蛋機的外觀 +// 決定要抽幾抽的表單 +var numDraws = document.getElementById('numDraws'); + +// 抓轉蛋機外觀元素,用來調整轉蛋機的外觀 var st3 = document.getElementsByClassName('st3'); var st4 = document.getElementsByClassName('st4'); var st5 = document.getElementsByClassName('st5'); var st6 = document.getElementsByClassName('st6'); -function changeMachine(color3,color4,color5,color6){ + +function changeMachine(color3, color4, color5, color6) { for (var i = 0; i < st3.length; i++) { st3[i].style.fill = color3; } + for (var i = 0; i < st4.length; i++) { st4[i].style.fill = color4; } + for (var i = 0; i < st5.length; i++) { st5[i].style.fill = color5; } + for (var i = 0; i < st6.length; i++) { st6[i].style.fill = color6; } } -function switchLeft(){//左邊,單抽 + +// 左邊,單抽 +function switchLeft() { switchBtnRight.classList.remove('active-case'); switchBtnLeft.classList.add('active-case'); - activeSwitch.style.left= '0%'; - numDraws.value=1; + activeSwitch.style.left = '0%'; + numDraws.value = 1; changeMachine('#1e90ff', '#00bfff', '#87cefa', '#4682b4'); } -function switchRight(){//右邊,10連 +// 右邊,10連 +function switchRight() { switchBtnRight.classList.add('active-case'); switchBtnLeft.classList.remove('active-case'); activeSwitch.style.left = '50%'; - numDraws.value=10; + numDraws.value = 10; changeMachine('#FF0000', '#FF4500', '#B22222', '#8B0000'); - achine('#FFD700', '#FFA500', '#FF6347', '#d76a1d');// Suspected Redundant Code } -switchBtnLeft.addEventListener('click', function(){ +switchBtnLeft.addEventListener('click', function() { switchLeft(); }, false); -switchBtnRight.addEventListener('click', function(){ +switchBtnRight.addEventListener('click', function() { switchRight(); }, false); - From a26545ae724521fb7968b761d785ed8a4ac9341b Mon Sep 17 00:00:00 2001 From: Each Chen Date: Mon, 3 Feb 2025 10:11:58 +0800 Subject: [PATCH 133/141] fix: Hide RPS game alert to public --- cog/game.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/cog/game.py b/cog/game.py index 941191d..898d9b7 100644 --- a/cog/game.py +++ b/cog/game.py @@ -42,7 +42,7 @@ async def rock_paper_scissors( self, interaction, choice: discord.Option(str, choices=["✊", "🤚", "✌️"]) ): if interaction.channel.id != get_channels()["channel"]["commandChannel"]: - await interaction.response.send_message("這裡不是指令區喔") + await interaction.response.send_message("這裡不是指令區喔", ephemeral=True) return user_id = interaction.user.id user_display_name = interaction.user @@ -51,11 +51,15 @@ async def rock_paper_scissors( point = read(user_id, "point", cursor) if point < 5: - await interaction.response.send_message("你的電電點不足以玩這個遊戲") + await interaction.response.send_message( + "你的電電點不足以玩這個遊戲", ephemeral=True + ) end(connection, cursor) return if choice not in ["✊", "🤚", "✌️"]: - await interaction.response.send_message("請輸入正確的選擇") + await interaction.response.send_message( + "請輸入正確的選擇", ephemeral=True + ) end(connection, cursor) return From 6c39d619e5317fc928089153fbb05f0b47f0a78c Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 3 Feb 2025 06:02:38 +0000 Subject: [PATCH 134/141] Bump mysql-connector-python from 9.1.0 to 9.2.0 Bumps [mysql-connector-python](https://github.com/mysql/mysql-connector-python) from 9.1.0 to 9.2.0. - [Changelog](https://github.com/mysql/mysql-connector-python/blob/trunk/CHANGES.txt) - [Commits](https://github.com/mysql/mysql-connector-python/compare/9.1.0...9.2.0) --- updated-dependencies: - dependency-name: mysql-connector-python dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- pyproject.toml | 2 +- requirements.txt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 33772cc..f68ac23 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -29,7 +29,7 @@ urls.issues = "https://github.com/SCAICT/SCAICT-uwu/issues" # Lock file: requirements.txt dependencies = [ "flask == 3.1.0", - "mysql-connector-python == 9.1.0", + "mysql-connector-python == 9.2.0", "py-cord == 2.6.1", "python-dotenv == 1.0.1", "requests == 2.32.3", diff --git a/requirements.txt b/requirements.txt index d183b88..1c786f1 100644 --- a/requirements.txt +++ b/requirements.txt @@ -14,7 +14,7 @@ itsdangerous == 2.2.0 jinja2 == 3.1.5 markupsafe == 3.0.2 multidict == 6.1.0 -mysql-connector-python == 9.1.0 +mysql-connector-python == 9.2.0 propcache == 0.2.1 py-cord == 2.6.1 python-dotenv == 1.0.1 From 365740797276405b6d54d1affc419589b1cd8366 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 3 Feb 2025 06:05:59 +0000 Subject: [PATCH 135/141] Bump attrs from 24.3.0 to 25.1.0 Bumps [attrs](https://github.com/sponsors/hynek) from 24.3.0 to 25.1.0. - [Commits](https://github.com/sponsors/hynek/commits) --- updated-dependencies: - dependency-name: attrs dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index 1c786f1..aa8735c 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,7 +1,7 @@ aiohappyeyeballs == 2.4.4 aiohttp == 3.11.11 aiosignal == 1.3.2 -attrs == 24.3.0 +attrs == 25.1.0 blinker == 1.9.0 certifi == 2024.12.14 charset-normalizer == 3.4.1 From 68721f2445dd935643096b75e6b8edf52553d4a5 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 3 Feb 2025 06:15:50 +0000 Subject: [PATCH 136/141] Bump pylint from 3.3.3 to 3.3.4 Bumps [pylint](https://github.com/pylint-dev/pylint) from 3.3.3 to 3.3.4. - [Release notes](https://github.com/pylint-dev/pylint/releases) - [Commits](https://github.com/pylint-dev/pylint/compare/v3.3.3...v3.3.4) --- updated-dependencies: - dependency-name: pylint dependency-type: direct:development update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- pyproject.toml | 2 +- requirements_dev.txt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index f68ac23..151a209 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -37,6 +37,6 @@ dependencies = [ # Lock file: requirements_dev.txt optional-dependencies.dev = [ "black == 24.10.0", - "pylint == 3.3.3", + "pylint == 3.3.4", "pytest == 8.3.4", ] diff --git a/requirements_dev.txt b/requirements_dev.txt index 98e99c1..ebff1d1 100644 --- a/requirements_dev.txt +++ b/requirements_dev.txt @@ -11,6 +11,6 @@ packaging == 24.2 pathspec == 0.12.1 platformdirs == 4.3.6 pluggy == 1.5.0 -pylint == 3.3.3 +pylint == 3.3.4 pytest == 8.3.4 tomlkit == 0.13.2 From 329bd1a584ba7fe2c070d18f36c1b0301bfdf584 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 3 Feb 2025 06:19:49 +0000 Subject: [PATCH 137/141] Bump isort from 5.13.2 to 6.0.0 Bumps [isort](https://github.com/pycqa/isort) from 5.13.2 to 6.0.0. - [Release notes](https://github.com/pycqa/isort/releases) - [Changelog](https://github.com/PyCQA/isort/blob/main/CHANGELOG.md) - [Commits](https://github.com/pycqa/isort/compare/5.13.2...6.0.0) --- updated-dependencies: - dependency-name: isort dependency-type: direct:development update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] --- requirements_dev.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements_dev.txt b/requirements_dev.txt index ebff1d1..7fa944b 100644 --- a/requirements_dev.txt +++ b/requirements_dev.txt @@ -4,7 +4,7 @@ click == 8.1.8 colorama == 0.4.6 dill == 0.3.9 iniconfig == 2.0.0 -isort == 5.13.2 +isort == 6.0.0 mccabe == 0.7.0 mypy-extensions == 1.0.0 packaging == 24.2 From 30b7127010c14d768fbc6b50a48471b0057ab907 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 3 Feb 2025 07:19:52 +0000 Subject: [PATCH 138/141] Bump black from 24.10.0 to 25.1.0 Bumps [black](https://github.com/psf/black) from 24.10.0 to 25.1.0. - [Release notes](https://github.com/psf/black/releases) - [Changelog](https://github.com/psf/black/blob/main/CHANGES.md) - [Commits](https://github.com/psf/black/compare/24.10.0...25.1.0) --- updated-dependencies: - dependency-name: black dependency-type: direct:development update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] --- pyproject.toml | 2 +- requirements_dev.txt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 151a209..d7dd10e 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -36,7 +36,7 @@ dependencies = [ ] # Lock file: requirements_dev.txt optional-dependencies.dev = [ - "black == 24.10.0", + "black == 25.1.0", "pylint == 3.3.4", "pytest == 8.3.4", ] diff --git a/requirements_dev.txt b/requirements_dev.txt index 7fa944b..1999913 100644 --- a/requirements_dev.txt +++ b/requirements_dev.txt @@ -1,5 +1,5 @@ astroid == 3.3.8 -black == 24.10.0 +black == 25.1.0 click == 8.1.8 colorama == 0.4.6 dill == 0.3.9 From dd4137204324474515c60d213bc110b1dbe05ad0 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 3 Feb 2025 07:24:34 +0000 Subject: [PATCH 139/141] Bump certifi from 2024.12.14 to 2025.1.31 Bumps [certifi](https://github.com/certifi/python-certifi) from 2024.12.14 to 2025.1.31. - [Commits](https://github.com/certifi/python-certifi/compare/2024.12.14...2025.01.31) --- updated-dependencies: - dependency-name: certifi dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index aa8735c..46ef619 100644 --- a/requirements.txt +++ b/requirements.txt @@ -3,7 +3,7 @@ aiohttp == 3.11.11 aiosignal == 1.3.2 attrs == 25.1.0 blinker == 1.9.0 -certifi == 2024.12.14 +certifi == 2025.1.31 charset-normalizer == 3.4.1 click == 8.1.8 colorama == 0.4.6 From 36f2b9dbf9884210fa3a23c079be42f8d6c577a4 Mon Sep 17 00:00:00 2001 From: Winston Sung Date: Mon, 3 Feb 2025 16:57:34 +0800 Subject: [PATCH 140/141] Packaging: Prepare src layout migration * Support lowercase to BCP 47 letter case conversion Change-Id: I4748dcdb8b9ccb372fa3f1febfd6b9e246832984 --- src/scaict_uwu/libs/language/language_tag.py | 2 +- .../libs/language/language_tag_factory.py | 45 ++++-- .../libs/language/language_utils.py | 128 +++++++++++++++++- tests/unittest/test_language_tag_factory.py | 8 ++ 4 files changed, 170 insertions(+), 13 deletions(-) diff --git a/src/scaict_uwu/libs/language/language_tag.py b/src/scaict_uwu/libs/language/language_tag.py index d667584..602c996 100644 --- a/src/scaict_uwu/libs/language/language_tag.py +++ b/src/scaict_uwu/libs/language/language_tag.py @@ -24,7 +24,7 @@ class LanguageTag: _tag (str): The BCP 47 language subtag of the LanguageTag object. """ - def __init__(self, tag: str) -> None: + def __init__(self, tag: str, /) -> None: """ Parameters: tag (str): BCP 47 language tag. diff --git a/src/scaict_uwu/libs/language/language_tag_factory.py b/src/scaict_uwu/libs/language/language_tag_factory.py index 865ea8c..f2caec6 100644 --- a/src/scaict_uwu/libs/language/language_tag_factory.py +++ b/src/scaict_uwu/libs/language/language_tag_factory.py @@ -20,12 +20,12 @@ class LanguageTagFactory: _tags (dict): The LanguageTag objects. """ - def get(self, tag: str) -> LanguageTag: + def _get(self, tag: str, /) -> LanguageTag: """ - Get LanguageTag object by BCP 47 language tag. + Get LanguageTag object by normalized BCP 47 language tag. Parameters: - tag (str): BCP 47 language tag. + tag (str): Normalized BCP 47 language tag. Returns: LanguageTag: The LanguageTag object to the corresponding BCP 47\ @@ -37,7 +37,39 @@ def get(self, tag: str) -> LanguageTag: return self._tags[tag] - def get_by_discord_code(self, code: str) -> LanguageTag | None: + def get(self, tag: str, /) -> LanguageTag: + """ + Get LanguageTag object by normalized BCP 47 language tag. + + Parameters: + tag (str): Normalized BCP 47 language tag. + + Returns: + LanguageTag: The LanguageTag object to the corresponding BCP 47\ + language tag. + """ + + tag = LanguageUtils.to_bcp_47_case(tag) + + return self._get(tag) + + def get_by_unnormalized(self, tag: str, /) -> LanguageTag: + """ + Get LanguageTag object by unnormalized BCP 47 language tag. + + Parameters: + tag (str): Unnormalized BCP 47 language tag. + + Returns: + LanguageTag: The LanguageTag object to the corresponding BCP 47\ + language tag. + """ + + tag = LanguageUtils.to_bcp_47(tag) + + return self._get(tag) + + def get_by_discord_code(self, code: str, /) -> LanguageTag | None: """ Get LanguageTag object by Discord locale code. @@ -55,7 +87,4 @@ def get_by_discord_code(self, code: str) -> LanguageTag | None: tag = LanguageUtils.get_from_discord_code(code) - if tag not in self._tags: - self._tags[tag] = LanguageTag(tag) - - return self._tags[tag] + return self._get(tag) diff --git a/src/scaict_uwu/libs/language/language_utils.py b/src/scaict_uwu/libs/language/language_utils.py index 523fe60..09a1580 100644 --- a/src/scaict_uwu/libs/language/language_utils.py +++ b/src/scaict_uwu/libs/language/language_utils.py @@ -8,6 +8,65 @@ class LanguageUtils: The LanguageUtils class deals with language utilities. """ + @staticmethod + def get_bcp_47_prefix_mapping() -> dict[str, str]: + """ + Get the mapping of unnormalized BCP 47 language tag prefix to\ + normalized BCP 47 language tag prefix. + + Returns: + dict[str, str]: The mapping of unnormalized BCP 47 language tag\ + prefix to normalized BCP 47 language tag prefix. + """ + + return { + "art-lojban": "jbo", + "en-GB-oed": "en-GB-oxendict", + "i-ami": "ami", + "i-bnn": "bnn", + "i-hak": "hak", + "i-klingon": "tlh", + "i-lux": "lb", + "i-navajo": "nv", + "i-pwn": "pwn", + "i-tao": "tao", + "i-tay": "tay", + "i-tsu": "tsu", + "no-bok": "nb", + "no-nyn": "nn", + "sgn-BE-FR": "sfb", + "sgn-BE-NL": "vgt", + "sgn-BR": "bzs", + "sgn-CH-DE": "sgg", + "sgn-CO": "csn", + "sgn-DE": "gsg", + "sgn-DK": "dsl", + "sgn-ES": "ssp", + "sgn-FR": "fsl", + "sgn-GB": "bfi", + "sgn-GR": "gss", + "sgn-IE": "isg", + "sgn-IT": "ise", + "sgn-JP": "jsl", + "sgn-MX": "mfs", + "sgn-NI": "ncs", + "sgn-NL": "dse", + "sgn-NO": "nsl", + "sgn-PT": "psr", + "sgn-SE": "swl", + "sgn-US": "ase", + "sgn-ZA": "sfs", + "zh-cmn": "cmn", + "zh-gan": "gan", + "zh-guoyu": "cmn", + "zh-hakka": "hak", + "zh-min-nan": "nan", + "zh-nan": "nan", + "zh-wuu": "wuu", + "zh-xiang": "hsn", + "zh-yue": "yue", + } + @staticmethod def get_supported_discord_codes() -> list[str]: """ @@ -76,7 +135,7 @@ def get_discord_code_mapping() -> dict[str, str]: } @classmethod - def get_discord_code_to_bcp_47_mapping(cls) -> dict: + def get_discord_code_to_bcp_47_mapping(cls, /) -> dict: """ Get the mapping of Discord locale code to BCP 47 language tag. @@ -86,8 +145,69 @@ def get_discord_code_to_bcp_47_mapping(cls) -> dict: return {v: k for k, v in cls.get_discord_code_mapping().items()} + @staticmethod + def to_bcp_47_case(tag: str, /) -> str: + """ + Convert language tag string to BCP 47 letter case. + + * language subtag: all lowercase. For example, zh. + * script subtag: first letter uppercase. For example, Latn. + * region subtag: all uppercase. For example, TW. + * variant subtags: all lowercase. For example, wadegile. + + Parameters: + tag (str): BCP 47 language tag string. + + Returns: + str: BCP 47 language tag string with BCP 47 letter case. + """ + + tag_lower_subtags: list[str] = tag.lower().split("-") + tag_bcp_47_case_subtags: list[str] = [] + + for index, subtag in enumerate(tag_lower_subtags): + if index > 0 and tag_lower_subtags[index - 1] == "x": + # When the previous segment is x, it is a private subtag and + # should be lowercase + tag_bcp_47_case_subtags.append(subtag.lower()) + elif len(subtag) == 2 and index > 0: + # BCP 47 region subtag + tag_bcp_47_case_subtags.append(subtag.upper()) + elif len(subtag) == 4 and index > 0: + # BCP 47 script subtag + tag_bcp_47_case_subtags.append(subtag.title()) + else: + # Use lowercase for other cases + tag_bcp_47_case_subtags.append(subtag.lower()) + + return "-".join(tag_bcp_47_case_subtags) + + @classmethod + def to_bcp_47(cls, tag: str, /) -> str: + """ + Normalize language tag string to BCP 47 language tag string, with + letter case formatting and deprecated code replacements (for example, + zh-min-nan => nan). + + Parameters: + tag (str): Unnormalized BCP 47 language tag string. + + Returns: + str: Normalized BCP 47 language tag string. + """ + + tag = tag.lower() + + for k, v in cls.get_bcp_47_prefix_mapping().items(): + if tag.startswith(k): + tag = v + tag.removeprefix(k) + + break + + return cls.to_bcp_47_case(tag) + @classmethod - def is_supported_discord_code(cls, code: str) -> bool: + def is_supported_discord_code(cls, code: str, /) -> bool: """ Check if the given code is a supported Discord locale code. @@ -101,7 +221,7 @@ def is_supported_discord_code(cls, code: str) -> bool: return code in cls.get_supported_discord_codes() @classmethod - def get_discord_code(cls, tag: str) -> str | None: + def get_discord_code(cls, tag: str, /) -> str | None: """ Get the Discord locale code from BCP 47 language tag. @@ -122,7 +242,7 @@ def get_discord_code(cls, tag: str) -> str | None: return None @classmethod - def get_from_discord_code(cls, code: str) -> str: + def get_from_discord_code(cls, code: str, /) -> str: """ Get the BCP 47 language tag from Discord locale code. diff --git a/tests/unittest/test_language_tag_factory.py b/tests/unittest/test_language_tag_factory.py index 98e5321..0cbb927 100644 --- a/tests/unittest/test_language_tag_factory.py +++ b/tests/unittest/test_language_tag_factory.py @@ -23,6 +23,13 @@ def test_get(self) -> None: language_tag: LanguageTag = self.language_tag_factory.get("zh-Hant") self.assertEqual(language_tag.get_bcp_47_tag(), "zh-Hant") + self.assertEqual(language_tag.get_system_message_tag(), "zh-hant") + self.assertEqual(language_tag.get_discord_code(), "zh-TW") + + language_tag = self.language_tag_factory.get("zh-hant") + + self.assertEqual(language_tag.get_bcp_47_tag(), "zh-Hant") + self.assertEqual(language_tag.get_system_message_tag(), "zh-hant") self.assertEqual(language_tag.get_discord_code(), "zh-TW") def test_get_by_discord_code(self) -> None: @@ -32,6 +39,7 @@ def test_get_by_discord_code(self) -> None: self.assertIsNotNone(language_tag) self.assertEqual(language_tag.get_bcp_47_tag(), "zh-Hant") + self.assertEqual(language_tag.get_system_message_tag(), "zh-hant") self.assertEqual(language_tag.get_discord_code(), "zh-TW") From 0c622a73fe4db674ede7da31d472b824eff010da Mon Sep 17 00:00:00 2001 From: Winston Sung Date: Wed, 9 Oct 2024 15:46:21 +0800 Subject: [PATCH 141/141] Version 0.2.0 Bug: #147 Change-Id: I04dbfb2269ba2c7ba9068e1e4417067285b945eb --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index d7dd10e..6baeef5 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -5,7 +5,7 @@ name = "scaict-uwu" # PEP 440 # @see https://sethmlarson.dev/pep-440 -version = "0.1.9.dev0" +version = "0.2.0" description = "A cat living in SCAICT Discord server." readme.file = "README.md" readme.content-type = "text/markdown"