Reply to thread

I copied the "slap" command's code to whip this up.


Create the src/addons/Siropu/Chat/Command/Same.php file

[CODE=php]<?php


namespace Siropu\Chat\Command;


class Same

{

     public static function run(\XF\Mvc\Controller $controller, \Siropu\Chat\Entity\Command $command, $messageEntity, $input)

     {

          if (!$controller->isLoggedIn())

          {

               return $controller->view();

          }


          $user = \XF::em()->findOne('XF:User', ['username' => ltrim($input, '@')]);


          if (!$user)

          {

               return $controller->message(\XF::phrase('requested_user_not_found'));

          }


          $visitor = \XF::visitor();


          if ($user->user_id == $visitor->user_id)

          {

               return $controller->message(\XF::phrase('siropu_chat_cannot_same_yourself'));

          }


          $phrase = 'siropu_chat_same_message';

          $object = '';


          $messageEntity->message_type = 'same';

          $messageEntity->message_text = \XF::phrase($phrase, [

               'fromUser' => new \XF\PreEscaped($visitor->siropuChatGetUserWrapper()),

               'toUser'   => new \XF\PreEscaped($user->siropuChatGetUserWrapper()),

               'object'   => $object

          ]);

     }

}

[/CODE]


Add the following two phrases:

siropu_chat_cannot_same_yourself -> You cannot Same yourself!

siropu_chat_same_message -> {toUser} got samed by {fromUser}!


Add the custom command in Chat -> Custom commands -> Add command

Command name: same

Execute callback: Siropu\Chat\Command\Same :: run


[USER=1]@RastaLulz[/USER]


Top