-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #19 from Vrabbers/game-refactor
Game refactor
- Loading branch information
Showing
22 changed files
with
1,139 additions
and
851 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
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,53 @@ | ||
defmodule FfcEx.Broadcaster do | ||
alias FfcEx.ThumbnailCache | ||
alias FfcEx.DmCache | ||
|
||
def tell(user_id, message) do | ||
send_messages({:tell, user_id, message}, :no_author) | ||
end | ||
|
||
def broadcast_to(users, message) do | ||
send_messages({:broadcast_to, users, message}, :no_author) | ||
end | ||
|
||
def send_messages(messages, author_id) when is_list(messages) do | ||
Enum.each(messages, &send_messages(&1, author_id)) | ||
end | ||
|
||
def send_messages({:tell, uid, msg}, author_id) do | ||
Task.await(do_tell(uid, msg, author_id)) | ||
end | ||
|
||
def send_messages({:broadcast_to, uids, msg}, _author_id) do | ||
Task.await_many( | ||
for user_id <- uids do | ||
do_tell(user_id, msg) | ||
end | ||
) | ||
end | ||
|
||
defp do_tell(user_id, message, author_id) do | ||
id = | ||
if user_id == :author do | ||
author_id | ||
else | ||
user_id | ||
end | ||
|
||
Task.Supervisor.async(FfcEx.TaskSupervisor, fn -> do_send_to(id, message) end) | ||
end | ||
|
||
defp do_tell(user_id, message) do | ||
Task.Supervisor.async(FfcEx.TaskSupervisor, fn -> do_send_to(user_id, message) end) | ||
end | ||
|
||
defp do_send_to(user_id, message) do | ||
{:ok, channel} = DmCache.create(user_id) | ||
|
||
if Keyword.keyword?(message) do | ||
ThumbnailCache.send_with_thumbnail_caching!(channel, message) | ||
else | ||
Nostrum.Api.create_message!(channel, message) | ||
end | ||
end | ||
end |
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,13 @@ | ||
defmodule FfcEx.Format do | ||
def uname(uid) when is_integer(uid) do | ||
{:ok, user} = Nostrum.Api.get_user(uid) | ||
uname(user) | ||
end | ||
|
||
def uname(user) do | ||
case user.discriminator do | ||
"0" -> user.username | ||
x -> "#{user.username}\##{x}" | ||
end | ||
end | ||
end |
Oops, something went wrong.