Skip to content

Commit

Permalink
auto migrate
Browse files Browse the repository at this point in the history
  • Loading branch information
DanceMore committed Jan 18, 2024
1 parent ef3dbc1 commit 2d1bbc8
Show file tree
Hide file tree
Showing 3 changed files with 118 additions and 27 deletions.
109 changes: 97 additions & 12 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ tokio = { version = "1.34.0", features = ["macros", "rt-multi-thread"] }
diesel = { version = "2.1.4", features = ["postgres"] }
log = "0.4"
env_logger = "0.10"
diesel_migrations = "2.1.0"
35 changes: 20 additions & 15 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,17 @@ use diesel::ExpressionMethods;
use diesel::QueryDsl;
use diesel::RunQueryDsl;

use rust_bridgebot::establish_connection;
use rust_bridgebot::models::*;
use diesel_migrations::{embed_migrations, EmbeddedMigrations, MigrationHarness};

pub const MIGRATIONS: EmbeddedMigrations = embed_migrations!();

fn run_migrations() {
let mut conn = establish_connection();
conn.run_pending_migrations(MIGRATIONS).unwrap();
}

use discord_bridgebot::establish_connection;
use discord_bridgebot::models::*;

extern crate env_logger;
#[macro_use]
Expand Down Expand Up @@ -99,7 +108,7 @@ fn get_channel_pairs(channel_id: i64) -> Result<Vec<(i64, i64)>, diesel::result:
let connection = &mut establish_connection();

debug!("[-] db query for channel id {}", channel_id);
use rust_bridgebot::schema::channel_pairs::dsl::*;
use discord_bridgebot::schema::channel_pairs::dsl::*;

// this works
let results = channel_pairs
Expand Down Expand Up @@ -128,17 +137,12 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
dotenv().ok();
debug!("[+] config loaded!");

// we don't actually pass this around ..?
//let connection = &mut establish_connection();
//println!("{:?}", connection);
// perform migrations
run_migrations();

let framework = StandardFramework::new()
.group(&GENERAL_GROUP);
let framework = StandardFramework::new().group(&GENERAL_GROUP);

framework.configure(
Configuration::new().with_whitespace(true)
.prefix("!")
);
framework.configure(Configuration::new().with_whitespace(true).prefix("!"));

// Login with a bot token from the environment
let token = env::var("DISCORD_TOKEN").expect("token");
Expand Down Expand Up @@ -186,7 +190,7 @@ async fn getcurrentid(ctx: &Context, msg: &Message) -> CommandResult {
async fn register(ctx: &Context, msg: &Message) -> CommandResult {
// it seems like limiting the scope of the imports is important?
// I can definitely break code with name-conflicts by putting this at the top....
use rust_bridgebot::schema::channel_pairs;
use discord_bridgebot::schema::channel_pairs;
let connection = &mut establish_connection();

// Extract the text content of the message
Expand Down Expand Up @@ -217,7 +221,8 @@ async fn register(ctx: &Context, msg: &Message) -> CommandResult {
// Get the ID of the channel where the message was sent
let channel1 = msg.channel_id;

let channel2_o = serenity::model::id::ChannelId::from( NonZeroU64::new(channel2 as u64).unwrap() );
let channel2_o =
serenity::model::id::ChannelId::from(NonZeroU64::new(channel2 as u64).unwrap());

// make sure we can see the channel target...
match ctx.http.get_channel(channel2_o).await {
Expand Down Expand Up @@ -260,7 +265,7 @@ async fn mirror_message(
custom_username: &str,
message_content: &str,
) {
let channel = serenity::model::id::ChannelId::from( NonZeroU64::new(channel_id as u64).unwrap() );
let channel = serenity::model::id::ChannelId::from(NonZeroU64::new(channel_id as u64).unwrap());

let message = format!("🔊 {}: {}", custom_username, message_content);

Expand Down

0 comments on commit 2d1bbc8

Please sign in to comment.