From eda49be9b8fdd8d9e9a5e3b32fc35ca636cd34b3 Mon Sep 17 00:00:00 2001 From: Mistivia Date: Wed, 5 Nov 2025 02:30:08 +0800 Subject: use config file --- .gitignore | 1 + config.json.example | 13 +++++++++++++ deploy.sh | 3 ++- main.py | 32 +++++++++++++++++--------------- 4 files changed, 33 insertions(+), 16 deletions(-) create mode 100644 config.json.example diff --git a/.gitignore b/.gitignore index c18dd8d..de4fe8f 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ __pycache__/ +config.json \ No newline at end of file diff --git a/config.json.example b/config.json.example new file mode 100644 index 0000000..8be5183 --- /dev/null +++ b/config.json.example @@ -0,0 +1,13 @@ +{ + "server": "irc.example.com", + "port": 6697, + "nickname": "ezlivebot", + "channels": [ + "#xxxxxxxxx", + "#yyyyyyyyy" + ], + "use_ssl": true, + "tgtoken": "xxxxxxx:xxxxxxxxxxxxxxxxxx", + "tgchat": -0000000000000, + "tgthread": 0000 +} \ No newline at end of file diff --git a/deploy.sh b/deploy.sh index 1ef4e95..12ec93c 100644 --- a/deploy.sh +++ b/deploy.sh @@ -1 +1,2 @@ -rsync -avz ./ root@raye:./ezlivebot/ \ No newline at end of file +rsync -avz ./ root@raye:./ezlivebot/ +ssh root@raye 'podman restart ezlivebot-c' \ No newline at end of file diff --git a/main.py b/main.py index a117d8d..4341137 100644 --- a/main.py +++ b/main.py @@ -4,26 +4,28 @@ from airc import Client, Message from aiogram import Bot, Dispatcher from aiogram.filters import Command from aiogram.types import Message +import json -SERVER = "raye.mistivia.com" -PORT = 6697 -NICKNAME = "ezlivebot" -CHANNELS = [ - "#xxxxxxxxx", - "#xxxxxxxxx" -] +config = None +with open('config.json', 'r') as fp: + config = json.load(fp) -TGTOKEN = 'xxxxxxxxx:xxxxxxxx' -TGCHAT = -0000000000000 -TGTHREAD = 000 +SERVER = config['server'] +PORT = config['port'] +NICKNAME = config['nickname'] +CHANNELS = config['channels'] +USE_SSL = config['use_ssl'] +TGTOKEN = config['tgtoken'] +TGCHAT = config['tgchat'] +TGTHREAD = config['tgthread'] # --- Instantiate the Client --- irc_client = Client( host=SERVER, port=PORT, nickname=NICKNAME, - realname="My Awesome Async Bot", - use_ssl=True + realname="bot", + use_ssl=USE_SSL ) tgbot = Bot(token=TGTOKEN) @@ -75,9 +77,9 @@ def get_sender(msg): if msg.from_user is None: return user = msg.from_user - if user.username is not None: - return user.username - if user.last_name is not None: + # if user.username is not None: + # return user.username + if user.last_name is None: return user.first_name + ' ' + user.last_name return user.first_name -- cgit v1.0