Date: 2021/04/28 03:21:57 UTC-07:00
Type: Denizen 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
tag_parser_bot:
type: world
debug: false
samples:
link: (UNSET)
sample_bool: true
sample_0: 0
sample_1: 1
sample_10: 10
sample_0p5: 0.5
sample_text: Hello, world!
help: try typing 'help' to the bot!
script_paths:
stop_bot:
- if <server.has_flag[tag_parser_bot_running]>:
- ~discord id:tag_parser disconnect
- flag server tag_parser_bot_running:!
start_bot:
- inject tag_parser_bot.script_paths.stop_bot
- yaml load:data/tag_parser.yml id:tag_parser_temp
- if !<yaml.list.contains[tag_parser_temp]>:
- debug error "Load failed."
- stop
- flag server tag_parser_logpath:<yaml[tag_parser_temp].read[bot.discord.log_path]>
- flag server tag_parser_validchannels:!
- flag server tag_parser_validchannels:|:<yaml[tag_parser_temp].read[bot.discord.valid_channels]>
- flag server tag_parser_barredchannels:!
- flag server tag_parser_barredchannels:|:<yaml[tag_parser_temp].read[bot.discord.barred_channels]>
- flag server tag_parser_barredchannelmessages:!
- flag server tag_parser_barredchannelmessages:|:<yaml[tag_parser_temp].read[bot.discord.barred_channel_messages]>
- flag server tag_parser_link:<yaml[tag_parser_temp].read[script.link]>
- yaml unload id:tag_parser_temp
- define samples <script.data_key[samples].with[link].as[<server.flag[tag_parser_link]>].with[version].as[<server.version>].with[denizen_version].as[<server.denizen_version>]>
- flag server tag_parser_samples:<[samples]>
- ~discordconnect id:tag_parser tokenfile:data/tagparser_token.txt
- flag server tag_parser_bot_running
process_tag:
- log "<util.time_now.format> [<[name]>] in [<[origin]>] wants to process tag <[tag]>" file:<server.flag[tag_parser_logpath]>
- flag server tag_parser_result_temp:!
# If you ever enable this on your own copy of the bot I will break your knees. Don't do it. Official dTagParser instance only.
- define should_record false
- ~run tag_run_task def:<list_single[<[tag]>].include[<[should_record]>]>
- define result <server.flag[tag_parser_result_temp].if_null[<map.with[failed].as[FAILED=FLAG_MISSING]>]>
- flag server tag_parser_result_temp:!
- log "<util.time_now.format> [<[name]>] in [<[origin]>] got result <[result]>" file:<server.flag[tag_parser_logpath]>
crunch_result:
- define final_result <empty>
- if <[result].contains[valid]>:
- define final_result <[result].get[valid]><n>
- if <[result].contains[failed]>:
- foreach <[result].get[failed]>:
- if <[value].starts_with[Error=]>:
- define final_result "<[final_result]>Had error: <[value].after[Error=]><n>"
- else if <[value].starts_with[Exception=]>:
- define final_result "<[final_result]>Had internal exception: <[value].after[Exception=]><n>"
- else if <[value].starts_with[FAILED=]>:
- define fail_reason <[value].after[FAILED=]>
- if <[fail_reason]> == FLAG_MISSING:
- define final_result "<[final_result]>Got no result value.<n>"
- else:
- define final_result "<[final_result]>Got failure '<[fail_reason]>'.<n>"
- if <[final_result].trim.length> == 0:
- define final_result <empty>
- if <[final_result].length> > 1000 || <[tag].length.add[<[final_result].length>]> > 1500:
- define tag (Spam)
- define final_result "Input too long, refused."
- if <[final_result].to_list.filter[is[==].to[<n>]].size> > 10:
- define final_result "Newline spam, refused."
events:
on server start:
- wait 5s
- flag server tag_parser_bot_running:!
- inject tag_parser_bot.script_paths.start_bot
on script generates error:
- flag server tag_parser_result_temp.failed:|:Error=<context.message.strip_color>
on server generates exception:
- flag server tag_parser_result_temp.failed:|:Exception=<context.type>-<context.message>
on discord message received for:tag_parser:
- flag server tag_parser_bot_running
- define name <context.new_message.author.id>/<context.new_message.author.name>
- define origin <context.group>/<context.channel>/<context.group.name>/<context.channel.name>
- announce to_console "Discord chatter! [<[name]>] in [<[origin]>] saying <context.new_message.text> and mentioning <context.new_message.mentioned_users>"
- if !<context.new_message.mentioned_users.parse[id].contains[<context.bot.self_user.id>]>:
- stop
- if !<server.flag[tag_parser_validchannels].contains[<context.channel.id>]>:
- define found <server.flag[tag_parser_barredchannels].find[<context.channel.id>]>
- if <[found]> > 0:
- ~discordmessage id:tag_parser channel:<context.channel> "Cannot parse that in this channel! <server.flag[tag_parser_barredchannelmessages].get[<[found]>]>"
- stop
- if <context.new_message.text_no_mentions.trim> == link:
- ~discordmessage id:tag_parser channel:<context.channel> "The source script for **dTagParser** can be found at <<><server.flag[tag_parser_samples].as_map.get[link]><>>"
- stop
- waituntil rate:1s !<server.has_flag[tag_parser_bot_processing_now]>
- flag server tag_parser_bot_processing_now duration:1m
- define tag <context.new_message.text_no_mentions.replace_text[<n>].with[<&sp>].trim>
- inject tag_parser_bot.script_paths.process_tag player:<server.players.get[1]> npc:<server.npcs.get[1]>
- inject tag_parser_bot.script_paths.crunch_result
- ~discordmessage id:tag_parser channel:<context.channel> "Tag parse results for `<[tag].replace_text[`].with[']>`<&co> <[result].get[recording].if_null[]><n>```<n><[final_result].replace_text[`].with[']>```"
- flag server tag_parser_bot_processing_now:!
tag_run_task:
type: task
definitions: tag|record
debug: false
script:
- define samples <server.flag[tag_parser_samples].as_map.with[sample_player].as[<player>].with[sample_npc].as[<npc>]>
- foreach <[samples].keys> as:key:
- define <[key]> <[samples].get[<[key]>]>
- define help "Tell me any valid Denizen tags, like <<>player.name<>> and I'll parse them for you! Alternately, tell me a valid definition name (like 'samples') and I'll tell you its contents."
- if !<[tag].contains_text[<<>]> && <[<[tag]>].exists>:
- flag server tag_parser_result_temp.valid:<[<[tag]>]>
- else:
#- if <[record]>:
# - debug record start
- inject tag_parser_task
#- if <[record]>:
# - ~debug record submit save:recorded
# - if !<entry[recorded].submitted.exists>:
# - define record_url "(Submit Failed)"
# - else:
# - define record_url <<><entry[recorded].submitted><>>
# - flag server tag_parser_result_temp.recording:<[record_url]>
- flag server tag_parser_result_temp.valid:<[result]>
tag_parser_task:
type: task
definitions: tag
script:
- define result <[tag].parsed>