Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
UCC
Discord Bot
Commits
b783b165
Unverified
Commit
b783b165
authored
Feb 04, 2020
by
tec
Browse files
Refactor cowsay
parent
d0cc9ca7
Changes
1
Hide whitespace changes
Inline
Side-by-side
src/voting.rs
View file @
b783b165
...
...
@@ -56,25 +56,23 @@ impl Commands {
);
}
pub
fn
cowsay
(
ctx
:
Context
,
msg
:
Message
,
content
:
&
str
)
{
let
output
;
if
!
content
.trim
()
.is_empty
()
{
let
output
=
if
!
content
.trim
()
.is_empty
()
{
let
mut
text
=
content
.to_owned
();
text
.escape_default
();
// Guess what buddy! You definitely are passing a string to cowsay
text
.insert
(
0
,
'\''
);
text
.insert
(
text
.len
(),
'\''
);
output
=
std
::
process
::
Command
::
new
(
"cowsay"
)
std
::
process
::
Command
::
new
(
"cowsay"
)
.arg
(
text
)
.output
()
// btw, if we can't execute cowsay we crash
.expect
(
"failed to execute cowsay"
);
.expect
(
"failed to execute cowsay"
)
}
else
{
output
=
std
::
process
::
Command
::
new
(
"sh"
)
std
::
process
::
Command
::
new
(
"sh"
)
.arg
(
"-c"
)
.arg
(
"sh -c fortune | cowsay -f
\"
/usr/share/cowsay/cows/$(echo 'www
\n
hellokitty
\n
bud-frogs
\n
koala
\n
suse
\n
three-eyes
\n
pony-smaller
\n
sheep
\n
vader
\n
cower
\n
moofasa
\n
elephant
\n
flaming-sheep
\n
skeleton
\n
snowman
\n
tux
\n
apt
\n
moose' | shuf -n 1).cow
\"
"
)
.output
()
.expect
(
"failed to execute fortune/cowsay"
)
;
}
.expect
(
"failed to execute fortune/cowsay"
)
}
;
let
mut
message
=
MessageBuilder
::
new
();
message
.push_codeblock
(
String
::
from_utf8
(
output
.stdout
)
.expect
(
"unable to parse stdout to String"
),
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment