Struct Twitter

Source
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

Source

pub fn new(wakeup_list: Vec<NaiveTime>) -> Result<Self>

Source

async fn twitter_task(&mut self, ctrl: &Control) -> Result<()>

Twitter 巡回タスク。

Source

fn create_reply_list(&self, tl: &Timeline, me: &User) -> Vec<Reply>

全リプライを生成する

Source

async fn create_ai_reply_list( &self, ctrl: &Control, tl: &Timeline, me: &User, ) -> Vec<Reply>

全 AI リプライを生成する

Source

fn resolve_user<'a>(id: &str, users: &'a [User]) -> Option<&'a User>

Source

fn pattern_match(pat: &str, text: &str) -> bool

text から pat を検索する。 先頭が ‘^’ だとそれで始まる場合のみ。 末尾が ‘$’ だとそれで終わる場合のみ。

Source

async fn get_since_id(&mut self) -> Result<String>

自分のツイートリストを得て最終ツイート ID を得る(キャッシュ付き)。

Source

pub async fn tweet(&mut self, text: &str) -> Result<()>

シンプルなツイート。 中身は Self::tweet_raw

Source

pub async fn tweet_custom( &mut self, text: &str, reply_to: Option<&str>, media_ids: &[u64], ) -> Result<()>

メディア付きツイート。 中身は Self::tweet_raw

Source

async fn tweet_raw(&mut self, param: TweetParam) -> Result<()>

TwitterConfig::fake_tweet 設定に対応したツイート。

Source

fn truncate_tweet_text(text: &str) -> &str

140 字に切り詰める

Source

pub async fn media_upload<T: Into<Body>>(&self, bin: T) -> Result<u64>

Source

async fn twitter_task_entry(ctrl: Control) -> Result<()>

エントリ関数。Self::twitter_task を呼ぶ。

Control 内の Twitter オブジェクトを lock するので Self::twitter_task は排他実行となる。

Source

async fn get_my_id(&mut self) -> Result<User>

自身の Twitter ID を返す。 Self::users_me の キャッシュ付きバージョン。

Source

fn get_user_from_username(&self, name: &String) -> Option<&User>

Source

fn get_username_from_id(&self, id: &String) -> Option<&String>

Source

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 でユーザに知らせる。

Source

async fn users_me(&self) -> Result<UsersMe>

Source

async fn users_by(&self, users: &[String]) -> Result<UsersBy>

Source

async fn users_timelines_home( &self, id: &str, since_id: &str, ) -> Result<Timeline>

Source

async fn users_tweets(&self, id: &str) -> Result<Timeline>

Source

async fn tweets_post(&self, param: TweetParam) -> Result<TweetResponse>

Source

async fn http_oauth_get( &self, base_url: &str, query_param: &BTreeMap<String, String>, ) -> Result<Response>

Source

async fn http_oauth_post_json<T: Serialize>( &self, base_url: &str, query_param: &BTreeMap<String, String>, body_param: &T, ) -> Result<Response>

Source

async fn http_oauth_post_multipart( &self, base_url: &str, query_param: &BTreeMap<String, String>, body: Form, ) -> Result<Response>

Source

fn http_oauth_post( &self, client: &Client, base_url: &str, query_param: &BTreeMap<String, String>, ) -> RequestBuilder

Trait Implementations§

Source§

impl SystemModule for Twitter

Source§

fn on_start(&mut self, ctrl: &Control)

SystemModule の初期化時には [crate::sys::taskserver::TaskServer] がまだ存在しないので タスクの登録はこのタイミングまで遅延させる。

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
§

impl<T> Pointable for T

§

const ALIGN: usize

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
§

impl<T> PolicyExt for T
where T: ?Sized,

§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns [Action::Follow] only if self and other return Action::Follow. Read more
§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns [Action::Follow] if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

impl<T> ErasedDestructor for T
where T: 'static,