1
1
using Discord ;
2
2
using Discord . Commands ;
3
+ using Discord . WebSocket ;
3
4
using PKHeX . Core ;
4
5
using System . Linq ;
5
6
using System . Threading . Tasks ;
@@ -34,22 +35,8 @@ public async Task GetTradeListAsync()
34
35
[ RequireQueueRole ( nameof ( DiscordManager . RolesTrade ) ) ]
35
36
public async Task TradeAsyncAttach ( [ Summary ( "Trade Code" ) ] int code )
36
37
{
37
- var attachment = Context . Message . Attachments . FirstOrDefault ( ) ;
38
- if ( attachment == default )
39
- {
40
- await ReplyAsync ( "No attachment provided!" ) . ConfigureAwait ( false ) ;
41
- return ;
42
- }
43
-
44
- var att = await NetUtil . DownloadPKMAsync ( attachment ) . ConfigureAwait ( false ) ;
45
- if ( ! att . Success || ! ( att . Data is PK8 pk8 ) )
46
- {
47
- await ReplyAsync ( "No PK8 attachment provided!" ) . ConfigureAwait ( false ) ;
48
- return ;
49
- }
50
-
51
38
var sig = Context . User . GetFavor ( ) ;
52
- await AddTradeToQueueAsync ( code , Context . User . Username , pk8 , sig ) . ConfigureAwait ( false ) ;
39
+ await TradeAsyncAttach ( code , sig , Context . User ) . ConfigureAwait ( false ) ;
53
40
}
54
41
55
42
[ Command ( "trade" ) ]
@@ -85,7 +72,7 @@ public async Task TradeAsync([Summary("Trade Code")] int code, [Summary("Showdow
85
72
86
73
pkm . ResetPartyStats ( ) ;
87
74
var sig = Context . User . GetFavor ( ) ;
88
- await AddTradeToQueueAsync ( code , Context . User . Username , ( PK8 ) pkm , sig ) . ConfigureAwait ( false ) ;
75
+ await AddTradeToQueueAsync ( code , Context . User . Username , ( PK8 ) pkm , sig , Context . User ) . ConfigureAwait ( false ) ;
89
76
}
90
77
91
78
[ Command ( "trade" ) ]
@@ -108,7 +95,59 @@ public async Task TradeAsyncAttach()
108
95
await TradeAsyncAttach ( code ) . ConfigureAwait ( false ) ;
109
96
}
110
97
111
- private async Task AddTradeToQueueAsync ( int code , string trainerName , PK8 pk8 , RequestSignificance sig )
98
+ [ Command ( "tradeUser" ) ]
99
+ [ Alias ( "tu" , "tradeOther" ) ]
100
+ [ Summary ( "Makes the bot trade the mentioned user the attached file." ) ]
101
+ [ RequireSudo ]
102
+ public async Task TradeAsyncAttachUser ( [ Summary ( "Trade Code" ) ] int code , [ Remainder ] string _ )
103
+ {
104
+ if ( Context . Message . MentionedUsers . Count > 1 )
105
+ {
106
+ await ReplyAsync ( "Too many mentions. Queue one user at a time." ) . ConfigureAwait ( false ) ;
107
+ return ;
108
+ }
109
+
110
+ if ( Context . Message . MentionedUsers . Count == 0 )
111
+ {
112
+ await ReplyAsync ( "A user must be mentioned in order to do this." ) . ConfigureAwait ( false ) ;
113
+ return ;
114
+ }
115
+
116
+ var usr = Context . Message . MentionedUsers . ElementAt ( 0 ) ;
117
+ var sig = usr . GetFavor ( ) ;
118
+ await TradeAsyncAttach ( code , sig , usr ) . ConfigureAwait ( false ) ;
119
+ }
120
+
121
+ [ Command ( "tradeUser" ) ]
122
+ [ Alias ( "tu" , "tradeOther" ) ]
123
+ [ Summary ( "Makes the bot trade the mentioned user the attached file." ) ]
124
+ [ RequireSudo ]
125
+ public async Task TradeAsyncAttachUser ( [ Remainder ] string _ )
126
+ {
127
+ var code = Info . GetRandomTradeCode ( ) ;
128
+ await TradeAsyncAttachUser ( code , _ ) . ConfigureAwait ( false ) ;
129
+ }
130
+
131
+ private async Task TradeAsyncAttach ( int code , RequestSignificance sig , SocketUser usr )
132
+ {
133
+ var attachment = Context . Message . Attachments . FirstOrDefault ( ) ;
134
+ if ( attachment == default )
135
+ {
136
+ await ReplyAsync ( "No attachment provided!" ) . ConfigureAwait ( false ) ;
137
+ return ;
138
+ }
139
+
140
+ var att = await NetUtil . DownloadPKMAsync ( attachment ) . ConfigureAwait ( false ) ;
141
+ if ( ! att . Success || ! ( att . Data is PK8 pk8 ) )
142
+ {
143
+ await ReplyAsync ( "No PK8 attachment provided!" ) . ConfigureAwait ( false ) ;
144
+ return ;
145
+ }
146
+
147
+ await AddTradeToQueueAsync ( code , usr . Username , pk8 , sig , usr ) . ConfigureAwait ( false ) ;
148
+ }
149
+
150
+ private async Task AddTradeToQueueAsync ( int code , string trainerName , PK8 pk8 , RequestSignificance sig , SocketUser usr )
112
151
{
113
152
if ( ! pk8 . CanBeTraded ( ) )
114
153
{
@@ -123,7 +162,7 @@ private async Task AddTradeToQueueAsync(int code, string trainerName, PK8 pk8, R
123
162
return ;
124
163
}
125
164
126
- await Context . AddToQueueAsync ( code , trainerName , sig , pk8 , PokeRoutineType . LinkTrade , PokeTradeType . Specific ) . ConfigureAwait ( false ) ;
165
+ await Context . AddToQueueAsync ( code , trainerName , sig , pk8 , PokeRoutineType . LinkTrade , PokeTradeType . Specific , usr ) . ConfigureAwait ( false ) ;
127
166
}
128
167
}
129
168
}
0 commit comments