Paste #18383: Edit of P#18382 dIRCBot Tag Parser

Date: 2015/07/19 07:08:28 UTC-07:00
Type: Denizen Script

View Raw Paste Download This Paste
Copy Link


######################################################################################################
######################################################################################################
##          _   _____    __     ___   _____                   ___                                   ##
##       __| |  \_   \  /__\   / __\ /__   \  __ _   __ _    / _ \  __ _  _ __  ___   ___  _ __     ##
##      / _` |   / /\/ / \//  / /      / /\/ / _` | / _` |  / /_)/ / _` || '__|/ __| / _ \| '__|    ##
##     | (_| |/\/ /_  / _  \ / /___   / /   | (_| || (_| | / ___/ | (_| || |   \__ \|  __/| |       ##
##      \__,_|\____/  \/ \_/ \____/   \/     \__,_| \__, | \/      \__,_||_|   |___/ \___||_|       ##
##                                                   |___/                                          ##
##   Made by Fortifier42                                                                            ##
######################################################################################################
######################################################################################################

IRC_Chat:
  debug: false
  type: format
  format: "<&sp><&7>[<&a>IRC<&7>] <&3><text>"

IRC_Config:
  type: yaml data

  # Change this to change the name your bot will display with in the IRC Channel!
  #Probably a good idea to change this so you don't get conflicts between other bots/users.
  botname: "Tag-Parser"

  # Change the following line to change the join command argument(s)!
  # At this stage, it does not change the /help irc output. :(
  joincmds: join|connect|start

  # Change the following line to change the quit command argument(s)!
  # At this stage, it does not change the /help irc output. :(
  quitcmds: quit|leave|exit|disconnect|stop

  # Change the following line to change the msg command argument(s)!
  # At this stage, it does not change the /help irc output. :(
  msgcmds: send|say|tell|msg|message

  # Change the following line to change the irc server to join!
  server: "irc.esper.net"

  # Change the following line to change the channel the bot will join!
  channel: "#Denizen-Dev"

  # Change the following line to determine what the prefix should be.
  # It is good to have a space after the trigger to ensure readability and compatability!
  trigger: ">tag "

  # Set this to "" to stop logging all together, or change the file which IRC actions will be logged to.
  # Currently only /irc send <message> and tag parsing are logged.
  logfile: plugins/Denizen/logs/ircbot.log

IRC_Command:
  debug: false
  type: command
  name: irc
  usage: /irc <&lt>(join/quit/msg <&lt>message<&gt>)<&gt>
  permission: irc.admin
  description: Used to connect, leave and send messages to IRC.
  script:
    - if <context.args.size> == 0 {
      - narrate format:IRC_Chat "<&c><script.yaml_key[usage]>"
      - queue clear
    }
    - define cmd <context.args.get[1]>
    - if <context.args.size> == 1 {
      - if <s@IRC_Config.yaml_key[joincmds].as_list.contains_any[%cmd%]> {
        - ~irc connect ircserver@<s@IRC_Config.yaml_key[server]>
        - irc raw ircserver@<s@IRC_Config.yaml_key[server]> "USER <s@IRC_Config.yaml_key[botname]> <s@IRC_Config.yaml_key[botname]>_ <s@IRC_Config.yaml_key[botname]>__ <s@IRC_Config.yaml_key[botname]>"
        - irc raw ircserver@<s@IRC_Config.yaml_key[server]> "NICK <s@IRC_Config.yaml_key[botname]>"
        - irc join ircchannel@<s@IRC_Config.yaml_key[server]><s@IRC_Config.yaml_key[channel]>
        - narrate format:IRC_Chat "Joined the IRC."
        - queue clear
      }
      else if <s@IRC_Config.yaml_key[quitcmds].as_list.contains_any[%cmd%]> {
        - ~irc leave ircchannel@<s@IRC_Config.yaml_key[server]><s@IRC_Config.yaml_key[channel]>
        - ~irc quit ircserver@<s@IRC_Config.yaml_key[server]>
        - narrate format:IRC_Chat "Left the IRC."
        - queue clear
      }
      else {
      else {
        - narrate format:IRC_Chat "<&c>Invalid command!"
        - queue clear
      }
    }
    else {
      - if <s@IRC_Config.yaml_key[msgcmds].contains_any[%cmd%]> {
        - define msg "<context.args.get[2].to[<context.args.size>].space_separated||null>"
        - if %msg% == null {
          - narrate format:IRC_Chat "<&c>No message has been specified."
          - queue clear
        }
        - irc message ircchannel@<s@IRC_Config.yaml_key[server]><s@IRC_Config.yaml_key[channel]> <def[msg]>
        - narrate format:IRC_Chat "Sent message: <&f><&sq>%msg%<&sq>"
        - if <s@IRC_Config.yaml_key[logfile]> == "" queue clear
        - log "<player.name||Console> sent <&sq>%msg%<&sq>"" file:<s@IRC_Config.yaml_key[logfile]>
      }
    }

IRC_Parsing:
  debug: false
  type: world
  events:
    on irc message:
      - if <context.channel> != "ircchannel@<s@IRC_Config.yaml_key[server]><s@IRC_Config.yaml_key[channel]>" || <context.message.substring[1,<s@IRC_Config.yaml_key[trigger].length>]> != <s@IRC_Config.yaml_key[trigger]> {
        - queue clear
      }
      - define tags "<context.message.after[<s@IRC_Config.yaml_key[trigger]>]>"
      - define parsed <parse.substring[1,300]:<def[tags]>>
      - irc message ircchannel@<s@IRC_Config.yaml_key[server]><s@IRC_Config.yaml_key[channel]> "<context.speaker><&r><&co> the tag <&sq><&b><def[tags]><&r><&sq> fills with <&sq><&b><def[parsed]><&r><&sq>"
      - if <s@IRC_Config.yaml_key[logfile]> == "" queue clear
      - log "<context.speaker> parsed <def[tags]>" file:<s@IRC_Config.yaml_key[logfile]>