You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

32 lines
792 B

function Channel(name) {
this.name = name
this.userlist = []
this.join = function(user) {
let channel = this
this.userlist.push(user)
this.userlist.forEach(function(item) {
item.sendRaw(`:${user.nickname} JOIN ${channel.name}`)
})
}
this.part = function(user) {
let channel = this
let userIndex = this.userlist.indexOf(user)
if (userIndex >= 0) {
this.userlist.forEach(function(item) {
item.sendRaw(`:${user.nickname} PART ${channel.name}`)
})
this.userlist.splice(index, 1)
}
}
this.sendMsg = function(from, message) {
const channel = this
this.userlist.forEach(function(item) {
item.sendMsg(from, message, channel.name)
})
}
}
module.exports = Channel