this repo has no description
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

fix: xD

isabel f8649091 683b8d93

+41 -18
+41 -18
src/commands/misc/starboard.rs
··· 1 1 use crate::types::Context; 2 2 use color_eyre::eyre::Result; 3 - use poise::CreateReply; 4 3 use poise::serenity_prelude::ChannelId; 4 + use poise::CreateReply; 5 5 use rusqlite::Connection; 6 6 use std::sync::{LazyLock, Mutex}; 7 7 ··· 10 10 Mutex::new(Connection::open(db_path).expect("Failed to open starboard database")) 11 11 }); 12 12 13 + fn ensure_tables_exist(conn: &Connection) -> rusqlite::Result<()> { 14 + conn.execute( 15 + "CREATE TABLE IF NOT EXISTS starred_messages ( 16 + message_id INTEGER PRIMARY KEY, 17 + guild_id INTEGER NOT NULL, 18 + channel_id INTEGER NOT NULL, 19 + starboard_message_id INTEGER, 20 + star_count INTEGER NOT NULL DEFAULT 1, 21 + UNIQUE(message_id) 22 + )", 23 + [], 24 + )?; 25 + 26 + conn.execute( 27 + "CREATE TABLE IF NOT EXISTS starboard_config ( 28 + guild_id INTEGER PRIMARY KEY, 29 + channel_id INTEGER NOT NULL, 30 + threshold INTEGER NOT NULL DEFAULT 3 31 + )", 32 + [], 33 + )?; 34 + 35 + Ok(()) 36 + } 37 + 13 38 /// Enable the starboard feature for this server 14 39 #[poise::command(slash_command, required_permissions = "ADMINISTRATOR")] 15 40 pub async fn starboard_enable( ··· 32 57 33 58 { 34 59 let conn = STARBOARD_DB.lock().unwrap(); 60 + ensure_tables_exist(&conn)?; 35 61 conn.execute( 36 62 "INSERT OR REPLACE INTO starboard_config (guild_id, channel_id, threshold) VALUES (?, ?, ?)", 37 63 [guild_id.get() as i64, channel.get() as i64, i64::from(threshold)], ··· 65 91 66 92 { 67 93 let conn = STARBOARD_DB.lock().unwrap(); 94 + ensure_tables_exist(&conn)?; 68 95 conn.execute( 69 96 "DELETE FROM starboard_config WHERE guild_id = ?", 70 97 [guild_id.get() as i64], ··· 96 123 97 124 let config: Option<(u64, i32)> = { 98 125 let conn = STARBOARD_DB.lock().unwrap(); 99 - conn 100 - .query_row( 101 - "SELECT channel_id, threshold FROM starboard_config WHERE guild_id = ?", 102 - [guild_id.get() as i64], 103 - |row| { 104 - let channel_id: i64 = row.get(0)?; 105 - let threshold: i32 = row.get(1)?; 106 - Ok((channel_id as u64, threshold)) 107 - }, 108 - ) 109 - .ok() 126 + ensure_tables_exist(&conn).ok(); 127 + conn.query_row( 128 + "SELECT channel_id, threshold FROM starboard_config WHERE guild_id = ?", 129 + [guild_id.get() as i64], 130 + |row| { 131 + let channel_id: i64 = row.get(0)?; 132 + let threshold: i32 = row.get(1)?; 133 + Ok((channel_id as u64, threshold)) 134 + }, 135 + ) 136 + .ok() 110 137 }; 111 138 112 139 let response = if let Some((channel_id, threshold)) = config { ··· 118 145 .to_string() 119 146 }; 120 147 121 - ctx.send( 122 - CreateReply::default() 123 - .content(response) 124 - .ephemeral(true), 125 - ) 126 - .await?; 148 + ctx.send(CreateReply::default().content(response).ephemeral(true)) 149 + .await?; 127 150 128 151 Ok(()) 129 152 }