@@ -4,38 +4,16 @@ use scope_chat::reaction::{MessageReaction, ReactionEmoji, MessageReactionType};
4
4
5
5
#[ derive( Clone , Debug ) ]
6
6
pub struct DiscordMessageReaction {
7
- pub data : serenity:: all:: MessageReaction ,
7
+ pub count : u32 ,
8
+ pub count_burst : u32 ,
9
+ pub self_reaction : Option < MessageReactionType > ,
10
+ pub emoji : ReactionEmoji ,
11
+ pub burst_colors : Vec < Rgba > ,
8
12
}
9
13
10
14
impl DiscordMessageReaction {
11
- pub fn from_serenity ( reaction : & serenity:: all:: MessageReaction ) -> Self {
12
- DiscordMessageReaction {
13
- data : reaction. clone ( ) ,
14
- }
15
- }
16
- }
17
-
18
- impl MessageReaction for DiscordMessageReaction {
19
- fn get_count ( & self , kind : Option < MessageReactionType > ) -> u64 {
20
- match kind {
21
- Some ( MessageReactionType :: Burst ) => self . data . count_details . burst ,
22
- Some ( MessageReactionType :: Normal ) => self . data . count_details . normal ,
23
- None => self . data . count ,
24
- }
25
- }
26
-
27
- fn get_self_reaction ( & self ) -> Option < MessageReactionType > {
28
- if self . data . me {
29
- Some ( MessageReactionType :: Normal )
30
- } else if self . data . me_burst {
31
- Some ( MessageReactionType :: Burst )
32
- } else {
33
- None
34
- }
35
- }
36
-
37
- fn get_emoji ( & self ) -> ReactionEmoji {
38
- match & self . data . reaction_type {
15
+ pub fn from_serenity ( reaction : & serenity:: all:: MessageReaction ) -> Result < Self , String > {
16
+ let emoji = match & reaction. reaction_type {
39
17
ReactionType :: Custom { animated, id, name } => {
40
18
ReactionEmoji :: Custom {
41
19
url : format ! ( "https://cdn.discordapp.com/emojis/{}.png" , id) ,
@@ -47,20 +25,57 @@ impl MessageReaction for DiscordMessageReaction {
47
25
ReactionEmoji :: Simple ( character. clone ( ) )
48
26
}
49
27
ty => {
50
- eprintln ! ( "Unsupported reaction type: {:?}" , ty) ;
51
- ReactionEmoji :: Simple ( "❓" . to_string ( ) )
28
+ return Err ( format ! ( "Unsupported reaction type: {:?}" , ty) ) ;
52
29
}
53
- }
54
- }
30
+ } ;
55
31
56
- fn get_burst_colors ( & self ) -> Vec < Rgba > {
57
- self . data . burst_colours . iter ( ) . map ( |color| {
32
+ let count = reaction. count_details . normal as u32 ;
33
+ let count_burst = reaction. count_details . burst as u32 ;
34
+ let burst_colors = reaction. burst_colours . iter ( ) . map ( |color| {
58
35
Rgba {
59
36
r : color. r ( ) as f32 ,
60
37
g : color. g ( ) as f32 ,
61
38
b : color. b ( ) as f32 ,
62
39
a : 1f32 ,
63
40
}
64
- } ) . collect ( )
41
+ } ) . collect ( ) ;
42
+
43
+ let self_reaction = if reaction. me {
44
+ Some ( MessageReactionType :: Normal )
45
+ } else if reaction. me_burst {
46
+ Some ( MessageReactionType :: Burst )
47
+ } else {
48
+ None
49
+ } ;
50
+
51
+ Ok ( DiscordMessageReaction {
52
+ count,
53
+ count_burst,
54
+ self_reaction,
55
+ emoji,
56
+ burst_colors,
57
+ } )
58
+ }
59
+ }
60
+
61
+ impl MessageReaction for DiscordMessageReaction {
62
+ fn get_count ( & self , kind : Option < MessageReactionType > ) -> u32 {
63
+ match kind {
64
+ Some ( MessageReactionType :: Burst ) => self . count_burst ,
65
+ Some ( MessageReactionType :: Normal ) => self . count ,
66
+ None => self . count + self . count_burst ,
67
+ }
68
+ }
69
+
70
+ fn get_self_reaction ( & self ) -> Option < MessageReactionType > {
71
+ self . self_reaction
72
+ }
73
+
74
+ fn get_emoji ( & self ) -> ReactionEmoji {
75
+ self . emoji . clone ( )
76
+ }
77
+
78
+ fn get_burst_colors ( & self ) -> Vec < Rgba > {
79
+ self . burst_colors . clone ( )
65
80
}
66
81
}
0 commit comments