From d8b334488cdfac4ecc9f79c279f62c97a1e1ea71 Mon Sep 17 00:00:00 2001 From: Yuuzi261 Date: Sun, 24 Nov 2024 18:34:28 +0800 Subject: [PATCH 1/5] feat: in response to tweety-ns version update, the operation is changed to coroutine --- cogs/notification.py | 29 +++++++++++++++++------------ src/notification/account_tracker.py | 4 ++-- src/sync_db/sync_db.py | 6 +++--- 3 files changed, 22 insertions(+), 17 deletions(-) diff --git a/cogs/notification.py b/cogs/notification.py index 91d62ce..a4b06a0 100644 --- a/cogs/notification.py +++ b/cogs/notification.py @@ -66,9 +66,9 @@ async def notifier(self, itn: discord.Interaction, username: str, channel: disco roleID = str(mention.id) if mention is not None else '' if match_user is None or match_user['enabled'] == 0: app = Twitter(account_used) - app.load_auth_token(get_accounts()[account_used]) + await app.load_auth_token(get_accounts()[account_used]) try: - new_user = app.get_user_info(username) + new_user = await app.get_user_info(username) except Exception: await itn.followup.send(f'user {username} not found', ephemeral=True) return @@ -83,13 +83,15 @@ async def notifier(self, itn: discord.Interaction, username: str, channel: disco if configs['auto_unfollow'] or configs['auto_turn_off_notification']: old_client_used = match_user['client_used'] old_app = Twitter(old_client_used) - old_app.load_auth_token(get_accounts()[old_client_used]) - target_user = old_app.get_user_info(username) + await old_app.load_auth_token(get_accounts()[old_client_used]) + target_user = await old_app.get_user_info(username) if configs['auto_unfollow']: - log.info(f'successfully unfollowed {username} (due to client change)') if old_app.unfollow_user(target_user) else log.warning(f'unable to unfollow {username}') + status = await old_app.unfollow_user(target_user) + log.info(f'successfully unfollowed {username} (due to client change)') if status else log.warning(f'unable to unfollow {username}') else: - log.info(f'successfully turned off notification for {username} (due to client change)') if old_app.disable_user_notification(target_user) else log.warning(f'unable to turn off notifications for {username}') + status = await old_app.disable_user_notification(target_user) + log.info(f'successfully turned off notification for {username} (due to client change)') if status else log.warning(f'unable to turn off notifications for {username}') await cursor.execute('REPLACE INTO user (client_used) VALUES (?) WHERE id = ?', (account_used, match_user['id'])) else: @@ -100,9 +102,10 @@ async def notifier(self, itn: discord.Interaction, username: str, channel: disco await cursor.execute('REPLACE INTO notification (user_id, channel_id, role_id, enable_type, enable_media_type) VALUES (?, ?, ?, ?, ?)', (match_user['id'], str(channel.id), roleID, enable_type, media_type)) await cursor.execute('UPDATE user SET enabled = 1 WHERE id = ?', (match_user['id'],)) - app.follow_user(new_user) + await app.follow_user(new_user) - if app.enable_user_notification(new_user): + status = await app.enable_user_notification(new_user) + if status: log.info(f'successfully turned on notification for {username}') else: log.warning(f'unable to turn on notifications for {username}') @@ -155,13 +158,15 @@ async def r_notifier(self, itn: discord.Interaction, channel_id: str, username: result = await cursor.fetchone() client_used = result['client_used'] app = Twitter(client_used) - app.load_auth_token(get_accounts()[client_used]) - target_user = app.get_user_info(username) + await app.load_auth_token(get_accounts()[client_used]) + target_user = await app.get_user_info(username) if configs['auto_unfollow']: - log.info(f'successfully unfollowed {username}') if app.unfollow_user(target_user) else log.warning(f'unable to unfollow {username}') + status = await app.unfollow_user(target_user) + log.info(f'successfully unfollowed {username}') if status else log.warning(f'unable to unfollow {username}') else: - log.info(f'successfully turned off notification for {username}') if app.disable_user_notification(target_user) else log.warning(f'unable to turn off notifications for {username}') + status = await app.disable_user_notification(target_user) + log.info(f'successfully turned off notification for {username}') if status else log.warning(f'unable to turn off notifications for {username}') else: await itn.followup.send(f'can\'t find notifier {username} in {channel.mention}!', ephemeral=True) diff --git a/src/notification/account_tracker.py b/src/notification/account_tracker.py index 26980fe..6b8a8e7 100644 --- a/src/notification/account_tracker.py +++ b/src/notification/account_tracker.py @@ -33,7 +33,7 @@ async def setup_tasks(self): self.apps = [] for account_name, account_token in self.accounts_data.items(): app = Twitter(account_name) - app.load_auth_token(account_token) + await app.load_auth_token(account_token) self.bot.loop.create_task(self.tweetsUpdater(app)).set_name(f'TweetsUpdater_{account_name}') self.apps.append(app) @@ -87,7 +87,7 @@ async def tweetsUpdater(self, app: Twitter): updater_name = asyncio.current_task().get_name().split('_', 1)[1] while True: try: - self.tweets[updater_name] = app.get_tweet_notifications() + self.tweets[updater_name] = await app.get_tweet_notifications() await asyncio.sleep(configs['tweets_check_period']) except Exception as e: log.error(f'{e} (task : tweets updater {updater_name})') diff --git a/src/sync_db/sync_db.py b/src/sync_db/sync_db.py index 7d65f65..d79d103 100644 --- a/src/sync_db/sync_db.py +++ b/src/sync_db/sync_db.py @@ -13,13 +13,13 @@ async def sync_db(follow_list: dict[str, str]) -> None: apps: dict[str, Twitter] = {} for account_name, account_token in get_accounts().items(): app = Twitter(account_name) - app.load_auth_token(account_token) + await app.load_auth_token(account_token) apps[account_name] = app for user_id, client_used in follow_list.items(): app = apps[client_used] - app.follow_user(user_id) - app.enable_user_notification(user_id) + await app.follow_user(user_id) + await app.enable_user_notification(user_id) await asyncio.sleep(1) log.info('synchronization with database completed') From fa9c6ad1341058d9feea61b25d98ba6c0265b61a Mon Sep 17 00:00:00 2001 From: Yuuzi261 Date: Sun, 24 Nov 2024 18:35:33 +0800 Subject: [PATCH 2/5] docs: tweety-ns instead pulls the latest updates from the repo --- docs/README.md | 1 + docs/README_zh.md | 1 + requirements.txt | 1 - 3 files changed, 2 insertions(+), 1 deletion(-) diff --git a/docs/README.md b/docs/README.md index a701058..39f85a5 100644 --- a/docs/README.md +++ b/docs/README.md @@ -88,6 +88,7 @@ Before running the bot, you need to install the necessary modules. ```shell pip install -r requirements.txt +pip install https://github.com/mahrtayyab/tweety/archive/main.zip --upgrade ``` ## ⚡Usage diff --git a/docs/README_zh.md b/docs/README_zh.md index b1f86bc..c4b2ca5 100644 --- a/docs/README_zh.md +++ b/docs/README_zh.md @@ -88,6 +88,7 @@ Tweetcord是一個Discord機器人,它使用[tweety-ns](https://github.com/mah ```shell pip install -r requirements.txt +pip install https://github.com/mahrtayyab/tweety/archive/main.zip --upgrade ``` ## ⚡使用 diff --git a/requirements.txt b/requirements.txt index bc6566d..d250b11 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,5 +1,4 @@ discord.py==2.3.2 -tweety-ns==1.0.9.2 python-dotenv==1.0.0 pyyaml==6.0.1 aiosqlite==0.18.0 \ No newline at end of file From 8434500a812e21ad49a999a7d3063025420fe8bd Mon Sep 17 00:00:00 2001 From: Yuuzi261 Date: Mon, 25 Nov 2024 08:15:53 +0800 Subject: [PATCH 3/5] fix: update tweety-ns to solve problem of being unable to follow user --- requirements.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/requirements.txt b/requirements.txt index d250b11..f3491a0 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,5 @@ discord.py==2.3.2 +tweety-ns==2.0.4 python-dotenv==1.0.0 pyyaml==6.0.1 aiosqlite==0.18.0 \ No newline at end of file From c54864e858b4533a79c2a54b9fb76c88a379abdd Mon Sep 17 00:00:00 2001 From: Yuuzi261 Date: Mon, 25 Nov 2024 08:18:31 +0800 Subject: [PATCH 4/5] docs: install tweety-ns 2.0.4 by requirements.txt --- docs/README.md | 1 - docs/README_zh.md | 1 - 2 files changed, 2 deletions(-) diff --git a/docs/README.md b/docs/README.md index 39f85a5..a701058 100644 --- a/docs/README.md +++ b/docs/README.md @@ -88,7 +88,6 @@ Before running the bot, you need to install the necessary modules. ```shell pip install -r requirements.txt -pip install https://github.com/mahrtayyab/tweety/archive/main.zip --upgrade ``` ## ⚡Usage diff --git a/docs/README_zh.md b/docs/README_zh.md index c4b2ca5..b1f86bc 100644 --- a/docs/README_zh.md +++ b/docs/README_zh.md @@ -88,7 +88,6 @@ Tweetcord是一個Discord機器人,它使用[tweety-ns](https://github.com/mah ```shell pip install -r requirements.txt -pip install https://github.com/mahrtayyab/tweety/archive/main.zip --upgrade ``` ## ⚡使用 From a8c83e5d32d05e5096c6f17d521ee59a28668ce7 Mon Sep 17 00:00:00 2001 From: Yuuzi261 Date: Tue, 26 Nov 2024 08:11:43 +0800 Subject: [PATCH 5/5] docs: update upgrade guide --- docs/UPGRADE_GUIDE.md | 30 ++++++++++++++++++++++++++---- 1 file changed, 26 insertions(+), 4 deletions(-) diff --git a/docs/UPGRADE_GUIDE.md b/docs/UPGRADE_GUIDE.md index 3c90035..7d75da4 100644 --- a/docs/UPGRADE_GUIDE.md +++ b/docs/UPGRADE_GUIDE.md @@ -4,9 +4,20 @@ > Cross-version updates are **NOT SUPPORTED**. For multi-version updates, please iterate through each version to update to the latest version. Before updating, please back up your data using the prefix command `download_data`.
- ⬆️click here to upgrade from 0.4.1 to 0.5 + ⬆️Click Here to Upgrade from 0.5.1 to 0.5.2 -**📢Version 0.5 involves changes to dependency packages. Please ensure that all required packages are correctly installed in your environment.** +This update does not involve any changes to the database structure, so there is no need to use an upgrade script. Simply pull the updated code and upgrade the environment to complete the update. + +```bash +pip install --upgrade -r requirements.txt +``` + +
+ +
+ ⬆️click here to upgrade from 0.4.1 to 0.5.1 + +**📢Version 0.5.1 involves changes to dependency packages. Please ensure that all required packages are correctly installed in your environment.** **📢This update includes significant changes to environment variables and configuration files. Please refer to the [README](./README.md) for details to ensure proper operation.** @@ -60,9 +71,20 @@ Because the database structure has been updated, you must use the following code > **不支援**跨版本更新,多版本更新請迭代更新至新版本。更新前請先透過前綴指令 `download_data` 進行資料備份。
- ⬆️0.4.1升級到0.5請點這裡 + ⬆️0.5.1升級到0.5.2請點這裡 + +本次更新不涉及資料庫結構更新,因此不用使用升級腳本來完成升級,請直接拉取程式碼並升級環境即可完成更新。 + +```bash +pip install --upgrade -r requirements.txt +``` + +
+ +
+ ⬆️0.4.1升級到0.5.1請點這裡 -**📢0.5版本涉及依賴套件更動,請確定環境正確安裝所有所需的套件** +**📢0.5.1版本涉及依賴套件更動,請確定環境正確安裝所有所需的套件** **📢本次更新對環境變數、設定檔進行了大量改動,詳情請見[README](./README_zh.md)以確保運作正常**