-
-
Notifications
You must be signed in to change notification settings - Fork 4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
33 changed files
with
1,418 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
'use strict'; | ||
|
||
const Action = require('./Action'); | ||
const { Events } = require('../../util/Constants'); | ||
|
||
class ThreadCreateAction extends Action { | ||
handle(data) { | ||
const client = this.client; | ||
const existing = client.channels.cache.has(data.id); | ||
const thread = client.channels.add(data); | ||
if (!existing && thread) { | ||
/** | ||
* Emitted whenever a thread is created or when the client user is added to a thread. | ||
* @event Client#threadCreate | ||
* @param {ThreadChannel} thread The thread that was created | ||
*/ | ||
client.emit(Events.THREAD_CREATE, thread); | ||
} | ||
return { thread }; | ||
} | ||
} | ||
|
||
module.exports = ThreadCreateAction; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
'use strict'; | ||
|
||
const Action = require('./Action'); | ||
const { Events } = require('../../util/Constants'); | ||
|
||
class ThreadDeleteAction extends Action { | ||
constructor(client) { | ||
super(client); | ||
this.deleted = new Map(); | ||
} | ||
|
||
handle(data) { | ||
const client = this.client; | ||
let thread = client.channels.cache.get(data.id); | ||
|
||
if (thread) { | ||
client.channels.remove(thread.id); | ||
thread.deleted = true; | ||
for (const message of thread.messages.cache.values()) { | ||
message.deleted = true; | ||
} | ||
/** | ||
* Emitted whenever a thread is deleted. | ||
* @event Client#threadDelete | ||
* @param {ThreadChannel} thread The thread that was deleted | ||
*/ | ||
client.emit(Events.THREAD_DELETE, thread); | ||
} | ||
|
||
return { thread }; | ||
} | ||
} | ||
|
||
module.exports = ThreadDeleteAction; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
'use strict'; | ||
|
||
const Action = require('./Action'); | ||
const Collection = require('../../util/Collection'); | ||
const { Events } = require('../../util/Constants'); | ||
|
||
class ThreadListSyncAction extends Action { | ||
handle(data) { | ||
const client = this.client; | ||
|
||
let guild = client.guilds.cache.get(data.guild_id); | ||
if (guild) { | ||
if (!data.channels_ids) { | ||
guild.channels.cache.forEach(channel => { | ||
this.removeStale(channel); | ||
}); | ||
} else { | ||
data.channel_ids.forEach(id => { | ||
const channel = client.channels.resolve(id); | ||
if (channel) this.removeStale(channel); | ||
}); | ||
} | ||
|
||
const syncedThreads = new Collection(); | ||
data.threads.forEach(rawThread => { | ||
const thread = client.channels.add(rawThread); | ||
syncedThreads.set(thread.id, thread); | ||
}); | ||
|
||
let members = data.members; | ||
if (typeof members === 'object') { | ||
members = Object.values(members); | ||
} | ||
|
||
members.forEach(rawMember => { | ||
const thread = client.channels.cache.get(rawMember.id); | ||
if (thread) { | ||
thread.members.add(rawMember); | ||
} | ||
}); | ||
|
||
/** | ||
* Emitted whenever the client user gains access to a text or news channel | ||
* @event Client#threadListSync | ||
* @param {Collection<Snwoflake, ThreadChannel>} threads The threads that were synced | ||
*/ | ||
client.emit(Events.THREAD_LIST_SYNC, syncedThreads); | ||
|
||
return { | ||
syncedThreads, | ||
}; | ||
} | ||
|
||
return {}; | ||
} | ||
|
||
removeStale(channel) { | ||
if (channel.threads) { | ||
channel.threads.cache.forEach(thread => { | ||
if (!thread.archived) { | ||
this.client.channels.remove(thread.id); | ||
} | ||
}); | ||
} | ||
} | ||
} | ||
|
||
module.exports = ThreadListSyncAction; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
'use strict'; | ||
|
||
const Action = require('./Action'); | ||
const { Events } = require('../../util/Constants'); | ||
|
||
class ThreadMemberUpdateAction extends Action { | ||
handle(data) { | ||
const client = this.client; | ||
const thread = client.channels.cache.get(data.id); | ||
if (thread) { | ||
const member = thread.members.cache.get(data.user_id); | ||
if (!member) { | ||
const newMember = thread.members.add(data); | ||
return { newMember }; | ||
} | ||
const old = member._update(data); | ||
/** | ||
* Emitted whenever the client users thread member is updated. | ||
* @event Client#threadMemberUpdate | ||
* @param {ThreadMember} oldMember The member before the update | ||
* @param {ThreadMember} newMember The member after the update | ||
*/ | ||
client.emit(Events.THREAD_MEMBER_UPDATE, old, member); | ||
} | ||
return {}; | ||
} | ||
} | ||
|
||
module.exports = ThreadMemberUpdateAction; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
'use strict'; | ||
|
||
const Action = require('./Action'); | ||
const { Events } = require('../../util/Constants'); | ||
|
||
class ThreadMembersUpdateAction extends Action { | ||
handle(data) { | ||
const client = this.client; | ||
const thread = client.channels.cache.get(data.id); | ||
if (thread) { | ||
const old = thread.members.cache.clone(); | ||
thread.memberCount = data.member_count; | ||
|
||
if (data.added_members) { | ||
data.added_members.forEach(rawMember => { | ||
thread.members.add(rawMember); | ||
}); | ||
} | ||
|
||
if (data.removed_member_ids) { | ||
data.removed_member_ids.forEach(memberId => { | ||
thread.members.cache.delete(memberId); | ||
}); | ||
} | ||
/** | ||
* Emitted whenever members are added or removed from a thread. Requires `GUILD_MEMBERS` privileged intent | ||
* @event Client#threadMembersUpdate | ||
* @param {Collection<Snowflake, ThreadMember>} oldMembers The members before the update | ||
* @param {Collection<Snowflake, ThreadMember>} newMembers The members after the update | ||
*/ | ||
client.emit(Events.THREAD_MEMBERS_UPDATE, old, thread.members.cache); | ||
} | ||
return {}; | ||
} | ||
} | ||
|
||
module.exports = ThreadMembersUpdateAction; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
'use strict'; | ||
|
||
module.exports = (client, packet) => { | ||
client.actions.ThreadCreate.handle(packet.d); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
'use strict'; | ||
|
||
module.exports = (client, packet) => { | ||
client.actions.ThreadDelete.handle(packet.d); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
'use strict'; | ||
|
||
module.exports = (client, packet) => { | ||
client.actions.ThreadListSync.handle(packet.d); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
'use strict'; | ||
|
||
module.exports = (client, packet) => { | ||
client.actions.ThreadMembersUpdate.handle(packet.d); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
'use strict'; | ||
|
||
module.exports = (client, packet) => { | ||
client.actions.ThreadMemberUpdate.handle(packet.d); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
'use strict'; | ||
|
||
const { Events } = require('../../../util/Constants'); | ||
|
||
module.exports = (client, packet) => { | ||
const { old, updated } = client.actions.ChannelUpdate.handle(packet.d); | ||
if (old && updated) { | ||
/** | ||
* Emitted whenever a thread is updated - e.g. name change, archive state change, locked state change. | ||
* @event Client#threadUpdate | ||
* @param {ThreadChannel} oldThread The thread before the update | ||
* @param {ThreadChannel} newThread The thread after the update | ||
*/ | ||
client.emit(Events.THREAD_UPDATE, old, updated); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.