@@ -5,6 +5,7 @@ import { formatDistance } from 'date-fns';
5
5
import { User } from 'discord.js' ;
6
6
import { Pug , Users , Pugs , GuildStats } from '~/models' ;
7
7
import {
8
+ Period ,
8
9
computePickingOrder ,
9
10
CONSTANTS ,
10
11
emojis ,
@@ -15,6 +16,7 @@ import {
15
16
getRandomPickIndex ,
16
17
teamEmojiTypes ,
17
18
getPlayerIndexFromPlayerList ,
19
+ getHumanReadablePeriodName ,
18
20
} from '~/utils' ;
19
21
import {
20
22
addGuildGameType ,
@@ -424,6 +426,9 @@ export const handleJoinGameTypes: Handler = async (
424
426
toBroadcast . players . forEach ( ( player ) => {
425
427
const user = message . client . users . cache . get ( player . id ) ;
426
428
user ?. send ( DM ) ;
429
+ store . dispatch (
430
+ clearAutoRemoval ( { guildId : guild . id , userId : player . id } )
431
+ ) ;
427
432
} ) ;
428
433
429
434
// If 1v1/mix/deathmatch pug, there wont be live picking
@@ -459,9 +464,6 @@ export const handleJoinGameTypes: Handler = async (
459
464
`Remove pug ${ toBroadcast . name } at guild ${ guild . id } from store`
460
465
) ;
461
466
store . dispatch ( removePug ( { guildId : guild . id , name : toBroadcast . name } ) ) ;
462
- store . dispatch (
463
- clearAutoRemoval ( { guildId : guild . id , userId : author . id } )
464
- ) ;
465
467
}
466
468
}
467
469
@@ -1402,10 +1404,7 @@ export const handleAdminBlockPlayer: Handler = async (message, args) => {
1402
1404
const blockLength = parseInt ( blockLengthString ) ;
1403
1405
if ( blockLength <= 0 ) return ;
1404
1406
1405
- const expiry = calculateExpiry (
1406
- blockPeriodString as 'm' | 'h' | 'd' ,
1407
- blockLength
1408
- ) ;
1407
+ const expiry = calculateExpiry ( blockPeriodString as Period , blockLength ) ;
1409
1408
1410
1409
const newBlock = {
1411
1410
blockedOn : new Date ( ) ,
@@ -1742,7 +1741,7 @@ export const handleAddAutoRemove: Handler = async (message, args) => {
1742
1741
const { list } = pugs ;
1743
1742
1744
1743
const userHasJoinedAtleastOnePug = list . some ( ( pug ) =>
1745
- pug . players . find ( ( p ) => p . id === userId )
1744
+ pug . players . some ( ( p ) => p . id === userId )
1746
1745
) ;
1747
1746
1748
1747
if ( ! userHasJoinedAtleastOnePug ) {
@@ -1753,6 +1752,17 @@ export const handleAddAutoRemove: Handler = async (message, args) => {
1753
1752
return ;
1754
1753
}
1755
1754
1755
+ const userIsPartOfFilledPug = list . some (
1756
+ ( pug ) => pug . isInPickingMode && pug . players . some ( ( p ) => p . id === userId )
1757
+ ) ;
1758
+ if ( userIsPartOfFilledPug ) {
1759
+ log . debug ( `User ${ userId } is part of filled pug, so no autoremoval` ) ;
1760
+ message . channel . send (
1761
+ `You cannot use autoremove while you're in a filled pug`
1762
+ ) ;
1763
+ return ;
1764
+ }
1765
+
1756
1766
const [ timeframe = '' ] = args ;
1757
1767
const [ autoRemoveLengthString ] = timeframe . match ( / [ 0 - 9 ] + / g) ?? [ ] ;
1758
1768
const [ autoRemovePeriodString ] = timeframe . match ( / [ m | h | d ] / g) ?? [ ] ;
@@ -1766,15 +1776,17 @@ export const handleAddAutoRemove: Handler = async (message, args) => {
1766
1776
if ( autoRemoveLength <= 0 ) return ;
1767
1777
1768
1778
const expiry = calculateExpiry (
1769
- autoRemovePeriodString as 'm' | 'h' | 'd' ,
1779
+ autoRemovePeriodString as Period ,
1770
1780
autoRemoveLength
1771
1781
) ;
1772
1782
1773
1783
store . dispatch ( addAutoRemoval ( { guildId : guild . id , userId, expiry } ) ) ;
1774
1784
log . info ( `Autoremoval added for user ${ userId } at ${ expiry . toUTCString ( ) } ` ) ;
1775
1785
1776
1786
message . channel . send (
1777
- `<@${ userId } >, you will be autoremoved from every pug at **${ expiry . toUTCString ( ) } **`
1787
+ `<@${ userId } >, you will be automatically removed from every pug in **${ autoRemoveLength } ${ getHumanReadablePeriodName (
1788
+ autoRemovePeriodString as Period
1789
+ ) } ${ autoRemoveLength > 1 ? 's' : '' } ** (${ expiry . toUTCString ( ) } )`
1778
1790
) ;
1779
1791
1780
1792
log . info ( `Exiting handleAddAutoRemove` ) ;
0 commit comments