Skip to content

Instantly share code, notes, and snippets.

@Ismael-VC
Created August 17, 2017 04:47
Show Gist options
  • Save Ismael-VC/3fd6cf6beb64d19406087c2e276de49c to your computer and use it in GitHub Desktop.
Save Ismael-VC/3fd6cf6beb64d19406087c2e276de49c to your computer and use it in GitHub Desktop.
PyCall Julia Discord bot.
#!/usr/bin/env julia
module JuliaTanBot
export julia_tan
using PyCall
@pyimport textwrap
@pyimport discord.ext.commands as discord
function julia_tan()
dd = tw.dedent
bot = discord.Bot(command_prefix = "j", description = description)
separador = "#" ^ 80
patron = r"""
^
(
\s* |
\s*`\s* |
\s*```\s+ |
\s*```julia\s+
)
(
.*?
)
(
\s*
\s*`\s* |
\s*```\s* |
)
$
"""sx
py"""
@$bot.event
async def on_ready():
print($dd(
'''
{0}
Julia-tan JuliaLangEs Discord bot.
BOT NAME: {1}
BOT ID : {2}
{0}
'''.format(
$separator,
$bot.user.name,
$bot.user.id
)
))
"""
py"""
@$bot.command()
async def l(*, entrada: str):
match = $match
eval = $eval
parse = $parse
comando = match($patron, entrada).captures[1]
resultado = eval(parse(comando))
await $bot.say($dd(
'''
```julia
julia> {0}
{1}
```
'''.format(comando, resultado)
))
"""
bot[:run](ENV["DISCORD_BOT_TOKEN"])
end
end # module
using JuliaTanBot
julia_tan()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment