Skip to content

Commit

Permalink
some debugging/print changes
Browse files Browse the repository at this point in the history
  • Loading branch information
bsoule committed Aug 10, 2022
1 parent 1630a04 commit 49e0b5d
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 17 deletions.
13 changes: 7 additions & 6 deletions lib/beebot.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ if (process.env.REDIS_URL) {

var https = require('https')
var karmabot = require('./karma.js')
console.log(`DEBUG3: karmabot = ${JSON.stringify(karmabot)}`)
//console.log(`DEBUG3: karmabot = ${JSON.stringify(karmabot)}`)
var bots = []

// handle a message and pass it through to the Beeminder server
var handleMessage = function(rtm, message) {
console.log(`DEBUG4: handleMessage ${message.text}`)
//console.log(`DEBUG4: handleMessage ${message.text}`)
var text = message.text
var regexpString = "<@" + rtm.activeUserId + ">"
if (message.text.match(new RegExp(regexpString))) {
Expand Down Expand Up @@ -51,8 +51,9 @@ var stopBot = function(teamId) {

var startBot = function(teamId, rurl=null) {
redis.hgetall("beebot.teamid." + teamId, function(err, obj) {
console.log("DEBUG: obj and err are both null!")
console.log(`DEBUG: teamId/obj/err = ${teamId} / ${obj} / ${err}`)
//console.log("DEBUG: obj and err are both null!")
//console.log(`DEBUG: teamId/obj/err = ${teamId} / ${obj} / ${err}`)
console.log("DEBUG: teamId/obj/err", teamId, obj, err)
var RtmClient = require('@slack/client').RtmClient
var MemoryDataStore = require('@slack/client').MemoryDataStore
if (obj === null && rurl !== null) {
Expand Down Expand Up @@ -101,11 +102,11 @@ var startBot = function(teamId, rurl=null) {
}

var handleCreateBot = function(req, resp) {
console.log(`DEBUG5: req = ${JSON.stringify(req)}`)
//console.log(`DEBUG5: req = ${JSON.stringify(req)}`)
redis.hmset("beebot.teamid." + req.body.team_id,
{ bot_access_token: req.body.bot_access_token },
function(err, obj) {
console.log("DEBUG2")
//console.log("DEBUG2")
startBot(req.body.team_id)
resp.send("OK")
}
Expand Down
12 changes: 7 additions & 5 deletions lib/botils.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,14 @@ var blurt = (rurl, txt) => {
"text": txt }
}, (err, resp, body) => {
if (err) {
console.log(`BLURT ERROR sending ${txt} to ${rurl}!\n` +
`${JSON.stringify(err)}\n` +
`${JSON.stringify(resp)}\n` +
`${JSON.stringify(body)}\n`)
//console.log(`BLURT ERROR sending ${txt} to ${rurl}!\n` +
// `${JSON.stringify(err)}\n` +
// `${JSON.stringify(resp)}\n` +
// `${JSON.stringify(body)}\n`)
console.log("BLURT ERROR sending "+txt+" to "+rurl, err, resp, body)
} else {
console.log(`Successful blurt(${rurl}, ${txt.substring(0,10)}...)`)
//console.log(`Successful blurt(${rurl}, ${txt.substring(0,10)}...)`)
console.log("Successful blurt("+rurl+", "+txt.substring(0,10)+"...)")
}
})
}
Expand Down
11 changes: 6 additions & 5 deletions lib/karma.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ function changeKarmaAndPost(rtm, team, channel, entity, delta) {
var handleMessage = function(rtm, message) {
console.log("karmabot handling message")
redis.get(rkey(message.team, "on"), function(err, obj) {
console.log("redis get success: err:" + err + " obj: " + obj)
//console.log("redis get success: err:" + err + " obj: " + obj)
if (obj && !err) {
var regex = /(\S+)(\+\+|--)/g
var match = null
Expand Down Expand Up @@ -56,7 +56,8 @@ var handleMessage = function(rtm, message) {
}
console.log('done matching')
} else {
console.log(`DEBUG8: handleMessage error: ${JSON.stringify(err)}`)
//console.log(`DEBUG8: handleMessage error: ${JSON.stringify(err)}`)
console.log("DEBUG8: handleMessage error: ",err)
}
})
}
Expand Down Expand Up @@ -85,9 +86,9 @@ var handleSlash = function(req, resp) {

if (text === "on") {
redis.set(rkey(team_id, "on"), 1, function(err, obj) {
console.log(`DEBUG: in handleSlash() about to call ` +
`beebot.startBot("${team_id}", ${rurl})`)
console.log(`DEBUG err/obj = ${JSON.stringify(err)}/${JSON.stringify(obj)}`)
console.log("DEBUG: in handleSlash() about to call " +
"beebot.startBot("+team_id+", "+rurl+")")
console.log("DEBUG err/obj", err, obj)
beebot.startBot(team_id, rurl)
botils.holla(resp, "now tracking karma")
})
Expand Down
2 changes: 1 addition & 1 deletion server.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ app.set('port', (process.env.PORT || 5000))
app.get('/debugger', (req, resp) => { debugger })

function dbg(slash, req) {
console.log(`/${slash} request body: ${JSON.stringify(req.body)}`)
console.log(`/${slash} request body:`, req.body)
}

app.post('/bot', (req, resp) => {
Expand Down

0 comments on commit 49e0b5d

Please sign in to comment.