File: report.py

package info (click to toggle)
crossfire-maps 1.75.0%2Bdfsg1-1
  • links: PTS
  • area: main
  • in suites: bookworm, bullseye, forky, sid, trixie
  • size: 275,656 kB
  • sloc: python: 7,711; sql: 92; sh: 73; makefile: 7
file content (39 lines) | stat: -rw-r--r-- 1,087 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
from email.mime.text import MIMEText
import subprocess

import Crossfire

def report(pl):
    desc = Crossfire.ScriptParameters()
    if desc == None:
        pl.Message("To report an issue, type 'report <description of the issue>'.")
        return

    details = {
        'PLAYER': Crossfire.WhoAmI().Name,
        'MAP': Crossfire.WhoAmI().Map.Path,
        'X': Crossfire.WhoAmI().X,
        'Y': Crossfire.WhoAmI().Y,
        'DESC': desc,
    }

    report = """
Reporter:   {PLAYER}
Map:        {MAP} ({X}, {Y})
Report:     {DESC}
""".format(**details)

    Crossfire.Log(Crossfire.LogInfo, "A problem was reported: %s" % (report))

    msg = MIMEText(report)
    recipient = "crossfire"
    msg["From"] = "crossfire"
    msg["Subject"] = "Crossfire issue report"

    result = subprocess.run(['sendmail', recipient], input=msg.as_bytes())
    if result.returncode == 0:
        pl.Message("Thank you for your report.")
    else:
        pl.Message("There was an error reporting your problem. Please contact a Dungeon Master to report your problem.")

report(Crossfire.WhoAmI())