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
Commits
a31e3aa6
Commit
a31e3aa6
authored
2 years ago
by
Stephen D
Browse files
Options
Downloads
Patches
Plain Diff
make the DB stuff more generic
parent
0b9d6604
No related branches found
Branches containing commit
No related tags found
1 merge request
!9
Starboard
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/handlers/mod.rs
+14
-1
14 additions, 1 deletion
src/handlers/mod.rs
src/handlers/xbasic.rs
+8
-19
8 additions, 19 deletions
src/handlers/xbasic.rs
with
22 additions
and
20 deletions
src/handlers/mod.rs
+
14
−
1
View file @
a31e3aa6
...
@@ -10,10 +10,14 @@ use crate::handlers::react::*;
...
@@ -10,10 +10,14 @@ use crate::handlers::react::*;
use
crate
::
handlers
::
sus
::
*
;
use
crate
::
handlers
::
sus
::
*
;
use
crate
::
handlers
::
xbasic
::
*
;
use
crate
::
handlers
::
xbasic
::
*
;
use
diesel
::{
Connection
,
PgConnection
};
use
dotenv
::
dotenv
;
use
serenity
::
async_trait
;
use
serenity
::
async_trait
;
use
serenity
::
model
::
channel
::
Message
;
use
serenity
::
model
::
channel
::
Message
;
use
serenity
::
model
::
prelude
::
Ready
;
use
serenity
::
model
::
prelude
::
Ready
;
use
serenity
::
prelude
::
*
;
use
serenity
::
prelude
::
*
;
use
std
::
env
;
use
std
::
sync
::{
Arc
,
Mutex
};
#[async_trait]
#[async_trait]
pub
(
crate
)
trait
LineHandler
:
Send
+
Sync
{
pub
(
crate
)
trait
LineHandler
:
Send
+
Sync
{
...
@@ -45,9 +49,11 @@ impl EventHandler for Dispatcher {
...
@@ -45,9 +49,11 @@ impl EventHandler for Dispatcher {
impl
Default
for
Dispatcher
{
impl
Default
for
Dispatcher
{
fn
default
()
->
Self
{
fn
default
()
->
Self
{
let
conn
=
Arc
::
new
(
Mutex
::
new
(
establish_connection
()));
Self
{
Self
{
handlers
:
vec!
[
handlers
:
vec!
[
Box
::
new
(
XbasicHandler
::
default
(
)),
Box
::
new
(
XbasicHandler
::
new
(
conn
)),
Box
::
new
(
JokeHandler
::
default
()),
Box
::
new
(
JokeHandler
::
default
()),
Box
::
new
(
ReactHandler
::
default
()),
Box
::
new
(
ReactHandler
::
default
()),
Box
::
new
(
SusHandler
::
default
()),
Box
::
new
(
SusHandler
::
default
()),
...
@@ -56,3 +62,10 @@ impl Default for Dispatcher {
...
@@ -56,3 +62,10 @@ impl Default for Dispatcher {
}
}
}
}
}
}
fn
establish_connection
()
->
PgConnection
{
dotenv
()
.ok
();
let
database_url
=
env
::
var
(
"DATABASE_URL"
)
.expect
(
"DATABASE_URL must be set"
);
PgConnection
::
establish
(
&
database_url
)
.expect
(
"Error connecting to database"
)
}
This diff is collapsed.
Click to expand it.
src/handlers/xbasic.rs
+
8
−
19
View file @
a31e3aa6
use
crate
::
framebuffer
::
FrameBuffer
;
use
crate
::
framebuffer
::
FrameBuffer
;
use
crate
::
handlers
::
LineHandler
;
use
crate
::
handlers
::
LineHandler
;
use
crate
::
program
::
Program
;
use
crate
::
program
::
Program
;
use
diesel
::{
Connection
,
PgConnection
};
use
diesel
::
PgConnection
;
use
dotenv
::
dotenv
;
use
serenity
::
async_trait
;
use
serenity
::
async_trait
;
use
serenity
::
http
::
AttachmentType
;
use
serenity
::
http
::
AttachmentType
;
use
serenity
::
model
::
channel
::{
Message
,
ReactionType
};
use
serenity
::
model
::
channel
::{
Message
,
ReactionType
};
...
@@ -10,7 +9,6 @@ use serenity::model::id::UserId;
...
@@ -10,7 +9,6 @@ use serenity::model::id::UserId;
use
serenity
::
prelude
::
*
;
use
serenity
::
prelude
::
*
;
use
std
::
borrow
::{
Borrow
,
Cow
};
use
std
::
borrow
::{
Borrow
,
Cow
};
use
std
::
collections
::
HashMap
;
use
std
::
collections
::
HashMap
;
use
std
::
env
;
use
std
::
str
::
FromStr
;
use
std
::
str
::
FromStr
;
use
std
::
sync
::{
Arc
,
Mutex
};
use
std
::
sync
::{
Arc
,
Mutex
};
use
tokio
::
task
;
use
tokio
::
task
;
...
@@ -54,6 +52,13 @@ pub struct XbasicHandler {
...
@@ -54,6 +52,13 @@ pub struct XbasicHandler {
}
}
impl
XbasicHandler
{
impl
XbasicHandler
{
pub
fn
new
(
conn
:
Arc
<
Mutex
<
PgConnection
>>
)
->
Self
{
Self
{
programs
:
Arc
::
new
(
Mutex
::
new
(
HashMap
::
new
())),
conn
,
}
}
async
fn
interpret_line
(
&
self
,
msg
:
&
Message
,
ctx
:
&
Context
,
line
:
&
str
)
{
async
fn
interpret_line
(
&
self
,
msg
:
&
Message
,
ctx
:
&
Context
,
line
:
&
str
)
{
// TODO we lock the mutex to check, but unlock before locking again later
// TODO we lock the mutex to check, but unlock before locking again later
// allows another thread to screw it up
// allows another thread to screw it up
...
@@ -410,19 +415,3 @@ impl LineHandler for XbasicHandler {
...
@@ -410,19 +415,3 @@ impl LineHandler for XbasicHandler {
self
.interpret_line
(
msg
,
ctx
,
line
)
.await
;
self
.interpret_line
(
msg
,
ctx
,
line
)
.await
;
}
}
}
}
impl
Default
for
XbasicHandler
{
fn
default
()
->
Self
{
Self
{
programs
:
Arc
::
new
(
Mutex
::
new
(
HashMap
::
new
())),
conn
:
Arc
::
new
(
Mutex
::
new
(
establish_connection
())),
}
}
}
fn
establish_connection
()
->
PgConnection
{
dotenv
()
.ok
();
let
database_url
=
env
::
var
(
"DATABASE_URL"
)
.expect
(
"DATABASE_URL must be set"
);
PgConnection
::
establish
(
&
database_url
)
.expect
(
"Error connecting to database"
)
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment