forked from neomatrixcode/Julia-tan
-
Notifications
You must be signed in to change notification settings - Fork 0
/
julia_tan.jl
87 lines (69 loc) · 1.86 KB
/
julia_tan.jl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#!/usr/bin/env julia
module JuliaTanBot
export julia_tan
using PyCall
using Suppressor
@pyimport textwrap
@pyimport discord.ext.commands as discord
function julia_tan()
dd = textwrap.dedent
bot = discord.Bot(command_prefix = "j", description = "bot julia tan")
separador = "#" ^ 80
py"""
import re
patron = \"^(\s*|\s*`\s* |\s*```\s+|\s*```julia\s+)(.*?)(\s*\s*`\s*|\s*```\s* |)$\"
"""
py"""
@$bot.event
async def on_ready():
print($dd(
'''
{0}
Julia-tan JuliaLangEs Discord bot.
BOT NAME: {1}
BOT ID : {2}
{0}
'''.format(
$separador,
$bot.user.name,
$bot.user.id
)
))
"""
py"""
@$bot.command()
async def l(*, entrada: str):
n= entrada.count("@show")
eval = $eval
parse = $parse
entrada= entrada.replace(\"\n\", \";\")
comando = re.match(patron, entrada)
print(\"Entrada: \",entrada)
print(\"Comando: \",comando)
if (comando!=None):
comando=comando.group(0)
if (n==0):
resultado = eval(parse(comando))
else:
resultado = eval(parse("@capture_out begin "+comando+" end;"))
else:
if (n==0):
resultado = eval(parse(entrada))
else:
resultado = eval(parse("@capture_out begin "+entrada+" end;"))
comando= comando.replace(\";\", \"\n julia> \")
print(\"Resultado: \",resultado)
await $bot.say($dd(
'''
```julia
julia> {0}
{1}
```
'''.format(comando, resultado)
))
"""
bot[:run](ENV["DISCORD_BOT_TOKEN"])
end
end # module
using JuliaTanBot
julia_tan()