pub struct Twitter {
config: TwitterConfig,
wakeup_list: Vec<NaiveTime>,
font: Option<FontRenderer>,
tl_check_since_id: Option<String>,
my_user_cache: Option<User>,
username_user_cache: HashMap<String, User>,
id_username_cache: HashMap<String, String>,
}
Fields§
§config: TwitterConfig
§wakeup_list: Vec<NaiveTime>
§font: Option<FontRenderer>
§tl_check_since_id: Option<String>
タイムラインチェックの際の走査開始 tweet id。
初期状態は None で、未取得状態を表す。 最初の設定は、自身の最新ツイートを取得して設定する。 ツイートを行うと最新ツイートが変わってしまうため、 ツイート時、この値が None ならばツイート前に設定を行う。
ツイート成功後、その ID で更新する。
my_user_cache: Option<User>
自身の User オブジェクト。最初の1回だけ取得を行う。
username_user_cache: HashMap<String, User>
screen name -> User オブジェクトのマップ。
id_username_cache: HashMap<String, String>
ID -> screen name のマップ。
Implementations§
Source§impl Twitter
impl Twitter
pub fn new(wakeup_list: Vec<NaiveTime>) -> Result<Self>
Sourceasync fn twitter_task(&mut self, ctrl: &Control) -> Result<()>
async fn twitter_task(&mut self, ctrl: &Control) -> Result<()>
Twitter 巡回タスク。
Sourceasync fn create_ai_reply_list(
&self,
ctrl: &Control,
tl: &Timeline,
me: &User,
) -> Vec<Reply>
async fn create_ai_reply_list( &self, ctrl: &Control, tl: &Timeline, me: &User, ) -> Vec<Reply>
全 AI リプライを生成する
fn resolve_user<'a>(id: &str, users: &'a [User]) -> Option<&'a User>
Sourcefn pattern_match(pat: &str, text: &str) -> bool
fn pattern_match(pat: &str, text: &str) -> bool
text から pat を検索する。 先頭が ‘^’ だとそれで始まる場合のみ。 末尾が ‘$’ だとそれで終わる場合のみ。
Sourceasync fn get_since_id(&mut self) -> Result<String>
async fn get_since_id(&mut self) -> Result<String>
自分のツイートリストを得て最終ツイート ID を得る(キャッシュ付き)。
Sourcepub async fn tweet_custom(
&mut self,
text: &str,
reply_to: Option<&str>,
media_ids: &[u64],
) -> Result<()>
pub async fn tweet_custom( &mut self, text: &str, reply_to: Option<&str>, media_ids: &[u64], ) -> Result<()>
メディア付きツイート。 中身は Self::tweet_raw。
Sourceasync fn tweet_raw(&mut self, param: TweetParam) -> Result<()>
async fn tweet_raw(&mut self, param: TweetParam) -> Result<()>
TwitterConfig::fake_tweet 設定に対応したツイート。
Sourcefn truncate_tweet_text(text: &str) -> &str
fn truncate_tweet_text(text: &str) -> &str
140 字に切り詰める
Sourcepub async fn media_upload<T: Into<Body>>(&self, bin: T) -> Result<u64>
pub async fn media_upload<T: Into<Body>>(&self, bin: T) -> Result<u64>
Sourceasync fn twitter_task_entry(ctrl: Control) -> Result<()>
async fn twitter_task_entry(ctrl: Control) -> Result<()>
エントリ関数。Self::twitter_task を呼ぶ。
Control 内の Twitter オブジェクトを lock するので Self::twitter_task は排他実行となる。
Sourceasync fn get_my_id(&mut self) -> Result<User>
async fn get_my_id(&mut self) -> Result<User>
自身の Twitter ID を返す。 Self::users_me の キャッシュ付きバージョン。
fn get_user_from_username(&self, name: &String) -> Option<&User>
fn get_username_from_id(&self, id: &String) -> Option<&String>
Sourceasync fn resolve_ids(&mut self, user_names: &[String]) -> Result<()>
async fn resolve_ids(&mut self, user_names: &[String]) -> Result<()>
user name (screen name) から id を取得する。 id -> user name のマップも同時に作成する。
結果は Self::username_user_cache, Self::id_username_cache に入れる。 凍結等で取得できない可能性があり、その場合はエラーを出しながら続行するよりは panic でユーザに知らせる。
async fn users_me(&self) -> Result<UsersMe>
async fn users_by(&self, users: &[String]) -> Result<UsersBy>
async fn users_timelines_home( &self, id: &str, since_id: &str, ) -> Result<Timeline>
async fn users_tweets(&self, id: &str) -> Result<Timeline>
async fn tweets_post(&self, param: TweetParam) -> Result<TweetResponse>
async fn http_oauth_get( &self, base_url: &str, query_param: &BTreeMap<String, String>, ) -> Result<Response>
async fn http_oauth_post_json<T: Serialize>( &self, base_url: &str, query_param: &BTreeMap<String, String>, body_param: &T, ) -> Result<Response>
async fn http_oauth_post_multipart( &self, base_url: &str, query_param: &BTreeMap<String, String>, body: Form, ) -> Result<Response>
fn http_oauth_post( &self, client: &Client, base_url: &str, query_param: &BTreeMap<String, String>, ) -> RequestBuilder
Trait Implementations§
Source§impl SystemModule for Twitter
impl SystemModule for Twitter
Source§fn on_start(&mut self, ctrl: &Control)
fn on_start(&mut self, ctrl: &Control)
Auto Trait Implementations§
impl Freeze for Twitter
impl RefUnwindSafe for Twitter
impl Send for Twitter
impl Sync for Twitter
impl Unpin for Twitter
impl UnwindSafe for Twitter
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more