Following last year’s article on Slack, here is how to create a bot for Discord. We will go through a minimalist bot that does close to nothing. Most of the provided examples using libraries like discord.py hide asyncio away. Here we will make it explicit how it works under the hood. Be aware that this is not the easiest way to build a bot but a step-stone to understand what complete libraries do for you.
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
bcmail-jdk15on-1.55.jar | |
bcpkix-jdk15on-1.55.jar | |
bcprov-jdk15on-1.55.jar | |
commons-beanutils-1.8.0.jar | |
commons-codec-1.10.jar | |
commons-collections-3.2.2.jar | |
commons-csv-1.3.jar | |
commons-digester-1.7.jar | |
commons-lang-2.6.jar | |
commons-logging-1.1.1.jar |
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
import subprocess | |
with open("foo.py.gz", "wb") as f: | |
q = subprocess.Popen(["gzip"], stdout=f, stdin=subprocess.PIPE) | |
p = subprocess.Popen(["more", "foo.py"], stdout=q.stdin) | |
q.communicate() | |
p.wait() |
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
package main | |
import ( | |
"context" | |
"fmt" | |
"net/http" | |
"time" | |
) | |
func test(a, b, c int) { |
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
-- read metadata file into string | |
local metafile = io.open('metadata.yaml', 'r') | |
local content = metafile:read("*a") | |
metafile:close() | |
-- new elements | |
local before = pandoc.RawInline('tex', '\\begin{otherlanguage}{english}') | |
local after = pandoc.RawInline('tex', '\\end{otherlanguage}') |
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
#!/usr/bin/env python3 | |
""" | |
Convert the CodeBlock into english text. Very useful if the base language adds | |
some special magic rules which are altering the context. E.g. french puts a | |
space before the colon (:). | |
:: | |
$ pandoc \ | |
--filter ./code-block-in-english.py \ | |
... |
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
package main | |
import ( | |
"fmt" | |
"gopkg.in/h2non/bimg.v1" | |
"os" | |
"runtime" | |
"strconv" | |
"sync" | |
) |
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
import java.io.BufferedReader; | |
import java.io.IOException; | |
import java.io.InputStreamReader; | |
import java.io.PrintWriter; | |
import java.net.DatagramPacket; | |
import java.net.DatagramSocket; | |
import java.net.ServerSocket; | |
import java.net.Socket; | |
import java.util.concurrent.ExecutorService; | |
import java.util.concurrent.Executors; |
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
$ hug -f light.py | |
/#######################################################################\ | |
`.----``..-------..``.----. | |
:/:::::--:---------:--::::://. | |
.+::::----##/-/oo+:-##----::::// | |
`//::-------/oosoo-------::://. ## ## ## ## ##### | |
.-:------./++o/o-.------::-` ``` ## ## ## ## ## | |
`----.-./+o+:..----. `.:///. ######## ## ## ## | |
``` `----.-::::::------ `.-:::://. ## ## ## ## ## #### | |
://::--.``` -:``...-----...` `:--::::::-.` ## ## ## ## ## ## |
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
package ch.hearc.airport; | |
import java.util.HashMap; | |
import java.util.concurrent.ArrayBlockingQueue; | |
public class Main { | |
static String[] codePlane = { "3B147", "B3291", "6B239", "B1086", "780B4", | |
"32A64", "17A69", "2A431", "647B8", "349A8", "536B8", "9103A", | |
"9B210", "139A4", "96B01", "207B9", "830B6", "8435A", "7301B", |