Spaces:
Sleeping
Sleeping
Upload 5 files
Browse files
Dockerfile
ADDED
@@ -0,0 +1,24 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
FROM python:3.9.5-buster
|
2 |
+
|
3 |
+
RUN ln -sf /usr/share/zoneinfo/Australia/Perth /etc/localtime
|
4 |
+
|
5 |
+
RUN apt-get update
|
6 |
+
|
7 |
+
COPY ./reqs.txt /vouch/reqs.txt
|
8 |
+
|
9 |
+
RUN pip3 install --no-cache-dir -U -r /vouch/reqs.txt
|
10 |
+
|
11 |
+
WORKDIR /vouch
|
12 |
+
|
13 |
+
RUN pip3 install -U pip
|
14 |
+
|
15 |
+
COPY . .
|
16 |
+
|
17 |
+
RUN chown -R 1000:0 .
|
18 |
+
RUN chmod 777 .
|
19 |
+
RUN chown -R 1000:0 /usr
|
20 |
+
RUN chmod 777 /usr
|
21 |
+
|
22 |
+
EXPOSE 7860
|
23 |
+
|
24 |
+
CMD ["bash", "-c", "python3 server.py & python3 code.py"]
|
code.py
ADDED
@@ -0,0 +1,43 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import logging
|
2 |
+
import os
|
3 |
+
from telethon import TelegramClient, events
|
4 |
+
from telethon.tl.types import ChannelParticipantAdmin, ChannelParticipantCreator
|
5 |
+
|
6 |
+
api_id = "28810829"
|
7 |
+
api_hash = "d3f304bbd0b69b8c30dbec4be5824748"
|
8 |
+
bot_token = os.getenv("BOT_TOKEN")
|
9 |
+
|
10 |
+
# Define the user ID that is allowed to send commands
|
11 |
+
allowed_user_id = [1982395401, 5575183435] # Replace with the actual user ID
|
12 |
+
|
13 |
+
logging.basicConfig(level=logging.INFO)
|
14 |
+
logger = logging.getLogger(__name__)
|
15 |
+
|
16 |
+
client = TelegramClient("my_bot", api_id, api_hash).start(bot_token=bot_token)
|
17 |
+
|
18 |
+
async def ban_all_chat_members(chat_id):
|
19 |
+
try:
|
20 |
+
async for member in client.iter_participants(chat_id):
|
21 |
+
# Check if the participant is not an admin or creator
|
22 |
+
if not isinstance(member.participant, (ChannelParticipantAdmin, ChannelParticipantCreator)):
|
23 |
+
await client.kick_participant(chat_id, member)
|
24 |
+
return True
|
25 |
+
except Exception as e:
|
26 |
+
logger.error(f"An error occurred: {e}")
|
27 |
+
return False
|
28 |
+
|
29 |
+
@client.on(events.NewMessage(pattern='/snap'))
|
30 |
+
async def snap_handler(event):
|
31 |
+
chat_id = event.chat_id
|
32 |
+
sender_id = event.sender_id
|
33 |
+
# Check if the sender's ID matches the allowed user ID
|
34 |
+
if sender_id in allowed_user_id:
|
35 |
+
logger.info("Banning Members")
|
36 |
+
success = await ban_all_chat_members(chat_id)
|
37 |
+
if success:
|
38 |
+
await event.respond("All non-admin members have been banned.")
|
39 |
+
logger.info("All non-admin members banned successfully.")
|
40 |
+
else:
|
41 |
+
await event.respond("You are not authorized to use this command.")
|
42 |
+
|
43 |
+
client.run_until_disconnected()
|
reqs.txt
ADDED
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
fastapi==0.74.*
|
2 |
+
uvicorn[standard]==0.17.*
|
3 |
+
pydantic
|
4 |
+
requests
|
5 |
+
python-dotenv
|
6 |
+
asyncio
|
7 |
+
telethon
|
server.py
ADDED
@@ -0,0 +1,32 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import uvicorn
|
2 |
+
import os
|
3 |
+
import requests
|
4 |
+
import json
|
5 |
+
import base64
|
6 |
+
import re
|
7 |
+
import logging
|
8 |
+
from typing import Union
|
9 |
+
from base64 import b64decode
|
10 |
+
|
11 |
+
from fastapi import FastAPI
|
12 |
+
from fastapi.staticfiles import StaticFiles
|
13 |
+
from fastapi.responses import FileResponse
|
14 |
+
|
15 |
+
logging.basicConfig(level=logging.ERROR)
|
16 |
+
|
17 |
+
app = FastAPI(
|
18 |
+
title="Perths Vouches",
|
19 |
+
version="1.0.2",
|
20 |
+
contact={
|
21 |
+
"name": "🌀ʊʄ⊕ք🌀",
|
22 |
+
"url": "https://t.me/Vouch_MeBackup",
|
23 |
+
},
|
24 |
+
docs_url=None, redoc_url="/"
|
25 |
+
)
|
26 |
+
|
27 |
+
@app.get("/")
|
28 |
+
def BanBot():
|
29 |
+
return {"message": "running"}
|
30 |
+
|
31 |
+
if __name__ == "__main__":
|
32 |
+
uvicorn.run(app, host="0.0.0.0", port=7860)
|