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
54b61a30
Commit
54b61a30
authored
Mar 28, 2020
by
Ash
Browse files
Merge branch 'morefix2' into 'master'
cleanup See merge request
!10
parents
bc3a4f18
7eb33928
Pipeline
#207
failed with stages
in 4 seconds
Changes
7
Pipelines
1
Show whitespace changes
Inline
Side-by-side
src/config.rs
View file @
54b61a30
...
...
@@ -36,12 +36,6 @@ pub struct UccbotConfig {
pub
bind_address
:
String
,
}
#[derive(Debug,
Deserialize)]
pub
struct
UccbotSecrets
{
pub
ldap_pass
:
String
,
pub
discord_token
:
String
,
}
pub
fn
ldap_bind_address
()
->
String
{
"ldaps://samson.ucc.asn.au:636"
.to_string
()
}
...
...
@@ -59,6 +53,12 @@ impl UccbotConfig {
}
}
#[derive(Debug,
Deserialize)]
pub
struct
UccbotSecrets
{
pub
ldap_pass
:
String
,
pub
discord_token
:
String
,
}
pub
type
ReactRoleMap
=
IndexMap
<
String
,
id
::
RoleId
>
;
#[derive(Debug,
Deserialize,
Clone)]
...
...
src/ldap.rs
View file @
54b61a30
...
...
@@ -30,7 +30,7 @@ pub fn ldap_search(username: &str) -> Option<LDAPUser> {
.success
()
.expect
(
"LDAP search error"
);
if
rs
.is_empty
()
{
return
None
;
return
None
}
let
result
=
SearchEntry
::
construct
(
rs
[
0
]
.clone
())
.attrs
;
Some
(
LDAPUser
{
...
...
src/main.rs
View file @
54b61a30
...
...
@@ -130,7 +130,7 @@ impl EventHandler for Handler {
Ok
(
message
)
=>
match
get_message_type
(
&
message
)
{
MessageType
::
RoleReactMessage
if
add_reaction
.user_id
.0
!=
CONFIG
.bot_id
=>
{
add_role_by_reaction
(
&
ctx
,
message
,
add_reaction
);
return
;
return
}
_
if
message
.author.id
.0
!=
CONFIG
.bot_id
||
add_reaction
.user_id
==
CONFIG
.bot_id
=>
...
...
@@ -146,7 +146,7 @@ impl EventHandler for Handler {
"The logreact message {} just tried to use is too old"
,
react_user
.name
);
return
;
return
}
info!
(
"The react {} just added is {:?}. In full: {:?}"
,
...
...
@@ -172,7 +172,7 @@ impl EventHandler for Handler {
Ok
(
message
)
=>
match
get_message_type
(
&
message
)
{
MessageType
::
RoleReactMessage
if
removed_reaction
.user_id
!=
CONFIG
.bot_id
=>
{
remove_role_by_reaction
(
&
ctx
,
message
,
removed_reaction
);
return
;
return
}
_
if
message
.author.id
.0
!=
CONFIG
.bot_id
||
removed_reaction
.user_id
==
CONFIG
.bot_id
=>
...
...
src/reaction_roles.rs
View file @
54b61a30
...
...
@@ -97,7 +97,7 @@ pub fn sync_all_role_reactions(ctx: &Context) {
for
react
in
&
message
.reactions
{
let
react_as_string
=
get_string_from_react
(
&
react
.reaction_type
);
if
mapping
.contains_key
(
&
react_as_string
)
{
continue
;
continue
}
info!
(
" message #{}: Removing non-role react '{}'"
,
...
...
src/token_management.rs
View file @
54b61a30
...
...
@@ -75,7 +75,7 @@ pub fn parse_token(discord_user: &User, encrypted_token: &str) -> Result<String,
let
token_username
=
token_components
[
2
];
if
token_discord_user
!=
discord_user
.id
.0
.to_string
()
{
warn!
(
"... attempt failed : DiscordID mismatch"
);
return
Err
(
TokenError
::
DiscordIdMismatch
)
;
return
Err
(
TokenError
::
DiscordIdMismatch
)
}
let
time_delta_seconds
=
Utc
::
now
()
.timestamp
()
-
token_timestamp
.timestamp
();
if
time_delta_seconds
>
TOKEN_LIFETIME
{
...
...
@@ -83,7 +83,7 @@ pub fn parse_token(discord_user: &User, encrypted_token: &str) -> Result<String,
"... attempt failed : token expired ({} seconds old)"
,
time_delta_seconds
);
return
Err
(
TokenError
::
TokenExpired
)
;
return
Err
(
TokenError
::
TokenExpired
)
}
info!
(
"... verification successful (token {} seconds old)"
,
...
...
src/user_management.rs
View file @
54b61a30
...
...
@@ -78,7 +78,7 @@ impl Commands {
&
ctx
.http
,
format!
(
"Usage: {}register <username>"
,
CONFIG
.command_prefix
)
);
return
;
return
}
if
RESERVED_NAMES
.contains
(
&
account_name
)
||
database
::
username_exists
(
account_name
)
{
send_message!
(
...
...
@@ -88,7 +88,7 @@ impl Commands {
.choose
(
&
mut
rand
::
thread_rng
())
.expect
(
"We couldn't get any sass"
)
);
return
;
return
}
if
!
ldap_exists
(
account_name
)
{
send_message!
(
...
...
@@ -99,7 +99,7 @@ impl Commands {
account_name
)
);
return
;
return
}
send_message!
(
msg
.channel_id
,
...
...
@@ -200,7 +200,7 @@ impl Commands {
&
ctx
.http
,
"Sorry, I couldn't find that profile (you need to !register for a profile)"
);
return
;
return
}
let
member
=
possible_member
.unwrap
();
let
result
=
msg
.channel_id
.send_message
(
&
ctx
.http
,
|
m
|
{
...
...
@@ -272,7 +272,7 @@ impl Commands {
m
})
.expect
(
"Failed to send usage help embed"
);
return
;
return
}
let
info_content
:
Vec
<
_
>
=
info
.splitn
(
2
,
' '
)
.collect
();
let
mut
property
=
String
::
from
(
info_content
[
0
]);
...
...
@@ -316,7 +316,7 @@ impl Commands {
m
})
.expect
(
"Failed to send usage embed"
);
return
;
return
}
let
mut
value
=
info_content
[
1
]
.to_string
();
...
...
@@ -333,7 +333,7 @@ impl Commands {
&
ctx
.http
,
"That ain't a URL where I come from..."
);
return
;
return
}
}
}
...
...
src/voting.rs
View file @
54b61a30
...
...
@@ -15,7 +15,7 @@ impl Commands {
let
motion
=
content
;
if
!
motion
.is_empty
()
{
create_motion
(
&
ctx
,
&
msg
,
motion
);
return
;
return
}
send_message!
(
msg
.channel_id
,
...
...
@@ -34,7 +34,7 @@ impl Commands {
let
topic
=
content
;
if
!
topic
.is_empty
()
{
create_poll
(
&
ctx
,
&
msg
,
topic
);
return
;
return
}
send_message!
(
msg
.channel_id
,
...
...
@@ -193,7 +193,7 @@ fn get_cached_motion(ctx: &Context, msg: &Message) -> MotionInfo {
fn
set_cached_motion
(
id
:
serenity
::
model
::
id
::
MessageId
,
motion_info
:
MotionInfo
)
{
if
let
Some
(
motion
)
=
MOTIONS_CACHE
.lock
()
.unwrap
()
.get_mut
(
&
id
)
{
*
motion
=
motion_info
;
return
;
return
}
warn!
(
"{}"
,
"Couldn't find motion in cache to set"
);
}
...
...
@@ -208,7 +208,7 @@ macro_rules! tiebreaker {
}
else
{
0.0
}
}
;
}
}
fn
update_motion
(
...
...
@@ -225,10 +225,8 @@ fn update_motion(
let
abstain_votes
=
motion_info
.votes
.get
(
&
CONFIG
.abstain_vote
)
.unwrap
()
.len
()
as
isize
-
1
;
let
for_strength
=
for_votes
as
f32
+
tiebreaker!
(
ctx
,
&
CONFIG
.for_vote
,
motion_info
);
let
against_strength
=
against_votes
as
f32
+
tiebreaker!
(
ctx
,
&
CONFIG
.against_vote
,
motion_info
);
let
abstain_strength
=
abstain_votes
as
f32
+
tiebreaker!
(
ctx
,
&
CONFIG
.abstain_vote
,
motion_info
);
let
against_strength
=
against_votes
as
f32
+
tiebreaker!
(
ctx
,
&
CONFIG
.against_vote
,
motion_info
);
let
abstain_strength
=
abstain_votes
as
f32
+
tiebreaker!
(
ctx
,
&
CONFIG
.abstain_vote
,
motion_info
);
let
old_embed
=
msg
.embeds
[
0
]
.clone
();
let
topic
=
old_embed
.clone
()
.title
.unwrap
();
...
...
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