Files
2026-05-02 03:23:51 +02:00

130 lines
6.0 KiB
Go

package transcript
const HTMLTemplate = `<!DOCTYPE html>
<html lang="fr">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width,initial-scale=1">
<title>Transcript {{.Ticket.Type}}-{{printf "%04d" .Ticket.TicketNumber}}</title>
<style>
*{box-sizing:border-box;margin:0;padding:0;}
body{background:#36393f;color:#dcddde;font-family:'Segoe UI',Arial,sans-serif;font-size:14px;line-height:1.5;}
.header{background:#2f3136;padding:16px 24px;border-bottom:1px solid #202225;}
.header h1{color:#fff;font-size:1.1em;margin-bottom:4px;}
.header p{color:#b9bbbe;font-size:.85em;margin-top:2px;}
.messages{padding:8px 0;}
.message{display:flex;padding:6px 16px;gap:12px;min-width:0;}
.message:hover{background:#32353b;}
.avatar{width:40px;height:40px;border-radius:50%;flex-shrink:0;object-fit:cover;}
.avatar-placeholder{width:40px;height:40px;border-radius:50%;flex-shrink:0;background:#5865f2;display:flex;align-items:center;justify-content:center;color:#fff;font-weight:700;font-size:1.1em;}
.msg-body{flex:1;min-width:0;}
.msg-header{display:flex;align-items:baseline;gap:8px;margin-bottom:2px;}
.author{font-weight:700;color:#fff;font-size:.9em;}
.timestamp{color:#72767d;font-size:.75em;}
.text{color:#dcddde;word-break:break-word;}
.attachment{margin-top:4px;}
.attachment a{color:#00b0f4;text-decoration:none;font-size:.85em;}
.attachment a:hover{text-decoration:underline;}
/* Embeds */
.embed{background:#2f3136;border-radius:0 4px 4px 0;margin-top:6px;padding:8px 12px 12px 12px;max-width:520px;border-left:4px solid #4f545c;}
.embed-author{display:flex;align-items:center;gap:6px;margin-bottom:4px;}
.embed-author-icon{width:20px;height:20px;border-radius:50%;object-fit:cover;}
.embed-author-name{font-size:.85em;font-weight:600;color:#fff;}
.embed-author-name a{color:#fff;text-decoration:none;}
.embed-author-name a:hover{text-decoration:underline;}
.embed-header{display:flex;justify-content:space-between;align-items:flex-start;gap:8px;}
.embed-title-wrap{flex:1;}
.embed-title{font-weight:700;font-size:.95em;color:#fff;margin-bottom:4px;}
.embed-title a{color:#00b0f4;text-decoration:none;}
.embed-title a:hover{text-decoration:underline;}
.embed-thumb{width:80px;height:80px;border-radius:4px;object-fit:cover;flex-shrink:0;}
.embed-description{color:#dcddde;font-size:.9em;margin-bottom:8px;word-break:break-word;}
.embed-fields{display:flex;flex-wrap:wrap;gap:8px;margin-bottom:8px;}
.embed-field{min-width:0;}
.embed-field.inline{flex:1 1 140px;max-width:calc(33% - 6px);}
.embed-field.block{flex:1 1 100%;}
.embed-field-name{font-weight:700;font-size:.85em;color:#fff;margin-bottom:2px;}
.embed-field-value{font-size:.85em;color:#dcddde;word-break:break-word;}
.embed-image{margin-top:8px;}
.embed-image img{max-width:400px;max-height:300px;border-radius:4px;display:block;}
.embed-footer{display:flex;align-items:center;gap:6px;margin-top:8px;}
.embed-footer-icon{width:16px;height:16px;border-radius:50%;object-fit:cover;}
.embed-footer-text{color:#72767d;font-size:.75em;}
.embed-footer-sep{color:#72767d;font-size:.75em;}
.embed-empty{color:#72767d;font-style:italic;font-size:.85em;}
.footer{text-align:center;color:#72767d;font-size:.8em;padding:12px;border-top:1px solid #202225;margin-top:8px;}
</style>
</head>
<body>
<div class="header">
<h1>Transcript — {{.Ticket.Type}}-{{printf "%04d" .Ticket.TicketNumber}}</h1>
<p>Utilisateur : {{.Ticket.UserID}} &nbsp;|&nbsp; Ouvert le : {{.Ticket.OpenedAt.Format "02/01/2006 à 15:04 UTC"}}</p>
<p>Généré le {{.Generated}} &nbsp;|&nbsp; {{len .Messages}} messages</p>
</div>
<div class="messages">
{{range .Messages}}
<div class="message">
{{if .AuthorAvatar}}<img class="avatar" src="{{.AuthorAvatar}}" alt="" onerror="this.style.display='none'">
{{else}}<div class="avatar-placeholder">{{.AuthorInitial}}</div>{{end}}
<div class="msg-body">
<div class="msg-header">
<span class="author">{{.AuthorName}}</span>
<span class="timestamp">{{.Timestamp}}</span>
</div>
{{if .Content}}<div class="text">{{.Content}}</div>{{end}}
{{range .Attachments}}
<div class="attachment">📎 <a href="{{.URL}}" target="_blank" rel="noopener">{{.Name}}</a></div>
{{end}}
{{range .Embeds}}
{{template "embed" .}}
{{end}}
</div>
</div>
{{end}}
</div>
<div class="footer">Bot Ticket — Transcript généré automatiquement</div>
</body>
</html>
{{define "embed"}}
<div class="embed" style="border-left-color:{{.Color}}">
<div class="embed-inner">
{{if .Empty}}<span class="embed-empty">[Embed vide]</span>{{else}}
{{if .AuthorName}}
<div class="embed-author">
{{if .AuthorIcon}}<img class="embed-author-icon" src="{{.AuthorIcon}}" alt="">{{end}}
<span class="embed-author-name">{{if .AuthorURL}}<a href="{{.AuthorURL}}" target="_blank" rel="noopener">{{.AuthorName}}</a>{{else}}{{.AuthorName}}{{end}}</span>
</div>
{{end}}
<div class="embed-header">
<div class="embed-title-wrap">
{{if .Title}}<div class="embed-title">{{if .TitleURL}}<a href="{{.TitleURL}}" target="_blank" rel="noopener">{{.Title}}</a>{{else}}{{.Title}}{{end}}</div>{{end}}
{{if .Description}}<div class="embed-description">{{.Description}}</div>{{end}}
</div>
{{if .ThumbURL}}<img class="embed-thumb" src="{{.ThumbURL}}" alt="">{{end}}
</div>
{{if .Fields}}
<div class="embed-fields">
{{range .Fields}}
<div class="embed-field {{if .Inline}}inline{{else}}block{{end}}">
<div class="embed-field-name">{{.Name}}</div>
<div class="embed-field-value">{{.Value}}</div>
</div>
{{end}}
</div>
{{end}}
{{if .ImageURL}}<div class="embed-image"><img src="{{.ImageURL}}" alt=""></div>{{end}}
{{if or .FooterText .Timestamp}}
<div class="embed-footer">
{{if .FooterIcon}}<img class="embed-footer-icon" src="{{.FooterIcon}}" alt="">{{end}}
{{if .FooterText}}<span class="embed-footer-text">{{.FooterText}}</span>{{end}}
{{if and .FooterText .Timestamp}}<span class="embed-footer-sep">•</span>{{end}}
{{if .Timestamp}}<span class="embed-footer-text">{{.Timestamp}}</span>{{end}}
</div>
{{end}}
{{end}}
</div>
</div>
{{end}}`