Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • stephen/cat-disruptor-6500
  • roygbyte/cat-disruptor-6500
  • tinyconan/cat-disruptor-6500
3 results
Show changes
Commits on Source (71)
Showing
with 1421 additions and 495 deletions
DATABASE_URL=postgres://stephen@localhost/cat_disruptor_6500
image: "rust:latest"
before_script:
- rustup component add rustfmt
- rustup component add clippy
- cargo install cargo-deb
test:
script:
- cargo fmt -- --check
- cargo clippy --all-targets --all-features -- -D warnings
- cargo test
build:
script:
- cargo deb
artifacts:
paths:
- target/debian/*.deb
This diff is collapsed.
[package] [package]
name = "cat-disruptor-6500" name = "cat-disruptor-6500"
version = "0.1.0" version = "0.3.0"
authors = ["Stephen <stephen@stephendownward.ca>"] authors = ["Stephen <wemaster@scd31.com>"]
edition = "2018" edition = "2018"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies] [dependencies]
serenity = {version = "0.9", default-features = false, features = ["client", "gateway", "rustls_backend", "model", "static_assertions"] } serenity = {version = "0.11", default-features = false, features = ["client", "gateway", "rustls_backend", "model", "static_assertions", "cache"] }
tokio = {version = "0.2", features = ["full", "time"] } tokio = {version = "1.21", features = ["full", "time"] }
phf = { version = "0.8", features = ["macros"] } phf = { version = "0.8", features = ["macros"] }
toml = "0.5" toml = "0.5"
serde = { version = "1.0", features = ["derive"] } serde = { version = "1.0", features = ["derive"] }
xbasic = "0.3.1"
png = "0.16"
diesel = { version = "2", features = ["postgres", "numeric"] }
dotenv = "0.15.0"
bigdecimal = "0.1.2"
reqwest = { version = "0.11", features = ["json"] }
serde_json = "1.0"
rusttype = "0.4.3"
rand = "0.8"
itertools = "0.10"
anyhow = "1.0"
ollama-rs = "0.1.5"
# 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 get `libpq-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 then `ALTER ROLE postgres WITH PASSWORD 'password';`
- Update the database environment variable (`DATABASE_URL=postgres://postgres:password@localhost/cat_disruptor_6500`)
- Create a new [Discord bot](https://discord.com/developers/applications)
- 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 with `token=<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!
![Example session](example.png)
# For documentation on how to configure this file,
# see diesel.rs/guides/configuring-diesel-cli
[print_schema]
file = "src/schema.rs"
example.png

135 KiB

-- This file was automatically created by Diesel to setup helper functions
-- and other internal bookkeeping. This file is safe to edit, any future
-- changes will be added to existing projects as new migrations.
DROP FUNCTION IF EXISTS diesel_manage_updated_at(_tbl regclass);
DROP FUNCTION IF EXISTS diesel_set_updated_at();
-- This file was automatically created by Diesel to setup helper functions
-- and other internal bookkeeping. This file is safe to edit, any future
-- changes will be added to existing projects as new migrations.
-- Sets up a trigger for the given table to automatically set a column called
-- `updated_at` whenever the row is modified (unless `updated_at` was included
-- in the modified columns)
--
-- # Example
--
-- ```sql
-- CREATE TABLE users (id SERIAL PRIMARY KEY, updated_at TIMESTAMP NOT NULL DEFAULT NOW());
--
-- SELECT diesel_manage_updated_at('users');
-- ```
CREATE OR REPLACE FUNCTION diesel_manage_updated_at(_tbl regclass) RETURNS VOID AS $$
BEGIN
EXECUTE format('CREATE TRIGGER set_updated_at BEFORE UPDATE ON %s
FOR EACH ROW EXECUTE PROCEDURE diesel_set_updated_at()', _tbl);
END;
$$ LANGUAGE plpgsql;
CREATE OR REPLACE FUNCTION diesel_set_updated_at() RETURNS trigger AS $$
BEGIN
IF (
NEW IS DISTINCT FROM OLD AND
NEW.updated_at IS NOT DISTINCT FROM OLD.updated_at
) THEN
NEW.updated_at := current_timestamp;
END IF;
RETURN NEW;
END;
$$ LANGUAGE plpgsql;
DROP TABLE user_programs
\ No newline at end of file
CREATE TABLE user_programs (
id SERIAL PRIMARY KEY,
discord_user_id NUMERIC NOT NULL,
name VARCHAR NOT NULL,
code TEXT NOT NULL
);
CREATE UNIQUE INDEX user_programs_name_id_index ON user_programs (
discord_user_id,
name
);
\ No newline at end of file
-- This file should undo anything in `up.sql`
ALTER TABLE user_programs DROP COLUMN published;
\ No newline at end of file
ALTER TABLE user_programs ADD COLUMN published INT NOT NULL DEFAULT 0;
\ No newline at end of file
DROP TABLE server_settings;
CREATE TABLE server_settings (
id SERIAL PRIMARY KEY NOT NULL,
guild_id NUMERIC NOT NULL UNIQUE,
starboard_threshold INTEGER NOT NULL,
starboard_emoji_id NUMERIC NOT NULL,
starboard_channel NUMERIC NOT NULL
);
DROP TABLE starboard_mappings;
CREATE TABLE starboard_mappings (
original_id NUMERIC NOT NULL UNIQUE PRIMARY KEY,
repost_id NUMERIC UNIQUE
);
tab_spaces = 4 tab_spaces = 4
hard_tabs = true hard_tabs = true
\ No newline at end of file edition = "2018"
File added