I have been trying to make a fake nitro command. I made an accept button under the embed that takes the user to a link (probably a troll GIF image or picture).
Currently, this is the code.
import discord
from discord.ext import commands
from discord_components import *
from discord_buttons_plugin import *
def __init__(self, client):
self.client = client
buttons = ButtonsClient(client)
#commands.command(name='nitro')
#commands.has_permissions(ban_members=True)
async def nitro(self,ctx, member: discord.Member = None):
if member == None:
member = ctx.author
embed = discord.Embed(title = "**You've been gifted a subscription!**",
description = f"||**{member.mention}**|| has gifted you Nitro for **1 month!**",
color = 0xc17ce0)
embed.set_image(url = 'https://media.threatpost.com/wp-content/uploads/sites/103/2021/04/19145523/Discord-Nitro-e1618858537976.png' )
await buttons.send(
content = None,
embed = embed,
channel = ctx.channel.id,
components = [
ActionRow([
Button(
style = ButtonType().Link,
label = "Accept",
url = "https://c.tenor.com/Bvb1iMhQQUUAAAAC/gorilla-middle-finger.gif"
)
])
]
)
It’s not showing any error, but the command is not working. How can I do it?
Those are third-party APIs which are similar to discord.py. For using interactions and buttons in discord.py, you can use Discord's master version which can be downloaded by doing:
pip install -U git+https://github.com/Rapptz/discord.py
Support regarding that will be available at their Official Support server.
Related
Relatively new to Splash. I'm trying to scrape a website which needs a login. I started off with the Splash API for which I was able to login perfectly. However, when I put my code in a scrapy spider script, using SplashRequest, it's not able to login.
import scrapy
from scrapy_splash import SplashRequest
class Payer1Spider(scrapy.Spider):
name = "payer1"
start_url = "https://provider.wellcare.com/provider/claims/search"
lua_script = """
function main(splash,args)
assert(splash:go(args.url))
splash:wait(0.5)
local search_input = splash:select('#Username')
search_input:send_text('')
local search_input = splash:select('#Password')
search_input:send_text('')
assert(splash:wait(0.5))
local login_button = splash:select('#btnSubmit')
login_button:mouse_click()
assert(splash:wait(7))
return{splash:html()}
end
"""
def start_requests(self):
yield SplashRequest(self.start_url, self.parse_result,args={'lua_source': self.lua_script},)
def parse_result(self, response):
yield {'doc_title' : response.text}
The output HTML is the login page and not the one after logging in.
You have to add endpoint='execute' to your SplashRequest to execute the lua-script:
yield SplashRequest(self.start_url, self.parse_result, args={'lua_source': self.lua_script}, endpoint='execute')
I believe you don't need splash to login to the site indeed. You can try next:
Get https://provider.wellcare.com and then..
# Get request verification token..
token = response.css('input[name=__RequestVerificationToken]::attr(value)').get()
# Forge post request payload...
data = [
('__RequestVerificationToken', token),
('Username', 'user'),
('Password', 'pass'),
('ReturnUrl', '/provider/claims/search'),
]
#Make dict from list of tuples
formdata=dict(data)
# And then execute request
scrapy.FormRequest(
url='https://provider.wellcare.com/api/sitecore/Login',
formdata=formdata
)
Not completely sure if all of this will work. But you can try.
I can save multiple web pages with using these codes; however, I cant see a proper website view after saving them as html. For example, the texts in table are slipped and images can't be seen.
I need to download entire pages just as we do save as in any web browser so that I can see a proper view.
import urllib.request
url= 'https://asd.com/asdID='
for i in range(1, 5):
print(' --> ID:', i)
newurl = url + str(i)
f = open(str(i)+'.html', 'w')
page = urllib.request.urlopen(newurl)
pagetext = str(page.read())
f.write(pagetext)
f.close()
You can use selenium instead to download full website nicely
Just run the following code
from selenium import webdriver
#Download the chrome driver from the link below and specify the path of chromedriver
#https://chromedriver.storage.googleapis.com/index.html?path=2.40/
chromedriver = 'C:/python36/chromedriver.exe'
url= 'https://asd.com/asdID='
for i in range(1, 5):
browser = webdriver.Chrome(chromedriver)
browser.get(url + str(i))
data = browser.page_source
with open("webpage%s.html" %(str(i)), "w+") as f:
f.write(data)
UPDATE
from selenium.webdriver.firefox.firefox_binary import FirefoxBinary
import ahk
firefox = FirefoxBinary("C:\\Program Files (x86)\\Mozilla Firefox\\firefox.exe")
from selenium import webdriver
driver = web.Firefox(firefox_binary=firefox)
driver.get("http://www.yahoo.com")
ahk.start()
ahk.ready()
ahk.execute("Send,^s")
ahk.execute("WinWaitActive, Save As,,2")
ahk.execute("WinActivate, Save As")
ahk.execute("Send, C:\\path\\to\\file.htm")
ahk.execute("Send, {Enter}")
You will now get everything
I am attempting to delete some components in a repository via the nexus 3 api
I have followed the instructions in the following question
Using the Nexus3 API how do I get a list of artifacts in a repository
and have modified it as follows to delete an artifact
import groovy.json.JsonOutput
import org.sonatype.nexus.repository.storage.Component
import org.sonatype.nexus.repository.storage.Query
import org.sonatype.nexus.repository.storage.StorageFacet
def repoName = "eddie-test"
def startDate = "2016/01/01"
def artifactName = "you-artifact-name"
def artifactVersion = "1.0.6"
log.info(" Attempting to delete for repository: ${repoName} as of startDate: ${startDate}")
def repo = repository.repositoryManager.get(repoName)
StorageFacet storageFacet = repo.facet(StorageFacet)
def tx = storageFacet.txSupplier().get()
tx.begin()
// build a query to return a list of components scoped by name and version
Iterable<Component> foundComponents = tx.findComponents(Query.builder().where('name = ').param(artifactName).and('version = ').param(artifactVersion).build(), [repo])
// extra logic for validation goes here
if (foundComponents.size() == 1) {
tx.deleteComponent(foundComponents[0])
}
tx.commit()
log.info("done")
however when I interrogate the maven-metadata.xml in
http://localhost:32769/repository/eddie-test/com/company/you-artifact-name/maven-metadata.xml
the version is still listed.
i.e.
<metadata>
<groupId>com.company</groupId>
<artifactId>you-artifact-name</artifactId>
<versioning>
<release>1.0.7</release>
<versions>
<version>1.0.6</version>
<version>1.0.7</version>
</versions>
<lastUpdated>20161213115754</lastUpdated>
</versioning>
(deleting the component via the delete component button in the ui, updates the maven-metadata.xml as expected)
So is there a way to make sure that the file is updated when deleting via the API?
After running this, you can run the Rebuild Maven repository metadata Scheduled Task and that will accomplish what you aim to achieve.
There is currently no Public API for calling that task. If you want, pop on over to https://issues.sonatype.org/browse/NEXUS and make an issue for that :)
In my Plone 4 site, I have installed quintagroup.transmogrifier (I tried both release 0.5 and the bleeding-edge github version) and collective.transmogrifier 1.5.
I found an example for an export based on a portal_catalog search here.
I have the following export configuration, registered as catalogsearch:
[transmogrifier]
pipeline =
catalog
fileexporter
marshaller
datacorrector
portletsexporter
writer
EXPORTING
[catalog]
blueprint = quintagroup.transmogrifier.catalogsource
path = query= /Plone/some/existing/folder/
[fileexporter]
blueprint = quintagroup.transmogrifier.fileexporter
[marshaller]
blueprint = quintagroup.transmogrifier.marshaller
[datacorrector]
blueprint = quintagroup.transmogrifier.datacorrector
sources =
marshall
[portletsexporter]
blueprint = quintagroup.transmogrifier.portletsexporter
[writer]
blueprint = quintagroup.transmogrifier.writer
prefix = structure
[EXPORTING]
blueprint = quintagroup.transmogrifier.logger
keys =
_type
_path
The idea is to specify the search expression when calling the transmogrifier:
$ bin/instance debug
>>> portal = app.Plone
>>> from collective.transmogrifier.transmogrifier import Transmogrifier
>>> tm = Transmogrifier(portal)
>>> tm('catalogsearch')
>>> tm('catalogsearch', catalog={'path': '/Plone/some/existing/folder/'})
However, both calls to the Transmogrifier object never return; I need to terminate them with Ctrl+C.
Shouldn't this work, regardless of the debug session?
What is wrong?
I have a Plone application in which I can upload images, which are ATImages. I want to validate the extension file (mainly to forbid pdf files). There are created with a url call like http://blablba.com/createObject?type_name=Image
I have tried setting the /content_type_registry with file extensions associated with images, with no success (pdf upload still work)
I guess I could write a new class extending ATImages, create a form with a validator, but it looks a little bit complicated and it seemed that some settings on content_type registry would be enough (or elsewhere).
How would you do that ? (forbid pdf ?)
thx
We had a similar problem.
Archetypes fires several events during its magic, amongst others a "post validation event" (IObjectPostValidation). This way we added a check for the content-type.
subscriber (zcml):
<subscriber provides="Products.Archetypes.interfaces.IObjectPostValidation"
factory=".subscribers.ImageFieldContentValidator" />
quick and dirty implementation:
from Products.Archetypes.interfaces.field import IImageField
from plone.app.blob.interfaces import IBlobImageField
from Products.Archetypes.interfaces import IObjectPostValidation
from zope.interface import implements
from zope.component import adapts
# import your message factory as _
ALLOWED_IMAGETYPES = ['image/png',
'image/jpeg',
'image/gif',
'image/pjpeg',
'image/x-png']
class ImageFieldContentValidator(object):
"""Validate that the ImageField really contains a Imagefile.
Show a Errormessage if it doesn't.
"""
implements(IObjectPostValidation)
adapts(IBaseObject)
img_interfaces = [IBlobImageField, IImageField]
msg = _(u"error_not_image",
default="The File you wanted to upload is no image")
def __init__(self, context):
self.context = context
def __call__(self, request):
for fieldname in self.context.Schema().keys():
field = self.context.getField(fieldname)
if True in [img_interface.providedBy(field) \
for img_interface in self.img_interfaces]:
item = request.get(fieldname + '_file', None)
if item:
header = item.headers
ct = header.get('content-type')
if ct in ALLOWED_IMAGETYPES:
return
else:
return {fieldname: self.msg}