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
Ash
Discord Bot
Commits
0475b328
Commit
0475b328
authored
Aug 08, 2019
by
tec
Committed by
tecosaur
Aug 08, 2019
Browse files
Add polling
parent
df856f9a
Changes
1
Show whitespace changes
Inline
Side-by-side
src/main.rs
View file @
0475b328
...
@@ -30,7 +30,17 @@ static REGISTERED_MEMBER_ROLE: u64 = 608282133118582815;
...
@@ -30,7 +30,17 @@ static REGISTERED_MEMBER_ROLE: u64 = 608282133118582815;
static
FOR_VOTE
:
&
str
=
"👍"
;
static
FOR_VOTE
:
&
str
=
"👍"
;
static
AGAINST_VOTE
:
&
str
=
"👎"
;
static
AGAINST_VOTE
:
&
str
=
"👎"
;
static
ABSTAIN_VOTE
:
&
str
=
"🙊"
;
static
ABSTAIN_VOTE
:
&
str
=
"🙊"
;
static
ALLOWED_REACTS
:
&
[
&
'static
str
]
=
&
[
FOR_VOTE
,
AGAINST_VOTE
,
ABSTAIN_VOTE
];
static
APPROVE_REACT
:
&
str
=
"⬆"
;
static
DISAPPROVE_REACT
:
&
str
=
"⬇"
;
static
UNSURE_REACT
:
&
str
=
"❔"
;
static
ALLOWED_REACTS
:
&
[
&
'static
str
]
=
&
[
FOR_VOTE
,
AGAINST_VOTE
,
ABSTAIN_VOTE
,
APPROVE_REACT
,
DISAPPROVE_REACT
,
UNSURE_REACT
,
];
impl
EventHandler
for
Handler
{
impl
EventHandler
for
Handler
{
// Set a handler for the `message` event - so that whenever a new message
// Set a handler for the `message` event - so that whenever a new message
...
@@ -81,6 +91,21 @@ impl EventHandler for Handler {
...
@@ -81,6 +91,21 @@ impl EventHandler for Handler {
if
let
Err
(
why
)
=
msg
.channel_id
.say
(
&
ctx
.http
,
"I hope you're not having a motion. You may have wanted to !move something instead."
)
{
if
let
Err
(
why
)
=
msg
.channel_id
.say
(
&
ctx
.http
,
"I hope you're not having a motion. You may have wanted to !move something instead."
)
{
println!
(
"Error sending message: {:?}"
,
why
);
println!
(
"Error sending message: {:?}"
,
why
);
}
}
}
if
msg
.content
.starts_with
(
"!poll"
)
{
let
mut
iter
=
msg
.content
.chars
();
iter
.by_ref
()
.nth
(
5
);
let
topic
=
iter
.as_str
();
if
topic
==
""
{
if
let
Err
(
why
)
=
msg
.channel_id
.say
(
&
ctx
.http
,
"If there's something you want to poll, put it after the !move keyword"
,
)
{
println!
(
"Error sending message: {:?}"
,
why
);
}
}
else
{
create_poll
(
&
ctx
,
&
msg
,
topic
);
}
}
else
if
msg
.content
.starts_with
(
"!register"
)
{
}
else
if
msg
.content
.starts_with
(
"!register"
)
{
let
mut
iter
=
msg
.content
.chars
();
let
mut
iter
=
msg
.content
.chars
();
iter
.by_ref
()
.nth
(
9
);
iter
.by_ref
()
.nth
(
9
);
...
@@ -169,7 +194,8 @@ impl EventHandler for Handler {
...
@@ -169,7 +194,8 @@ impl EventHandler for Handler {
}
}
}
else
if
msg
.content
==
"!help"
{
}
else
if
msg
.content
==
"!help"
{
let
mut
message
=
MessageBuilder
::
new
();
let
mut
message
=
MessageBuilder
::
new
();
message
.push
(
"Use !move <action> to make a circular motion"
);
message
.push_line
(
"Use !move <action> to make a circular motion"
);
message
.push_line
(
"Use !poll <proposal> to see what people think about something"
);
if
let
Err
(
why
)
=
msg
.channel_id
.say
(
&
ctx
.http
,
message
.build
())
{
if
let
Err
(
why
)
=
msg
.channel_id
.say
(
&
ctx
.http
,
message
.build
())
{
println!
(
"Error sending message: {:?}"
,
why
);
println!
(
"Error sending message: {:?}"
,
why
);
}
}
...
@@ -309,6 +335,32 @@ fn create_motion(ctx: &Context, msg: &Message, topic: &str) {
...
@@ -309,6 +335,32 @@ fn create_motion(ctx: &Context, msg: &Message, topic: &str) {
}
}
}
}
fn
create_poll
(
ctx
:
&
Context
,
msg
:
&
Message
,
topic
:
&
str
)
{
println!
(
"{} created a poll {}"
,
msg
.author.name
,
topic
);
match
msg
.channel_id
.send_message
(
&
ctx
.http
,
|
m
|
{
m
.embed
(|
embed
|
{
embed
.colour
(
serenity
::
utils
::
Colour
::
BLUE
);
embed
.title
(
format!
(
"Poll {}"
,
topic
));
let
mut
desc
=
MessageBuilder
::
new
();
desc
.mention
(
&
msg
.author
);
desc
.push
(
" wants to know what you think."
);
embed
.description
(
desc
.build
());
embed
});
m
.reactions
(
vec!
[
APPROVE_REACT
,
DISAPPROVE_REACT
,
UNSURE_REACT
]);
m
})
{
Err
(
why
)
=>
{
println!
(
"Error sending message: {:?}"
,
why
);
}
Ok
(
_
)
=>
{
if
let
Err
(
why
)
=
msg
.delete
(
ctx
)
{
println!
(
"Error deleting motion prompt: {:?}"
,
why
);
}
}
}
}
fn
update_motion
(
fn
update_motion
(
ctx
:
&
Context
,
ctx
:
&
Context
,
msg
:
&
mut
Message
,
msg
:
&
mut
Message
,
...
@@ -444,7 +496,7 @@ fn new_member(ctx: &Context, mut new_member: Member) {
...
@@ -444,7 +496,7 @@ fn new_member(ctx: &Context, mut new_member: Member) {
}
}
let
mut
message
=
MessageBuilder
::
new
();
let
mut
message
=
MessageBuilder
::
new
();
message
.push
(
format!
(
"Say hi to {
:?
} in "
,
new_member
.display_name
()));
message
.push
(
format!
(
"Say hi to {} in "
,
new_member
.display_name
()));
message
.mention
(
&
WELCOME_CHANNEL
);
message
.mention
(
&
WELCOME_CHANNEL
);
if
let
Err
(
why
)
=
MAIN_CHANNEL
.say
(
&
ctx
,
message
.build
())
{
if
let
Err
(
why
)
=
MAIN_CHANNEL
.say
(
&
ctx
,
message
.build
())
{
println!
(
"Error sending message: {:?}"
,
why
);
println!
(
"Error sending message: {:?}"
,
why
);
...
...
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