1
0
Fork 0
mirror of https://git.mctaylors.ru/mctaylors/Lurker.git synced 2024-11-25 12:18:03 +03:00
Lurker/client.py

115 lines
4.2 KiB
Python
Raw Normal View History

import next
import extensions
from random import randrange
from time import time
from math import trunc
from next.ext import commands
class Client(commands.CommandsClient):
async def get_prefix(self, message: next.Message):
return "!"
async def on_ready(self):
print(f"Authorized as {self.user.name}#{self.user.discriminator}")
try:
await self.edit_status(presence=next.PresenceType.focus,
text="Watching friend requests...")
except Exception as e:
print(f"Unable to edit status. ({e})")
@commands.command()
async def random(self, ctx: commands.Context, *args):
"""[x] (y) - Generates a random number"""
if not args:
await ctx.send("No arguments passed!")
return
try:
x = int(args[0])
y = 0
if 1 < len(args):
y = int(args[1])
except ValueError:
await ctx.send("Not a number!")
return
if x > y:
message = randrange(y, x + 1)
await ctx.send(f"**{str(message)}** `({y};{x})`")
return
message = randrange(x, y + 1)
await ctx.send(f"**{str(message)}** `({x};{y})`")
@commands.command()
async def timestamp(self, ctx: commands.Context):
"""Shows current timestamp"""
message = trunc(time())
await ctx.send(str(message))
@commands.command()
async def self(self, ctx: commands.Context):
"""Shows info about current user"""
author = ctx.author
name = f"{author.original_name}#{author.discriminator}"
if author.display_name is not None:
name = f"{author.display_name}\n" + name
original_avatar = None
if author.original_avatar is not None:
original_avatar = extensions.icon_info(author.original_avatar)
guild_avatar = None
if author.guild_avatar is not None:
guild_avatar = extensions.icon_info(author.guild_avatar)
roles = str()
for role in author.roles:
roles = f"{roles} {role.name},"
roles = roles[:-1]
if roles is str():
roles = None
logo = ":01J37TY299JWPPAT121HT2KKS9:"
await ctx.send(f"## {name}\n"
f"| ID | `{author.id}` |\n| --- | --- |\n"
f"| {logo} member since | <t:{trunc(author.created_at.timestamp())}:D> |\n"
f"| Profile picture | {original_avatar} |\n"
f"---\n| Server statistics | Value |\n| --- | --- |\n"
f"| Server nickname | {author.nickname} |\n"
f"| Server member since | <t:{trunc(author.created_at.timestamp())}:D> |\n"
f"| Server profile picture | {guild_avatar} |\n"
f"| Roles | {roles} |")
@commands.command()
async def server(self, ctx: commands.Context):
"""Shows info about current server"""
server = ctx.author.server
description = "No server description."
if server.description is not None:
description = '>'.join(('\n' + server.description.lstrip()).splitlines(True))
icon = None
if server.icon is not None:
icon = extensions.icon_info(server.icon)
banner = None
if server.banner is not None:
banner = extensions.icon_info(server.banner)
state = server.state # used for statistics
await ctx.send(f"## {server.name}\n"
f"{description}\n"
f"| ID | `{server.id}` |\n| --- | --- |\n"
f"| Created at | <t:{trunc(server.created_at.timestamp())}:D> |\n"
f"| Server icon | {icon} |\n"
f"| Server banner | {banner} |\n"
f"| Server owner | {server.owner.original_name}#{server.owner.discriminator} |\n"
f"---\n| Statistics | Value |\n| --- | --- |\n"
f"| Members | {len(state.users)} |\n"
f"| Channels | {len(state.channels)} |\n"
f"| Roles | {len(server.roles)} |\n"
f"| Emojis | {len(server.emojis)} |")