• This repository has been archived on 07/Feb/2023
  • Stars
    star
    157
  • Rank 238,399 (Top 5 %)
  • Language
    Elixir
  • License
    MIT License
  • Created almost 8 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A discord library for Elixir

Alchemy

A Discord library / framework for Elixir.

This library aims to provide a solid foundation, upon which to build a simple, yet powerful interface. Unlike other libraries, this one comes along with a framework for defining commands, and event hooks. No need to mess around with consumers, or handlers, defining a command is as simple as defining a function!

Installation

Simply add Alchemy to your dependencies in your mix.exs file:

def deps do
  [{:alchemy, "~> 0.7.0", hex: :discord_alchemy}]
end

Docs

This is the stable documentation for the library, I highly recommend going through it, as most of the relevant information resides there.

QuickStart

Run mix alchemy.init to generate a template bot file for your project.

Getting Started

The first thing we need to do is define some kind of application for our bot. Thankfully, the Application module encapsulates this need.

defmodule MyBot do
  use Application
  alias Alchemy.Client


  defmodule Commands do
    use Alchemy.Cogs

    Cogs.def ping do
      Cogs.say "pong!"
    end
  end


  def start(_type, _args) do
    run = Client.start("your token here")
    use Commands
    run
  end
end

So we defined what we call a Cog in the Commands module, a cog is simply a module that contains commands. To wire up this command into the bot, we need to use the module, which we do after starting the client. We need to provide a valid return type in start/2, which is why we capture the result of Client.start in a variable.

Now all we need to do to wire up this application, is to add it to our mix.exs:

def application do
  [mod: {MyBot, []}]
end

This makes our bot automatically start when we run our project. Now, to run this project, we have 2 options:

  • use mix run --no-halt (the flags being necessary to prevent the app from ending once our start/2 function finishes)
  • or use iex -S mix to start our application in the repl.

Starting the application in the repl is very advantageous, as it allows you to interact with the bot live.

Using Voice

Alchemy also supports using Discord's Voice API to play audio. We rely on ffmpeg for audio encoding, as well as youtube-dl for streaming audio from sites. Before the Voice API can be used, you'll need to acquire the latest versions of those from their sites (make sure you get ffmpeg with opus support), and then configure the path to those executables in alchemy like so:

# in config.exs
config :alchemy,
  ffmpeg_path: "path/to/ffmpeg",
  youtube_dl_path: "path/to/youtube_dl"

Now you're all set to start playing some audio!

The first step is to connect to a voice channel with Alchemy.Voice.join/2, then, you can start playing audio with Alchemy.Voice.play_file/2, or Alchemy.Voice.play_url/2. Here's an example command to show off these features:

Cogs.def play(url) do
  {:ok, guild} = Cogs.guild()
  default_voice_channel = Enum.find(guild.channels, &match?(%{type: 2}, &1))
  # joins the default channel for this guild
  # this will check if a connection already exists for you
  Alchemy.Voice.join(guild.id, default_voice_channel.id)
  Alchemy.Voice.play_url(guild.id, url)
  Cogs.say "Now playing #{url}"
end

Porcelain

Alchemy uses Porcelain, to help with managing external processes, to help save on memory usage, you may want to use the goon driver, as suggested by Porcelain. For more information, check out their GitHub.

Other Examples

If you'd like to see a larger example of a bot using Alchemy, checkout out Viviani.

More Repositories

1

haskell-in-haskell

Trying to write an understandable implementation of Haskell, in Haskell
Haskell
119
star
2

haze

A bittorrent client, for learning purposes
Haskell
106
star
3

saferith

Constant time big numbers for Go
Go
97
star
4

cait-sith

Threshold ECDSA via Triples
Rust
72
star
5

seed-split

Splitting seed phrases into shares
Rust
63
star
6

boo-hoo

An implementation of ZKBoo
Rust
33
star
7

yao-gc

A basic implementation of Yao's Garbled Circuits
Rust
30
star
8

ludus

A pluggable NES emulator
Rust
29
star
9

multiset-hash

A small crate for hashing multi sets
Rust
14
star
10

magikitten

Easy Fiat-Shamirization using Meow
Rust
13
star
11

meow

Rust
13
star
12

deevee

Designatived verifier Schnorr signatures
Rust
13
star
13

poline

Tiny language with green threads
Rust
10
star
14

persistent-ts

Persistent data structures for Typescript
TypeScript
9
star
15

nimotsu

Rolling some crypto for PGP-esque public key message sending
Rust
9
star
16

kyokusen

Elliptic Curves for Cryptography
Go
9
star
17

viviani

Elixir
8
star
18

cauchy

A hardware accelerated complex function plotter
Rust
7
star
19

bittrickle

UDP bittorrent tracker
Rust
7
star
20

Rem-Boo

Fast ZK proofs over boolean circuits with RAM
Rust
6
star
21

ginkou

Japanese sentence bank program. Add and find sentences for language learning.
Rust
6
star
22

nuntius

Having fun making an E2E messaging app
Go
6
star
23

serve-csv

Create a web API from static csv files
Go
5
star
24

raymarch

Rust
5
star
25

populate

Populate a music library based on a descriptive file
Haskell
5
star
26

hax

A bullet hell game in haskell
Haskell
4
star
27

arbor

A rusty replacement for the `tree` command
Rust
4
star
28

nicer-mecab

Japanese morphological analysis. Wrapper over mecab.
Rust
4
star
29

polka

A C compiler, using the most advanced version of Scala
Scala
4
star
30

eddo

Playing around with Ed25519 signatures
Rust
4
star
31

Advent-2018

Haskell
4
star
32

ovis

Simple functional programming language
Rust
4
star
33

chika

A low level procedural language, compiling to assembly
Rust
4
star
34

iku

WIP programming language
Rust
3
star
35

typhoon

A decent bittorrent library and program
Rust
3
star
36

advent

Advent of code solutions
Haskell
3
star
37

ludus-emu

An NES emulator using the ludus crate
Rust
3
star
38

haisou-chan

A library for simulating network delays
Rust
3
star
39

modular-protocol-security-paper

TeX
3
star
40

peerbin

Peer based code sharing site
JavaScript
3
star
41

strix

Rust
2
star
42

alchaline

Elixir
2
star
43

delay-coin

Playing around with a cryptocurrency based on verifiable delay functions.
Rust
2
star
44

Kirbot-1.5

A simple discord bot, written in python
Python
2
star
45

dex

Pokedex viewing app
JavaScript
2
star
46

talks

TypeScript
2
star
47

sally

Learning how to make a basic shell in C
C
2
star
48

mpc-for-group-reconstruction-circuits

TeX
2
star
49

butterfly-test

Testing an algorithm for creating routing networks from permutations
Jupyter Notebook
2
star
50

big-boo

Experimenting with fast symmetric ZK proofs of knowledge
Rust
2
star
51

katex-playground

Play around with katex in your browser!
TypeScript
2
star
52

toy-stark

A toy implementation of the STARK protocol
Rust
2
star
53

wordle

Playing around with the infamous word game hit of 2022
Rust
2
star
54

mariner

An experiment in ZK circuit DSLs
Rust
2
star
55

omocha

A toy blockchain
Rust
2
star
56

solopong

A simple pong game
TypeScript
1
star
57

lambdabot

Elixir
1
star
58

chess

TypeScript
1
star
59

conway

Playing around with Conway's game of life
Haskell
1
star
60

alg-intro-exercises

C++
1
star
61

ripple

Decentralised IRC-like service
Go
1
star
62

huffman-rs

An implementation of Huffman coding
Rust
1
star
63

ludus-web

Seeing if I can get my NES emulator to work through WASM
HTML
1
star
64

micro-ecs

A small ecs framework for TypeScript
TypeScript
1
star
65

CSES

Solutions to https://cses.fi/problemset/
C++
1
star
66

musync

Configuration based music syncing
Go
1
star
67

srhub

Elixir
1
star
68

aldash

Elixir
1
star
69

on-security-against-time-traveling-adversaries

TeX
1
star
70

bridger

Elixir
1
star
71

kirbot

Elixir
1
star
72

hirch

Haskell
1
star
73

web-craft

WebGL voxel game
TypeScript
1
star
74

reg-viz

Visualizing Regular Expressions
Haskell
1
star
75

disco-old

Haskell
1
star
76

advent-2022

Rust
1
star
77

scroll

Little dungeon crawler
TypeScript
1
star
78

parcel-ts-react-demo

An example of using Typescript & React with Parcel
TypeScript
1
star
79

wahlbergdown

Silly language for the https://github.com/langjam/jam0001
Rust
1
star
80

cici

A self-hosting C compiler
C
1
star
81

ck-dodo

Double odd curve(s)
Rust
1
star