remove bot, force role order

This commit is contained in:
41666 2023-05-28 09:47:19 -04:00
parent 677d91b17b
commit dc1e7718bc
13 changed files with 15 additions and 1659 deletions

View file

@ -47,15 +47,18 @@ export const getGuild = async (
.filter((x) => x !== undefined) as APIRole[]
)?.position || -1;
const roles = guildRaw.roles.map<Role>((role) => ({
id: role.id,
name: role.name,
color: role.color,
managed: role.managed,
position: role.position,
permissions: role.permissions,
safety: calculateRoleSafety(role, highestRolePosition),
}));
const roles = guildRaw.roles
.map<Role>((role) => ({
id: role.id,
name: role.name,
color: role.color,
managed: role.managed,
position: role.position,
permissions: role.permissions,
safety: calculateRoleSafety(role, highestRolePosition),
}))
// sort so that highest is first
.sort((a, b) => b.position - a.position);
const guild: Guild & OwnRoleInfo = {
id,

View file

@ -1 +0,0 @@
target

1283
packages/bot/Cargo.lock generated

File diff suppressed because it is too large Load diff

View file

@ -1,12 +0,0 @@
[package]
name = "bot"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
serenity = { version = "0.10.10", default-features = false, features = ["client", "gateway", "rustls_backend", "model", "unstable_discord_api", "collector"] }
dotenv = "0.15.0"
tokio = { version = "1.0", features = ["macros", "rt-multi-thread"] }
url = "2.2.2"

View file

@ -1,22 +0,0 @@
# Leveraging the pre-built Docker images with
# cargo-chef and the Rust toolchain
FROM lukemathwalker/cargo-chef:latest-rust-1.58.1 AS chef
WORKDIR /app
FROM chef AS planner
COPY . .
RUN cargo chef prepare --recipe-path recipe.json
FROM chef AS builder
COPY --from=planner /app/recipe.json recipe.json
# Build dependencies - this is the caching Docker layer!
RUN cargo chef cook --release --recipe-path recipe.json
# Build application
COPY . .
RUN cargo build --release --bin bot
# We do not need the Rust toolchain to run the binary!
FROM debian:bullseye-slim AS runtime
WORKDIR /app
COPY --from=builder /app/target/release/bot /usr/local/bin/bot
ENTRYPOINT ["/usr/local/bin/bot"]

View file

@ -1,19 +0,0 @@
# Roleypoly Mention Responder
This is written in Rust.
You'll need:
- The rust toolchain (cargo, rust, etc)
...and nothing else.
## Premise of why Rust
Node.js is slow. It's fast enough for 90% of what we want to do, but due to the slowness and memory constraints we'd like to utilize, something else, particularly one designed for extreme multiprocessing (like Rust or Go) is infinitely better. More threads, more memory control (e.g. we can GC the majority of incoming info before we care about it), just better.
This was a very simple Node.js app, but it just couldn't be used with the production workload.
Roleypoly Legacy was running a Go-based bot that worked extremely well, and this iteration's de-evolution back to JS didn't end up working.
**tl;dr:** this piece of shit only responds to mentions. it has no real logic. it shouldn't take a $45/m cloud server to run it.

View file

@ -1,7 +0,0 @@
{
"name": "@roleypoly/bot",
"version": "0.0.1",
"scripts": {
"start": "cargo run"
}
}

View file

@ -1,94 +0,0 @@
extern crate dotenv;
extern crate tokio;
use dotenv::dotenv;
use std::env;
use serenity::{
async_trait,
model::{
channel::Message,
gateway::Ready,
interactions::{
message_component::ButtonStyle,
},
},
prelude::*,
client::bridge::gateway::GatewayIntents
};
struct Handler {
ui_public_uri : String,
ui_hostname : String,
}
#[async_trait]
impl EventHandler for Handler {
async fn message(&self, ctx: Context, msg: Message) {
// No DMs, bots, or self.
if msg.is_private() || msg.author.bot {
return;
}
// Ignore messages that don't mention the bot
if !msg.mentions_me(&ctx).await.unwrap_or(false) {
return;
}
msg.channel_id.send_message(&ctx, |m| {
m.reference_message(&msg).allowed_mentions(|f| {
f.replied_user(false)
});
let guild_url = format!("{}/s/{}", self.ui_public_uri, msg.guild_id.unwrap().0);
m.embed(|e| {
e.title(":beginner: Howdy, pick your roles here!");
e.description("Roleypoly will open in your browser.\n\nIf that's not cool with you, try the `/roleypoly` command!");
e.url(&guild_url);
e.color(0x453e3d);
e
});
m.components(|c| {
c.create_action_row(|r| {
r.create_button(|b| {
b.style(ButtonStyle::Link);
b.url(&guild_url);
b.label(format!("Pick your roles on {}", self.ui_hostname));
b
});
r
});
c
});
m
}).await.unwrap();
}
async fn ready(&self, _: Context, ready: Ready) {
println!("{} is connected! (shard: {:?})", ready.user.name, ready.shard.unwrap_or_default());
}
}
#[tokio::main]
async fn main() {
dotenv().ok();
let token = env::var("BOT_TOKEN").expect("BOT_TOKEN not set");
let client_id: u64 = env::var("BOT_CLIENT_ID").expect("BOT_CLIENT_ID not set").parse().unwrap();
let ui_public_uri = env::var("UI_PUBLIC_URI").expect("UI_PUBLIC_URI not set");
let ui_hostname = url::Url::parse(&ui_public_uri).unwrap().host_str().unwrap().to_string();
let mut client =
Client::builder(&token).application_id(client_id)
.intents(GatewayIntents::GUILD_MESSAGES)
.event_handler(Handler {
ui_public_uri,
ui_hostname,
}).await.expect("Err creating client");
if let Err(why) = client.start_autosharded().await {
println!("Client error: {:?}", why);
}
}