raise_event from client not working in dev - krl

I have the following code, and raising the web event doesn't do what it should do. I have disabled all of my extensions to ensure that it isn't something there. Please help. I find it hard to build an app if I can't debug my junk. HELP ME!!!
dispatch {
// Some example dispatch domains
// domain "example.com"
domain "google.com"
}
global {
}
rule temp_rule is active{
select when pageview ".*"
pre{
}
{
notify("111",'123');
emit<<
var tempapp = KOBJ.get_application("a710x19");
tempapp.raise_event("temp2");
>>;
}
}
rule temp2 is active{
select when web temp2
pre{
}
{
notify("222",'<div id="fbp_fblogo">123</div>');
emit<<
try{
console.log("TEMP2'd");
}catch(e){}
>>;
}
}

The problem is that your event name contains a numeral. Event names are only to contain letters.
Remove the 2 from your raise_event call in your emit and from your select statement and it will work.

Related

My Discord bot recently won't respond when mentioned

This is my first time using this site so I apologize if the formatting's sub par.
The problem:
My Discord bot (javascript) recently has stopped responding when #mentioned. There were no changes to the code to cause this and it was working perfectly fine not too long ago. A friend who's bot is programmed similarly also has this issue so I know that it's not only me.
The bot's basically a chat-and-reply bot; you #mention it's name and include a trigger and it has a random chance to respond with one of four responses. However, something's happened where it doesn't seem to register that it's been #mentioned and therefore doesn't reply.
So, for example, if I were to type "#bot hi!" in discord, the bot would reply with one of the following replies: "It's too early for this.", "Mornin'.", "I need coffee.". "[yawn, mumbled greeting]".
I've tried replacing client.user.toString() directly with it's client identifier as well as the identifiers that would be used in discord (for example; "#name#0000", "<#########>") but those are also ignored. I've added an arrow next to this area in the code.
I'm not sure if there was an update that's made some of the code go out of date, but I've tried searching for similar issues with no success.
I'm relatively sure that the issue isn't with the processChat(receivedMessage) function, as I can replace the noted problem section with an alternate trigger such as:
if (receivedMessage.content.startsWith("#all ")) {
processChat(receivedMessage)
}
and the bot will send a reply. It simply doesn't seem to want to respond when mentioned; the rest of the code works as it should. While this is something I can convert to, I've had this bot on my server for almost a year now and there are multiple other server members who'd need to adapt to the change. I'd rather get things running the way they used to than have everyone fall out of habit to compensate.
Is there a way to fix this?
Here's a small example code that has the same issue:
const Discord = require('discord.js');
const client = new Discord.Client();
client.on('ready', () => {
console.log("Connected as " + client.user.tag);
})
//The color for all of the bot's messages
messageColor = 4611141;
client.on('message', receivedMessage => {
// Prevent bot from responding to its own messages
if (receivedMessage.author == client.user) {
return;
}
//process regular triggers (# mentions)
//This is where the issue seems to be <--------------------------
if ((receivedMessage.content.includes(client.user.toString()))) {
processChat(receivedMessage);
}
});
//For usage with chat prompts and triggers
function processChat(receivedMessage) {
if ((receivedMessage.content.toLowerCase().includes("hi"))){
var random = randomInt(5, 1) ;
if (random == 1) {
receivedMessage.channel.send({embed: {
color: messageColor,
description: "It's too early for this."
}});
} else if (random == 2) {
receivedMessage.channel.send({embed: {
color: messageColor,
description: "Mornin'."
}});
} else if (random == 3) {
receivedMessage.channel.send({embed: {
color: messageColor,
description: "I need coffee."
}});
} else if (random == 4) {
receivedMessage.channel.send({embed: {
color: messageColor,
description: "*[yawn, mumbled greeting]*"
}});
} else {
return;
}
}
}
//Random number generation
function randomInt(max, min) {
min = Math.ceil(min);
max = Math.floor(max);
return Math.floor(Math.random() * (max - min)) + min;
}
client.on('error', console.error);
client.login(token)
Switching from
if ((receivedMessage.content.includes(client.user.toString()))) {
processChat(receivedMessage);
}
to
if (recievedMessage.isMemberMentioned(client.user)) {
processChat(recievedMessage)
}
Solved the problem. Thanks, Bauke, for those links.

How to redirect using F5 iRules with a variable in the URL

Hi I'm new to F5 iRule.
I'm trying to redirect
https://website1.com/userid=1234
to
https://website2.com/userid=1234
such that whatever value the userid may have will be carried over after redirection.
I'm thinking userid value should be set to a variable.
Can someone share what code to use? Thanks!
So https://website1.com/userid=8888 should go to https://website2.com/userid=8888 and so on.
You shouldn't need a variable if that pattern is consistent. A simple rule would be:
when HTTP_REQUEST {
if { [HTTP::host] eq "website1.com" } {
HTTP::redirect https://websitesite2.com[HTTP::uri]
}
}
However, if you are on v11.4+, you really should use a local traffic policy for this as it is more performant as a built-in feature of TMOS.
ltm policy sample_site_redirect {
controls { forwarding }
last-modified 2018-12-20:09:33:02
requires { http }
rules {
full_uri_redirect {
actions {
0 {
http-reply
redirect
location tcl:https://website2.com[HTTP::uri]
}
}
conditions {
0 {
http-host
host
values { website1.com }
}
}
}
}
status published
strategy first-match
}
if all traffic to the virtual server this rule or policy is attached to is intended for website1 only, you can eliminate those conditions. I didn't want to assume. If it's only the URI starting with /user= that you want to match, and redirect on, you can do that this way:
when HTTP_REQUEST {
if { ([HTTP::host] eq "website1.com") && ([string tolower [HTTP::uri]] starts_with "/user=") } {
HTTP::redirect https://website2.com[HTTP::uri]
}
}

Double registration form in moodle

I'm editing a site based on moodle, and i need to create a double registration form. The first is already set (for schools), i need to create another one for private user. What would be the best way to do it?
Would be worth to copy the main signup files (signup.php and signup_form.php) and then make changes there?
Really thanks
I think the best solution would be to create a new authentication plugin.
https://docs.moodle.org/dev/Authentication_plugins
Maybe copy the code from here /auth/email into /auth/newname - replacing email with newname in the code.
Possibly extend the class? so something like this in /auth/newname/auth.php
defined('MOODLE_INTERNAL') || die();
require_once($CFG->dirroot . '/auth/email/auth.php');
class auth_plugin_newname extends auth_plugin_email {
...
function can_signup() {
return true;
}
...
Then copy /login/signup_form.php into /auth/newname/signup_form.php
The next bit I'm not too sure about but you will probably need to modify /login/signup.php
Around the lines
if (empty($CFG->registerauth)) {
print_error('notlocalisederrormessage', 'error', '', 'Sorry, you may not use this page.');
}
$authplugin = get_auth_plugin($CFG->registerauth);
Change to
if (optional_param('newname', false, PARAM_BOOL)) {
$authplugin = get_auth_plugin('newname');
} else {
if (empty($CFG->registerauth)) {
print_error('notlocalisederrormessage', 'error', '', 'Sorry, you may not use this page.');
}
$authplugin = get_auth_plugin($CFG->registerauth);
}
Then for private registrations use
http://www.yoursite.com/login/signup.php?newname=1
Replace 'newname' with the name of your new authentication plugin.

KRL: Pragmatically access current ruleset id

How do I get the name of the current ruleset in a KRL rule? I find that I often write
notify("a421x70","Your Message Here") with sticky = true;
but when I copy the ruleset I have to go through and change the "a421x70" part. It would be so much better to have the current ruleset in a variable and use that in my notify() action.
In the pre block of a rule you can
rid = meta:rid();
http://docs.kynetx.com/docs/Meta_Info
Example:
ruleset a60x598 {
meta {
name "appid tester"
description <<
getting app rid pragmatically
>>
author "Michael Grace"
logging off
}
rule get_rid_rule {
select when web pageview ".*"
pre {
rid = meta:rid();
}
{
notify("Current App rid is", "#{rid}") with sticky = true;
}
}
}

KRL - How do you get the value of a watched field?

I am watching a field on a page with a change.
watch("#searchbox","change");
How do you get the new value of the field in the rule that fires after it changes?
I have a rule like this
rule get_update is active {
select when web change "#searchbox"
....
}
I cannot find out how to get the new value. I cannot use watch it with a submit.
Thanks
I am going to guess what I think you are trying to do:
You have an input on a page and when a user types in the input, you want to be able to raise an event and get the new value from the input that the user was typing into so you can react to what ever it is that they typed in.
Based on the assumptions I have made:
The watch action is not what you really want to use because it only raises an event on the action that it is watching and doesn't send any other data along with the event. You will want to write some of your own custom JavaScript to
watch for the user typing
get the new value from the input
raise web event with the new value as a parameter
Here is some sample code taken from http://kynetxappaday.wordpress.com/2010/12/16/day-8-raise-web-events-from-javascript/ that illustrates raising a web event with a parameter in JavaScript
ruleset a60x488 {
meta {
name "raising-custom-web-events"
description <<
raising-custom-web-events
>>
author "Mike Grace"
logging on
}
rule run_on_a_pageview {
select when pageview ".*"
{
notify("Hello","I ran on a pageview") with sticky = true;
emit <|
app = KOBJ.get_application("a60x488");
app.raise_event("custom_event_just_for_me", {"answer":42});
|>;
}
}
rule respond_to_custom_event_raised_from_emitted_js {
select when web custom_event_just_for_me
pre {
answer = event:param("answer");
}
{
notify("What is the answer?",answer) with sticky = true;
}
}
}