Skip to content

Commit 8b107da

Browse files
committed
add zulip integration
1 parent 7033ce3 commit 8b107da

File tree

4 files changed

+34
-16
lines changed

4 files changed

+34
-16
lines changed

app.py

+11
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from flask import Flask, request, jsonify
22
from judge import runProcess
33
from flask_cors import CORS
4+
from bot import send_message
45

56
app = Flask('dexter')
67
CORS(app)
@@ -40,5 +41,15 @@ def interpret():
4041
return jsonify({'out': str(outBuf), 'err': str(errBuf)})
4142

4243

44+
@app.route('/zulip', methods=['POST'])
45+
def zulip():
46+
# email = request.form['email']
47+
email = 'kuchtohtha@gmail.com'
48+
content = request.form['content']
49+
send_message(email, content)
50+
return 'ok'
51+
52+
53+
4354
if __name__ == '__main__':
4455
app.run(debug=True)

bot.py

+6-15
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,16 @@
11
#!/usr/bin/env python
22

33
import zulip
4-
import sys
54

65
# Keyword arguments 'email' and 'api_key' are not required if you are using ~/.zuliprc
76
client = zulip.Client(email="mydexter-bot@hack36.zulipchat.com",
87
api_key="gX6ulWhAzExkZcYSAtWgpsAMbrXLjcJn",
98
site="https://hack36.zulipchat.com")
109

1110
# Send a private message
12-
client.send_message({
13-
"type": "private",
14-
"to": "himanshushekharb16@gmail.com",
15-
"content": "I come not, friends, to steal away your hearts."
16-
})
17-
18-
# Print each message the user receives
19-
# This is a blocking call that will run forever
20-
client.call_on_each_message(lambda msg: sys.stdout.write(str(msg) + "\n"))
21-
22-
# Print every event relevant to the user
23-
# This is a blocking call that will run forever
24-
# This will never be reached unless you comment out the previous line
25-
client.call_on_each_event(lambda msg: sys.stdout.write(str(msg) + "\n"))
11+
def send_message(message, email):
12+
client.send_message({
13+
"type": "private",
14+
"to": email,
15+
"content": message,
16+
})

js/app.js

+14
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,18 @@ function runJavascript() {
7979
})
8080
}
8181

82+
function runZulip() {
83+
let content = editor1.getValue()
84+
$.ajax({
85+
url: 'http://localhost:5000/zulip',
86+
type: 'POST',
87+
crossDomain: true,
88+
data: { content:content },
89+
success: console.log,
90+
error: console.log,
91+
})
92+
}
93+
8294
function commandHandlers(command) {
8395
if (command == 'dexter_start') {
8496
dexterIsRunning = true
@@ -112,5 +124,7 @@ function commandHandlers(command) {
112124
} else if (command == 'dexter_run') {
113125
runPython()
114126
runJavascript()
127+
} else if (command == 'dexter_zulip') {
128+
runZulip()
115129
}
116130
}

js/parser.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,9 @@ var known_commands = [
6363

6464
{ id: 'dexter_run', text: 'dexter run code' },
6565
{ id: 'dexter_run', text: 'code chala do bhai' },
66-
{ id: 'dexter_run', text: 'arey bhai bhai bhai' }
66+
{ id: 'dexter_run', text: 'arey bhai bhai bhai' },
67+
{ id: 'dexter_zulip', text: 'zulip pe bhej do' },
68+
{ id: 'dexter_zulip', text: 'dexter send to zulip' },
6769
]
6870

6971
function IsKnownCommand(command) {

0 commit comments

Comments
 (0)