Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Recreate parser for !roll #12

Closed
earlduque opened this issue Sep 28, 2022 · 1 comment
Closed

Recreate parser for !roll #12

earlduque opened this issue Sep 28, 2022 · 1 comment
Assignees

Comments

@earlduque
Copy link
Collaborator

old script:

(function executeRule(current, previous /*null when async*/) {

	var sentence = current.text.substr(5).trim();
	if (sentence == '') {
		var send_confusion = new SlackFall().send_chat(current.channel, ':upside_down_face: Say `number` `d` `number`!', false, '', current.thread_ts);
		return;
	}
	var numbers = sentence.split('d');
	for(var k=0; k<numbers.length; k++) { numbers[k] = parseInt(numbers[k], 10); } 
// 	var what = new SlackFall().send_chat(current.channel, isNaN(numbers[0]) + ' ' + isNaN(numbers[1]),false); return;
	if (isNaN(numbers[0]) || isNaN(numbers[1])) {
		var send_more_confusion = new SlackFall().send_chat(current.channel, 'One of those is not a number!', false, '', current.thread_ts);
		return;
	}
	if (numbers[0]>100 || numbers[1]>1000000){
		var send_ridiculous = new SlackFall().send_chat(current.channel, 'You rolled: a lot', false, '', current.thread_ts);
		return;
	}
	if (numbers[0]<1 || numbers[1]<1){
		var send_err = new SlackFall().send_chat(current.channel, 'Stop that', false, '', current.thread_ts);
		return;
	}
	var total_dice = numbers[0];
	var sides = numbers[1];
	var message = 'You rolled: ';
	var current_roll = 0;
	var all_rolls = [];
	for (var i = 1; i <= total_dice; i++){
		current_roll = Math.floor(Math.random() * sides) + 1;
		all_rolls.push(current_roll);
	}
	var sum = 0;
	for( var j = 0; j < all_rolls.length; j++ ){
		sum += parseInt( all_rolls[j], 10 ); //don't forget to add the base
	}

	var avg = sum/all_rolls.length;
	message += all_rolls.join(', ')+'. `Average of ' + avg + '` `Sum of ' + sum + '`';

	var send_lmgtfy = new SlackFall().send_chat(current.channel, message, false, '', current.thread_ts);

})(current, previous);
@johndahl-now
Copy link
Contributor

I'll take this one.

earlduque pushed a commit that referenced this issue Oct 25, 2024
* feat: introduce interactivity support

added: Interaction table
added: Payload type to Payload to discern events and Interactivity
added: New endpoint to insert Interactions
updated: Filters on payload table BRs
updated: Updated repo event endpoint to handle Interactions

* Add Interactions path for workflow

change: Add interactions path
test: Change Deployment repository

* feat: Migrate the quiz functionality to an Interaction

added: first interaction handler and path

* Interaction support (#11) (#12)

* feat: introduce interactivity support

added: Interaction table
added: Payload type to Payload to discern events and Interactivity
added: New endpoint to insert Interactions
updated: Filters on payload table BRs
updated: Updated repo event endpoint to handle Interactions

* Add Interactions path for workflow

change: Add interactions path
test: Change Deployment repository

* feat: Migrate the quiz functionality to an Interaction

added: first interaction handler and path

* tweak: Update path

* tweak: Change directory name

* fix: Update variable name

* fix: url variable

* Delete Interactions/Handle an SN quiz.js

* tweak: Repoint to correct repo
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants