Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
UCC
Discord Bot
Commits
9d80f19d
Unverified
Commit
9d80f19d
authored
Aug 18, 2019
by
tec
Browse files
Add identification of message type
parent
77b925f2
Changes
1
Hide whitespace changes
Inline
Side-by-side
src/main.rs
View file @
9d80f19d
...
...
@@ -85,11 +85,35 @@ impl EventHandler for Handler {
}
fn
reaction_add
(
&
self
,
ctx
:
Context
,
add_reaction
:
channel
::
Reaction
)
{
voting
::
reaction_add
(
ctx
,
add_reaction
);
match
add_reaction
.message
(
&
ctx
.http
)
{
Ok
(
message
)
=>
{
if
message
.author.id
.0
==
config
::
BOT_ID
{
match
message_type
(
&
message
)
{
"motion"
=>
{
voting
::
reaction_add
(
ctx
,
add_reaction
);
}
_
=>
{}
}
}
}
Err
(
why
)
=>
error!
(
"Failed to get react message {:?}"
,
why
),
}
}
fn
reaction_remove
(
&
self
,
ctx
:
Context
,
removed_reaction
:
channel
::
Reaction
)
{
voting
::
reaction_remove
(
ctx
,
removed_reaction
);
match
removed_reaction
.message
(
&
ctx
.http
)
{
Ok
(
message
)
=>
{
if
message
.author.id
.0
==
config
::
BOT_ID
{
match
message_type
(
&
message
)
{
"motion"
=>
{
voting
::
reaction_remove
(
ctx
,
removed_reaction
);
}
_
=>
{}
}
}
}
Err
(
why
)
=>
error!
(
"Failed to get react message {:?}"
,
why
),
}
}
fn
guild_member_addition
(
...
...
@@ -138,3 +162,18 @@ fn main() {
error!
(
"Client error: {:?}"
,
why
);
}
}
fn
message_type
(
message
:
&
Message
)
->
&
'static
str
{
if
message
.embeds
.len
()
>
0
{
let
title
:
String
=
message
.embeds
[
0
]
.title
.clone
()
.unwrap
();
let
words_of_title
:
Vec
<
_
>
=
title
.splitn
(
2
,
' '
)
.collect
();
let
first_word_of_title
=
words_of_title
[
0
];
return
match
first_word_of_title
{
"Motion"
=>
"motion"
,
"Poll"
=>
"poll"
,
_
=>
"misc"
,
};
}
else
{
return
"misc"
;
}
}
Write
Preview
Markdown
is supported
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