Skip to content

Commit a4a1d01

Browse files
committed
rename Discord to Bot (more accurate)
1 parent ec669f8 commit a4a1d01

File tree

6 files changed

+19
-23
lines changed

6 files changed

+19
-23
lines changed

discord/partial_id/src/lib.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ pub fn derive_partial(input: proc_macro::TokenStream) -> proc_macro::TokenStream
103103
impl #impl_generics #ty #ty_generics
104104
#where_clause
105105
{
106-
#vis async fn update(&mut self, client: &crate::request::Discord) -> crate::request::Result<()> {
106+
#vis async fn update(&mut self, client: &crate::request::Bot) -> crate::request::Result<()> {
107107
*self = crate::request::Request::request(crate::request::HttpRequest::get(crate::resource::Endpoint::uri(&self.id)), client).await?;
108108
crate::request::Result::Ok(())
109109
}
@@ -112,12 +112,12 @@ pub fn derive_partial(input: proc_macro::TokenStream) -> proc_macro::TokenStream
112112
impl #impl_generics #partial_ty #ty_generics
113113
#where_clause
114114
{
115-
#vis async fn update(&mut self, client: &crate::request::Discord) -> crate::request::Result<()> {
115+
#vis async fn update(&mut self, client: &crate::request::Bot) -> crate::request::Result<()> {
116116
let full: #ty = crate::request::Request::request(crate::request::HttpRequest::get(crate::resource::Endpoint::uri(&self.id)), client).await?;
117117
*self = full.into();
118118
crate::request::Result::Ok(())
119119
}
120-
#vis async fn get_field<T>(&mut self, client: &crate::request::Discord, f: fn(&Self) -> &::core::option::Option<T>) -> crate::request::Result<&T> {
120+
#vis async fn get_field<T>(&mut self, client: &crate::request::Bot, f: fn(&Self) -> &::core::option::Option<T>) -> crate::request::Result<&T> {
121121
crate::request::Result::Ok(match f(self) {
122122
::core::option::Option::Some(_) => {
123123
f(self).as_ref().unwrap()

discord/resource/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ fn resource_impl(attr: TokenStream, item: TokenStream) -> syn::Result<TokenStrea
3939
let return_type = params.result;
4040
let client_type = match params.client {
4141
Some(t) => t,
42-
None => parse_quote!(crate::request::Discord),
42+
None => parse_quote!(crate::request::Bot),
4343
};
4444

4545
let result_type = parse_quote!(

discord/src/gateway.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ use tokio_tungstenite::{connect_async, tungstenite::Message, MaybeTlsStream, Web
2121
use crate::request::Request;
2222

2323
use super::request::{self, HttpRequest, RequestError};
24-
use super::{interaction::AnyInteraction, request::Discord};
24+
use super::{interaction::AnyInteraction, request::Bot};
2525

2626
struct GatewayState {
2727
interval: Interval,
@@ -216,7 +216,7 @@ impl Stream for Gateway {
216216
const NAME: &str = env!("CARGO_PKG_NAME");
217217

218218
impl Gateway {
219-
pub async fn connect(client: &Discord) -> request::Result<Self> {
219+
pub async fn connect(client: &Bot) -> request::Result<Self> {
220220
let GatewayResponse { url } = HttpRequest::get("/gateway").request(client).await?;
221221
let full_url = url + "/?v=10&encoding=json";
222222

discord/src/request.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use serde::{de::DeserializeOwned, Deserialize, Serialize};
99
use tokio::{sync::Mutex, time::Instant};
1010

1111
#[async_trait]
12-
pub trait Request<C = Discord>
12+
pub trait Request<C = Bot>
1313
where
1414
Self: Sized + Send,
1515
C: ?Sized + Sync,
@@ -20,7 +20,7 @@ where
2020
async fn request(self, client: &C) -> Result<Self::Output>;
2121
}
2222

23-
pub struct HttpRequest<T, C = Discord>
23+
pub struct HttpRequest<T, C = Bot>
2424
where
2525
T: DeserializeOwned,
2626
C: Client + ?Sized,
@@ -138,7 +138,7 @@ struct DiscordRateLimits {
138138
}
139139

140140
#[derive(Clone)]
141-
pub struct Discord {
141+
pub struct Bot {
142142
token: String,
143143
limits: Arc<Mutex<DiscordRateLimits>>,
144144
}
@@ -191,7 +191,7 @@ pub trait Client: Sync {
191191
}
192192
}
193193

194-
impl Discord {
194+
impl Bot {
195195
pub fn new<S: Into<String>>(token: S) -> Self {
196196
Self {
197197
token: token.into(),
@@ -227,14 +227,14 @@ impl Discord {
227227
}
228228

229229
#[async_trait]
230-
impl Client for Discord {
230+
impl Client for Bot {
231231
async fn request_weak<T: DeserializeOwned>(
232232
&self,
233233
method: Method,
234234
uri: &str,
235235
body: Option<&str>,
236236
) -> Result<T> {
237-
let bucket = Discord::get_bucket(uri);
237+
let bucket = Bot::get_bucket(uri);
238238

239239
// rate limits
240240
let now = {
@@ -244,7 +244,7 @@ impl Client for Discord {
244244
let mut time = me.retry_after.duration_since(now);
245245

246246
// global rate limit
247-
let global = Discord::bound_to_global_limit(uri);
247+
let global = Bot::bound_to_global_limit(uri);
248248
if global && me.request_rate >= GLOBAL_RATE_LIMIT {
249249
time = time.max(Duration::from_secs_f32(1.0 / GLOBAL_RATE_LIMIT));
250250
}

src/game/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ use discord::{
1717
message::{
1818
ActionRow, Author, CreateMessage, Embed, Field, Message, MessageResource, PatchMessage,
1919
},
20-
request::{Discord, Result},
20+
request::{Bot, Result},
2121
resource::Snowflake,
2222
user::User,
2323
};
@@ -271,7 +271,7 @@ pub trait Game: Logic<Return = ()> + Sized + 'static {
271271
async fn start(
272272
token: InteractionToken<ApplicationCommand>,
273273
user: User,
274-
thread: Option<&Discord>,
274+
thread: Option<&Bot>,
275275
) -> Result<GameTask> {
276276
let me = Self::new(user);
277277

src/main.rs

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use discord::command::{Param, StringOption};
1010
use discord::interaction::{
1111
AnyInteraction, CreateReply, InteractionResource, MessageComponent, Webhook,
1212
};
13-
use discord::request::Discord;
13+
use discord::request::Bot;
1414
use discord::user::{self, User};
1515
use dotenv::dotenv;
1616
use futures_util::StreamExt;
@@ -29,7 +29,7 @@ use crate::cah::CAH;
2929
mod cah;
3030
mod game;
3131

32-
async fn purge(commands: Commands, client: &Discord) -> Result<()> {
32+
async fn purge(commands: Commands, client: &Bot) -> Result<()> {
3333
if let Ok(commands) = commands.all(client).await {
3434
for command in commands {
3535
command.delete(client).await?;
@@ -38,11 +38,7 @@ async fn purge(commands: Commands, client: &Discord) -> Result<()> {
3838
Ok(())
3939
}
4040

41-
async fn on_command(
42-
i: AnyInteraction,
43-
d: &mut InteractionDispatcher,
44-
client: &Discord,
45-
) -> Result<()> {
41+
async fn on_command(i: AnyInteraction, d: &mut InteractionDispatcher, client: &Bot) -> Result<()> {
4642
match i {
4743
AnyInteraction::Command(command) => match command.data.name.as_str() {
4844
"ping" => {
@@ -108,7 +104,7 @@ async fn run() -> Result<()> {
108104
let token = env::var("CARDMASTER").expect("Bot token CARDMASTER must be set");
109105

110106
// connect
111-
let client = Discord::new(token);
107+
let client = Bot::new(token);
112108
let application = application::Me.get(&client).await?;
113109

114110
// list guilds

0 commit comments

Comments
 (0)