Packages
telegex
1.2.2
1.9.0-rc.0
1.8.0
1.7.0
1.6.0
1.5.0
1.4.2
1.4.1
1.4.0
1.3.2
1.3.1
1.3.0
1.2.3-dev
1.2.2
1.2.1
1.2.0
1.1.1
1.1.0
1.0.1
1.0.0
1.0.0-rc.10
1.0.0-rc.9
1.0.0-rc.8
1.0.0-rc.7
1.0.0-rc.6
1.0.0-rc.5
1.0.0-rc.4
1.0.0-rc.3
1.0.0-rc.2
1.0.0-rc.1
1.0.0-rc.0
0.1.10
0.1.9
0.1.8
0.1.7
0.1.6
0.1.5
0.1.4
0.1.3
0.1.2
0.1.1
0.1.0
0.1.0-rc.11
0.1.0-rc.10
0.1.0-rc.9
0.1.0-rc.8
0.1.0-rc.7
0.1.0-rc.6
0.1.0-rc.5
0.1.0-rc.4
0.1.0-rc.3
0.1.0-rc.2
0.1.0-rc.1
0.0.4
0.0.3
0.0.2
0.0.1
A Telegram bot framework, with its client-side based on data and code generation, boasts unparalleled adaptation speed and correctness for new versions.
Current section
Files
Jump to
Current section
Files
lib/telegex/instance.ex
defmodule Telegex.Instance do
@moduledoc """
Independent configuration and information for bot instances.
**Note: This module is not officially implemented at the moment, reserved for multi-instance support.**
"""
use GenServer
require Logger
def start_link(_) do
GenServer.start_link(__MODULE__, %{me: nil}, name: __MODULE__)
end
@spec token() :: String.t()
def token, do: Telegex.Global.token()
@impl true
def init(state) do
{:ok, state}
end
@spec get_me :: {:ok, Telegex.Type.User.t()} | {:error, Telegex.Type.error()}
def get_me do
GenServer.call(__MODULE__, :get_me, :infinity)
end
@spec me :: Telegex.Type.User.t()
def me do
GenServer.call(__MODULE__, :me)
end
@impl true
def handle_call(:get_me, _from, state) do
r = Telegex.get_me()
case r do
{:ok, bot} ->
{:reply, r, %{state | me: bot}}
{:error, _} ->
{:reply, r, state}
end
end
@impl true
def handle_call(:me, _from, %{me: bot} = state) do
{:reply, bot, state}
end
end