GithubHelp home page GithubHelp logo

newdelion / flowy Goto Github PK

View Code? Open in Web Editor NEW
16.0 2.0 2.0 36 KB

Awaitable for PocketMine-MP. MOVED(https://github.com/FlowyProject)

Home Page: https://github.com/FlowyProject

License: GNU Lesser General Public License v2.1

PHP 100.00%
pocketmine-mp pocketmine pmmp pmmp-plugin pmmp-flowy

flowy's Introduction

Flowy

Awaitable for PocketMine-MP

This project is moved => FlowyProject

Install

Composer

composer config repositories.NewDelion/Flowy vcs https://github.com/NewDelion/Flowy
composer require NewDelion/Flowy:dev-master

GitSubmodule

git submodule add https://github.com/NewDelion/Flowy

Example

<?php
namespace FlowyExample;

use Flowy\Flowy;
use Flowy\ListenAwaitable;
use function Flowy\listen;
#use function Flowy\delay;
#use function Flowy\done;
#use function Flowy\cancel;

use pocketmine\event\player\PlayerJoinEvent;
use pocketmine\event\player\PlayerQuitEvent;
use pocketmine\event\player\PlayerChatEvent;

class HeySiri extends Flowy{
    function onEnable(){
        ListenAwaitable::registerMethod('filter_eq', 
            function(string $methodName, $obj, bool $strict = true){
                return $this->filter(function($ev) use ($methodName, $obj, $strict){
                    if($strict){
                        return $ev->{$methodName}() === $obj;
                    }
                    else{
                        return $ev->{$methodName}() == $obj;
                    }
                });
            }
        );
        $this->start($this->heysiri());
    }

    function heysiri(){
        $event = yield listen(PlayerJoinEvent::class);
        $this->start($this->heysiri());
        $player = $event->getPlayer();

        $branch_quit = function(){ yield listen(PlayerQuitEvent::class); };

        while(true){
            $event = yield listen(PlayerChatEvent::class)
                ->filter_eq('getPlayer', $player)
                ->filter_eq('getMessage', 'heysiri')
                ->branch($branch_quit);

            $player->sendMessage("What can I help you with?\nGo ahead. I'm listening...");
            $event->setCancelled();

            $event = yield listen(PlayerChatEvent::class)
                ->filter_eq('getPlayer', $player)
                ->timeout(20 * 15, [$player, 'sendMessage'], ["(♪popon)"], true)
                ->branch($branch_quit);

            if($event !== null){
                $player->sendMessage("I'm not sure I understand.");
                $event->setCancelled();
            }
        }
    }
}

flowy's People

Contributors

newdelion avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

flowyproject

flowy's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.