Compare commits
4 Commits
99b9680ef2
...
v1.0
Author | SHA1 | Date | |
---|---|---|---|
b92356a42d | |||
9b26aa113b | |||
b29ed09f71 | |||
81233011b0 |
76
README.md
76
README.md
@ -1,35 +1,61 @@
|
||||
GarfBot is a discord bot that uses openai generative pre-trained AI models to produce text and images for your personal entertainment and companionship.
|
||||
Who is GarfBot?
|
||||
======
|
||||

|
||||
|
||||
GarfBot is a discord bot that uses OpenAI's generative pre-trained models to produce text and images for your personal entertainment and companionship. There are a few ways you can interact with him on discord, either in a public server or by direct message:
|
||||
|
||||
To interact: (not case-sensitive)
|
||||
`hey garfield {prompt}`
|
||||
Responds with text.
|
||||
|
||||
`"hey garfield {prompt}"`
|
||||
responds with text.
|
||||
`garfpic {prompt}`
|
||||
Responds with an image.
|
||||
|
||||
`"garfpic {prompt}"`
|
||||
responds with image.
|
||||
`garfping {target}`
|
||||
Responds with iputils-ping result from target.
|
||||
|
||||
`garfpic {target}`
|
||||
Responds with dns lookup result from target.
|
||||
|
||||
To get started, clone this repo and create a `config.py` file in GarfBot's root directory. Open your favorite text editor or IDE and add your various API tokens as such:
|
||||
`garfpic {target}`
|
||||
Responds with nmap scan result from target.
|
||||
|
||||
`garfshop {item} {zip}`
|
||||
Responds with 10 grocery {item}s from the nearest Kroger location, listed from least to most expensive.
|
||||
|
||||
Installation
|
||||
======
|
||||
|
||||
To get started, clone this repo and create a config file.
|
||||
|
||||
```console
|
||||
$ git clone https://git.crate.zip/crate/garfbot.git && cd garfbot/ && nano config.py
|
||||
```
|
||||
|
||||
Add your various API tokens:
|
||||
|
||||
```python
|
||||
GARFBOT_TOKEN = "token"
|
||||
OPENAI_TOKEN = "token"
|
||||
GIF_TOKEN = "token"
|
||||
GARFBOT_TOKEN = "Discord API token"
|
||||
OPENAI_TOKEN = "OpenAI API token"
|
||||
GIF_TOKEN = "tenor.com API token"
|
||||
```
|
||||
If you want to configure a more secure setup, go ahead.
|
||||
|
||||
Next, I recommend building a docker image for each bot using the included DockerFile as a template. Run each container binding /usr/src/app to GarfBot's CWD.
|
||||
I recommend building a docker image using the included DockerFile as a template. Run the container binding /usr/src/app to GarfBot's CWD:
|
||||
|
||||
A terraform file has been included to launch all three containers, or you can do it manually.
|
||||
|
||||
Example:
|
||||
```console
|
||||
crate@raspberrypi:~/garfbot $ docker build -t garfbot .
|
||||
crate@raspberrypi:~/garfbot $ docker run -d --restart always -v $PWD:/usr/src/app --name garfbot garfbot
|
||||
$ docker build -t garfbot .
|
||||
$ docker run -d --restart always -v $PWD:/usr/src/app --name garfbot garfbot
|
||||
```
|
||||
|
||||
Or if you prefer to install dependencies (from requirements.txt) on you own host and run as a systemd service:
|
||||
In case you'd rather not do it manually, a `garfbot.tf` file has been included to launch GarfBot and his friends' containers.
|
||||
|
||||
If you prefer to install dependencies on you own host and run as a systemd service:
|
||||
|
||||
```console
|
||||
$ sudo nano /etc/systemd/system/garfbot.service
|
||||
```
|
||||
|
||||
Replace {user} with your username:
|
||||
|
||||
```console
|
||||
[Unit]
|
||||
Description=garfbot
|
||||
@ -38,10 +64,18 @@ After=multi-user.target
|
||||
[Service]
|
||||
Type=simple
|
||||
Restart=always
|
||||
User=pi
|
||||
WorkingDirectory=/home/crate/garfbot
|
||||
ExecStart=/usr/bin/python ./garfbot.py
|
||||
User={user}
|
||||
WorkingDirectory=/home/{user}/garfbot
|
||||
ExecStart=/usr/bin/python garfbot.py
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
```
|
||||
|
||||
And finally:
|
||||
|
||||
```console
|
||||
$ sudo systemctl daemon-reload
|
||||
$ sudo systemctl enable garfbot
|
||||
$ sudo systemctl start garfbot
|
||||
```
|
@ -1,3 +1,3 @@
|
||||
#!/bin/bash
|
||||
|
||||
docker run -d --restart always -v $PWD:/usr/src/app --name garfbot garfbot
|
||||
docker run -d --restart always -v $PWD:/usr/src/app --name garfbot abcrate/garfbot
|
||||
|
21
jonbot.py
21
jonbot.py
@ -1,11 +1,12 @@
|
||||
import config
|
||||
import openai
|
||||
import discord
|
||||
import asyncio
|
||||
import os
|
||||
|
||||
openai.api_key = config.OPENAI_TOKEN
|
||||
jonkey = config.JONBOT_TOKEN
|
||||
model = "gpt-3.5-turbo"
|
||||
model = config.TXT_MODEL
|
||||
|
||||
intents = discord.Intents.default()
|
||||
intents.messages = True
|
||||
@ -14,7 +15,7 @@ client = discord.Client(intents=intents)
|
||||
|
||||
@client.event
|
||||
async def on_ready():
|
||||
print(f"Logged in as {client.user.name} running gpt-3.5-turbo.", flush=True)
|
||||
print(f"Logged in as {client.user.name} running {model}.", flush=True)
|
||||
|
||||
@client.event
|
||||
async def on_message(message):
|
||||
@ -39,8 +40,14 @@ async def on_message(message):
|
||||
e = str(e)
|
||||
await message.channel.send(f"`JonBot Error: {e}`")
|
||||
|
||||
try:
|
||||
client.run(jonkey)
|
||||
except Exception as e:
|
||||
e = str(e)
|
||||
print(f"JonBot Error: {e}")
|
||||
async def jonbot_connect():
|
||||
while True:
|
||||
try:
|
||||
await client.start(jonkey)
|
||||
except Exception as e:
|
||||
e = str(e)
|
||||
logger.error(f"Jonbot couldn't connect! {e}")
|
||||
await asyncio.sleep(60)
|
||||
|
||||
if __name__ == "__main__":
|
||||
asyncio.run(jonbot_connect())
|
||||
|
17
moneybot.py
17
moneybot.py
@ -1,11 +1,12 @@
|
||||
import config
|
||||
import openai
|
||||
import discord
|
||||
import asyncio
|
||||
import os
|
||||
|
||||
openai.api_key = config.OPENAI_TOKEN
|
||||
moneykey = config.MONEYBOT_TOKEN
|
||||
model = "gpt-4"
|
||||
model = config.TXT_MODEL
|
||||
|
||||
intents = discord.Intents.default()
|
||||
intents.messages = True
|
||||
@ -14,7 +15,7 @@ client = discord.Client(intents=intents)
|
||||
|
||||
@client.event
|
||||
async def on_ready():
|
||||
print(f"Logged in as {client.user.name} running gpt-4.", flush=True)
|
||||
print(f"Logged in as {client.user.name} running {model}.", flush=True)
|
||||
|
||||
@client.event
|
||||
async def on_message(message):
|
||||
@ -39,4 +40,14 @@ async def on_message(message):
|
||||
e = str(e)
|
||||
await message.channel.send(f"`MoneyBot Error: {e}`")
|
||||
|
||||
client.run(moneykey)
|
||||
async def moneybot_connect():
|
||||
while True:
|
||||
try:
|
||||
await client.start(moneykey)
|
||||
except Exception as e:
|
||||
e = str(e)
|
||||
logger.error(f"Moneybot couldn't connect! {e}")
|
||||
await asyncio.sleep(60)
|
||||
|
||||
if __name__ == "__main__":
|
||||
asyncio.run(moneybot_connect())
|
||||
|
Reference in New Issue
Block a user