Metadata-Version: 2.4
Name: mper
Version: 1.0.0
Summary: Discord bot permission scanner - Analyzes discord.py code to detect required permissions and generate invite links
Author-email: FreeWiFiTech <wifi@freewifitech.jp>
Maintainer-email: FreeWiFi7749 <wifi@freewifitech.jp>
License: MIT License
        
        Copyright (c) 2024 easy-make-invite-url-for-discord-bot
        
        Permission is hereby granted, free of charge, to any person obtaining a copy
        of this software and associated documentation files (the "Software"), to deal
        in the Software without restriction, including without limitation the rights
        to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
        copies of the Software, and to permit persons to whom the Software is
        furnished to do so, subject to the following conditions:
        
        The above copyright notice and this permission notice shall be included in all
        copies or substantial portions of the Software.
        
        THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
        IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
        FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
        AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
        LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
        OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
        SOFTWARE.
        
Project-URL: Homepage, https://github.com/FreeWiFi7749/mper.py
Project-URL: Repository, https://github.com/FreeWiFi7749/mper.py
Project-URL: Issues, https://github.com/FreeWiFi7749/mper.py/issues
Keywords: discord,discord.py,bot,permissions,invite,scanner,ast,code-analysis
Classifier: Development Status :: 4 - Beta
Classifier: Environment :: Console
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Classifier: Topic :: Utilities
Classifier: Typing :: Typed
Requires-Python: >=3.9
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: rich>=13.0.0
Provides-Extra: dev
Requires-Dist: ruff>=0.1.0; extra == "dev"
Requires-Dist: pytest>=7.0.0; extra == "dev"
Dynamic: license-file

# mper.py

Discord bot permission scanner - Analyzes discord.py code to detect required permissions and generate invite links.

discord.pyボットのコードを解析し、必要な権限を検出して招待リンクを生成するツールです。

## Features / 機能

- **Method-based detection (PRIMARY)**: Detects discord.py method calls (`.ban()`, `.kick()`, `.send()`, etc.) and infers required BOT permissions
- **Evidence tracking**: Shows which method calls at which lines require which permissions
- **All 49 Discord permissions**: Supports all Discord API permissions (as of 2025-12-22)
- **Context-aware detection**: Handles `member.edit(nick=...)`, `member.edit(mute=...)`, etc.
- **Decorator support**: `@bot_has_permissions` (supplementary), `@has_permissions` (user requirements only)

## Installation / インストール方法

```sh
pip install mper
```

## Usage / 使い方

```sh
mper /path/to/bot/directory CLIENT_ID
```

### Examples / 例

```sh
# Basic usage
mper /home/user/my_discord_bot 123456789012345678

# With detailed report
mper /home/user/my_discord_bot 123456789012345678 --report

# Verbose output
mper /home/user/my_discord_bot 123456789012345678 --verbose

# Exclude directories
mper /home/user/my_discord_bot 123456789012345678 --exclude tests docs

# Custom OAuth2 scopes
mper /home/user/my_discord_bot 123456789012345678 --scope bot --scope applications.commands
```

### CLI Options / オプション

| Option | Description |
|--------|-------------|
| `--report` | Print detailed permissions report with evidence |
| `--verbose`, `-v` | Show detailed output during scanning |
| `--no-inferred` | Only use declared permissions (from decorators) |
| `--exclude` | Additional directories to exclude |
| `--scope` | OAuth2 scopes for invite link (default: bot, applications.commands) |
| `--output`, `-o` | Output file for invite link (default: bot_invite_url.txt) |

### Output Example / 出力例

```
======================================================================
DETECTED PERMISSIONS (from method calls - PRIMARY)
----------------------------------------------------------------------

ban_members (0x4):
  bot.py:15 -> member.ban()
    [high] Ban a member from the guild

manage_messages (0x2000):
  bot.py:25 -> channel.purge()
    [high] Bulk delete messages

======================================================================
INVITE LINK PERMISSIONS
======================================================================
Source: method-based detection + @bot_has_permissions

  Permissions: ban_members, manage_messages, send_messages
  Integer: 10246
  Hex: 0x2806
```

## How It Works / 仕組み

1. **Method-based detection (PRIMARY)**: Scans Python AST for discord.py method calls and maps them to required permissions
2. **`@bot_has_permissions` (SUPPLEMENTARY)**: Explicit bot permission declarations are added to invite link
3. **`@has_permissions` (REFERENCE ONLY)**: User permission requirements are shown in report but NOT included in invite link

## Supported Permissions / 対応権限

All 49 Discord permissions are supported (bits 0-46, 49-50). See [Discord API Documentation](https://discord.com/developers/docs/topics/permissions) for details.

## License / ライセンス

This project is licensed under the MIT License. See [LICENSE](LICENSE) for details.

このツールはMITライセンスのもとで公開されています。複製、編集、再公開は基本的に全て許可されています。

## Issues / 質問や不具合の報告

Please create issues with appropriate tags:
- `bug` - Bug reports / バグ報告
- `enhancement` - Feature requests / 要望
- `question` - Questions / 質問

## Credits / クレジット

- Developer: [@FreeWiFi7749](https://github.com/FreeWiFi7749)
