1
- import { container } from '@sapphire/framework' ;
2
- import { User } from 'discord.js' ;
1
+ import { SapphireClient , container } from '@sapphire/framework' ;
2
+ import { CommandInteraction , EmbedBuilder , Message , User , userMention } from 'discord.js' ;
3
3
import {
4
4
CodeyCommandOptionType ,
5
5
CodeyCommandDetails ,
@@ -41,6 +41,11 @@ const coinTransferExecuteCommand: SapphireMessageExecuteType = async (
41
41
return new SapphireMessageResponseWithMetadata ( `You can't transfer to yourself.` , { } ) ;
42
42
}
43
43
44
+ // Ensure the transfer involves a non-bot recipient
45
+ if ( receivingUser . bot ) {
46
+ return new SapphireMessageResponseWithMetadata ( `You can't transfer to bots.` , { } ) ;
47
+ }
48
+
44
49
// Retrieve sending user balance and ensure transferred amount is valid
45
50
const senderBalance = await getCoinBalanceByUserId ( sendingUser . id ) ;
46
51
if ( amount > senderBalance ) {
@@ -63,12 +68,38 @@ const coinTransferExecuteCommand: SapphireMessageExecuteType = async (
63
68
64
69
return new SapphireMessageResponseWithMetadata ( await transfer . getTransferResponse ( ) , {
65
70
transferId : transfer . transferId ,
71
+ _client : client ,
72
+ receiver : receivingUser ,
66
73
} ) ;
67
74
} ;
68
75
69
76
const transferAfterMessageReply : SapphireAfterReplyType = async ( result , sentMessage ) => {
70
77
if ( typeof result . metadata . transferId === 'undefined' ) return ;
71
- // Store the message which the game takes place in the game object
78
+
79
+ // Send a dm to the transfer receiver
80
+ const receivingUser = < User > result . metadata [ 'receiver' ] ;
81
+ const client = < SapphireClient > result . metadata [ '_client' ] ;
82
+
83
+ const mentionUser = userMention ( receivingUser . id ) ;
84
+
85
+ const message = < Message > sentMessage ;
86
+ let messageLink = message . url ;
87
+ if ( ! messageLink ) {
88
+ // if command was run as a slash command, the above will fail
89
+ const commandInteraction = < CommandInteraction > sentMessage ;
90
+ const messageReply = await commandInteraction . fetchReply ( ) ;
91
+ messageLink = messageReply . url ;
92
+ }
93
+ const transferPingMessage = `Hey ${ mentionUser } , you've received a CodeyCoin transfer!
94
+
95
+ Check it out here: ${ messageLink } ` ;
96
+
97
+ const transferPingEmbed = new EmbedBuilder ( )
98
+ . setColor ( 'Green' )
99
+ . setTitle ( 'New CodeyCoin Transfer!' )
100
+ . setDescription ( transferPingMessage ) ;
101
+ client . users . send ( receivingUser , { embeds : [ transferPingEmbed ] } ) ;
102
+
72
103
transferTracker . runFuncOnTransfer ( < string > result . metadata . transferId , ( transfer ) => {
73
104
transfer . transferMessage = sentMessage ;
74
105
} ) ;
@@ -83,7 +114,7 @@ export const coinTransferCommandDetails: CodeyCommandDetails = {
83
114
\`${ container . botPrefix } coin transfer @Codey 10 Lost a bet to @Codey\`` ,
84
115
85
116
isCommandResponseEphemeral : false ,
86
- messageWhenExecutingCommand : 'Transferring coins ...' ,
117
+ messageWhenExecutingCommand : 'Setting up the transaction ...' ,
87
118
afterMessageReply : transferAfterMessageReply ,
88
119
executeCommand : coinTransferExecuteCommand ,
89
120
options : [
0 commit comments