Mafiabot Code Questions

Questions for @Roragok but anyone else who is familiar with the mafiabot code please chime in. Maybe you might know this @SOPHIE?

Let me preface by saying I'm completely new to coffee script, so some of these questions might be ■■■■■■■■■

# LYNCH ALIAS

  robot.hear /@mafiabot vote (.*)/i, (res) ->

    voter =  res.envelope.user.username

I looked through hubot's /src folder on github and didn't see a 'username' function defined under the user class. Where can I see the source for this on mafiabot? I'm trying to see all of the attributes listed, it'd be nice if I could run it to debug and see what the data is..

result = getDay(threadId)

Where is the source for these commands like getDay/getGame etc? Edit: NVM I think I found it in start_game.coffee

Would it be possible to create a duplicate instance of the mafiabot like 'testbot' or 'stovebot' which has permissions set to allow me to push directly into the directory and test code so I don't mess w/ the underlying mafiabot until bugs have been ironed out?

Fuck you and your comments.

Looks like you already wrote a sub command into play_game.coffee.

# HOST Subs a player in the current Day

  robot.hear /@mafiabot sub (.*)/i, (res) ->

    host =  res.envelope.user.username

    targets = res.match[1] . replace '@', ''

    threadId = res.message.room

    result = getDay(threadId)

    result.then (data) ->

      if data.Count > 0

        for item in data.Items

          # Add User to Signup

          if host is item.host

            subPlayer(threadId, item.alive_players, targets)

Reading through it, looks like the function is incomplete.

Here's my suggested edit with #### on the changes.

Call:

# HOST Subs a player in the current Day
####robot.hear /@mafiabot sub (.*) for (.*)/i, (res) ->

host =  res.envelope.user.username
####sub_out = res.match[1] . replace '@', ''
####sub_in = res.match[2] . replace '@', ''
threadId = res.message.room

result = getDay(threadId)
result.then (data) ->
  if data.Count > 0
    for item in data.Items
      if host is item.host
        ####subPlayer(threadId, sub_out, sub_in)

Function:

subPlayer = (threadId, sub_out, sub_in) ->
  #verify player being subbed is alive and in the game
  if sub_out in game[0].alive_players
	#grab index containing the player to be subbed out
	index = game[0].alive_players.indexOf(sub_out)
	
	#replace the player
	game[0].alive_players[index] = sub_in


	
  ##########################################################

Does item.alive_players also need to be updated as well? So item.alive_players = game[0].alive_players ? IDK if this is updating the value or the reference.

yea it never got finished. dan started it but its not active cause it didnt work or get tested.

I also know nothing of coffeescript i think dan was interested in reworking it maybe.

the documentation is pretty up to date.

uses the https://www.npmjs.com/package/hubot-discourse-adapter

1 Like

Let me update the bot code. I can fix that kill command too

1 Like

Yeah whats been going on with the kill command that it is getting the wrong player every game

Submit a pr and I will review and approve

1 Like

Unclear at first it was case sensitive problems. Like you need to match the case of the user. Tried a fix didn't seem to work. Hard to debug tho

Is there any way to make a duplicate instance like @testbot to push the test code into before finalizing to @mafiabot so it doesn't brick any running games? I have code written out, but I'm not sure about pushing to prod without testing first.

Would pushing a code change have any impact on ongoing games?

Not really. I would review it and I push it during a downtime for testing.

@ironstove are you doing it now? I can pair

Idk what this means, but how do you test your code?

last time i was "testing the code" i was straightup making commits to a repo and then some jenkins shit was running the bot so id just test teh commands somewhere

tldr prolly should be adding jest or some shit and writing tests

Don't really test cause well lots of moving parts.

DB in aws. Hosted in heroku to interact with the forum.

https://amussey.github.io/2015/08/11/testing-hubot-scripts.html wouldnt this be sufficient

If you have a different adapter maybe? I don't know a whole lot about it tbh. Honestly lol. Ipuut it together pretty fast and it shows.

what kinda adapter would you want to mess around with? i linked this article cuz the beginning references the alternatives, i was gonna link https://github.com/hubotio/hubot-mock-adapter for our use

realtalk if you would host it i might ask that we just have the bot just handle post and get from some small node+w/e service that ill write so we can begin separating logic from the thing handling the presentation. then we'd get to also drop coffeescript and easily integrate tests etc

also in addition to the new service you should/would have to also run a duplicate of mafiabot for prod during the transition