-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
66 lines (48 loc) · 1.95 KB
/
main.py
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
import disnake
from disnake.ext import commands, tasks
from PIL import Image, ImageDraw, ImageFont, ImageSequence
import io
from config import *
intents = disnake.Intents.all()
intents.members = True
bot = commands.Bot(command_prefix='!', intents=intents)
@bot.event
async def on_ready():
print(f'Зашёл в {bot.user.name}')
guild = bot.get_guild(GUILD_ID)
if guild:
banner_loop.start(guild)
@tasks.loop(seconds=10)
async def banner_loop(guild):
await update_server_banner(guild)
async def update_server_banner(guild):
if not guild:
return await print("Invalid guild ID.")
banner_path = 'banner/banner.gif'
im = Image.open(banner_path)
frames = []
for frame in ImageSequence.Iterator(im):
width, height = frame.size
image = Image.new("RGBA", (width, height), (255, 255, 255, 0))
draw = ImageDraw.Draw(image)
total_members = guild.member_count
voice_members = sum(1 for member in guild.members if member.voice)
font_path = 'fonts/txt.ttf'
try:
font = ImageFont.truetype(font_path, size=40)
fontr = ImageFont.truetype(font_path, size=60)
except IOError:
return await print(f"Ошибка загрузки шрифта: {font_path}")
text = f"{total_members}"
draw.text((100, 160), text, fill=COLOR, font=font)
draw.text((150, 220), f"{voice_members}", fill=COLOR, font=fontr)
combined_frame = Image.alpha_composite(frame.convert('RGBA'), image)
frame_bytes = io.BytesIO()
combined_frame.save(frame_bytes, format="GIF")
frame = Image.open(frame_bytes)
frames.append(frame)
frames[0].save('server_stats.gif', save_all=True, append_images=frames[1:])
with open('server_stats.gif', 'rb') as file:
gif_data = file.read()
await guild.edit(banner=gif_data)
bot.run(TOKEN)