summaryrefslogtreecommitdiff
path: root/ircbot
diff options
context:
space:
mode:
Diffstat (limited to 'ircbot')
-rw-r--r--ircbot/.gitignore1
-rw-r--r--ircbot/config.json.example14
-rw-r--r--ircbot/deploy.sh1
-rw-r--r--ircbot/main.py57
4 files changed, 52 insertions, 21 deletions
diff --git a/ircbot/.gitignore b/ircbot/.gitignore
new file mode 100644
index 0000000..d344ba6
--- /dev/null
+++ b/ircbot/.gitignore
@@ -0,0 +1 @@
+config.json
diff --git a/ircbot/config.json.example b/ircbot/config.json.example
new file mode 100644
index 0000000..7889331
--- /dev/null
+++ b/ircbot/config.json.example
@@ -0,0 +1,14 @@
+{
+ "server": "raye.mistivia.com",
+ "port": 6667,
+ "nickname": "android",
+ "realname": "bot",
+ "channels": [
+ "#main",
+ ],
+ "greetings": [
+ "#main"
+ ],
+ "logpath": "/var/log/irclog",
+ "relaybot": "TeleIRC"
+} \ No newline at end of file
diff --git a/ircbot/deploy.sh b/ircbot/deploy.sh
index b643dff..ea48acd 100644
--- a/ircbot/deploy.sh
+++ b/ircbot/deploy.sh
@@ -1,2 +1,3 @@
scp main.py root@raye:/home/user/ircbot/
+scp config.json root@raye:/home/user/ircbot/
ssh root@raye 'nitroctl restart ircbot' \ No newline at end of file
diff --git a/ircbot/main.py b/ircbot/main.py
index 3c8c40b..8b1e214 100644
--- a/ircbot/main.py
+++ b/ircbot/main.py
@@ -7,16 +7,19 @@ import os
import datetime
import urllib.parse
-SERVER = "raye.mistivia.com"
-PORT = 6667
-NICKNAME = "android"
+config = None
+with open('./config.json', 'r', encoding='utf-8') as f:
+ config = json.load(f)
+SERVER = config['server']
+PORT = config['port']
+NICKNAME = config['nickname']
+REALNAME = config['realname']
+CHANNELS = config['channels']
+GREETINGS = config['greetings']
+LOGPATH = config['logpath']
+RELAYBOT = config['relaybot']
+
IDENT = NICKNAME
-REALNAME = "bot"
-CHANNELS = [
-]
-GREETINGS = ["#main"]
-LOGPATH = '/volume/webroot/irclog'
-RELAYBOT = 'TeleIRC'
BUFFER_SIZE = 2048
@@ -136,6 +139,26 @@ def roll_command(chan, sender, args):
# ========================================================================
+def cut_string(text, chunk_size=420):
+ chunks = []
+ current_chunk = []
+ current_length = 0
+
+ for char in text:
+ char_bytes = char.encode('utf-8')
+ char_length = len(char_bytes)
+ if current_length + char_length > chunk_size:
+ if len(current_chunk) > 0:
+ chunks.append("".join(current_chunk))
+ current_chunk = [char]
+ current_length = char_length
+ else:
+ current_chunk.append(char)
+ current_length += char_length
+ if len(current_chunk) > 0:
+ chunks.append("".join(current_chunk))
+ return chunks
+
def write_log(channel, nick, msg):
if msg.startswith('!log'):
return
@@ -209,20 +232,12 @@ class IRCBot:
self.send_line(target, line)
def send_line(self, target, msg):
+ chunks = cut_string(msg)
max_length = 100
message_length = len(msg)
- if message_length > max_length:
- num_batches = (message_length + max_length - 1) // max_length
-
- for i in range(num_batches):
- start_index = i * max_length
- end_index = min((i + 1) * max_length, message_length)
- chunk = msg[start_index:end_index]
- self.send_raw(f"PRIVMSG {target} :{chunk}")
- write_log(target, NICKNAME, chunk)
- else:
- self.send_raw(f"PRIVMSG {target} :{msg}")
- write_log(target, NICKNAME, msg)
+ for chunk in chunks:
+ self.send_raw(f"PRIVMSG {target} :{chunk}")
+ write_log(target, NICKNAME, chunk)
def connect(self):
print(f"Connecting to {self.server}:{self.port}...")