Skip to content

Commit

Permalink
Merge pull request #28 from Yuuzi261/develope
Browse files Browse the repository at this point in the history
0.4.1
  • Loading branch information
Yuuzi261 authored Jul 31, 2024
2 parents c384f95 + cea165f commit 4133f61
Show file tree
Hide file tree
Showing 10 changed files with 443 additions and 253 deletions.
127 changes: 7 additions & 120 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,14 @@ Tweetcord is a discord bot that uses the tweety-ns module to let you receive twe

</summary>

👉 `/add notifier` `username` `channel` | `mention`
👉 `/add notifier` `username` `channel` | `mention` `type`

| parameters | types | descriptions |
| --------- | ----- | ----------- |
| `username` | str | The username of the twitter user you want to turn on notifications for |
| `channel` | discord.TextChannel | The channel to which the bot delivers notifications |
| `mention` | discord.Role | The role to mention when notifying |
| `type` | str | Whether to enable notifications for retweets & quotes _(new in 0.4.1)_ |

👉 `/remove notifier` `username` `channel`

Expand Down Expand Up @@ -89,125 +90,7 @@ In certain operating systems, you may need to use the command `pip3` instead of

**📢This tutorial is suitable for version 0.3.2 or later. (Recommended: 0.3.5 or later)**

<details>
<summary><b>📌click here to upgrade from 0.3.5 to 0.4</b></summary>

⚠️Before everything starts you must upgrade the version of `tweety-ns` to `1.0.9.2` first and download or pull the new code from this repo.

Create a python file in the `cogs` folder and name it `upgrade.py`. Paste the following code and run the bot. Use the slash command `/upgrade version` to upgrade. This cog can be removed after the upgrade is completed.

```py
import discord
from discord import app_commands
from core.classes import Cog_Extension
import sqlite3
import os

from src.permission import ADMINISTRATOR

class Upgrade(Cog_Extension):

upgrade_group = app_commands.Group(name='upgrade', description='Upgrade something', default_permissions=ADMINISTRATOR)

@upgrade_group.command(name='version', description='upgrade to Tweetcord 0.4')
async def upgrade(self, itn: discord.Interaction):

await itn.response.defer(ephemeral=True)

conn = sqlite3.connect(f"{os.getenv('DATA_PATH')}tracked_accounts.db")
cursor = conn.cursor()

try:
cursor.executescript("""
ALTER TABLE user ADD enabled INTEGER DEFAULT 1;
ALTER TABLE notification ADD customized_msg TEXT DEFAULT NULL;
""")
await itn.followup.send('successfully upgrade to 0.4, you can remove this cog and reboot the bot.')
except:
await itn.followup.send('upgrading to 0.4 failed, please try again or contact the author.')


async def setup(bot):
await bot.add_cog(Upgrade(bot))
```

</details>

<details>
<summary><b>📌click here to upgrade from 0.3.4 to 0.3.5</b></summary>

Create a python file in the `cogs` folder and name it `upgrade.py`. Paste the following code and run the bot. Use the slash command `/upgrade` to upgrade. This cog can be removed after the upgrade is completed.

```py
import discord
from discord import app_commands
from core.classes import Cog_Extension
import sqlite3
import os

from src.log import setup_logger
from src.permission_check import is_administrator

log = setup_logger(__name__)

class Upgrade(Cog_Extension):

@is_administrator()
@app_commands.command(name='upgrade', description='upgrade to Tweetcord 0.3.5')
async def upgrade(self, itn: discord.Interaction):

await itn.response.defer(ephemeral=True)

conn = sqlite3.connect(f"{os.getenv('DATA_PATH')}tracked_accounts.db")
cursor = conn.cursor()

cursor.executescript('ALTER TABLE channel ADD server_id TEXT')

cursor.execute('SELECT id FROM channel')
channels = cursor.fetchall()

for c in channels:
try:
channel = self.bot.get_channel(int(c[0]))
cursor.execute('UPDATE channel SET server_id = ? WHERE id = ?', (channel.guild.id, channel.id))
except:
log.warning(f'the bot cannot obtain channel: {c[0]}, but this will not cause problems with the original features. The new feature can also be used normally on existing servers.')


conn.commit()
conn.close()

await itn.followup.send('successfully upgrade to 0.3.5, you can remove this cog.')


async def setup(bot):
await bot.add_cog(Upgrade(bot))
```

</details>

<details>
<summary><b>📌click here to upgrade from 0.3.3 to 0.3.4</b></summary>

Because the database structure has been updated, you must use the following code to update the database structure.

```py
from dotenv import load_dotenv
import os
import sqlite3

load_dotenv()

conn = sqlite3.connect(f"{os.getenv('DATA_PATH')}tracked_accounts.db")
cursor = conn.cursor()

cursor.execute('ALTER TABLE notification ADD enabled INTEGER DEFAULT 1')

conn.commit()
conn.close()
```

</details>
### [⬆️View Version Upgrade Guides](./UPGRADE_GUIDE.md)

### 1. Create and configure the .env file

Expand All @@ -232,6 +115,10 @@ tasks_monitor_check_period: 60 # Interval at which to check if each tasks i
tasks_monitor_log_period: 14400 # Interval at which to output the list of currently running tasks to the execution log.
auto_turn_off_notification: true # (v0.4 or later) If all notifications for a user are disabled, decide whether to unfollow the user.
auto_unfollow: true # (v0.4 or later) If all notifications for a user is disabled, decide whether to disable notification for the user (twitter side).
use_fx: false # (v0.4.1 or later) Whether to use FxTwitter to embed content instead of using the built-in embed
default_message: | # (v0.4.1 or later) Set default message format globally
{mention}**{author}** just {action} here:
{url}
```
### 3. Run and invite the bot to your server
Expand Down
127 changes: 7 additions & 120 deletions README_zh.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,14 @@ Tweetcord是一個discord機器人,它使用tweety-ns模組讓你在discord上

</summary>

👉 `/add notifier` `username` `channel` | `mention`
👉 `/add notifier` `username` `channel` | `mention` `type`

| 參數 | 類型 | 描述 |
| --------- | ----- | ----------- |
| `username` | str | 你想要開啟通知的Twitter用戶的用戶名 |
| `channel` | discord.TextChannel | 機器人發送通知的頻道 |
| `mention` | discord.Role | 通知時提及的身分組 |
| `type` | str | 設定是否啟用轉推和引用的通知 _(0.4.1版本的新功能)_ |

👉 `/remove notifier` `username` `channel`

Expand Down Expand Up @@ -89,125 +90,7 @@ pip install -r requirements.txt

**📢本教學適用於0.3.2或更高版本。(建議:0.3.5或更高版本)**

<details>
<summary><b>📌0.3.5升級到0.4請點這裡</b></summary>

⚠️在一切開始之前請先更新 `tweety-ns``1.0.9.2` 版本並且從這個repo下載或拉取新的程式碼。

`cogs` 資料夾創建一個python檔案並命名為 `upgrade.py`,貼上下面的程式碼並運行機器人,使用斜線指令 `/upgrade version` 進行升級。升級結束後可以移除這個cog。

```py
import discord
from discord import app_commands
from core.classes import Cog_Extension
import sqlite3
import os

from src.permission import ADMINISTRATOR

class Upgrade(Cog_Extension):

upgrade_group = app_commands.Group(name='upgrade', description='Upgrade something', default_permissions=ADMINISTRATOR)

@upgrade_group.command(name='version', description='upgrade to Tweetcord 0.4')
async def upgrade(self, itn: discord.Interaction):

await itn.response.defer(ephemeral=True)

conn = sqlite3.connect(f"{os.getenv('DATA_PATH')}tracked_accounts.db")
cursor = conn.cursor()

try:
cursor.executescript("""
ALTER TABLE user ADD enabled INTEGER DEFAULT 1;
ALTER TABLE notification ADD customized_msg TEXT DEFAULT NULL;
""")
await itn.followup.send('successfully upgrade to 0.4, you can remove this cog and reboot the bot.')
except:
await itn.followup.send('upgrading to 0.4 failed, please try again or contact the author.')


async def setup(bot):
await bot.add_cog(Upgrade(bot))
```

</details>

<details>
<summary><b>📌0.3.4升級到0.3.5請點這裡</b></summary>

`cogs` 資料夾創建一個python檔案並命名為 `upgrade.py`,貼上下面的程式碼並運行機器人,使用斜線指令 `/upgrade` 進行升級。升級結束後可以移除這個cog。

```py
import discord
from discord import app_commands
from core.classes import Cog_Extension
import sqlite3
import os

from src.log import setup_logger
from src.permission_check import is_administrator

log = setup_logger(__name__)

class Upgrade(Cog_Extension):

@is_administrator()
@app_commands.command(name='upgrade', description='upgrade to Tweetcord 0.3.5')
async def upgrade(self, itn: discord.Interaction):

await itn.response.defer(ephemeral=True)

conn = sqlite3.connect(f"{os.getenv('DATA_PATH')}tracked_accounts.db")
cursor = conn.cursor()

cursor.executescript('ALTER TABLE channel ADD server_id TEXT')

cursor.execute('SELECT id FROM channel')
channels = cursor.fetchall()

for c in channels:
try:
channel = self.bot.get_channel(int(c[0]))
cursor.execute('UPDATE channel SET server_id = ? WHERE id = ?', (channel.guild.id, channel.id))
except:
log.warning(f'the bot cannot obtain channel: {c[0]}, but this will not cause problems with the original features. The new feature can also be used normally on existing servers.')


conn.commit()
conn.close()

await itn.followup.send('successfully upgrade to 0.3.5, you can remove this cog.')


async def setup(bot):
await bot.add_cog(Upgrade(bot))
```

</details>

<details>
<summary><b>📌0.3.3升級到0.3.4請點這裡</b></summary>

因為資料庫結構更新因此必須使用以下程式碼更新資料庫結構。

```py
from dotenv import load_dotenv
import os
import sqlite3

load_dotenv()

conn = sqlite3.connect(f"{os.getenv('DATA_PATH')}tracked_accounts.db")
cursor = conn.cursor()

cursor.execute('ALTER TABLE notification ADD enabled INTEGER DEFAULT 1')

conn.commit()
conn.close()
```

</details>
### [⬆️查看歷史版本升級指南](./UPGRADE_GUIDE.md)

### 1. 創建並配置.env文件

Expand All @@ -232,6 +115,10 @@ tasks_monitor_check_period: 60 # 檢查每個任務是否正常運行的間
tasks_monitor_log_period: 14400 # 將當前運行中的任務列表輸出到執行日誌的間隔。
auto_turn_off_notification: true # (v0.4或更新版本) 如果某個使用者的所有通知都已停用,決定是否取消追蹤該使用者。
auto_unfollow: true # (v0.4或更新版本) 如果某個使用者的所有通知都已停用,決定是否停用該使用者的通知(Twitter端)。
use_fx: false # (v0.4.1或更新版本) 是否使用FixTweet來嵌入內容而不是使用內建的嵌入
default_message: | # (v0.4.1或更新版本) 全域設定預設的訊息格式
{mention}**{author}** just {action} here:
{url}
```
### 3. 運行機器人並邀請至你的伺服器
Expand Down
Loading

0 comments on commit 4133f61

Please sign in to comment.