chore(chat): create more chats/messages + set membership

This commit is contained in:
João Paulo Dubas 2025-01-27 23:10:17 +00:00
parent bc4480ef91
commit 37569de266
Signed by: joao.dubas
SSH Key Fingerprint: SHA256:V1mixgOGRc/YMhGx/DNkOSmJxgA2vHNrDZEk3wt/kOA

View File

@ -13,6 +13,7 @@
alias Slax.Accounts
alias Slax.Chat.Message
alias Slax.Chat.Room
alias Slax.Chat.RoomMembership
alias Slax.Repo
names = [
@ -20,6 +21,7 @@ names = [
"Boromir",
"Elrond",
"Frodo",
"Gandalf",
"Gimli",
"Legolas"
]
@ -31,13 +33,19 @@ for name <- names do
Accounts.register_user(%{email: email, password: pw, password_confirmation: pw})
end
elrond = Accounts.get_user_by_email("elrond@fellowship.me")
aragorn = Accounts.get_user_by_email("aragorn@fellowship.me")
boromir = Accounts.get_user_by_email("boromir@fellowship.me")
elrond = Accounts.get_user_by_email("elrond@fellowship.me")
frodo = Accounts.get_user_by_email("frodo@fellowship.me")
gandalf = Accounts.get_user_by_email("gandalf@fellowship.me")
gimli = Accounts.get_user_by_email("gimli@fellowship.me")
legolas = Accounts.get_user_by_email("legolas@fellowship.me")
room = Repo.insert!(%Room{name: "council-of-elrond", topic: "What to do with this ring?"})
for {user, message} <- [
rooms_and_messages = [
# Council of Elrond Room
%{
room: %{name: "council-of-elrond", topic: "What to do with this ring?"},
messages: [
{elrond,
"Strangers from distant lands, friends of old. You have beehn summoned here to answer the threat of Mordor. Middle-Earth stands upon the brink of destruction. None can escape it. You will unite or you will fall. Each race is bound to this fate - this one doom."},
{elrond, "Bring forth the Ring, Frodo."},
@ -47,6 +55,52 @@ for {user, message} <- [
{aragorn,
"You cannot yield! None of us can. The One Ring answers to Sauron alone. It has no other master."},
{boromir, "And what would a ranger know of this matter?"}
] do
Repo.insert(%Message{user: user, room: room, body: message})
]
},
# The Shire Room
%{
room: %{name: "the-shire", topic: "A peaceful place for hobbits"},
messages: [
{frodo, "What news of the outside world? Tell me everything!"},
{gandalf, "What can I tell you? Life in the wide world goes on much as it has this past Age..."},
{gandalf, "Full of its own comings and goings, scarcely aware of the existence of Hobbits..."},
{frodo, "You're late!"},
{gandalf, "A wizard is never late, Frodo Baggins. Nor is he early. He arrives precisely when he means to."}
]
},
# Moria Room
%{
room: %{name: "mines-of-moria", topic: "Speak friend and enter"},
messages: [
{gandalf, "The walls of Moria... Dwarf doors are invisible when closed."},
{gimli, "Their own masters cannot find them if their secrets are forgotten!"},
{gandalf, "Let's see... Ithildin. It mirrors only starlight and moonlight."},
{frodo, "What does the writing say?"},
{gandalf, "It reads 'The Doors of Durin, Lord of Moria. Speak, friend, and enter.'"},
{legolas, "I do not feel comfortable in here. This is no mine, it's a tomb!"}
]
},
# Helm's Deep Room
%{
room: %{name: "helms-deep", topic: "The fortress of Rohan"},
messages: [
{aragorn, "By nightfall these hills will be swarming with Orcs!"},
{legolas, "This is no rabble of mindless Orcs. These are Uruk-hai."},
{gimli, "Whatever luck you live by, let's hope it lasts the night."},
{legolas, "Your friends are with you, Aragorn."},
{gimli, "Let them come! There is one Dwarf yet in Moria who still draws breath!"}
]
}
]
for %{room: room, messages: messages} <- rooms_and_messages do
room = Room |> struct(room) |> Repo.insert!()
users =
for {user, message} <- messages do
Repo.insert!(%Message{user: user, room: room, body: message})
user
end
for user <- MapSet.new(users) do
Repo.insert!(%RoomMembership{user: user, room: room})
end
end