• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

thomwiggers / onebot / 20855798495

09 Jan 2026 02:54PM UTC coverage: 69.064%. Remained the same
20855798495

push

github

thomwiggers
style: fix unused import in entrypoint.py

826 of 1196 relevant lines covered (69.06%)

3.45 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

33.33
/onebot/plugins/python.py
1
"""
2
=====================================================
3
:mod:`onebot.plugins.python` Run python commands in docker
4
=====================================================
5

6
Allow to run Python commands
7

8
Config:
9
=======
10

11
.. code-block: ini
12

13
    [bot]
14
    includes=
15
      onebot.plugins.python
16
"""
17

18
from typing import Self
5✔
19
import irc3
5✔
20
from irc3.plugins.command import command
5✔
21
import subprocess
5✔
22

23

24
@irc3.plugin
5✔
25
class PythonPlugin:
5✔
26
    """Execute commands after having connected"""
27

28
    def __init__(self, bot):
5✔
29
        self.bot = bot
×
30
        self.log = bot.log.getChild(__name__)
×
31

32
    @command(use_shlex=False)
5✔
33
    def py(self, _mask, _target, args):
5✔
34
        """Execute a command in a Python 3 interpreter
35

36
        %%py <command>...
37
        """
38
        cmd = " ".join(args["<command>"])
×
39
        self.log.debug("Command: '%s'", cmd)
×
40
        proc = subprocess.run(
×
41
            [
42
                "docker",
43
                "run",
44
                "--rm",
45
                "--read-only",
46
                "--security-opt=no-new-privileges:true",
47
                "--net=none",
48
                "--log-driver=none",
49
                "--cap-drop=ALL",
50
                "--pids-limit=10",
51
                "--memory=50M",
52
                "--cpus=0.5",  # CPU shares
53
                "--ipc=none",  # inter-process communication (none < priv)
54
                "--tmpfs",
55
                "/tmp:rw,noexec,nosuid,size=64k",
56
                "ghcr.io/thomwiggers/onebot/python-sandbox",
57
                cmd,
58
            ],
59
            capture_output=True,
60
            text=True,
61
            timeout=20,
62
        )
63
        if proc.returncode != 0:
×
64
            self.log.warning("Error when calling docker: '%s'", proc.stderr)
×
65
            yield "Error code {} when calling Docker".format(proc.returncode)
×
66
            return
×
67
        lines = proc.stdout.split("\n")
×
68
        self.log.debug("Received: %s", proc.stdout)
×
69
        if len(lines) > 2:
×
70
            self.log.warning("Too many lines for '%s'", cmd)
×
71
            self.log.info("Output: %r", lines)
×
72
            yield "Too many lines returned?"
×
73
            return
×
74
        for line in lines:
×
75
            yield line[:200]
×
76

77
    @classmethod
78
    def reload(cls, old: Self) -> Self:  # pragma: no cover
79
        return cls(old.bot)
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc