How to use removeScreenshot method in fMBT

Best Python code snippet using fMBT_python

t100chart.py

Source:t100chart.py Github

copy

Full Screen

1import time2import asyncio3import datetime4from datetime import timedelta5from httpx import AsyncClient6from httpx_caching import CachingClient7import discord8from discord.ext import commands, tasks9from discord.commands import Option, SlashCommandGroup10from discord.commands.permissions import default_permissions11from formatting.embed import gen_embed, embed_splitter12from __main__ import log, db13class PersistentEvent(discord.ui.View):14 def __init__(self, bot):15 super().__init__(timeout=None)16 self.bot = bot17 @discord.ui.button(label="Send t100 Screenshot",18 style=discord.ButtonStyle.secondary,19 custom_id="persistent_view:t100charthub")20 async def currentevent(self, button: discord.ui.Button, interaction: discord.Interaction):21 async def message_content_prompt(listen_channel: discord.DMChannel):22 def check(m):23 return m.author == interaction.user and m.channel == listen_channel24 await listen_channel.send(embed=gen_embed(title='Send a t100 Screenshot',25 content=('Please attach your screenshots below and send. You can'26 ' send images by adding an attachement to the message'27 ' you send.')))28 try:29 mmsg = await self.bot.wait_for('message', check=check, timeout=300.0)30 except asyncio.TimeoutError:31 await listen_channel.send(embed=gen_embed(title='Sending Cancelled',32 content='The operation has been cancelled.'))33 return None34 return mmsg35 await interaction.response.defer()36 log.info('Begin screenshot interaction workflow')37 dm_channel = interaction.user.dm_channel38 if not dm_channel:39 dm_channel = await interaction.user.create_dm()40 message_content = await message_content_prompt(dm_channel)41 if message_content:42 log.info('Message detected from user')43 view = Confirm()44 sent_message = await dm_channel.send(embed=45 gen_embed(title='Are you sure you want to send this?',46 content='Please verify the contents before confirming.'),47 view=view)48 timeout = await view.wait()49 if timeout:50 log.info('Confirmation view timed out')51 for item in view.children:52 item.disabled = True53 await sent_message.edit(embed=gen_embed(title='Are you sure you want to send this?',54 content='Please verify the contents before confirming.'),55 view=view)56 return57 await sent_message.edit(embed=gen_embed(title='Are you sure you want to send this?',58 content='Please verify the contents before confirming.'),59 view=view)60 if view.value:61 log.info('Workflow confirm, compilation and send logic start')62 document = await db.servers.find_one({"server_id": 616088522100703241})63 if document['modmail_channel']:64 embed = gen_embed(name=f'{message_content.author.name}#{message_content.author.discriminator}',65 icon_url=message_content.author.display_avatar.url,66 title='New Screenshot',67 content=(f'{message_content.clean_content}\n\n'68 f'You may reply to these messages using the reply function.'))69 embed.set_footer(text=f'{message_content.author.id}')70 server = discord.utils.find(lambda s: s.id == 616088522100703241, self.bot.guilds)71 channel = discord.utils.find(lambda c: c.id == document['modmail_channel'], server.channels)72 await embed_splitter(embed=embed, destination=channel, footer=str(message_content.author.id))73 if len(message_content.attachments) > 0:74 attachnum = 175 valid_media_type = ['image/jpeg', 'image/png', 'image/svg+xml', 'image/avif', 'image/heif',76 'image/bmp', 'image/gif', 'image/vnd.mozilla.apng', 'image/tiff']77 for attachment in message_content.attachments:78 if attachment.content_type in valid_media_type:79 embed = gen_embed(80 name=f'{message_content.author.name}#{message_content.author.discriminator}',81 icon_url=message_content.author.display_avatar.url, title='Attachment',82 content=f'Attachment #{attachnum}:')83 embed.set_image(url=attachment.url)84 embed.set_footer(text=f'{message_content.author.id}')85 await channel.send(embed=embed)86 attachnum += 187 else:88 await dm_channel.send(content=f'Attachment #{attachnum} is not a supported media type.')89 await channel.send(embed=gen_embed(90 name=f'{message_content.author.name}#{message_content.author.discriminator}',91 icon_url=message_content.author.display_avatar.url, title='Attachment Failed',92 content=('The user attempted to send an attachement that is not a supported media'93 ' type.')))94 attachnum += 195 await channel.send(content=f"{message_content.author.mention}")96 await dm_channel.send(embed=gen_embed(title='Screenshots sent',97 content='Thank your for your contribution!'))98 else:99 log.warning("Error: This feature is Disabled")100 await dm_channel.send(101 embed=gen_embed(title='Disabled Command', content='Sorry, this feature is disabled.'))102# Define a simple View that gives us a confirmation menu103class Confirm(discord.ui.View):104 def __init__(self):105 super().__init__()106 self.value = None107 # When the confirm button is pressed, set the inner value to `True` and108 # stop the View from listening to more input.109 # We also send the user an ephemeral message that we're confirming their choice.110 @discord.ui.button(label="Yes", style=discord.ButtonStyle.green)111 async def confirm(self, button: discord.ui.Button, interaction: discord.Interaction):112 # await interaction.response.send_message("Confirming", ephemeral=True)113 for item in self.children:114 item.disabled = True115 self.value = True116 self.stop()117 # This one is similar to the confirmation button except sets the inner value to `False`118 @discord.ui.button(label="No", style=discord.ButtonStyle.red)119 async def cancel(self, button: discord.ui.Button, interaction: discord.Interaction):120 log.info('Workflow cancelled')121 await interaction.response.send_message("Operation cancelled.", ephemeral=True)122 for item in self.children:123 item.disabled = True124 self.value = False125 self.stop()126class Collection(commands.Cog):127 def __init__(self, bot):128 self.bot = bot129 self.view = None130 self.sendscreenshot_button.start()131 self.checkscreenshot_button.start()132 self.check_removescreenshot_button.start()133 self.update_endofevent.start()134 def cog_unload(self):135 self.sendscreenshot_button.cancel()136 self.checkscreenshot_button.cancel()137 self.check_removescreenshot_button.cancel()138 self.update_endofevent.cancel()139 @staticmethod140 def has_modrole():141 async def predicate(ctx):142 document = await db.servers.find_one({"server_id": ctx.guild.id})143 if document['modrole']:144 role = discord.utils.find(lambda r: r.id == document['modrole'], ctx.guild.roles)145 return role in ctx.author.roles146 else:147 return False148 return commands.check(predicate)149 @tasks.loop(seconds=1.0, count=1)150 async def sendscreenshot_button(self):151 document = await db.servers.find_one({"server_id": 432379300684103699})152 pubcord = self.bot.get_guild(432379300684103699)153 channel = pubcord.get_channel(913958768105103390)154 end_of_event_tz = document['end_of_event'].replace(tzinfo=datetime.timezone.utc)155 if document['prev_message_screenshot']:156 if end_of_event_tz < datetime.datetime.now(datetime.timezone.utc):157 message_id = document['prev_message_screenshot']158 prev_message = await channel.fetch_message(int(message_id))159 await prev_message.delete()160 log.info('Initial t100 screenshot button deleted')161 if end_of_event_tz < datetime.datetime.now(datetime.timezone.utc):162 self.view = PersistentEvent(bot=self.bot)163 if document['prev_message_screenshot']:164 missing = document['missing']165 else:166 missing = "1-100"167 if missing == "none":168 new_message = await channel.send(169 f"All T100 ranking screenshots for the most recent event have been obtained! Thank you <3",170 view=self.view)171 else:172 new_message = await channel.send((f"We’re collecting T100 ranking screenshots for the most recent event"173 f".\nPlease check the pins in "174 f"{pubcord.get_channel(432382183072858131).mention} for more info.\n"175 f"Missing: {missing}"),176 view=self.view)177 log.info('Initial t100 screenshot button posted')178 await db.servers.update_one({"server_id": 432379300684103699},179 {"$set": {'prev_message_screenshot': new_message.id, 'missing': missing}})180 @tasks.loop(seconds=300)181 async def checkscreenshot_button(self):182 document = await db.servers.find_one({"server_id": 432379300684103699})183 pubcord = self.bot.get_guild(432379300684103699)184 channel = pubcord.get_channel(913958768105103390)185 if not document['prev_message_screenshot']:186 end_of_event_tz = document['end_of_event'].replace(tzinfo=datetime.timezone.utc)187 current_timedelta = datetime.datetime.now(datetime.timezone.utc) - end_of_event_tz188 if end_of_event_tz < datetime.datetime.now(datetime.timezone.utc) and current_timedelta < timedelta(days=2):189 self.view = PersistentEvent(bot=self.bot)190 missing = "1-100"191 new_message = await channel.send((f"We’re collecting T100 ranking screenshots for the most recent event"192 f".\nPlease check the pins in "193 f"{pubcord.get_channel(432382183072858131).mention} for more info.\n"194 f"Missing: {missing}"),195 view=self.view)196 log.info('New t100 screenshot button posted')197 await db.servers.update_one({"server_id": 432379300684103699},198 {"$set": {'prev_message_screenshot': new_message.id, 'missing': missing}})199 @tasks.loop(seconds=300)200 async def check_removescreenshot_button(self):201 document = await db.servers.find_one({"server_id": 432379300684103699})202 pubcord = self.bot.get_guild(432379300684103699)203 channel = pubcord.get_channel(913958768105103390)204 if document['prev_message_screenshot']:205 end_of_event_tz = document['end_of_event'].replace(tzinfo=datetime.timezone.utc)206 current_timedelta = datetime.datetime.now(datetime.timezone.utc) - end_of_event_tz207 if current_timedelta > timedelta(days=2):208 message_id = document['prev_message_screenshot']209 try:210 prev_message = await channel.fetch_message(int(message_id))211 await prev_message.delete()212 log.info('Event timestamp exceeded, screenshot button deleted')213 except discord.NotFound:214 log.info('Screenshot button not found, ignoring')215 await db.servers.update_one({"server_id": 432379300684103699},216 {"$set": {'prev_message_screenshot': None}})217 @tasks.loop(hours=24)218 async def update_endofevent(self):219 current_time = time.time() * 1000220 url = 'https://bestdori.com/api/events/all.5.json'221 client = AsyncClient()222 client = CachingClient(client)223 r = await client.get(url)224 api = r.json()225 for event in api:226 if api[event]['startAt'][1]:227 if float(api[event]['startAt'][1]) < current_time < float(api[event]['endAt'][1]):228 end_time = int((int(api[event]['endAt'][1])) / 1000)229 end_time = datetime.datetime.fromtimestamp(end_time, datetime.timezone.utc)230 await db.servers.update_one({"server_id": 432379300684103699},231 {"$set": {'end_of_event': end_time}})232 log.info(f"Set end of event to {end_time}")233 @sendscreenshot_button.before_loop234 @update_endofevent.before_loop235 async def wait_ready(self):236 # log.info('wait till ready')237 await self.bot.wait_until_ready()238 @check_removescreenshot_button.before_loop239 @checkscreenshot_button.before_loop240 async def wait_ready_long(self):241 await self.bot.wait_until_ready()242 await asyncio.sleep(10)243 @discord.slash_command(name='missing',244 description='Change the description for missing t100 screenshots',245 guild_ids=[616088522100703241])246 @default_permissions()247 async def missing(self, ctx, *, description: str):248 await ctx.interaction.response.defer()249 document = await db.servers.find_one({"server_id": 432379300684103699})250 pubcord = self.bot.get_guild(432379300684103699)251 channel = pubcord.get_channel(913958768105103390)252 if document['prev_message_screenshot']:253 message_id = document['prev_message_screenshot']254 prev_message = await channel.fetch_message(int(message_id))255 if description == "none":256 await prev_message.edit(257 content=f"All T100 ranking screenshots for the most recent event have been obtained! Thank you <3")258 await db.servers.update_one({"server_id": 432379300684103699},259 {"$set": {'missing': description}})260 await ctx.respond(embed=gen_embed(title='missing',261 content=(f'Updated message content:\n\nAll T100 ranking screenshots'262 ' for the most recent event have been obtained! Thank you'263 ' <3.')))264 else:265 await prev_message.edit(content=(f"We’re collecting T100 ranking screenshots for the most recent event."266 f"\nPlease check the pins in "267 f"{pubcord.get_channel(432382183072858131).mention} for more info."268 f"\nMissing: {description}"))269 await db.servers.update_one({"server_id": 432379300684103699},270 {"$set": {'missing': description}})271 await ctx.respond(embed=gen_embed(title='missing',272 content=f'Updated message content:\n\nMissing: {description}.'))273 else:274 await ctx.respond(embed=gen_embed(title='missing',275 content='The message is not currently up! Cannot change description.'))276 t100 = SlashCommandGroup('t100', 't100 related commands', guild_ids=[616088522100703241])277 @t100.command(name='channel',278 description='Set the active channel for t100 screenshot collection',279 guild_ids=[616088522100703241])280 async def t100_channelconfig(self,281 ctx: discord.ApplicationContext,282 channel: Option(discord.SlashCommandOptionType.channel, 'Channel to set as active')):283 await ctx.interaction.response.defer()284 await db.servers.update_one({"server_id": ctx.guild.id}, {"$set": {'modmail_channel': channel.id}})285 await ctx.respond(embed=gen_embed(title='t100 Screenshot Collection Channel Configuration',286 content=f'Active channel set to {channel.mention}'))287def setup(bot):...

Full Screen

Full Screen

ShinyHuntLib.py

Source:ShinyHuntLib.py Github

copy

Full Screen

...41 pyautogui.mouseUp()42 time.sleep(waitTime)43# Used to take and save a screenshot44def getScreenshot(color=False):45 removeScreenshot()46 time.sleep(1)47 # Take screenshot - F1248 pyautogui.keyDown('f12')49 pyautogui.keyUp('f12')50 # Rename to "Screenshot"51 pyautogui.write("Screenshot")52 pyautogui.press('enter')53 time.sleep(2)54 if color:55 img = cv2.imread("Screenshot.png", 1) # in BGR56 else:57 img = cv2.imread("Screenshot.png", 0)58 return img59# Remove testing screenshot if it already exists60def removeScreenshot():61 if os.path.exists("Screenshot.png"):62 os.remove("Screenshot.png")63# What to do if find a shiny64def shinySequence():65 # If the enemy Pokemon is shiny,66 clickScreen("Pause")67 print("IT'S SHINY")68 print(datetime.now())69 exit(5) # Toggle comment on this line to exit or beep70 while True:71 winsound.Beep(2000, 100)...

Full Screen

Full Screen

removeScreenshots.py

Source:removeScreenshots.py Github

copy

Full Screen

...5##bind namespace=6##bind script=script7##bind subpath=traverse_subpath8##parameters=9def removeScreenshot(obj, path):10 obj.setScreenshot('DELETE_IMAGE')11context.ZopeFindAndApply(12 context, obj_metatypes=('SiteUsingPlone', 'CaseStudy'),...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run fMBT automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful