cat-disruptor-6500
A Discord bot that reacts to certain messages with certain emojis. More importantly, it also lets you write code!
Install
- Setup PostgreSQL
- Install via package manager
apt install postgresql
. Also getlibpq-dev
if you don't want a miserable life. -
sudo su postgres
to login to default database user -
createdb cat_disruptor_6500
to create the database -
psql
and thenALTER ROLE postgres WITH PASSWORD 'password';
- Install via package manager
- Update the database environment variable (
DATABASE_URL=postgres://postgres:password@localhost/cat_disruptor_6500
) - Create a new Discord bot
- Enable all Privileged Gateway Intents
- Go to OAuth2 menu, URL generator, click "bot" and "administrator"
- Open link to add bot to server
- Create a
config.toml
file in project directory withtoken=<your discord bot token>
- Generate token on your bot page
Commands:
!START - start the interpreter
!STOP - stop the interpreter
LIST - list all code in memory
SAVE filename - save code into database
LOAD filename - load filename into memory
DIR - list programs you have saved
PUB filename - Publish a program
PUBDIR - List published programs
PUBLOAD id - Load public program by ID (IDs are listed in PUBDIR)
Code is specified by writing line_num code
. For example, 10 print "hello world"
. This makes it easy to insert new code or overwrite lines.
Example session
!START
10 for x in 0 to 10
20 print x
RUN
> expected NEXT after FOR statement. # oops - we forgot a line
30 next x
LIST
> 10 for x in 0 to 10
> 20 print x
> 30 next x
RUN
> 0
> 1
> 2
> 3
> 4
> 5
> 6
> 7
> 8
> 9
> 10
# actually, let's print them all on the same line
5 a = ""
20 a += x
LIST
> 5 a = ""
> 10 for x in 0 to 10
> 20 a += x
> 30 next x
RUN
012345678910 # oops - let's add spaces
20 a += " " + x
RUN
> 0 1 2 3 4 5 6 7 8 9 10 # awesome! let's save this program
SAVE count_to_ten
> Saved as count_to_ten
The interpreter can execute arbitrary code safely - it includes CPU and memory limits. For information on syntax, check out the xBASIC interpreter: https://git.scd31.com/stephen/xbasic
It even does graphics!