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
Ash
Discord Bot
Commits
df856f9a
Commit
df856f9a
authored
Aug 08, 2019
by
tec
Committed by
tecosaur
Aug 08, 2019
Browse files
Add register template + new member test
parent
dac20229
Changes
1
Hide whitespace changes
Inline
Side-by-side
src/main.rs
View file @
df856f9a
...
...
@@ -24,6 +24,8 @@ static BOT_ID: u64 = 607078903969742848;
static
VOTE_POOL_SIZE
:
i8
=
2
;
static
VOTE_ROLE
:
u64
=
607478818038480937
;
static
TIEBREAKER_ROLE
:
u64
=
607509283483025409
;
static
UNREGISTERED_MEMBER_ROLE
:
u64
=
608282247350714408
;
static
REGISTERED_MEMBER_ROLE
:
u64
=
608282133118582815
;
static
FOR_VOTE
:
&
str
=
"👍"
;
static
AGAINST_VOTE
:
&
str
=
"👎"
;
...
...
@@ -42,17 +44,25 @@ impl EventHandler for Handler {
let
mut
message
=
MessageBuilder
::
new
();
message
.push
(
[
"
I see you have seen fit to send another message
"
,
"
That's quite enough from you
"
,
"Why do you continue to bother us "
,
"Oh. It's you again "
,
"What are you doing "
,
][
rng
.gen_range
(
0
,
3
)],
][
rng
.gen_range
(
0
,
4
)],
);
message
.mention
(
&
msg
.author
);
if
let
Err
(
why
)
=
msg
.channel_id
.say
(
&
ctx
.http
,
message
.build
())
{
println!
(
"Error sending message: {:?}"
,
why
);
}
}
if
msg
.content
.starts_with
(
"!join"
)
{
match
serenity
::
model
::
id
::
GuildId
(
SERVER_ID
)
.member
(
ctx
.http
.clone
(),
msg
.author.id
)
{
Ok
(
member
)
=>
{
new_member
(
&
ctx
,
member
);
}
_
=>
{}
}
}
if
msg
.content
.starts_with
(
"!move"
)
{
let
mut
iter
=
msg
.content
.chars
();
iter
.by_ref
()
.nth
(
5
);
...
...
@@ -71,6 +81,92 @@ 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."
)
{
println!
(
"Error sending message: {:?}"
,
why
);
}
}
else
if
msg
.content
.starts_with
(
"!register"
)
{
let
mut
iter
=
msg
.content
.chars
();
iter
.by_ref
()
.nth
(
9
);
let
name
=
iter
.as_str
();
if
name
==
""
{
if
let
Err
(
why
)
=
msg
.channel_id
.say
(
&
ctx
.http
,
"Usage: !register <ucc username>"
)
{
println!
(
"Error sending message: {:?}"
,
why
);
}
}
else
{
match
serenity
::
model
::
id
::
GuildId
(
SERVER_ID
)
.member
(
ctx
.http
.clone
(),
msg
.author.id
)
{
Ok
(
mut
member
)
=>
{
if
let
Err
(
why
)
=
member
.remove_role
(
&
ctx
.http
,
UNREGISTERED_MEMBER_ROLE
)
{
println!
(
"Unable to remove role: {:?}"
,
why
);
};
match
member
.edit
(
&
ctx
.http
,
|
m
|
{
let
mut
rng
=
rand
::
thread_rng
();
m
.nickname
(
format!
(
"{}, {}"
,
name
,
[
"The Big Cheese"
,
"The One and Only"
,
"The Exalted One"
,
"not to be trusted"
,
"The Scoundrel"
,
"A big fish in a small pond"
,
][
rng
.gen_range
(
0
,
4
)]
));
m
})
{
Ok
(
_
)
=>
{
if
let
Err
(
why
)
=
member
.add_role
(
&
ctx
.http
,
REGISTERED_MEMBER_ROLE
)
{
println!
(
"Unable to add role: {:?}"
,
why
);
};
}
Err
(
why
)
=>
{
println!
(
"Unable to edit nickname: {:?}"
,
why
);
}
};
}
Err
(
why
)
=>
{
println!
(
"Unable to get member: {:?}"
,
why
);
}
}
}
if
let
Err
(
why
)
=
msg
.delete
(
ctx
)
{
println!
(
"Error deleting motion prompt: {:?}"
,
why
);
}
}
else
if
msg
.content
.starts_with
(
"!cowsay"
)
{
let
mut
iter
=
msg
.content
.chars
();
iter
.by_ref
()
.nth
(
7
);
let
text
=
iter
.as_str
();
let
output
=
std
::
process
::
Command
::
new
(
"cowsay"
)
.arg
(
text
)
.output
()
.expect
(
"failed to execute cowsay"
);
let
mut
message
=
MessageBuilder
::
new
();
message
.push_codeblock
(
String
::
from_utf8
(
output
.stdout
)
.expect
(
"unable to parse stdout to String"
),
None
,
);
if
let
Err
(
why
)
=
msg
.channel_id
.say
(
&
ctx
.http
,
message
.build
())
{
println!
(
"Error sending message: {:?}"
,
why
);
}
}
else
if
msg
.content
.starts_with
(
"!troll"
)
{
let
mut
iter
=
msg
.content
.chars
();
iter
.by_ref
()
.nth
(
5
);
let
text
=
iter
.as_str
();
let
output
=
std
::
process
::
Command
::
new
(
"cat"
)
.arg
(
text
)
.output
()
.expect
(
"failed to execute cowsay"
);
let
mut
message
=
MessageBuilder
::
new
();
message
.push_codeblock
(
String
::
from_utf8
(
output
.stdout
)
.expect
(
"unable to parse stdout to String"
),
None
,
);
if
let
Err
(
why
)
=
msg
.channel_id
.say
(
&
ctx
.http
,
message
.build
())
{
println!
(
"Error sending message: {:?}"
,
why
);
}
}
else
if
msg
.content
==
"!help"
{
let
mut
message
=
MessageBuilder
::
new
();
message
.push
(
"Use !move <action> to make a circular motion"
);
...
...
@@ -150,23 +246,9 @@ impl EventHandler for Handler {
&
self
,
ctx
:
Context
,
_guild_id
:
serenity
::
model
::
id
::
GuildId
,
new_member
:
Member
,
the_
new_member
:
Member
,
)
{
let
mut
message
=
MessageBuilder
::
new
();
message
.push
(
"Nice to see you here "
);
message
.mention
(
&
new_member
);
message
.push_line
(
"! Would you care to introduce yourself?"
);
message
.push
(
"If you're not sure where to start, perhaps you could tell us about your projects, your first computer…"
);
if
let
Err
(
why
)
=
WELCOME_CHANNEL
.say
(
&
ctx
,
message
.build
())
{
println!
(
"Error sending message: {:?}"
,
why
);
}
let
mut
message
=
MessageBuilder
::
new
();
message
.push
(
format!
(
"Say hi to {:?} in "
,
new_member
.display_name
()));
message
.mention
(
&
WELCOME_CHANNEL
);
if
let
Err
(
why
)
=
MAIN_CHANNEL
.say
(
&
ctx
,
message
.build
())
{
println!
(
"Error sending message: {:?}"
,
why
);
}
new_member
(
&
ctx
,
the_new_member
);
}
// Set a handler to be called on the `ready` event. This is called when a
...
...
@@ -219,9 +301,9 @@ fn create_motion(ctx: &Context, msg: &Message, topic: &str) {
Err
(
why
)
=>
{
println!
(
"Error sending message: {:?}"
,
why
);
}
Ok
(
message
)
=>
{
if
let
Err
(
why
)
=
m
essage
.react
(
ctx
,
ABSTAIN_VOTE
)
{
println!
(
"Error
sending 🙊 reac
t: {:?}"
,
why
);
Ok
(
_
)
=>
{
if
let
Err
(
why
)
=
m
sg
.delete
(
ctx
)
{
println!
(
"Error
deleting motion promp
t: {:?}"
,
why
);
}
}
}
...
...
@@ -349,3 +431,26 @@ fn update_motion(
println!
(
"Error updating motion: {:?}"
,
why
);
}
}
fn
new_member
(
ctx
:
&
Context
,
mut
new_member
:
Member
)
{
let
mut
message
=
MessageBuilder
::
new
();
message
.push
(
"Nice to see you here "
);
message
.mention
(
&
new_member
);
message
.push_line
(
"! Would you care to introduce yourself?"
);
message
.push_line
(
"If you're not sure where to start, perhaps you could tell us about your projects, your first computer…"
);
message
.push_line
(
"You should also know that we follow the Freenode Channel Guidelines: https://freenode.net/changuide"
);
if
let
Err
(
why
)
=
WELCOME_CHANNEL
.say
(
&
ctx
,
message
.build
())
{
println!
(
"Error sending message: {:?}"
,
why
);
}
let
mut
message
=
MessageBuilder
::
new
();
message
.push
(
format!
(
"Say hi to {:?} in "
,
new_member
.display_name
()));
message
.mention
(
&
WELCOME_CHANNEL
);
if
let
Err
(
why
)
=
MAIN_CHANNEL
.say
(
&
ctx
,
message
.build
())
{
println!
(
"Error sending message: {:?}"
,
why
);
}
if
let
Err
(
why
)
=
new_member
.add_role
(
&
ctx
.http
,
UNREGISTERED_MEMBER_ROLE
)
{
println!
(
"Error adding user role: {:?}"
,
why
);
};
}
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