Skip to content

Commit

Permalink
Merge pull request #36 from Yuuzi261/develope
Browse files Browse the repository at this point in the history
0.5.2
  • Loading branch information
Yuuzi261 authored Nov 26, 2024
2 parents 32061fa + a8c83e5 commit 98521ab
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 22 deletions.
29 changes: 17 additions & 12 deletions cogs/notification.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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:
Expand All @@ -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}')
Expand Down Expand Up @@ -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)
Expand Down
30 changes: 26 additions & 4 deletions docs/UPGRADE_GUIDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
<details>
<summary><b>⬆️click here to upgrade from 0.4.1 to 0.5</b></summary>
<summary><b>⬆️Click Here to Upgrade from 0.5.1 to 0.5.2</b></summary>

**📢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
```

</details>

<details>
<summary><b>⬆️click here to upgrade from 0.4.1 to 0.5.1</b></summary>

**📢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.**

Expand Down Expand Up @@ -60,9 +71,20 @@ Because the database structure has been updated, you must use the following code
> **不支援**跨版本更新,多版本更新請迭代更新至新版本。更新前請先透過前綴指令 `download_data` 進行資料備份。
<details>
<summary><b>⬆️0.4.1升級到0.5請點這裡</b></summary>
<summary><b>⬆️0.5.1升級到0.5.2請點這裡</b></summary>

本次更新不涉及資料庫結構更新,因此不用使用升級腳本來完成升級,請直接拉取程式碼並升級環境即可完成更新。

```bash
pip install --upgrade -r requirements.txt
```

</details>

<details>
<summary><b>⬆️0.4.1升級到0.5.1請點這裡</b></summary>

**📢0.5版本涉及依賴套件更動,請確定環境正確安裝所有所需的套件**
**📢0.5.1版本涉及依賴套件更動,請確定環境正確安裝所有所需的套件**

**📢本次更新對環境變數、設定檔進行了大量改動,詳情請見[README](./README_zh.md)以確保運作正常**

Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
discord.py==2.3.2
tweety-ns==1.0.9.2
tweety-ns==2.0.4
python-dotenv==1.0.0
pyyaml==6.0.1
aiosqlite==0.18.0
4 changes: 2 additions & 2 deletions src/notification/account_tracker.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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})')
Expand Down
6 changes: 3 additions & 3 deletions src/sync_db/sync_db.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')

0 comments on commit 98521ab

Please sign in to comment.