Same command

Markshall

Русский Стандарт
Contributor
Dec 18, 2010
2,638
2,393
I’d like a same command in the chat box that would be used like so:
Code:
/same RastaLulz

And it would print:
Code:
RastaLulz got samed!

The printout could be:
Code:
RastaLulz got samed by Markshall!
…but this command will only be available to Markshall, as such, there is no requirement for this specification.
 

Weasel

👄 I'd intercept me
Nov 25, 2011
4,135
2,461
I copied the "slap" command's code to whip this up.

Create the src/addons/Siropu/Chat/Command/Same.php file
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
          ]);
     }
}

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

@RastaLulz
 

Users who are viewing this thread

Top