Add support for presence to the framework
This commit is contained in:
+18
-2
@@ -3,8 +3,9 @@ use std::{fmt::Debug, sync::Arc};
|
||||
use async_trait::async_trait;
|
||||
use thiserror::Error;
|
||||
use twilight_cache_inmemory::{DefaultInMemoryCache, ResourceType};
|
||||
use twilight_gateway::{Event, EventTypeFlags, Intents, Shard, ShardId, StreamExt};
|
||||
use twilight_gateway::{ConfigBuilder, Event, EventTypeFlags, Intents, Shard, ShardId, StreamExt};
|
||||
use twilight_http::Client;
|
||||
use twilight_model::gateway::payload::outgoing::update_presence::UpdatePresencePayload;
|
||||
|
||||
use crate::{
|
||||
framework::{
|
||||
@@ -92,6 +93,7 @@ where
|
||||
pub struct Bot<T: Send + Sync> {
|
||||
shard: ShardId,
|
||||
state: Arc<T>,
|
||||
presence: Option<UpdatePresencePayload>,
|
||||
prefixes: Arc<dyn PrefixGetter<T> + Send + Sync>,
|
||||
intents: Intents,
|
||||
cached_resource_types: Vec<ResourceType>,
|
||||
@@ -113,6 +115,7 @@ impl<T: 'static + Send + Sync> Bot<T> {
|
||||
Self {
|
||||
shard: ShardId::new(0, 1),
|
||||
state: Arc::new(state),
|
||||
presence: None,
|
||||
prefixes: Arc::new(prefixes),
|
||||
intents: Intents::empty(),
|
||||
cached_resource_types: Vec::new(),
|
||||
@@ -140,6 +143,11 @@ impl<T: 'static + Send + Sync> Bot<T> {
|
||||
self
|
||||
}
|
||||
|
||||
pub fn presence(mut self, presence: UpdatePresencePayload) -> Self {
|
||||
self.presence = Some(presence);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn command(mut self, command: impl Command<T> + 'static) -> Self {
|
||||
self.commands.push(Arc::new(command));
|
||||
self
|
||||
@@ -250,7 +258,15 @@ impl<T: 'static + Send + Sync> Bot<T> {
|
||||
cache,
|
||||
});
|
||||
|
||||
let mut gateway = Shard::new(bot.shard, token.to_string(), bot.intents);
|
||||
let mut config = ConfigBuilder::new(token.to_string(), bot.intents);
|
||||
|
||||
if let Some(presence) = &bot.presence {
|
||||
config = config.presence(presence.clone());
|
||||
}
|
||||
|
||||
let config = config.build();
|
||||
|
||||
let mut gateway = Shard::with_config(bot.shard, config);
|
||||
|
||||
loop {
|
||||
if let Some(Ok(event)) = gateway.next_event(EventTypeFlags::all()).await {
|
||||
|
||||
Reference in New Issue
Block a user