@@ -73,24 +73,44 @@ public async Task ShowAppreciationCommand(CommandContext ctx) {
73
73
}
74
74
}
75
75
76
+
77
+ private static Dictionary < ulong , LastPosters > LastMemberPerChannels = null ;
78
+
79
+ internal static void InitChannelList ( ) {
80
+ IReadOnlyDictionary < ulong , DiscordChannel > channels = Utils . GetGuild ( ) . Channels ;
81
+ LastMemberPerChannels = new Dictionary < ulong , LastPosters > ( ) ;
82
+ foreach ( ulong cid in channels . Keys )
83
+ LastMemberPerChannels [ cid ] = new LastPosters ( ) ;
84
+ }
85
+
76
86
internal static Task ThanksAdded ( DiscordClient sender , MessageCreateEventArgs args ) {
77
87
try {
78
88
string msg = args . Message . Content . ToLowerInvariant ( ) ;
89
+ ulong memberid = args . Message . Author . Id ;
90
+ ulong channelid = args . Message . ChannelId ;
91
+ if ( LastMemberPerChannels == null ) InitChannelList ( ) ;
92
+ LastPosters lp = LastMemberPerChannels [ channelid ] ;
93
+ lp . Add ( memberid ) ;
94
+
79
95
if ( thanks . IsMatch ( msg ) || thankyou . IsMatch ( msg ) || thank2you . IsMatch ( msg ) ) { // Add thanks
80
96
if ( thank4n . IsMatch ( msg ) ) return Task . FromResult ( 0 ) ;
81
97
if ( GetTracking ( ) ) return Task . FromResult ( 0 ) ;
82
98
83
99
DiscordMessage theMsg = args . Message ;
84
100
ulong authorId = theMsg . Author . Id ;
85
101
if ( theMsg . Reference == null && ( theMsg . MentionedUsers == null || theMsg . MentionedUsers . Count == 0 ) ) {
86
- // Unrelated thank you, get the previous message and check
87
- IReadOnlyList < DiscordMessage > msgs = theMsg . Channel . GetMessagesBeforeAsync ( theMsg . Id , 2 ) . Result ;
88
- theMsg = null ;
89
- foreach ( DiscordMessage m in msgs )
90
- if ( m . Author . Id != authorId ) {
91
- theMsg = m ;
92
- break ;
93
- }
102
+ if ( lp . secondLast != 0 || lp . secondLast != 875701548301299743ul )
103
+ tracking . AlterThankYou ( lp . secondLast ) ;
104
+ else {
105
+ // Unrelated thank you, get the previous message and check /*
106
+ IReadOnlyList < DiscordMessage > msgs = theMsg . Channel . GetMessagesBeforeAsync ( theMsg . Id , 2 ) . Result ;
107
+ theMsg = null ;
108
+ foreach ( DiscordMessage m in msgs )
109
+ if ( m . Author . Id != authorId ) {
110
+ theMsg = m ;
111
+ break ;
112
+ }
113
+ }
94
114
if ( theMsg == null ) return Task . FromResult ( 0 ) ;
95
115
}
96
116
@@ -111,7 +131,18 @@ internal static Task ThanksAdded(DiscordClient sender, MessageCreateEventArgs ar
111
131
}
112
132
113
133
134
+ internal class LastPosters {
135
+ public ulong thirdLast ;
136
+ public ulong secondLast ;
137
+ public ulong last ;
114
138
139
+ internal void Add ( ulong memberid ) {
140
+ if ( last == memberid ) return ;
141
+ thirdLast = secondLast ;
142
+ secondLast = last ;
143
+ last = memberid ;
144
+ }
145
+ }
115
146
116
147
117
148
0 commit comments