def Add(self, _Item): """ Adds a new item to the collection """ if not isinstance(_Item, self.Instance): Logs.Error(f'{_Item} is not instance of {self.Instance}!') Index = getattr(_Item, self.Index, None) if Index is None: Logs.Error(f'{self.Index} of {repr (_Item)} is invalid!') self[Index] = _Item
def __setitem__(self, _Key, _Value): """ Adds support for using this[Key] = Value on this """ if not isinstance(_Value, self.Instance): Logs.Error(f'{_Value} is not instance of {self.Instance}!') dict.__setitem__(self, _Key, _Value)
def Convert(Files=None): if isinstance(Files, str): Files = [Files] for InFile in Files: try: if not InFile.endswith('.obj'): Logs.Warning(InFile + ' Does not look like to be a valid obj file!') continue Object = ObjFile(InFile) Egg = Object.ToEgg() Root, Ext = os.path.splitext(InFile) OutFile = Root + '.egg' Egg.removeUnusedVertices(GlobPattern('')) if True: Egg.triangulatePolygons(EggData.TConvex & EggData.TPolygon) if True: Egg.recomputePolygonNormals() return Egg except Exception as Error: print(Error)
def Complete (self): FinishedPath = os.path.join (self.FilePath + self.FileName) + '.html' HTML = Evaluate (_Elements, self) with open (FinishedPath, 'w+') as File: File.write (HTML) Logs.Success ('Successfully created the HTML file at: ' + FinishedPath)
async def LoadCogs (self, _Folder, _Cogs, _IsCommands = True): for Cog in _Cogs: Cog = '{0}.{1}Command' if _IsCommands else '{0}.{1}' Cog = Cog.format (_Folder, Cog) try: self.load_extension (Cog) except Exception as Error: ErrorMsg = '{0} cannot be loaded. Error: {0}'.format (Cog, Error) Logs.Error (ErrorMsg)
def __init__ (self, Name, _Site, TextType, Color = '#000000', Bg_Color = '#ffffff', IsBold = False): if not isinstance (_Site, Site): #print ('Site needs to be a site element!') Logs.Error ('Site needs to be a site element!') return elif not isinstance (TextType, _Text): #print ('Text needs to be a text element!') Logs.Error ('Text needs to be a text element!') return self.Name = Name self._Site = _Site self.TextType = TextType self.Color = Color self.Bg_Color = Bg_Color self.IsBold = IsBold if not Name in _Classes[_Site.FileName].keys(): _Classes[_Site.FileName][Name] = [TextType, Color, Bg_Color, IsBold]
def __UseMaterial(self, _Material): if False: print('__usematerial:', 'material:', _Material) if _Material in self.MaterialsByName: self.CurrentMaterial = _Material else: Logs.Error('__UseMaterial: Unkown Material ' + _Material) return self
def __add__(self, _Value): """ Adds support for using + on this """ if isinstance(_Value, Collection): if isinstance(_Value.Instance, self.Instance): [self.Add(Item) for Item in _Value] elif isinstance(_Value, self.Instance): self.Add(_Value) else: raise Logs.Error('Item is not a collection or instance of')
def Add (self, _Type, _Class, _Position, _Text, _Button_Size = '', _IsLink = False, _Link = '#'): if not isinstance (_Class, Class): #print ('Class must be a class element!') Logs.Error ('Class must be a class element!') return if not _Type in _Elements[self.FileName].keys(): _Elements[self.FileName][_Type] = [] if not _Class in _Classes[self.FileName].keys(): _Classes[self.FileName][_Class] = [] _Elements[self.FileName][_Type].append([_Class, _Position, _Text, _Button_Size, _IsLink, _Link])
def Template (self, _Template): if not isinstance (_Template, Log): Logs.Error ('No template found!') return return Log (_Template.Message, _Template.IPrefix, _Template.ISuffix)
async def on_ready(self): Logs.Server('Chatto has been booted ;)')
def Evaluate (_Data, _Site): _HTML = '<html><head><title>{Title}</title><link rel = "shortcut icon" type = "image/png" href = "{Icon}" /><style>{{Style}}</style></head><body>{{Elements}}</body></html>' _Style_, _Elements_ = '', '' _HTML = _HTML.format (Title = _Site.Title, Icon = _Site.FavIcon) _Style_ += '*{background-color:' + _Site.Color + ';}' for Element in _Classes[_Site.FileName]: CurClass = _Classes[_Site.FileName][Element] if not CurClass: continue if CurClass[3] == True: _Style_ += f'.{Element}' + '{' + 'font-family:{0};font-size:{1};background-color:{2};color:{3};font-weight:{4};position:absolute;border:none;'.format (CurClass[0].Font, CurClass[0].Size, CurClass[2], CurClass[1], 'bold') + '}' else: _Style_ += f'.{Element}' + '{' + 'font-family:{0};font-size:{1};background-color:{2};color:{3};position:absolute;border:none'.format (CurClass[0].Font, CurClass[0].Size, CurClass[2], CurClass[1]) + '}' Object = _Data[_Site.FileName] _Texts = Object.get ('TEXT') _Buttons = Object.get ('BUTTON') _Images = Object.get ('IMAGE') try: for Element in _Texts: Current = '' Type = Element[0].TextType Name = Element[0].Name Value = Element[2] Left = Element[1][0] Top = Element[1][1] IsLink = Element[4] Link = Element[5] if Left.lower () == 'center': Left = (1920 / 2) - (ElementWidth / 2) _Link = '<a href = "{Link_}">{{Value_}}</a>'.format (Link_ = Link) if Type.Name.lower () in _TextTypes: Current = '<{0} class = "{1}" style = "left:{2}px;top:{3}px;">{4}</{5}>'.format (Type.Name.lower(), Name, Left, Top, Value, Type.Name.lower ()) else: #print ('Unkown text element!') Logs.Error ('Unkown text element!') return if IsLink: _Elements_ += _Link.format (Value_ = Current) else: _Elements_ += Current except: Logs.Debug ('No text elements..') try: for Element in _Buttons: Left = Element[1][0] Top = Element[1][1] if Element[2] != '': Width = Element[2][0] Height = Element[2][1] _Elements_ += '<form action = "{0}"><input class = "{1}" style = "left:{2}px;top:{3}px;width:{4};height:{5};" type = "submit" value = "{6}" /></form>'.format (Element[5], Element[0].Name, Left, Top, Width, Height, Element[3]) else: _Elements_ += '<form action = "{0}"><input class = "{1}" style = "left:{2}px;top:{3}px;" type = "submit" value = "{4}" /></form>'.format (Element[5], Element[0].Name, Left, Top, Element[3]) except: Logs.Debug ('No button elements..') try: for Element in _Images: Left = Element[1][0] Top = Element[1][1] Width = Element[2][0] Height = Element[2][0] IsLink = Element[3] Link = Element[4] if IsLink: _Elements_ += '<a href = "{0}"><img src = "{1}" width = "{2}" height = "{3}" style = "position:absolute;left:{4}px;top:{5}px;"></a>'.format (Link, Element[0], Width, Height, Left, Top) else: _Elements_ += '<img src = "{0}" width = "{1}" height = "{2}" style = "position:absolute;left:{3}px;top:{4}px;">'.format (Element[0], Width, Height, Left, Top) except: Logs.Debug ('No image elements..') return _HTML.format (Style = _Style_, Elements = _Elements_)
def debug(self, msg: str) -> NoReturn: Logs.Debug(msg)
def error(self, msg: str) -> NoReturn: Logs.Error(msg)
def warning(self, msg: str) -> NoReturn: Logs.Warning(msg)
def success(self, msg: str) -> NoReturn: Logs.Success(msg)
def server(self, msg: str) -> NoReturn: Logs.Server(msg)
Data['Users'] = str(Client.get_server(Data['ServerID']).member_count) with open('Config.json', 'w') as Config: Config.write(json.dumps(Data)) Client.remove_command('help') Client.load_extension('Events') for Command in Data['Commands']: Command = '{0}.{1}Command'.format(Data['CommandsFolder'], Command) try: Client.load_extension(Command) except Exception as Error: ErrorMsg = '{0} cannot be loaded. Error: {0}'.format( Command, Error) Logs.Error(ErrorMsg) for Module in Data['Modules']: Module = '{0}.{1}'.format(Data['ModulesFolder'], Module) try: Client.load_extension(Module) except Exception as Error: ErrorMsg = '{0} cannot be loaded. Error: {0}'.format(Module, Error) Logs.Error(ErrorMsg) Client.run(Token)
def Read(self, _FileName, _Verbose=False): if _Verbose: print('ObjFile.Read:', 'filename:', _FileName) self.FileName = _FileName self.Objects = ['defaultobject'] self.Groups = ['defaultgroup'] self.Points = [] self.UVS = [] self.Normals = [] self.Faces = [] self.PolyLines = [] self.MatLibs = [] self.MaterialsByName = {} self.Comments = {} self.CurrentObject = self.Objects[0] self.CurrentGroup = self.Groups[0] self.CurrentMaterial = None try: File = open(_FileName) Lines = File.readlines() except: return self LineNumber = 0 for Line in Lines: Line = Line.strip() LineNumber += 1 if not Line: continue if Line[0] == '#': self.Comments[LineNumber] = Line #print (Line) continue Tokens = Line.split() if not Tokens: continue if Tokens[0] == 'mtllib': if _Verbose: print('mtllib:', Tokens[1:]) Path = os.path.dirname(self.FileName) MtlLib = MtlFile(Path + '/' + Tokens[1]) self.MatLibs.append(MtlLib) self.IndexMaterials(MtlLib) continue if Tokens[0] == 'g': if _Verbose: print('g:', Tokens[1:]) self.__NewGroup(''.join(Tokens[1:])) continue if Tokens[0] == 'o': if _Verbose: print('o:', tokens[1:]) self.__NewObject(''.join(Tokens[1:])) continue if Tokens[0] == 'usemtl': if _Verbose: print('usemtl:', Tokens[1:]) self.__UseMaterial(Tokens[1]) continue if Tokens[0] == 'v': if _Verbose: print('v:', Tokens[1:]) self.__NewV(Tokens[1:]) continue if Tokens[0] == 'vn': if _Verbose: print('vn:', Tokens[1:]) self.__NewNormal(Tokens[1:]) continue if Tokens[0] == 'vt': if _Verbose: print('vt:', Tokens[1:]) self.__NewUV(Tokens[1:]) continue if Tokens[0] == 'f': if _Verbose: print('f:', Tokens[1:]) self.__NewFace(Tokens[1:]) continue if Tokens[0] == 's': Logs.Warning(f'{_FileName} @ {str (LineNumber)}: Ignoring: ' + ''.join(Tokens)) continue if Tokens[0] == 'l': if _Verbose: print('l:', Tokens[1:]) self.__NewPolyLine(Tokens[1:]) continue print(f'{_FileName}:{str (LineNumber)}:', 'Unknown:', Tokens) File.close() return self
async def on_ready(): await Client.change_presence(game=discord.Game( name=Data['Status'].format(Data['Prefix'], str(Data['Users'])))) Logs.Server('The bot has been booted!')
async def on_ready (self): await self.change_presence (game = discord.Game (name = self.Status)) Logs.Server ('The bot has been booted!') Log.Log ('[{}] : (Bot Ready) -> The bot is now ready!')