@@ -4,16 +4,38 @@ use scope_chat::reaction::{MessageReaction, ReactionEmoji, MessageReactionType};
44
55#[ derive( Clone , Debug ) ]
66pub 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 ,
128}
139
1410impl 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 {
1739 ReactionType :: Custom { animated, id, name } => {
1840 ReactionEmoji :: Custom {
1941 url : format ! ( "https://cdn.discordapp.com/emojis/{}.png" , id) ,
@@ -25,57 +47,20 @@ impl DiscordMessageReaction {
2547 ReactionEmoji :: Simple ( character. clone ( ) )
2648 }
2749 ty => {
28- return Err ( format ! ( "Unsupported reaction type: {:?}" , ty) ) ;
50+ eprintln ! ( "Unsupported reaction type: {:?}" , ty) ;
51+ ReactionEmoji :: Simple ( "❓" . to_string ( ) )
2952 }
30- } ;
53+ }
54+ }
3155
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| {
3558 Rgba {
3659 r : color. r ( ) as f32 ,
3760 g : color. g ( ) as f32 ,
3861 b : color. b ( ) as f32 ,
3962 a : 1f32 ,
4063 }
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 ( )
8065 }
8166}
0 commit comments