@@ -4,38 +4,16 @@ use scope_chat::reaction::{MessageReaction, ReactionEmoji, MessageReactionType};
44
55#[ derive( Clone , Debug ) ]
66pub 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 > ,
812}
913
1014impl 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 {
3917 ReactionType :: Custom { animated, id, name } => {
4018 ReactionEmoji :: Custom {
4119 url : format ! ( "https://cdn.discordapp.com/emojis/{}.png" , id) ,
@@ -47,20 +25,57 @@ impl MessageReaction for DiscordMessageReaction {
4725 ReactionEmoji :: Simple ( character. clone ( ) )
4826 }
4927 ty => {
50- eprintln ! ( "Unsupported reaction type: {:?}" , ty) ;
51- ReactionEmoji :: Simple ( "❓" . to_string ( ) )
28+ return Err ( format ! ( "Unsupported reaction type: {:?}" , ty) ) ;
5229 }
53- }
54- }
30+ } ;
5531
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| {
5835 Rgba {
5936 r : color. r ( ) as f32 ,
6037 g : color. g ( ) as f32 ,
6138 b : color. b ( ) as f32 ,
6239 a : 1f32 ,
6340 }
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 ( )
6580 }
6681}
0 commit comments