-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
128 lines (92 loc) · 3.54 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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
import os, dotenv
import hikari, lightbulb
import asyncio, functools
import images
import io
import random
import aiofiles
import multiprocessing
from datetime import datetime
dotenv.load_dotenv(".env")
bot = lightbulb.BotApp(
token=os.getenv("TOKEN", ""),
banner=None,
)
async def create_banner_command(ctx: lightbulb.Context, banner_type: images.bannerType):
await ctx.respond(hikari.ResponseType.DEFERRED_MESSAGE_CREATE)
start = datetime.now()
async with ctx.author.display_avatar_url.stream() as stream:
data = await stream.read()
member_count: int = 0
if ctx.guild_id != None:
member_count = len(await bot.rest.fetch_members(ctx.guild_id))
print(ctx.author.username)
banner_data = images.bannerData(
banner_type=banner_type,
username=(ctx.author.username.split("#"))[0],
user_descriminator=ctx.author.discriminator,
pfp_bytes=data,
member_count=member_count
)
loop = asyncio.get_running_loop()
result = await loop.run_in_executor(None, functools.partial(images.banner_create, data=banner_data))
current = datetime.now()
time_in_sec = (current - start).total_seconds()
print("created and saved image in: " + str(time_in_sec))
if result != None:
await ctx.respond(
hikari.ResponseType.DEFERRED_MESSAGE_UPDATE,
"Here you go! took `" + str(time_in_sec * 1000) + "`ms or `" + str(time_in_sec) + "`s",
attachment=hikari.Bytes(result, "welcome.jpeg"),
)
return
await ctx.respond(
hikari.ResponseType.DEFERRED_MESSAGE_UPDATE,
"Something went wrong.",
)
@bot.command
@lightbulb.command("join", "generate a join banner of you!")
@lightbulb.implements(lightbulb.SlashCommand)
async def test(ctx: lightbulb.Context) -> None:
await create_banner_command(ctx, images.bannerType.JOIN)
@bot.command
@lightbulb.command("leave", "generate a leave banner of you!")
@lightbulb.implements(lightbulb.SlashCommand)
async def leave(ctx: lightbulb.Context) -> None:
await create_banner_command(ctx, images.bannerType.LEAVE)
@bot.command
@lightbulb.command("level", "generate a level banner of you!")
@lightbulb.implements(lightbulb.SlashCommand)
async def level(ctx: lightbulb.Context) -> None:
await ctx.respond(hikari.ResponseType.DEFERRED_MESSAGE_CREATE)
start = datetime.now()
async with ctx.author.display_avatar_url.stream() as stream:
data = await stream.read()
member_count: int = 0
if ctx.guild_id != None:
member_count = len(await bot.rest.fetch_members(ctx.guild_id))
banner_data = images.bannerData(
banner_type=images.bannerType.LEVEL,
username=ctx.author.username,
user_descriminator=ctx.author.discriminator,
pfp_bytes=data,
member_count=member_count
)
loop = asyncio.get_running_loop()
result = await loop.run_in_executor(None, functools.partial(images.banner_create, data=banner_data))
current = datetime.now()
time_in_sec = (current - start).total_seconds()
print("created and saved image in: " + str(time_in_sec))
if result != None:
await ctx.respond(
hikari.ResponseType.DEFERRED_MESSAGE_UPDATE,
"Here you go! took `" + str(time_in_sec * 1000) + "`ms or `" + str(time_in_sec) + "`s",
attachment=hikari.Bytes(result, "welcome.jpeg"),
)
return
await ctx.respond(
hikari.ResponseType.DEFERRED_MESSAGE_UPDATE,
"Something went wrong.",
)
if __name__ == "__main__":
bot.run()