all repos — escarbot @ 0d332b999873f9a6d035d0977c0649b8ef7b6b19

Earthbound Café's custom Telegram bot, with lots of cool utilities built-in.

index.html (view raw)

  1<!DOCTYPE html>
  2<html lang="en">
  3<head>
  4    <meta charset="UTF-8">
  5    <meta name="viewport" content="width=device-width, initial-scale=1.0">
  6    <title>Bot Telegram Control Panel</title>
  7    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/milligram@1.4.1/dist/milligram.min.css">
  8    <style>
  9        label {
 10            display: inline-block;
 11        }
 12        body {
 13            background-color: #1f1f1f;
 14            color: #fff;
 15        }
 16        button:hover {
 17            background-color: #8842b3;
 18        }
 19        input, textarea {
 20            color: #fff;
 21            resize: vertical;
 22        }
 23    </style>
 24</head>
 25<body>
 26    <h1>EscarBot</h1>
 27
 28    <form action="/setLinks" id="linkForm">
 29        <label>
 30            <input type="checkbox" id="linkToggle" name="toggle"{{ if .LinkDetection }} checked{{ end }}>
 31            Link detection in group messages
 32        </label>
 33    </form>
 34
 35    <form action="/setChannelForward" id="channelForwardForm">
 36        <label>
 37            <input type="checkbox" id="channelForwardToggle" name="toggle"{{ if .ChannelForward }} checked{{ end }}>
 38            Message forwarding (channel)
 39        </label>
 40    </form>
 41
 42    <form action="/setAdminForward" id="adminForwardForm">
 43        <label>
 44            <input type="checkbox" id="adminForwardToggle" name="toggle"{{ if .AdminForward }} checked{{ end }}>
 45            Message forwarding (admin)
 46        </label>
 47    </form>
 48
 49    <form action="/setChannel" id="channelForm">
 50        <label>
 51            Channel ID:
 52            <input type="text" id="channelId" name="id" value="{{ .ChannelID }}" required>
 53        </label>
 54        <button type="submit">Change</button>
 55    </form>
 56
 57    <form action="/setGroup" id="groupForm">
 58        <label>
 59            Group ID:
 60            <input type="text" id="groupId" name="id" value="{{ .GroupID }}" required>
 61        </label>
 62        <button type="submit">Change</button>
 63    </form>
 64
 65    <form action="/setAdmin" id="adminForm">
 66        <label>
 67            Admin ID:
 68            <input type="text" id="adminId" name="id" value="{{ .AdminID }}" required>
 69        </label>
 70        <button type="submit">Change</button>
 71    </form>
 72
 73    <form id="messageForm">
 74        <label for="customMessage">Custom Message:</label>
 75        <textarea id="customMessage" name="customMessage" rows="4" required></textarea>
 76        <label>
 77            Recipient:
 78            <input type="text" id="recipientId" name="recipientId" value="{{ .GroupID }}" required>
 79        </label>
 80        <button id="customMessageButton">Send</button>
 81    </form>
 82
 83    <script>
 84        const sendMessageUrl = "https://api.telegram.org/bot{{ .Bot.Token }}/sendMessage"
 85        const messageParams = new URLSearchParams({
 86            "text": "",
 87            "chat_id": "",
 88            "reply_to_message_id": "",
 89            "parse_mode": "markdown",
 90            "disable_web_page_preview": "false",
 91            "disable_notification": "false",
 92        })
 93        const customMessageBox = document.getElementById("customMessage");
 94        function handleToggle(toggleId, formId) {
 95            document.getElementById(toggleId).addEventListener('change', () => {
 96                document.getElementById(formId).submit();
 97            });
 98        }
 99
100        handleToggle('linkToggle', 'linkForm');
101        handleToggle('channelForwardToggle', 'channelForwardForm');
102        handleToggle('adminForwardToggle', 'adminForwardForm');
103
104        document.getElementById("customMessageButton").addEventListener("click", (event) => {
105            event.preventDefault()
106            const value = customMessageBox.value;
107            const recipient = document.getElementById("recipientId").value;
108
109            messageParams.set("text", value);
110            messageParams.set("chat_id", recipient);
111            
112            const request_url = sendMessageUrl + "?" + messageParams;
113            console.log(request_url);
114            fetch(request_url).then((response) => {
115                response.json().then((data) => {
116                    console.log(data);
117                    if (data.ok) customMessageBox.value = "";
118                    else alert(data.description);
119                })
120            })
121        })
122    </script>
123</body>
124</html>