(&mut self, guild_id: Id<GuildMarker>)
| 261 | } |
| 262 | |
| 263 | async fn check_guild_acces(&mut self, guild_id: Id<GuildMarker>) -> WsResult { |
| 264 | let session = match &self.state { |
| 265 | WsState::Authorized(s) => s, |
| 266 | _ => panic!("can't check guild access when not authorized"), |
| 267 | }; |
| 268 | |
| 269 | let user_guilds = session |
| 270 | .session |
| 271 | .api_client |
| 272 | .current_user_guilds() |
| 273 | .await |
| 274 | .map_err(|_| WsCloseReason::InternalError)?; |
| 275 | |
| 276 | if let Some(ug) = user_guilds.into_iter().find(|e| e.id == guild_id) { |
| 277 | if ug |
| 278 | .permissions |
| 279 | .intersects(Permissions::ADMINISTRATOR | Permissions::MANAGE_GUILD) |
| 280 | { |
| 281 | return Ok(()); |
| 282 | } |
| 283 | |
| 284 | if ug.owner { |
| 285 | return Ok(()); |
| 286 | } |
| 287 | |
| 288 | Err(WsCloseReason::GuildMissingAccess) |
| 289 | } else { |
| 290 | Err(WsCloseReason::UnknownGuild) |
| 291 | } |
| 292 | } |
| 293 | |
| 294 | async fn send_ping(&mut self) -> bool { |
| 295 | match self.send(Message::Ping(vec![69])).await { |
no test coverage detected