1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
//! イベントペイロード内部で使われる型

use serde::{Deserialize, Serialize};

#[cfg(feature = "chrono")]
use chrono::{DateTime, Utc};

#[cfg(not(feature = "chrono"))]
#[cfg(feature = "time")]
use time::OffsetDateTime;

#[cfg(feature = "chrono")]
pub type TimeStamp = DateTime<Utc>;
#[cfg(not(feature = "chrono"))]
#[cfg(feature = "time")]
pub type TimeStamp = OffsetDateTime;
#[cfg(not(feature = "chrono"))]
#[cfg(not(feature = "time"))]
pub type TimeStamp = String;

#[cfg(feature = "uuid")]
pub type Uuid = uuid::Uuid;
#[cfg(not(feature = "uuid"))]
pub type Uuid = String;

/// [traQの型定義](https://github.com/traPtitech/traQ/blob/d2bc98f1e0e68f4acc371eb78e6a49a167446761/service/bot/event/payload/common.go#L69-L75)
#[derive(Debug, Clone, PartialEq, Eq, Deserialize, Serialize)]
pub struct User {
    pub id: Uuid,
    pub name: String,
    #[serde(rename = "displayName")]
    pub display_name: String,
    #[serde(rename = "iconId")]
    pub icon_id: Uuid,
    pub bot: bool,
}

/// [traQの型定義](https://github.com/traPtitech/traQ/blob/d2bc98f1e0e68f4acc371eb78e6a49a167446761/service/bot/event/payload/common.go#L47-L55)
#[derive(Debug, Clone, PartialEq, Eq, Deserialize, Serialize)]
pub struct Channel {
    pub id: Uuid,
    pub name: String,
    pub path: String,
    #[serde(rename = "parentId")]
    pub parent_id: Uuid,
    pub creator: User,
    #[serde(rename = "createdAt", with = "crate::payloads::serde::timestamp")]
    pub created_at: TimeStamp,
    #[serde(rename = "updatedAt", with = "crate::payloads::serde::timestamp")]
    pub updated_at: TimeStamp,
}

/// [traQの型定義](https://github.com/traPtitech/traQ/blob/d2bc98f1e0e68f4acc371eb78e6a49a167446761/utils/message/embedded.go#L9-L14)
#[derive(Debug, Clone, PartialEq, Eq, Deserialize, Serialize)]
pub struct EmbeddedInfo {
    pub raw: String,
    #[serde(rename = "type")]
    pub type_: String,
    pub id: Uuid,
}

/// [traQの型定義](https://github.com/traPtitech/traQ/blob/d2bc98f1e0e68f4acc371eb78e6a49a167446761/service/bot/event/payload/common.go#L23-L32)
#[derive(Debug, Clone, PartialEq, Eq, Deserialize, Serialize)]
pub struct Message {
    pub id: Uuid,
    pub user: User,
    #[serde(rename = "channelId")]
    pub channel_id: Uuid,
    pub text: String,
    #[serde(rename = "plainText")]
    pub plain_text: String,
    pub embedded: Vec<EmbeddedInfo>,
    #[serde(rename = "createdAt", with = "crate::payloads::serde::timestamp")]
    pub created_at: TimeStamp,
    #[serde(rename = "updatedAt", with = "crate::payloads::serde::timestamp")]
    pub updated_at: TimeStamp,
}

/// [traQの型定義](https://github.com/traPtitech/traQ/blob/d2bc98f1e0e68f4acc371eb78e6a49a167446761/service/bot/event/payload/ev_message_deleted.go#L14-L17)
#[derive(Debug, Clone, PartialEq, Eq, Deserialize, Serialize)]
pub struct DeletedMessage {
    pub id: Uuid,
    #[serde(rename = "channelId")]
    pub channel_id: Uuid,
}

/// [traQの型定義](https://github.com/traPtitech/traQ/blob/d2bc98f1e0e68f4acc371eb78e6a49a167446761/service/bot/event/payload/ev_direct_message_deleted.go#L14-L18)
#[derive(Debug, Clone, PartialEq, Eq, Deserialize, Serialize)]
pub struct DeletedDirectMessage {
    pub id: Uuid,
    #[serde(rename = "userId")]
    pub user_id: Uuid,
    #[serde(rename = "channelId")]
    pub channel_id: Uuid,
}

/// [traQの定義](https://github.com/traPtitech/traQ/blob/d2bc98f1e0e68f4acc371eb78e6a49a167446761/model/message_stamp.go#L9-L20)
#[derive(Debug, Clone, PartialEq, Eq, Deserialize, Serialize)]
pub struct MessageStamp {
    #[serde(rename = "stampId")]
    pub stamp_id: Uuid,
    #[serde(rename = "userId")]
    pub user_id: Uuid,
    pub count: i32,
    #[serde(rename = "createdAt", with = "crate::payloads::serde::timestamp")]
    pub created_at: TimeStamp,
    #[serde(rename = "updatedAt", with = "crate::payloads::serde::timestamp")]
    pub updated_at: TimeStamp,
}