Moved guid functions to guid.py
This commit is contained in:
parent
783fe679f1
commit
64ec852f6e
41
exts/imports/guid.py
Normal file
41
exts/imports/guid.py
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
from struct import Struct, pack
|
||||||
|
|
||||||
|
def hex_to_char(a: int):
|
||||||
|
a = a & 0xf
|
||||||
|
out = chr(a - 10 + 0x61 if a > 9 else a + 0x30)
|
||||||
|
return out
|
||||||
|
|
||||||
|
|
||||||
|
def hexs_to_chars(_a, _b):
|
||||||
|
out = f'{hex_to_char(_a>>4)}{hex_to_char(_a)}{hex_to_char(_b>>4)}{hex_to_char(_b)}'
|
||||||
|
return out
|
||||||
|
|
||||||
|
|
||||||
|
def to_string(guid):
|
||||||
|
output = ''
|
||||||
|
output += hexs_to_chars(guid[0] >> 24, guid[0] >> 16)
|
||||||
|
output += hexs_to_chars(guid[0] >> 8, guid[0])
|
||||||
|
output += '-'
|
||||||
|
output += hexs_to_chars(guid[1] >> 8, guid[1])
|
||||||
|
output += '-'
|
||||||
|
output += hexs_to_chars(guid[2] >> 8, guid[2])
|
||||||
|
output += '-'
|
||||||
|
output += hexs_to_chars(guid[3], guid[4])
|
||||||
|
output += '-'
|
||||||
|
output += hexs_to_chars(guid[5], guid[6])
|
||||||
|
output += hexs_to_chars(guid[7], guid[8])
|
||||||
|
output += hexs_to_chars(guid[9], guid[10])
|
||||||
|
return output
|
||||||
|
|
||||||
|
|
||||||
|
def get_guid_string(id1: int, id2: int):
|
||||||
|
id1, id2 = (id1 << 32), (id2 & 0xFFFFFFFF)
|
||||||
|
id_int = id1 | id2
|
||||||
|
b = pack('q8x', id_int)
|
||||||
|
s = Struct('i2h8b')
|
||||||
|
guid = s.pack((int(b[3]) << 24) | (int(b[2]) << 16) | (int(b[1]) << 8) | b[0],
|
||||||
|
((int(b[5]) << 8) | b[4]),
|
||||||
|
(int(b[7]) << 8) | b[6],
|
||||||
|
*b[8:16]
|
||||||
|
)
|
||||||
|
return to_string(s.unpack(guid))
|
||||||
@ -4,7 +4,6 @@ import asyncio
|
|||||||
import discord
|
import discord
|
||||||
from discord.ext.commands.formatter import Paginator
|
from discord.ext.commands.formatter import Paginator
|
||||||
import numpy as np
|
import numpy as np
|
||||||
from struct import Struct, pack
|
|
||||||
|
|
||||||
|
|
||||||
class Capturing(list):
|
class Capturing(list):
|
||||||
@ -83,44 +82,3 @@ async def run_command(args):
|
|||||||
stdout, stderr = await process.communicate()
|
stdout, stderr = await process.communicate()
|
||||||
# Return stdout
|
# Return stdout
|
||||||
return stdout.decode().strip()
|
return stdout.decode().strip()
|
||||||
|
|
||||||
|
|
||||||
def hex_to_char(a: int):
|
|
||||||
a = a & 0xf
|
|
||||||
out = chr(a - 10 + 0x61 if a > 9 else a + 0x30)
|
|
||||||
return out
|
|
||||||
|
|
||||||
|
|
||||||
def hexs_to_chars(_a, _b):
|
|
||||||
out = f'{hex_to_char(_a>>4)}{hex_to_char(_a)}{hex_to_char(_b>>4)}{hex_to_char(_b)}'
|
|
||||||
return out
|
|
||||||
|
|
||||||
|
|
||||||
def to_string(guid):
|
|
||||||
output = ''
|
|
||||||
output += hexs_to_chars(guid[0] >> 24, guid[0] >> 16)
|
|
||||||
output += hexs_to_chars(guid[0] >> 8, guid[0])
|
|
||||||
output += '-'
|
|
||||||
output += hexs_to_chars(guid[1] >> 8, guid[1])
|
|
||||||
output += '-'
|
|
||||||
output += hexs_to_chars(guid[2] >> 8, guid[2])
|
|
||||||
output += '-'
|
|
||||||
output += hexs_to_chars(guid[3], guid[4])
|
|
||||||
output += '-'
|
|
||||||
output += hexs_to_chars(guid[5], guid[6])
|
|
||||||
output += hexs_to_chars(guid[7], guid[8])
|
|
||||||
output += hexs_to_chars(guid[9], guid[10])
|
|
||||||
return output
|
|
||||||
|
|
||||||
|
|
||||||
def get_guid_string(id1: int, id2: int):
|
|
||||||
id1, id2 = (id1 << 32), (id2 & 0xFFFFFFFF)
|
|
||||||
id_int = id1 | id2
|
|
||||||
b = pack('q8x', id_int)
|
|
||||||
s = Struct('i2h8b')
|
|
||||||
guid = s.pack((int(b[3]) << 24) | (int(b[2]) << 16) | (int(b[1]) << 8) | b[0],
|
|
||||||
((int(b[5]) << 8) | b[4]),
|
|
||||||
(int(b[7]) << 8) | b[6],
|
|
||||||
*b[8:16]
|
|
||||||
)
|
|
||||||
return to_string(s.unpack(guid))
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user