Skip to content
This repository has been archived by the owner on May 15, 2023. It is now read-only.

Commit

Permalink
^^
Browse files Browse the repository at this point in the history
  • Loading branch information
vKxni committed Jul 5, 2022
0 parents commit 9a88505
Show file tree
Hide file tree
Showing 12 changed files with 177 additions and 0 deletions.
1 change: 1 addition & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
BOT_TOKEN=
4 changes: 4 additions & 0 deletions .formatter.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Used by "mix format"
[
inputs: ["{mix,.formatter}.exs", "{config,lib,test}/**/*.{ex,exs}"]
]
29 changes: 29 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# The directory Mix will write compiled artifacts to.
/_build/

# If you run "mix test --cover", coverage assets end up here.
/cover/

# The directory Mix downloads your dependencies sources to.
/deps/

# Where third-party dependencies like ExDoc output generated docs.
/doc/

# Ignore .fetch files in case you like to edit your project deps locally.
/.fetch

# If the VM crashes, it generates a dump, let's ignore it too.
erl_crash.dump

# Also ignore archive artifacts (built via "mix archive.build").
*.ez

# Ignore package tarball (built via "mix hex.build").
excrypt-*.tar

# Temporary files, for example, from tests.
/tmp/

# config files
.env
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Kefir
The Telegram integrations from Quendl.


## Get started
- Create an account [here at Telegram](https://web.telegram.org/k/)
- DM BotFather and run `/newbot`
Follow the instructions ...

- Copy the bot token, rename `.env.example` to `.env` and paste the bot token into it.

9 changes: 9 additions & 0 deletions lib/config/runtime.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import Config

if Config.config_env() == :dev do
DotenvParser.load_file(".env")
end

# Now variables from `.env` are loaded into system env
config :excrypt,
bot_token: System.fetch_env!("BOT_TOKEN")
5 changes: 5 additions & 0 deletions lib/excrypt.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
defmodule Excrypt do
def hello do
:world
end
end
20 changes: 20 additions & 0 deletions lib/excrypt/application.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
defmodule Excrypt.Application do
@moduledoc false

use Application

@impl true
def start(_type, _args) do
# fetch the bot token from the application
bot_token = Application.get_env(:excrypt, :bot_token)

children = [
ExGram,
{Excrypt.Bot, [method: :polling, token: bot_token]}
# ^ you could also replace this with "the bot token ..."
]

opts = [strategy: :one_for_one, name: Excrypt.Supervisor]
Supervisor.start_link(children, opts)
end
end
43 changes: 43 additions & 0 deletions lib/excrypt/bot.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
defmodule Excrypt.Bot do
@bot :excrypt

use ExGram.Bot,
name: @bot,
setup_commands: true

# commands of the bot
command("start")
command("help", description: "Print the bot's help")
command("github", description: "Returns the GitHub link")

# middleware integration
middleware(ExGram.Middleware.IgnoreUsername)

@spec bot :: :excrypt
def bot(), do: @bot

# bot commands
def handle({:command, :start, _msg}, context) do
answer(context, "Hello there! I am the Telegram integration for Quendl.")
end

def handle({:command, :github, _msg}, context) do
answer(context, "Here is your link: https://github.com/quendl/kefir")
end

# main command
def handle({:command, :help, _msg}, context) do
answer(context, get_help())
end

# This can be used to avoid hard coded answer contexts
# Tho I would only use this if the answer is longer than one line.
def get_help() do
"""
This bot has the following commands
/start - starts the bot with an introduction
/help - sends the help menu
/github - returns the github link
"""
end
end
31 changes: 31 additions & 0 deletions mix.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
defmodule Excrypt.MixProject do
use Mix.Project

def project do
[
app: :excrypt,
version: "0.1.0",
elixir: "~> 1.13",
start_permanent: Mix.env() == :prod,
deps: deps()
]
end

# Run "mix help compile.app" to learn about applications.
def application do
[
extra_applications: [:logger],
mod: {Excrypt.Application, []}
]
end

# Run "mix help deps" to learn about dependencies.
defp deps do
[
{:ex_gram, "~> 0.26"},
{:hackney, "~> 1.12"},
{:jason, ">= 1.0.0"},
{:dotenv_parser, "~> 2.0"}
]
end
end
15 changes: 15 additions & 0 deletions mix.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
%{
"certifi": {:hex, :certifi, "2.9.0", "6f2a475689dd47f19fb74334859d460a2dc4e3252a3324bd2111b8f0429e7e21", [:rebar3], [], "hexpm", "266da46bdb06d6c6d35fde799bcb28d36d985d424ad7c08b5bb48f5b5cdd4641"},
"dotenv_parser": {:hex, :dotenv_parser, "2.0.0", "0f999196857e4ee18cbba1413018d5e4980ab16b397e3a2f8d0cf541fe683181", [:mix], [], "hexpm", "e769bde2dbff5b0cd0d9d877a9ccfd2c6dd84772dfb405d5a43cceb4f93616c5"},
"ex_gram": {:hex, :ex_gram, "0.26.0", "4821e0a615c279052c77153ea6bf1ad43d5fe6ca02d4a5729e95c3140e826e4d", [:mix], [{:gun, "~> 1.3", [hex: :gun, repo: "hexpm", optional: true]}, {:hackney, "~> 1.12", [hex: :hackney, repo: "hexpm", optional: true]}, {:jason, ">= 1.0.0", [hex: :jason, repo: "hexpm", optional: true]}, {:maxwell, "~> 2.3.1", [hex: :maxwell, repo: "hexpm", optional: true]}, {:poison, ">= 1.0.0", [hex: :poison, repo: "hexpm", optional: true]}, {:tesla, "~> 1.2", [hex: :tesla, repo: "hexpm", optional: true]}], "hexpm", "1f07d0a4f51b0c910972c6aa0e28c39cc358c3743fca03671b0d86eafe17b4d1"},
"hackney": {:hex, :hackney, "1.18.1", "f48bf88f521f2a229fc7bae88cf4f85adc9cd9bcf23b5dc8eb6a1788c662c4f6", [:rebar3], [{:certifi, "~>2.9.0", [hex: :certifi, repo: "hexpm", optional: false]}, {:idna, "~>6.1.0", [hex: :idna, repo: "hexpm", optional: false]}, {:metrics, "~>1.0.0", [hex: :metrics, repo: "hexpm", optional: false]}, {:mimerl, "~>1.1", [hex: :mimerl, repo: "hexpm", optional: false]}, {:parse_trans, "3.3.1", [hex: :parse_trans, repo: "hexpm", optional: false]}, {:ssl_verify_fun, "~>1.1.0", [hex: :ssl_verify_fun, repo: "hexpm", optional: false]}, {:unicode_util_compat, "~>0.7.0", [hex: :unicode_util_compat, repo: "hexpm", optional: false]}], "hexpm", "a4ecdaff44297e9b5894ae499e9a070ea1888c84afdd1fd9b7b2bc384950128e"},
"idna": {:hex, :idna, "6.1.1", "8a63070e9f7d0c62eb9d9fcb360a7de382448200fbbd1b106cc96d3d8099df8d", [:rebar3], [{:unicode_util_compat, "~>0.7.0", [hex: :unicode_util_compat, repo: "hexpm", optional: false]}], "hexpm", "92376eb7894412ed19ac475e4a86f7b413c1b9fbb5bd16dccd57934157944cea"},
"jason": {:hex, :jason, "1.3.0", "fa6b82a934feb176263ad2df0dbd91bf633d4a46ebfdffea0c8ae82953714946", [:mix], [{:decimal, "~> 1.0 or ~> 2.0", [hex: :decimal, repo: "hexpm", optional: true]}], "hexpm", "53fc1f51255390e0ec7e50f9cb41e751c260d065dcba2bf0d08dc51a4002c2ac"},
"metrics": {:hex, :metrics, "1.0.1", "25f094dea2cda98213cecc3aeff09e940299d950904393b2a29d191c346a8486", [:rebar3], [], "hexpm", "69b09adddc4f74a40716ae54d140f93beb0fb8978d8636eaded0c31b6f099f16"},
"mime": {:hex, :mime, "2.0.2", "0b9e1a4c840eafb68d820b0e2158ef5c49385d17fb36855ac6e7e087d4b1dcc5", [:mix], [], "hexpm", "e6a3f76b4c277739e36c2e21a2c640778ba4c3846189d5ab19f97f126df5f9b7"},
"mimerl": {:hex, :mimerl, "1.2.0", "67e2d3f571088d5cfd3e550c383094b47159f3eee8ffa08e64106cdf5e981be3", [:rebar3], [], "hexpm", "f278585650aa581986264638ebf698f8bb19df297f66ad91b18910dfc6e19323"},
"parse_trans": {:hex, :parse_trans, "3.3.1", "16328ab840cc09919bd10dab29e431da3af9e9e7e7e6f0089dd5a2d2820011d8", [:rebar3], [], "hexpm", "07cd9577885f56362d414e8c4c4e6bdf10d43a8767abb92d24cbe8b24c54888b"},
"ssl_verify_fun": {:hex, :ssl_verify_fun, "1.1.6", "cf344f5692c82d2cd7554f5ec8fd961548d4fd09e7d22f5b62482e5aeaebd4b0", [:make, :mix, :rebar3], [], "hexpm", "bdb0d2471f453c88ff3908e7686f86f9be327d065cc1ec16fa4540197ea04680"},
"tesla": {:hex, :tesla, "1.4.4", "bb89aa0c9745190930366f6a2ac612cdf2d0e4d7fff449861baa7875afd797b2", [:mix], [{:castore, "~> 0.1", [hex: :castore, repo: "hexpm", optional: true]}, {:exjsx, ">= 3.0.0", [hex: :exjsx, repo: "hexpm", optional: true]}, {:finch, "~> 0.3", [hex: :finch, repo: "hexpm", optional: true]}, {:fuse, "~> 2.4", [hex: :fuse, repo: "hexpm", optional: true]}, {:gun, "~> 1.3", [hex: :gun, repo: "hexpm", optional: true]}, {:hackney, "~> 1.6", [hex: :hackney, repo: "hexpm", optional: true]}, {:ibrowse, "4.4.0", [hex: :ibrowse, repo: "hexpm", optional: true]}, {:jason, ">= 1.0.0", [hex: :jason, repo: "hexpm", optional: true]}, {:mime, "~> 1.0 or ~> 2.0", [hex: :mime, repo: "hexpm", optional: false]}, {:mint, "~> 1.0", [hex: :mint, repo: "hexpm", optional: true]}, {:poison, ">= 1.0.0", [hex: :poison, repo: "hexpm", optional: true]}, {:telemetry, "~> 0.4 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: true]}], "hexpm", "d5503a49f9dec1b287567ea8712d085947e247cb11b06bc54adb05bfde466457"},
"unicode_util_compat": {:hex, :unicode_util_compat, "0.7.0", "bc84380c9ab48177092f43ac89e4dfa2c6d62b40b8bd132b1059ecc7232f9a78", [:rebar3], [], "hexpm", "25eee6d67df61960cf6a794239566599b09e17e668d3700247bc498638152521"},
}
8 changes: 8 additions & 0 deletions test/excrypt_test.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
defmodule ExcryptTest do
use ExUnit.Case
doctest Excrypt

test "greets the world" do
assert Excrypt.hello() == :world
end
end
1 change: 1 addition & 0 deletions test/test_helper.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ExUnit.start()

0 comments on commit 9a88505

Please sign in to comment.