Python Forum
Trying to figure out Python IRC
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Trying to figure out Python IRC
#1
Hey guys. I'm obviously quite new here. I'm currently making a games and trivia-like bot for a friend's irc channel and I'm kind of stuck on something I'm trying to have it do.

Simply put I'd like to have the bot respond to a person when they say "hellO <botnick>". I have had no problem with this so far. Then, what I would like is for that to trigger another word that if entered the bot would respond to it as well. I tried to set it up so that if someone said hello it would increase a variable from 0 to 1 and if that variable is above 0 the bot would respond to a second word.

Basically the idea is:

Me: Hello <bot>
Bot: Hello, Tass. Care to play with me?
(increase variable counter from 0 to 1)
Me: Play
(check if variable is 1. If so)
Bot: Let's go on an adventure together!
(decrease variable back to 0)
If I say "play" while the variable is 0 it just proceeds with the rest of the script.

My current code is to follow:

def main():
  joinchan(channel)
  ircsock.send(bytes("PRIVMSG "+ "CHANSERV :op "+ channel +" "+ botnick +"\n", "UTF-8"))
  while 1:
    ircmsg = ircsock.recv(2048).decode("UTF-8")
    ircmsg = ircmsg.strip('\n\r')
    print(ircmsg)
    if ircmsg.find("PRIVMSG") != -1:
      name = ircmsg.split('!',1)[0][1:]
      message = ircmsg.split('PRIVMSG',1)[1].split(':',1)[1]
      if len(name) < 17:
        if message.rstrip() == "!np":
          sendmsg(np)
        if message.rstrip() == "!bot":
          sendmsg(botinfo)
        if message.find("hello "+ botnick) != -1:
          counter = 1
          sendmsg("こにちは "+ name +", " + "have you come to play with me?")
        ##########################################################
        # The following two lines are what I'm trying to work with
        if message.rstrip() == "play":
          sendmsg("Let's go on an adventure ... together, 先輩!")
        if message[:5].find('.tell') != -1:
          target = message.split(' ', 1)[1]
          if target.find(' ') != -1:
            message = target.split(' ', 1)[1]
            target = target.split(' ')[0]
          else:
            target = name
            message = "Could not parse. The message should be in the format of ‘.tell [target] [message]’ to work properly."
          sendmsg(message, target)
        if name.rstrip() == name in admins and message.rstrip() == "!op":
          ircsock.send(bytes("MODE "+ channel +" +o "+ name +"\n", "UTF-8"))
        if name.lower() == adminname.lower() and message.rstrip() == exitcode:
          sendmsg("Sayonara, "+ adminname +"-san")
          ircsock.send(bytes("QUIT \n", "UTF-8"))
          return
    else:
      if ircmsg.find("PING :") != -1:
        ping()
main()
Everything in the coding seems to work fine and without error. The section I have bolded is the code I'm trying to have only active if the previous condition was met.

Thanks in advance to any help or to anyone who can kinda kick my ass towards the right direction.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  saving only one line of a figure as an image (python matplotlib) nitrochloric 0 2,121 Nov-23-2020, 01:41 PM
Last Post: nitrochloric
  Python error. Can't figure it out. ignatius 9 5,103 Oct-21-2018, 11:47 PM
Last Post: ignatius
  Figure with Python maria 2 3,473 Jun-13-2017, 05:59 PM
Last Post: Larz60+

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020