teqny

الجمعة، 5 يوليو 2019

  1. class StateMachineCard extends HTMLElement {
  2.   set hass(hass) {
  3.     if (!this.content) {
  4.       const card = document.createElement('ha-card');
  5.       card.header = this.config.title;
  6.       this.content = document.createElement('div');
  7.       this.content.style.padding = '0 16px 16px';
  8.       card.appendChild(this.content);
  9.       this.appendChild(card);
  10.     }
  11.  
  12.     const entityId = this.config.entity;
  13.     const state = hass.states[entityId];
  14.     const stateStr = state ? state.state : 'unavailable';
  15.  
  16.     var html = '<table width="100%"><tr>';
  17.    
  18.     for (let i = 0; i <= this.config.states.length-1; i++){
  19.       const state = this.config.states[i]
  20.       var service_data = '{"entity_id": "light.bedroom", "value": "' + i.toString()+'.0' + '" }';
  21.       if (i.toString()+'.0' == stateStr) {
  22.         html = html + '<td style="' + this.config.style_disabled + '">[' + state.name + ']</td>';
  23.       } else {
  24.         html = html + '<td style="' + this.config.style_enabled + '">[' + state.name + ']</td>';
  25.         // var service_data = '{"entity_id": "input_number.state_machine_kitchen", "value": "2.0" }';
  26.         // hass.services.call('input_number', 'set_value', service_data, False)
  27.         // html = html + '<td style="' + this.config.style_enabled + ' " onclick=\'this._hass.services.call(\'input_number\'\'set_value\', ' + service_data + ', False)\'>[' + state.name + ']</td>';
  28.       }
  29.     }
  30.  
  31.     html = html + '</tr></table>';
  32.     this.content.innerHTML = html;
  33.   }
  34.  
  35.   setConfig(config) {
  36.     if (!config.entity) {
  37.       throw new Error('You need to define an entity');
  38.     }
  39.     this.config = config;
  40.   }
  41.  
  42.   getCardSize() {
  43.     return 3;
  44.   }
  45. }
  46.  
  47. customElements.define('state-machine-card', StateMachineCard);
0
إقرأ المقال

                                                        python bot at one
  1. # https://discordapp.com/oauth2/authorize?client_id=596095379716571290&scope=bot&permissions=8 // inv url
  2. import discord
  3. from discord.ext import commands
  4. bot = commands.Bot(command_prefix='$')
  5. bot.remove_command('help')
  6. @bot.event
  7. async def on_ready():
  8.     print("Everything's all ready to go~")
  9.         game = discord.Game("with my dick!")
  10.         await bot.change_presence(status=discord.Status.online, activity=game)
  11. @bot.command()
  12. async def test(ctx, *, arg):
  13.     '''
  14.    Tests the bot avaliblity.
  15.    '''
  16.     await ctx.send(f"```Test Command\n------------\nMessage: {arg}\nAuthor: {ctx.author}\nServer: {ctx.guild}```")
  17. @bot.command()
  18. async def ping(ctx):
  19.     '''
  20.    Tests the latency of the bot to the server it runs on [Chase#0157]
  21.    '''
  22.     # Get the latency of the bot
  23.     latency = bot.latency  # Included in the Discord.py library
  24.     # Send it to the user
  25.     await ctx.send(f"**PONG!!** :ping_pong:\nLatency = {latency}")
  26. @bot.command()
  27. async def greet(ctx, user):
  28.     '''
  29.    Greet somebody into joining the server!
  30.    '''
  31.     await ctx.send(f":smiley: :wave: Hello, there! {user}")
  32. @bot.command()
  33. async def cat(ctx):
  34.     await ctx.send("https://media.giphy.com/media/JIX9t2j0ZTN9S/giphy.gif")
  35. @bot.command()
  36. async def info(ctx):
  37.     embed = discord.Embed(title="Kermit", description="Nicest bot there is ever.", color=0xeee657)
  38.     # give info about you here
  39.     embed.add_field(name="Developer", value="Chase#0157")
  40.     # Shows the number of servers the bot is member of.
  41.     embed.add_field(name="Server count", value=f"{len(bot.guilds)}")
  42.     # give users a link to invite thsi bot to their server
  43.     embed.add_field(name="Invite", value="https://shorturl.at/jsuT1")
  44.     await ctx.send(embed=embed)
  45. @bot.command()
  46. async def help(ctx):
  47.     embed = discord.Embed(title="Kermit", description="A Very Nice bot. List of commands are:", color=0xeee657)
  48.     embed.add_field(name="$test [argument]", value="Tests the bot's avaliblity", inline=False)
  49.     embed.add_field(name="$ping", value="Tests the bot's ping to it's server", inline=False)
  50.     embed.add_field(name="$greet [user]", value="Gives a nice greet message", inline=False)
  51.     embed.add_field(name="$cat", value="Shows a cute cat gif to lighten up the mood.", inline=False)
  52.     embed.add_field(name="$info", value="Shows a little info about the bot", inline=False)
  53.     embed.add_field(name="$help", value="Shows this message", inline=False)
  54.     embed.add_field(name="$kick [user]", value="Kicks an asshole :)", inline=False)
  55.     embed.add_field(name="$ban [user]", value="Bans a bigger asshole :)", inline=False)
  56.     embed.add_field(name="$purge [number]", value="Removes a number of messages.", inline=False)
  57.     embed.add_field(name="$perms [user]", value="Returns the member’s guild permissions value.", inline=False)
  58.     embed.add_field(name="$nick [user]", value="Gives [user] a nickname in the server.", inline=False)
  59.     embed.add_field(name="$mute [user]", value="Mutes [user].", inline=False)
  60.     embed.add_field(name="$add_role [user]", value="Adds a role to [user].", inline=False)
  61.     embed.add_field(name="$remove_role [user]", value="Removes a role from [user].", inline=False)
  62.     await ctx.send(embed=embed)
  63. @bot.command()
  64. async def invite(ctx):
  65.     embed = discord.Embed(title="Kermit", description="A Very Nice bot!", color=0xeee657)
  66.     embed.add_field(name="Invite Link", value="https://shorturl.at/jsuT1", inline=True)
  67.     await ctx.send(embed=embed)
  68. @bot.command()
  69. async def kick(ctx, username: discord.Member):
  70.         kicker = ctx.author.mention
  71.         try:
  72.             if ctx.author.guild_permissions.administrator or ctx.author.guild_permissions.kick_members or ctx.author.id ==302409090959671297:
  73.                 await username.kick()
  74.                 await ctx.send(f"Successfully kicked {username} by {kicker}")
  75.             else:
  76.                 await ctx.send(f"You do not have permission to run this command. {kicker}")
  77.         except:
  78.             await ctx.send(f"Error kicking {username}!")
  79. @bot.command()
  80. async def purge(ctx, num: int):
  81.     '''Bulk Deletes Messages (Requires Admin Permissions)'''
  82.     mention = ctx.author.mention
  83.     try:
  84.         if ctx.author.guild_permissions.administrator or ctx.author.guild_permissions.manage_messages or ctx.author.id ==302409090959671297:
  85.             await ctx.channel.purge(limit=num + 1)
  86.             await ctx.send(f"Deleted {num} Messages Successfully! {mention}")
  87.         else:
  88.             await ctx.send(f"You do not have permission to run this command. {mention}")
  89.     except:
  90.         await ctx.send(f"Error Purging messages!")
  91. @bot.command()
  92. async def ban(ctx, username: discord.Member):
  93.         banner = ctx.author.mention
  94.         try:
  95.             if ctx.author.guild_permissions.administrator or ctx.author.guild_permissions.ban_members or ctx.author.id ==302409090959671297:
  96.                 await username.ban()
  97.                 await ctx.send(f"Successfully banned {username} by {banner}")
  98.             else:
  99.                 await ctx.send(f"You do not have permission to run this command. {banner}")
  100.         except:
  101.             await ctx.send(f"Error banning {username}!")
  102. @bot.command()
  103. async def perms(ctx, username: discord.Member):
  104.     await ctx.send(f"{username.guild_permissions}")
  105. @bot.command()
  106. async def nick(ctx, username: discord.Member, *, nickname):
  107.     caller = ctx.author.mention
  108.     try:
  109.         if ctx.author.guild_permissions.manage_nicknames or ctx.author.guild_permissions.administrator or ctx.author.id ==302409090959671297:
  110.             await username.edit(nick= nickname)
  111.         else:
  112.             await ctx.send(f"You do not have permission to run this command. {caller}")
  113.     except:
  114.         await ctx.send(f"Error calling this command {caller}!")
  115. @bot.command()
  116. async def mute(ctx, username: discord.Member):
  117.     muter = ctx.author.mention
  118.     try:
  119.         if ctx.author.guild_permissions.mute_members or ctx.author.guild_permissions.administrator or ctx.author.id == 302409090959671297:
  120.             await username.edit(mute=True)
  121.         else:
  122.             await ctx.send(f"You do not have permission to run this command. {muter}")
  123.     except:
  124.         await ctx.send(f"Error muting {username}!")
  125. @bot.command()
  126. async def add_role(ctx, Member: discord.Member, Role: discord.Role):
  127.     '''Adds Roles to a Member (Requires Admin Permissions)'''
  128.     mention = ctx.author.mention
  129.     try:
  130.         if ctx.author.guild_permissions.administrator or ctx.author.guild_permissions.manage_roles or ctx.author.id == 302409090959671297:
  131.             await Member.add_roles(Role, reason=None, atomic=True)
  132.             await ctx.send(f"Added Role: {Role} to {Member}")
  133.         else:
  134.             await ctx.send(f"You do not have permission to run this command. {mention}")
  135.     except:
  136.         await ctx.send(f"Error adding role to {Member}!")
  137. @bot.command()
  138. async def remove_role(ctx, Member: discord.Member, Role: discord.Role):
  139.     '''Removes Roles from a Member (Requires Admin Permissions)'''
  140.     mention = ctx.author.mention
  141.     try:
  142.         if ctx.author.guild_permissions.administrator or ctx.author.guild_permissions.manage_roles or ctx.author.id == 302409090959671297:
  143.             await Member.remove_roles(Role, reason=None, atomic=True)
  144.             await ctx.send(f"Removed Role: {Role} from {Member}")
  145.         else:
  146.             await ctx.send(f"You do not have permission to run this command. {mention}")
  147.     except:
  148.         await ctx.send(f"Error removing role from {Member}!")
  149. token = open("token.txt","r").read()
  150. bot.run(token)
  151. # shorturl.at/jsuT1
RAW Paste Data
0
إقرأ المقال

البث المباشرة مع محمد عبد العزيز للإجابة على تساؤلاتكم التقنية كل خميس فقط. على موقع Egyptian Bloggerقريبا....
7:30 بتوقيت مصر