diff options
Diffstat (limited to 'lib/telegram')
-rw-r--r-- | lib/telegram/room.ex | 8 | ||||
-rw-r--r-- | lib/telegram/telegram.ex | 22 |
2 files changed, 15 insertions, 15 deletions
diff --git a/lib/telegram/room.ex b/lib/telegram/room.ex index 49fc06d..cc10e90 100644 --- a/lib/telegram/room.ex +++ b/lib/telegram/room.ex @@ -72,7 +72,7 @@ defmodule Nola.TelegramRoom do end defp find_or_create_meta_account(from = %{"id" => user_id}, state) do - if account = IRC.Account.find_meta_account("telegram-id", user_id) do + if account = Nola.Account.find_meta_account("telegram-id", user_id) do account else first_name = Map.get(from, "first_name") @@ -84,9 +84,9 @@ defmodule Nola.TelegramRoom do username = Map.get(from, "username", first_name) account = username - |> IRC.Account.new_account() - |> IRC.Account.update_account_name(name) - |> IRC.Account.put_meta("telegram-id", user_id) + |> Nola.Account.new_account() + |> Nola.Account.update_account_name(name) + |> Nola.Account.put_meta("telegram-id", user_id) Logger.info("telegram_room: created account #{account.id} for telegram user #{user_id}") account diff --git a/lib/telegram/telegram.ex b/lib/telegram/telegram.ex index 1c6a9a9..a93f5bb 100644 --- a/lib/telegram/telegram.ex +++ b/lib/telegram/telegram.ex @@ -20,7 +20,7 @@ defmodule Nola.Telegram do end def init(chat_id) do Logger.info("Telegram session starting: #{chat_id}") - account = IRC.Account.find_meta_account("telegram-id", chat_id) + account = Nola.Account.find_meta_account("telegram-id", chat_id) account_id = if account, do: account.id {:ok, %{account: account_id}} end @@ -49,14 +49,14 @@ defmodule Nola.Telegram do # [%{"length" => 7, "offset" => 0, "type" => "bot_command"}], # "from" => %{"first_name" => "J", "id" => 2075406, "is_bot" => false, "language_code" => "en", "username" => "ahref"}, # "message_id" => 11, "text" => "/enable salope"}, "update_id" => 764148578} - account = IRC.Account.find_meta_account("telegram-validation-code", String.downcase(key)) + account = Nola.Account.find_meta_account("telegram-validation-code", String.downcase(key)) text = if account do - net = IRC.Account.get_meta(account, "telegram-validation-target") - IRC.Account.put_meta(account, "telegram-id", m["chat"]["id"]) - IRC.Account.put_meta(account, "telegram-username", m["chat"]["username"]) - IRC.Account.put_meta(account, "telegram-username", m["chat"]["username"]) - IRC.Account.delete_meta(account, "telegram-validation-code") - IRC.Account.delete_meta(account, "telegram-validation-target") + net = Nola.Account.get_meta(account, "telegram-validation-target") + Nola.Account.put_meta(account, "telegram-id", m["chat"]["id"]) + Nola.Account.put_meta(account, "telegram-username", m["chat"]["username"]) + Nola.Account.put_meta(account, "telegram-username", m["chat"]["username"]) + Nola.Account.delete_meta(account, "telegram-validation-code") + Nola.Account.delete_meta(account, "telegram-validation-target") IRC.Connection.broadcast_message(net, account, "Telegram #{m["chat"]["username"]} account added!") "Yay! Linked to account **#{account.name}**." else @@ -102,7 +102,7 @@ defmodule Nola.Telegram do #end def handle_update(%{"callback_query" => cb = %{"data" => "start-upload:"<>target, "id" => id, "message" => m = %{"message_id" => m_id, "chat" => %{"id" => chat_id}, "reply_to_message" => op}}}, t, state) do - account = IRC.Account.find_meta_account("telegram-id", chat_id) + account = Nola.Account.find_meta_account("telegram-id", chat_id) if account do target = case String.split(target, "/") do ["everywhere"] -> IRC.Membership.of_account(account) @@ -162,7 +162,7 @@ defmodule Nola.Telegram do end def handle_update(%{"message" => m = %{"chat" => %{"id" => id, "type" => "private"}, "text" => text}}, _, state) do - account = IRC.Account.find_meta_account("telegram-id", id) + account = Nola.Account.find_meta_account("telegram-id", id) if account do as_irc_message(id, text, account) end @@ -212,7 +212,7 @@ defmodule Nola.Telegram do end defp start_upload(_type, %{"message" => m = %{"chat" => %{"id" => id, "type" => "private"}}}, token, state) do - account = IRC.Account.find_meta_account("telegram-id", id) + account = Nola.Account.find_meta_account("telegram-id", id) if account do text = if(m["text"], do: m["text"], else: nil) targets = IRC.Membership.of_account(account) |