SOBotics / Botpy

A python framework for creating chatbots on the StackExchange network.
Other
5 stars 1 forks source link

Prevent race condition with messages #12

Closed CalvT closed 5 years ago

CalvT commented 5 years ago

At @fortunate-man 's request:

Having an issue with Botpy in my bot, CommentSmoker.

Bit of background: CommentSmoker is a project I'm doing to learn Python. The result I'm going for is a bot that uses Smokey's lists to look for comment spam across the network. Current status is a bot that scans SO for any comments that include links that aren't from the network. You can see it in action in my chatroom.

The trouble I'm having is messages will sometimes go missing. This is possibly down to my implementation of Botpy though.

My implementation is something like this:

bot = bp.Bot("CharlieB", commands, rooms, [], "stackexchange.com", email, password)
def cbm(msg):
  bot.post_global_message(msg)
def function():
  for i in items:
    cbm(msg)
  cbm('Finished')
while True:
  function()

Would be awesome if Botpy could queue the messages up itself, so avoiding this.

CalvT commented 5 years ago

So I edited my code with various prints to try and see what's going on:

bot = bp.Bot(name, commands, rooms, [], "stackexchange.com", email, password)

def cbm(msg):
    print("message received")
    bot.post_global_message(msg)
    print("message sent")

def function():
    for i in items:
        print("calling cbm")
        cbm(msg)
        print("call finished")

while True:
    function()

And everything printed correctly, so I'm guessing there's some throttling going on somewhere, either on the SE or CE side (or both?).

Also might be caused by my use of post_global_message instead of plain post - however I couldn't made post work.

double-fault commented 5 years ago

Looks like this has been fixed; this issue was with some chat messages being too long. If this problem occurs again, feel free to reopen this issue.