Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
cat-disruptor-6500
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Stephen D
cat-disruptor-6500
Compare revisions
dfca1b2807467a4e0619f68e96d098d8624b7a66 to master
Compare revisions
Changes are shown as if the
source
revision was being merged into the
target
revision.
Learn more about comparing revisions.
Source
stephen/cat-disruptor-6500
Select target project
No results found
master
Select Git revision
Branches
master
Swap
Target
roygbyte/cat-disruptor-6500
Select target project
stephen/cat-disruptor-6500
roygbyte/cat-disruptor-6500
tinyconan/cat-disruptor-6500
3 results
dfca1b2807467a4e0619f68e96d098d8624b7a66
Select Git revision
Branches
master
Show changes
Only incoming changes from source
Include changes to target since source was created
Compare
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
src/main.rs
+15
-19
15 additions, 19 deletions
src/main.rs
src/models.rs
+12
-9
12 additions, 9 deletions
src/models.rs
src/program.rs
+12
-7
12 additions, 7 deletions
src/program.rs
src/schema.rs
+19
-0
19 additions, 0 deletions
src/schema.rs
with
58 additions
and
35 deletions
src/main.rs
View file @
63c1ece6
...
@@ -3,36 +3,32 @@ extern crate diesel;
...
@@ -3,36 +3,32 @@ extern crate diesel;
mod
config
;
mod
config
;
mod
framebuffer
;
mod
framebuffer
;
mod
handler
;
mod
handlers
;
mod
joker
;
mod
models
;
mod
models
;
mod
program
;
mod
program
;
mod
schema
;
mod
schema
;
use
crate
::
handler
::
Handler
;
use
crate
::
handlers
::
Dispatcher
;
use
diesel
::{
Connection
,
PgConnection
};
use
dotenv
::
dotenv
;
use
serenity
::
Client
;
use
std
::
env
;
fn
establish_connection
()
->
PgConnection
{
dotenv
()
.ok
();
let
database_url
=
env
::
var
(
"DATABASE_URL"
)
.expect
(
"DATABASE_URL must be set"
);
use
serenity
::
prelude
::
GatewayIntents
;
PgConnection
::
establish
(
&
database_url
)
.expect
(
"Error connecting to database"
)
use
serenity
::
Client
;
}
#[tokio::main]
#[tokio::main]
async
fn
main
()
{
async
fn
main
()
{
let
config
=
config
::
get_conf
();
let
config
=
config
::
get_conf
();
let
token
=
config
.token
;
let
token
=
config
.token
;
let
conn
=
establish_connection
();
let
mut
client
=
Client
::
builder
(
&
token
,
let
mut
client
=
Client
::
builder
(
&
token
)
GatewayIntents
::
GUILD_MESSAGES
.event_handler
(
Handler
::
new
(
conn
))
.union
(
GatewayIntents
::
GUILD_MESSAGE_REACTIONS
)
.await
.union
(
GatewayIntents
::
MESSAGE_CONTENT
),
.expect
(
"Error creating client"
);
)
.event_handler
(
Dispatcher
::
new
(
config
.llama
))
.await
.expect
(
"Error creating client"
);
if
let
Err
(
e
)
=
client
.start
()
.await
{
if
let
Err
(
e
)
=
client
.start
()
.await
{
println!
(
"Client error: {}"
,
e
);
e
println!
(
"Client error: {
e
}"
);
}
}
}
}
This diff is collapsed.
Click to expand it.
src/models.rs
View file @
63c1ece6
use
crate
::
schema
::
user_programs
;
use
crate
::
schema
::
user_programs
;
use
bigdecimal
::
BigDecimal
;
use
bigdecimal
::
BigDecimal
;
#[derive(Queryable)]
pub
struct
UserProgram
{
pub
id
:
i32
,
pub
discord_user_id
:
u64
,
pub
name
:
String
,
pub
code
:
String
,
}
#[derive(Insertable)]
#[derive(Insertable)]
#[table_name
=
"
user_programs
"
]
#[
diesel(
table_name
=
user_programs
)
]
pub
struct
NewUserProgram
<
'a
>
{
pub
struct
NewUserProgram
<
'a
>
{
pub
discord_user_id
:
BigDecimal
,
pub
discord_user_id
:
BigDecimal
,
pub
name
:
&
'a
str
,
pub
name
:
&
'a
str
,
pub
code
:
&
'a
str
,
pub
code
:
&
'a
str
,
}
}
#[derive(Clone,
Queryable)]
pub
struct
ServerSetting
{
#[allow(dead_code)]
pub
id
:
i32
,
#[allow(dead_code)]
pub
guild_id
:
BigDecimal
,
pub
starboard_threshold
:
i32
,
pub
starboard_emoji_id
:
BigDecimal
,
pub
starboard_channel
:
BigDecimal
,
}
This diff is collapsed.
Click to expand it.
src/program.rs
View file @
63c1ece6
...
@@ -18,7 +18,7 @@ impl Program {
...
@@ -18,7 +18,7 @@ impl Program {
}
}
}
}
pub
fn
list_programs_by_user
(
conn
:
&
PgConnection
,
user_id
:
UserId
)
->
Option
<
Vec
<
String
>>
{
pub
fn
list_programs_by_user
(
conn
:
&
mut
PgConnection
,
user_id
:
UserId
)
->
Option
<
Vec
<
String
>>
{
user_programs
user_programs
.filter
(
columns
::
discord_user_id
.eq
(
BigDecimal
::
from_u64
(
*
user_id
.as_u64
())
.unwrap
()))
.filter
(
columns
::
discord_user_id
.eq
(
BigDecimal
::
from_u64
(
*
user_id
.as_u64
())
.unwrap
()))
.select
(
columns
::
name
)
.select
(
columns
::
name
)
...
@@ -26,7 +26,7 @@ impl Program {
...
@@ -26,7 +26,7 @@ impl Program {
.ok
()
.ok
()
}
}
pub
fn
list_published_programs
(
conn
:
&
PgConnection
)
->
Option
<
Vec
<
(
i32
,
String
)
>>
{
pub
fn
list_published_programs
(
conn
:
&
mut
PgConnection
)
->
Option
<
Vec
<
(
i32
,
String
)
>>
{
user_programs
user_programs
.filter
(
columns
::
published
.eq
(
1
))
.filter
(
columns
::
published
.eq
(
1
))
.select
((
columns
::
id
,
columns
::
name
))
.select
((
columns
::
id
,
columns
::
name
))
...
@@ -34,7 +34,7 @@ impl Program {
...
@@ -34,7 +34,7 @@ impl Program {
.ok
()
.ok
()
}
}
pub
fn
load_published_program
(
&
mut
self
,
conn
:
&
PgConnection
,
id
:
i32
)
->
Option
<
String
>
{
pub
fn
load_published_program
(
&
mut
self
,
conn
:
&
mut
PgConnection
,
id
:
i32
)
->
Option
<
String
>
{
let
program
:
Vec
<
(
String
,
String
)
>
=
user_programs
let
program
:
Vec
<
(
String
,
String
)
>
=
user_programs
.filter
(
columns
::
id
.eq
(
id
)
.and
(
columns
::
published
.eq
(
1
)))
.filter
(
columns
::
id
.eq
(
id
)
.and
(
columns
::
published
.eq
(
1
)))
.limit
(
1
)
.limit
(
1
)
...
@@ -55,7 +55,7 @@ impl Program {
...
@@ -55,7 +55,7 @@ impl Program {
}
}
pub
fn
set_program_published
(
pub
fn
set_program_published
(
conn
:
&
PgConnection
,
conn
:
&
mut
PgConnection
,
name
:
&
str
,
name
:
&
str
,
user_id
:
UserId
,
user_id
:
UserId
,
published
:
bool
,
published
:
bool
,
...
@@ -67,7 +67,7 @@ impl Program {
...
@@ -67,7 +67,7 @@ impl Program {
.and
(
columns
::
name
.eq
(
name
)),
.and
(
columns
::
name
.eq
(
name
)),
),
),
)
)
.set
(
columns
::
published
.eq
(
i
f
published
{
1
}
else
{
0
}
))
.set
(
columns
::
published
.eq
(
i
32
::
from
(
published
)
))
.execute
(
conn
)
.execute
(
conn
)
.ok
()
?
==
1
.ok
()
?
==
1
{
{
...
@@ -99,7 +99,7 @@ impl Program {
...
@@ -99,7 +99,7 @@ impl Program {
.join
(
"
\n
"
)
.join
(
"
\n
"
)
}
}
pub
fn
save_program
(
&
self
,
conn
:
&
PgConnection
,
user_id
:
UserId
,
name
:
&
str
)
->
Option
<
()
>
{
pub
fn
save_program
(
&
self
,
conn
:
&
mut
PgConnection
,
user_id
:
UserId
,
name
:
&
str
)
->
Option
<
()
>
{
let
code
=
self
.stringy_line_nums
();
let
code
=
self
.stringy_line_nums
();
let
new_program
=
NewUserProgram
{
let
new_program
=
NewUserProgram
{
discord_user_id
:
BigDecimal
::
from_u64
(
*
user_id
.as_u64
())
.unwrap
(),
discord_user_id
:
BigDecimal
::
from_u64
(
*
user_id
.as_u64
())
.unwrap
(),
...
@@ -118,7 +118,12 @@ impl Program {
...
@@ -118,7 +118,12 @@ impl Program {
Some
(())
Some
(())
}
}
pub
fn
load_program
(
&
mut
self
,
conn
:
&
PgConnection
,
user_id
:
UserId
,
name
:
&
str
)
->
Option
<
()
>
{
pub
fn
load_program
(
&
mut
self
,
conn
:
&
mut
PgConnection
,
user_id
:
UserId
,
name
:
&
str
,
)
->
Option
<
()
>
{
let
code
:
Vec
<
String
>
=
user_programs
let
code
:
Vec
<
String
>
=
user_programs
.filter
(
.filter
(
columns
::
discord_user_id
columns
::
discord_user_id
...
...
This diff is collapsed.
Click to expand it.
src/schema.rs
View file @
63c1ece6
table!
{
server_settings
(
id
)
{
id
->
Int4
,
guild_id
->
Numeric
,
starboard_threshold
->
Int4
,
starboard_emoji_id
->
Numeric
,
starboard_channel
->
Numeric
,
}
}
table!
{
starboard_mappings
(
original_id
)
{
original_id
->
Numeric
,
repost_id
->
Nullable
<
Numeric
>
,
}
}
table!
{
table!
{
user_programs
(
id
)
{
user_programs
(
id
)
{
id
->
Int4
,
id
->
Int4
,
...
@@ -7,3 +24,5 @@ table! {
...
@@ -7,3 +24,5 @@ table! {
published
->
Int4
,
published
->
Int4
,
}
}
}
}
allow_tables_to_appear_in_same_query!
(
server_settings
,
starboard_mappings
,
user_programs
,);
This diff is collapsed.
Click to expand it.
Prev
1
2
Next