-
-
Save joepie91/1e544a86334c7a1ecf0d8a0f70d04772 to your computer and use it in GitHub Desktop.
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
"use strict"; | |
const dm = require("node-data-modeling"); | |
module.exports = function (registry) { | |
const clientTypes = require("../../../types")(registry); | |
let ModeCharacter = registry.createType("IRCModeCharacter", dm.string({ | |
matches: /^[a-z]$/i | |
})); | |
let User = registry.createType("IRCUser", { | |
nickname: dm.string(), | |
username: dm.string(), | |
realname: dm.string(), | |
hostname: dm.string(), | |
joinedChannels: dm.setOf(registry.type("IRCChannel")) | |
}).implements(clientTypes.User, { | |
getIdentifier: dm.guard([], dm.string(), function () { | |
/* FIXME: Include server name in this? */ | |
return this.nickname; | |
}), | |
getDisplayName: dm.guard([], dm.string(), function () { | |
return this.nickname; | |
}), | |
getUsername: dm.guard([], dm.string(), function () { | |
return this.nickname; | |
}) | |
}); | |
let Channel = registry.createType("IRCChannel", { | |
name: dm.string(), | |
users: dm.setOf(registry.type("IRCUser")), | |
topic: dm.string().optional(), | |
eventUserJoined: dm.guard( | |
[registry.type("IRCUser")], | |
dm.nothing(), | |
function (user) { | |
this.users.add(user); | |
user.joinedChannels.add(this); | |
} | |
), | |
eventUserLeft: dm.guard( | |
[registry.type("IRCUser")], | |
dm.nothing(), | |
function (user) { | |
this.users.remove(user); | |
user.joinedChannels.delete(this); | |
} | |
), | |
eventUserQuit: dm.guard( | |
[registry.type("IRCUser")], | |
dm.nothing(), | |
function (user) { | |
this.users.remove(user); | |
user.joinedChannels.delete(this); | |
} | |
), | |
eventUserList: dm.guard( | |
[dm.setOf(registry.type("IRCUser"))], | |
dm.nothing(), | |
function (users) { | |
for (let user of this.users) { | |
user.joinedChannels.delete(this); | |
} | |
this.users = users; | |
for (let user of users) { | |
user.joinedChannels.add(this); | |
} | |
} | |
) | |
}).implements(clientTypes.Room, { | |
getIdentifier: dm.guard([], dm.string(), function () { | |
return this.name; | |
}), | |
getDisplayName: dm.guard([], dm.string(), function () { | |
return this.name | |
}), | |
getTopic: dm.guard([], dm.string(), function () { | |
return this.topic | |
}) | |
}); | |
let Role = registry.createTrait("IRCRole", { | |
mode: ModeCharacter | |
}); | |
let Operator = registry.createType("IRCOperator", { | |
// nothing | |
}).implements(Role, { | |
mode: "o" | |
}).implements(clientTypes.AdminRole, { | |
description: "Channel operator" | |
}); | |
let HalfOperator = registry.createType("IRCHalfOperator", { | |
// nothing | |
}).implements(Role, { | |
mode: "h" | |
}).implements(clientTypes.ModeratorRole, { | |
description: "Half-operator" | |
}); | |
let Voiced = registry.createType("IRCVoiced", { | |
// nothing | |
}).implements(Role, { | |
mode: "v" | |
}).implements(clientTypes.VoicedRole, { | |
description: "Voiced" | |
}); | |
let Presence = registry.createType("IRCPresence", { | |
user: User, | |
channel: Channel, | |
roles: Role | |
}); | |
return { | |
User, | |
Channel, | |
Role, | |
Operator, | |
HalfOperator, | |
Voiced, | |
ModeCharacter | |
}; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment