Skip to content

Ban system in bot #83

Closed Answered by punyflash
Playys228 asked this question in Q&A
Jul 25, 2023 · 1 comments · 1 reply
Discussion options

You must be logged in to vote

By architecture, bot handlers are middlewares (responsibility chain) by themselves, you can just create handler that will check if user is banned and then add it on top of your handlers list:

<?php

namespace Somewhere\InYour\App;

use App\Models\User;
use Illuminate\Support\Facades\Auth;
use WeStacks\TeleBot\Handlers\UpdateHandler;

class AuthHandler extends UpdateHandler
{
    public function __invoke($next)
    {
        if ($tgUser = $this->update->user()) {
            $user = User::where('telegram_id', $thUser->id)->first();

            // This will check if user is banned (you need to write ban functionality by yourself or use some package)
            if (!$user || $user->isBanned(…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@Playys228
Comment options

Answer selected by punyflash
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
question Further information is requested
2 participants