rj1
about | log | files | refs | license
commit c81cd9af14c77a7ace7fabc577592e7a1debad6a
parent b4a6c7589d999869d04069723dbff5eb5b47b982
author: rj1 <[email protected]>
date:   Thu,  8 Dec 2022 01:44:53 -0600

configuration options reside in config.json

Diffstat:
A.gitignore | 1+
MREADME.md | 22++++++++++++++++++++--
Mchatgpt-irc.py | 31++++++++-----------------------
Aexample-config.json | 12++++++++++++
4 files changed, 41 insertions(+), 25 deletions(-)

diff --git a/.gitignore b/.gitignore @@ -0,0 +1 @@ +config.json diff --git a/README.md b/README.md @@ -9,8 +9,26 @@ chat with chatgpt on irc! - say "hi" to chatgpt - collect your auth token from the *headers* tab - collect your conversation id & parent message id from the *payload* tab -- change the configuration options in `chatgpt-irc.py` -- have fun! +- create `config.json` using [the example configuration](#example-config.json) + below or by copying `example-config.json` +- run the bot: `python chatgpt-irc.py` ![](https://rj1.su/img/chatgpt-irc-sshot1.png) ![](https://rj1.su/img/chatgpt-irc-sshot2.png) + +## example config.json + +``` +{ + "server": "internetrelaychat.net", + "port": 6697, + "ssl": true, + "nickname": "chatgpt", + "ident": "chatgpt", + "realname": "chatgpt", + "channels": ["#rj1"], + "access_token": "", + "conversation_id": "", + "parent_message_id": "" +} +``` diff --git a/chatgpt-irc.py b/chatgpt-irc.py @@ -5,22 +5,6 @@ import json import requests import uuid -options = { - # irc - "server": "internetrelaychat.net", - "port": 6697, - "ssl": True, - "nickname": "chatgpt", - "ident": "chatgpt", - "realname": "chatgpt", - "channels": ["#rj1", "#h4x"], - - # openai - "access_token": "", - "conversation_id": "", - "parent_message_id": "", -} - class ChatGPT: def __init__(self): @@ -182,9 +166,7 @@ async def main_loop(**options): continue if parts[0] == "!reset": - sendcmd( - "PRIVMSG", target, f"{source}: Let's start fresh" - ) + sendcmd("PRIVMSG", target, f"{source}: Let's start fresh") chatgpt.reset() continue @@ -205,14 +187,14 @@ async def main_loop(**options): messages = [] for line in lines: if len(line) > 350: - words = line.split(' ') - current_message = '' + words = line.split(" ") + current_message = "" for word in words: if len(current_message) + len(word) + 1 <= 350: - current_message += word + ' ' + current_message += word + " " else: messages.append(current_message) - current_message = word + ' ' + current_message = word + " " messages.append(current_message) else: messages.append(line) @@ -226,4 +208,7 @@ async def main_loop(**options): sendcmd("PRIVMSG", target, f"{message}") +with open("config.json", "r") as f: + options = json.load(f) + asyncio.run(main_loop(**options)) diff --git a/example-config.json b/example-config.json @@ -0,0 +1,12 @@ +{ + "server": "internetrelaychat.net", + "port": 6697, + "ssl": true, + "nickname": "chatgpt", + "ident": "chatgpt", + "realname": "chatgpt", + "channels": ["#rj1"], + "access_token": "", + "conversation_id": "", + "parent_message_id": "" +}