@@ -4,16 +4,38 @@ use scope_chat::reaction::{MessageReaction, ReactionEmoji, MessageReactionType};
4
4
5
5
#[ derive( Clone , Debug ) ]
6
6
pub struct DiscordMessageReaction {
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 > ,
7
+ pub data : serenity:: all:: MessageReaction ,
12
8
}
13
9
14
10
impl DiscordMessageReaction {
15
- pub fn from_serenity ( reaction : & serenity:: all:: MessageReaction ) -> Result < Self , String > {
16
- let emoji = match & reaction. reaction_type {
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 {
17
39
ReactionType :: Custom { animated, id, name } => {
18
40
ReactionEmoji :: Custom {
19
41
url : format ! ( "https://cdn.discordapp.com/emojis/{}.png" , id) ,
@@ -25,57 +47,20 @@ impl DiscordMessageReaction {
25
47
ReactionEmoji :: Simple ( character. clone ( ) )
26
48
}
27
49
ty => {
28
- return Err ( format ! ( "Unsupported reaction type: {:?}" , ty) ) ;
50
+ eprintln ! ( "Unsupported reaction type: {:?}" , ty) ;
51
+ ReactionEmoji :: Simple ( "❓" . to_string ( ) )
29
52
}
30
- } ;
53
+ }
54
+ }
31
55
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| {
56
+ fn get_burst_colors ( & self ) -> Vec < Rgba > {
57
+ self . data . burst_colours . iter ( ) . map ( |color| {
35
58
Rgba {
36
59
r : color. r ( ) as f32 ,
37
60
g : color. g ( ) as f32 ,
38
61
b : color. b ( ) as f32 ,
39
62
a : 1f32 ,
40
63
}
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 ( )
64
+ } ) . collect ( )
80
65
}
81
66
}
0 commit comments