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
Scarlett M
cat-disruptor-6500
Commits
9950845a
Commit
9950845a
authored
4 years ago
by
Stephen D
Browse files
Options
Downloads
Patches
Plain Diff
Add DIR command to list user programs
parent
10f035d1
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/handler.rs
+25
-1
25 additions, 1 deletion
src/handler.rs
src/program.rs
+8
-0
8 additions, 0 deletions
src/program.rs
with
33 additions
and
1 deletion
src/handler.rs
+
25
−
1
View file @
9950845a
...
...
@@ -8,7 +8,7 @@ use serenity::model::channel::{Message, ReactionType};
use
serenity
::
model
::
id
::
UserId
;
use
serenity
::
model
::
prelude
::
Ready
;
use
serenity
::
prelude
::
*
;
use
std
::
borrow
::
Cow
;
use
std
::
borrow
::
{
Borrow
,
Cow
}
;
use
std
::
collections
::
HashMap
;
use
std
::
str
::
FromStr
;
use
std
::
sync
::{
Arc
,
Mutex
};
...
...
@@ -86,6 +86,12 @@ impl Handler {
"LIST"
=>
{
self
.interpreter_list
(
msg
,
ctx
)
.await
;
}
"DIR"
=>
{
if
self
.list_saved_programs
(
msg
,
ctx
)
.await
.is_none
()
{
msg
.channel_id
.send_message
(
&
ctx
,
"Could not get list of programs from database."
);
}
}
_
=>
{
if
let
Some
(
name
)
=
line
.strip_prefix
(
"SAVE "
)
{
self
.interpreter_save
(
name
,
msg
,
ctx
)
.await
;
...
...
@@ -139,6 +145,24 @@ impl Handler {
.insert
(
msg
.author.id
,
Program
::
new
());
}
async
fn
list_saved_programs
(
&
self
,
msg
:
&
Message
,
ctx
:
&
Context
)
->
Option
<
()
>
{
let
program_names
=
Program
::
list_programs_by_user
(
self
.conn
.lock
()
.ok
()
?
.borrow
(),
msg
.author.id
)
?
;
msg
.channel_id
.say
(
&
ctx
,
format!
(
"You have {} programs saved:
\r\n
```
\r\n
{}
\r\n
```"
,
program_names
.len
(),
program_names
.join
(
"
\r\n
"
)
),
)
.await
.ok
()
?
;
Some
(())
}
async
fn
interpreter_list
(
&
self
,
msg
:
&
Message
,
ctx
:
&
Context
)
{
msg
.channel_id
.say
(
...
...
This diff is collapsed.
Click to expand it.
src/program.rs
+
8
−
0
View file @
9950845a
...
...
@@ -18,6 +18,14 @@ impl Program {
}
}
pub
fn
list_programs_by_user
(
conn
:
&
PgConnection
,
user_id
:
UserId
)
->
Option
<
Vec
<
String
>>
{
user_programs
.filter
(
columns
::
discord_user_id
.eq
(
BigDecimal
::
from_u64
(
*
user_id
.as_u64
())
.unwrap
()))
.select
(
columns
::
name
)
.get_results
(
conn
)
.ok
()
}
pub
fn
stringify
(
&
self
)
->
String
{
let
mut
code
:
Vec
<
(
u32
,
String
)
>
=
self
.code
.iter
()
.map
(|(
a
,
b
)|
(
*
a
,
b
.to_owned
()))
.collect
();
...
...
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