- D1 Meta Docs - Denizen Script -
Home Page / Pi to one million places / Contact mcmonkey / Donate / Paste Scripts / Denizen Help /
You are browsing as a guest.
Login | Register








The script repo is an archive of historical scripts. For modern scripts, or to post your own, please use the Scripts forum section.





Staff Pick: dIRCBot Tag Parser


By Fortifier42
Created: 2015/07/19 07:07:48 UTC-07:00 (8 years and 308 days ago)
Edited: 2015/10/18 19:17:55 UTC-07:00 (8 years and 217 days ago)
Likes: 1

Staff pick as of: 2015/07/19 17:16:02 UTC-07:00 (8 years and 308 days ago)
Denizen Version: 0.9.7
Script Version: 2
Description:

This allows you to use your dIRC Bot as an IRC tag parser, allowing you to parse any tag, just as you would in a script.

It is entirely configurable, with the ability to specify your own server, channel, Bot-Name, etc. Simply change the config in the file!

Due to current dIRCBot limitations, I am unable to safely check if there is already an IRC connection established, this is why there is not an "auto-connect" feature, however this could easily be implemented with a on server start event.

Hopefully updates to come in the future :D

For this to work you will need dIRCBot, found here: https://github.com/DenizenScript/dIRCBot.
If your server is running a permissions plugin, give the people you want access to the /irc commands the "irc.admin" permission.

Usages:
..Ingame:
....'/irc join' to join the server and channel!
....'/irc quit' to leave the server and channel!
....'/irc send <message>' to send a message to the IRC channel as the bot.
..From the IRC:
..By default we use:
....'>tag <tags>' to parse tags.
....'>version <plugin>/Spigot/Bukkit/{Denizen}' to check the version of a plugin or server system.
....'>ram' to check the amount of ram the server is using.
....'>tps' to check the server's recent ticks per second values.
....'>count' to see how many 'tags' have been parsed
....'>help' to view the in-IRC help.
..Admins can use:
....'>restart' to restart the server.
....'>reload' to reload server scripts.
....'>command' to execute a command from console.


For security, at this stage quitting/sending messages etc is not available from the IRC.


Download script | View raw script
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
29500

######################################################################################################
######################################################################################################
##          _   _____    __     ___   _____                   ___                                   ##
##       __| |  \_   \  /__\   / __\ /__   \  __ _   __ _    / _ \  __ _  _ __  ___   ___  _ __     ##
##      / _` |   / /\/ / \//  / /      / /\/ / _` | / _` |  / /_)/ / _` || '__|/ __| / _ \| '__|    ##
##     | (_| |/\/ /_  / _  \ / /___   / /   | (_| || (_| | / ___/ | (_| || |   \__ \|  __/| |       ##
##      \__,_|\____/  \/ \_/ \____/   \/     \__,_| \__, | \/      \__,_||_|   |___/ \___||_|       ##
##                                                   |___/                                          ##
##   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"

  cmds:
    # Change the following line to change the join command argument(s)!
    # At this stage, it does not change the /help irc output. :(
    join:
    - 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. :(
    quit:
    - 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. :(
    msg:
    - 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"

  # Admins (Access to special commands)
  Admins:
  - Fortifier

  # Change the following line to change what the prefix should be for in-irc commands
  prefix">"

  # Change the in-irc commands here
  triggers:
    # To parse tags
    tag:
    - tag
    - tags
    - t
    # To check server versions
    version:
    - version
    - vers
    - ver
    - v
    # To check server RAM
    memory:
    - memory
    - mem
    - ram
    # Get help!
    help:
    - help
    - h
    # Check server TPS
    tps:
    - timings
    - timing
    - tps
    - lag
    # Check number of tags parsed
    count:
    - parsed
    - count
    - total
    # Reload Denizen scripts
    reload:
    - reloadscripts
    - reload
    - scripts
    # Restart the server
    restart:
    - restart
    # Execute a server command
    execute:
    - command
    - cmd
    - execute
    - ex

  # 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.
  # This is from the server's base directory
  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[cmds.join].contains[<def[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[cmds.quit].contains[<def[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 {
        - narrate format:IRC_Chat "<&c>Invalid command!"
        - queue clear
      }
    }
    else {
      - if <s@IRC_Config.yaml_key[cmds.msg].contains[<def[cmd]>]> {
        - define msg "<context.args.get[2].to[<context.args.size>].space_separated||null>"
        - if <def[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><def[msg]><&sq>"
        - if <s@IRC_Config.yaml_key[logfile]> == "" queue clear
        - log "<player.name||Console> sent <&sq><def[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.starts_with[<s@IRC_Config.yaml_key[prefix]>].not> {
        - queue clear
      }
      - define Msg <context.message.after[<s@IRC_Config.yaml_key[prefix]>].escaped.trim>
      - define Args <def[Msg].split[<&sp>]>
      - define Cmd <def[Args].get[1]||null>
      - if <def[Cmd]> == null || <def[Cmd]> == "" {
        - queue clear
      }
      - define Admin <s@IRC_Config.yaml_key[admins].contains[<context.speaker>]>


      ## Tag Parse section
      - if <s@IRC_Config.yaml_key[triggers.tag].contains[<def[Cmd]>]> {
        - define tags <def[Msg].after[<def[Cmd]>].unescaped>
        - if <def[tags]> == "" queue clear
        - 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]>
        - flag server ParseCount:++
      }


      ## Version Checking section
      else if <s@IRC_Config.yaml_key[triggers.version].contains[<def[Cmd]>]> {
        - define Choice <def[Msg].after[<def[Cmd]>].trim>
        - if <def[Choice]> == "denizen" || <def[Choice]> == "" {
            - define Version "Denizen Version '<&b><server.denizen_version><&9>'"
          }
          else if <def[Choice]> == "spigot" {
            - define Version "Spigot Version '<&b><server.version><&9>'"
          }
          else if <def[Choice]> == "bukkit" {
            - define Version "Bukkit Version '<&b><server.bukkit_version><&9>'"
          }
          else {
            - define Plugin <server.list_plugins.filter[name.starts_with[<def[Choice]>]].get[1]||null>
            - if <def[plugin]> == null {
              - irc message ircchannel@<s@IRC_Config.yaml_key[server]><s@IRC_Config.yaml_key[channel]> "<context.speaker><&c><&co> this server is not running that plugin!"
              - queue clear
            }
            - define Version "<def[Plugin].name> Version '<&b><def[Plugin].version><&9>'"
          }
        - irc message ircchannel@<s@IRC_Config.yaml_key[server]><s@IRC_Config.yaml_key[channel]> "<context.speaker><&co> <&9>this server is running <def[Version]>."
      }


      ## Memory Checking section
      else if <s@IRC_Config.yaml_key[triggers.memory].contains[<def[Args].get[1]>]> {
        - define Used <server.ram_allocated.sub[<server.ram_free>].div[1048576].round>
        - define Total <server.ram_max.div[1048576]>
        - define Usage "<&a><def[Used]><&9>/<&a><def[Total]><&9>MB"
        - irc message ircchannel@<s@IRC_Config.yaml_key[server]><s@IRC_Config.yaml_key[channel]> "<context.speaker><&9><&co> The server is currently using <def[Usage]> RAM."
      }


      ## TPS Checking section
      else if <s@IRC_Config.yaml_key[triggers.tps].contains[<def[Args].get[1]>]> {
        - define TPS <server.recent_tps.parse[round_to[2]]>
        - define TPS "<&r>1m ago - <def[TPS].get[1]><&9><&r> 5m ago - <def[TPS].get[2]><&9><&r> 15m ago - <def[TPS].get[3]><&9>"
        - irc message ircchannel@<s@IRC_Config.yaml_key[server]><s@IRC_Config.yaml_key[channel]> "<context.speaker><&9><&co> The 3 most recent TPS values are<def[TPS]>"
      }


      ## Parse Count section
      else if <s@IRC_Config.yaml_key[triggers.count].contains[<def[Cmd]>]> {
        - irc message ircchannel@<s@IRC_Config.yaml_key[server]><s@IRC_Config.yaml_key[channel]> "<context.speaker><&9><&co> I have parsed a total of <&r><server.flag[ParseCount].as_int||0><&9> tags!"
      }


      ## Help section
      else if <s@IRC_Config.yaml_key[triggers.help].contains[<def[Args].get[1]>]> {
        - ~irc raw ircserver@<s@IRC_Config.yaml_key[server]> "NOTICE <context.speaker> :<&4>Hi <&1><context.speaker><&4> I am a Denizen Tag-Parsing bot, developed by <&1>Fortifier42<&4> of <&1>http://www.theausfort.net/<&4>."
        - ~irc raw ircserver@<s@IRC_Config.yaml_key[server]> "NOTICE <context.speaker> :<&4>I have a number of commands available for you to use which all start with '<&1><s@IRC_Config.yaml_key[prefix]><&4>'"
        - ~irc raw ircserver@<s@IRC_Config.yaml_key[server]> "NOTICE <context.speaker> :<&4>To parse a tag, use the commands <&1><s@IRC_Config.yaml_key[triggers.tag].separated_by[<&4> or <&1>]><&4> <&lt>tags<&gt>."
        - ~irc raw ircserver@<s@IRC_Config.yaml_key[server]> "NOTICE <context.speaker> :<&4>To check a plugin or server version, use the commands <&1><s@IRC_Config.yaml_key[triggers.version].separated_by[<&4> or <&1>]><&4> followed by the name of the plugin or service."
        - ~irc raw ircserver@<s@IRC_Config.yaml_key[server]> "NOTICE <context.speaker> :<&4>To check the server's current RAM usage, use the commands <&1><s@IRC_Config.yaml_key[triggers.memory].separated_by[<&4> or <&1>]><&4>."
        - ~irc raw ircserver@<s@IRC_Config.yaml_key[server]> "NOTICE <context.speaker> :<&4>To see how many tags I have parsed, use the commands <&1><s@IRC_Config.yaml_key[triggers.count].separated_by[<&4> or <&1>]><&4>."
        - if <def[Admin]> {
          - ~irc raw ircserver@<s@IRC_Config.yaml_key[server]> "NOTICE <context.speaker> :<&4>To execute a command on the server use the commands <&1><s@IRC_Config.yaml_key[triggers.execute].separated_by[<&4> or <&1>]> <&lt>command (arguments)<&gt><&4>."
          - ~irc raw ircserver@<s@IRC_Config.yaml_key[server]> "NOTICE <context.speaker> :<&4>To restart the server use the commands <&1><s@IRC_Config.yaml_key[triggers.restart].separated_by[<&4> or <&1>]><&4>."
          - ~irc raw ircserver@<s@IRC_Config.yaml_key[server]> "NOTICE <context.speaker> :<&4>To reload the Denizen scripts running on the server use the commands <&1><s@IRC_Config.yaml_key[triggers.restart].separated_by[<&4> or <&1>]><&4>."
        }
        - ~irc raw ircserver@<s@IRC_Config.yaml_key[server]> "NOTICE <context.speaker> :<&4>To access this help again, use the commands <&1><s@IRC_Config.yaml_key[triggers.help].separated_by[<&4> or <&1>]><&4>."
      }


      ### ADMIN COMMANDS ###
      ## Restart Server
      else if <s@IRC_Config.yaml_key[triggers.restart].contains[<def[Cmd]>]> && <def[Admin]> {
        - irc message ircchannel@<s@IRC_Config.yaml_key[server]><s@IRC_Config.yaml_key[channel]> "<context.speaker><&c><&co> Restarting Server. Expect reconnection in ~ 1 Minute."
        - wait 2s
        - execute as_server "restart"
      }


      ## Reload Scripts
      else if <s@IRC_Config.yaml_key[triggers.reload].contains[<def[Cmd]>]> && <def[Admin]> {
        - irc message ircchannel@<s@IRC_Config.yaml_key[server]><s@IRC_Config.yaml_key[channel]> "<context.speaker><&c><&co> Reloading Scripts."
        - flag global Reloading
        - execute as_server "denizen reload scripts"
        #- ~irc raw ircserver@<s@IRC_Config.yaml_key[server]> "NOTICE <context.speaker> :<&c>Reloaded Scripts."
      }


      ## Execute Command
      else if <s@IRC_Config.yaml_key[triggers.execute].contains[<def[Cmd]>]> && <def[Admin]> {
        - define Cmd <def[Msg].after[<def[Cmd]>]>
        - if <def[Cmd].contains_any[stop|restart|irc]> {
          - irc message ircchannel@<s@IRC_Config.yaml_key[server]><s@IRC_Config.yaml_key[channel]> "<context.speaker><&c><&co> This command is prohibited!"
          - queue clear
        }
        - execute as_server <def[Cmd].unescaped> silent save:Cmd
        - irc message ircchannel@<s@IRC_Config.yaml_key[server]><s@IRC_Config.yaml_key[channel]> "<context.speaker><&9><&co> Command executed!"
        - irc message ircchannel@<s@IRC_Config.yaml_key[server]><s@IRC_Config.yaml_key[channel]> "<context.speaker><&9><&co> Output<&co> <&c><entry[Cmd].output.space_separated>"
      }

    on reload scripts:
      - if <server.has_flag[Reloading].not> queue clear
      - if <context.haderror> {
        - irc message ircchannel@<s@IRC_Config.yaml_key[server]><s@IRC_Config.yaml_key[channel]> "<&c>Error while reloading scripts!"
      }
      - flag global Reloading:!







View History