Using 2 Titles in an embed in Discord.py - duplicates

I'm making a discord bot for my server and I want to send 2 links when the user says vote.
client = discord.Client()
#client.event
async def on_message(message):
if message.content.startswith (']svote') :
await message.add_reaction (doubleupemote)
embed=discord.Embed(title="Vote the Server", url="https://top.gg/servers/876028384042426368/vote", color=0x00fa11)
await message.channel.send(embed=embed)
In here it sends an embed with Vote The Server. Is there any method to add another title to the same embed?
Or any alt way to send
Vote For Bot
Vote the server
I want to insert 2 links to these 2 sentences.

There is no way to have "two titles" in one embed. You can create a new line in the title with \n but you will not be able to post a second link/the titles will only link to one URL.
You can however make a description or add a field.
Have a look at the following example code for a description:
if message.content.startswith (']svote') :
await message.add_reaction (doubleupemote)
embed = discord.Embed(color=0x00fa11)
embed.title = "Links to vote"
embed.description = "**[Vote for the bot](https://top.gg/) \n [Vote for the server](https://top.gg/)**"
await message.channel.send(embed=embed)
The output:
If you want to have it in a title, you can use the method I mentioned, but it will not be the same output.
Code for a title that should work:
embed = discord.Embed(color=0x00fa11)
embed.title = "Vote for the bot: https://top.gg/ \nVote for the server: https://top.gg/"
The output:

Related

Using a bot to open embed hyperlinks sent in a discord channel by another bot

Situation: 3rd Party Discord Bot sends masked URL in case of certain events into a private discord channel as an embedded message, instead of clicking on them manually the goal is to have another bot opening those hyperlinks automatically.
Current Status: With a lot of research (also on stack overflow) I managed to get to the following state that will open hyperlinks that are sent as normal text in the respective discord channel or that are included in the description of an embedded message (Kudos to Zach C & Daemon Beast):
client.on("message", message => {
if (message.channel.id == config.channelIds) {
//first part analyses normal messages
if (message.content.includes("https")) {
var link = message.content.split("https")[1]
console.log(link)
var linktest = `https${link}`
console.log(`opening ${linktest}`)
open(linktest)
}
//second part analyses embeded messsages
else if (message.embeds) {
message.embeds.forEach(embed => {
if (embed.description.includes("https")){
var link = embed.description.split("https")[1];
link = link.replace(")", "");
console.log(link);
var linktest = `https${link}`;
console.log(`opening ${linktest}`);
open(linktest);
}
});
}
}
})
Testing: Testing was done using another Bot sending embedded hyperlinks. When they were embedded in the Body/Description the hyperlinks are being opened just fine.
//Testing Bot:
{"content": null,
"embeds": [
{
"title": "Test Title",
"description": "Test Description",
"color": 2108322,
"fields": [
{
"name": "Test Name",
"value": "Test Value\n[Click here to test](https://google.com)"
}]}]}
Problem: In this particular use case hyperlinks are not included in the body/description but rather in the field value which currently not being recognized by the bot and thus not opened.
I already went tough a couple of hours of research & trial/error but was not able to change the code in a way that it would work.
I have tried to use "some" functionality
if (embed.fields.some(f => f.value.includes("https")))
and "includes"
if(message.content.toLowerCase().includes("https"))
But while with the some functionality I was able to make some progress by getting a return value "true" I struggle in adjusting the "var link =" in a way to then get to a proper link.
I have used the replace function to remove the closing bracket ) from the hyperlink.
I feel like I have reached 95% and there is only a small adjustment necessary that the code actually targets the right fields in the embedded message.
Your support is very much appreciated, thank you in advance!
For the sake of completion I would like to share the found solution, there would be better ones with loops but this one worked for me as the link is always at the same place in the embed:
else if (message.embeds) {
message.embeds.forEach(embed => {
console.log(message.embeds[0].fields[8].value);
if (embed.fields[6].value.includes("https")){
var link = embed.fields[6].value.split("https")[1];
link = link.replace(")", "");
console.log(link);
var linktest = `https${link}`;
console.log(`opening ${linktest}`);
open(linktest);

how to redirect in Django correctly?

There is a button in the profile page in my django application,after clicking that button,I want to redirect it to my home page.
On the click of that button,a function in views.py is mapped which is working fine and the function is:
#require_http_methods(['GET','POST'])
def permanentblock(request,Username):
blocker = MyUser.objects.get(username=request.user.username)
blocked = MyUser.objects.get(username=Username)
a = bl_.objects.create(blocker=blocker,blocked=blocked,myboolean=True)
redirect(reverse('home',kwargs={'id':request.user.id}));
#there is a entry in my urls.py for 'home' variable along with the parameter.
Now,till the second last line of the function,it is working correctly,the table is updated.But, there is an error shown:
ValueError at /account/permanentblock/insta/
The view account.views.permanentblock didn't return an HttpResponse object. It returned None instead.
Now,I don't want to return anything from this function,I just want a re-direction. Isn't it the correct way of redirecting to a html page?
Please provide suggestions on how to correct this implementation.
Thanks.
i dont know why you are using ; at the end? anyways use this
#require_http_methods(['GET','POST'])
def permanentblock(request,Username):
blocker = MyUser.objects.get(username=request.user.username)
blocked = MyUser.objects.get(username=Username)
a = bl_.objects.create(blocker=blocker,blocked=blocked,myboolean=True)
return redirect(reverse('home',kwargs={'id':request.user.id}))

Jsoup not displaying tags using the select() function

I'm trying to scrape the team win-loss record data from the NBA website here. Here's an image of the lines of text I want to capture, it is circled in black:
Can someone try scraping this exact data and seeing if it works? I've been at it for hours and nothing is working. I was able to scrape the team names and start times but when I try using jsoup's select function on the record lines, I get 0 results back. It's as if the tags are hidden from the html hierarchy. Is this possible? I'm new to this and I may be doing something wrong.
Code I have tried:
Document document = Jsoup.connect("http://espn.go.com/nba/scoreboard/_/date/20160315").get();
games = document.select("section.sb-score");
for(Element game : games)
{
mHomeTeam = game.select("td.home").select("div.sb-meta").text();
Elements test = game.select("p.record.overall");
mAwayTeam = game.select("td.away").select("div.sb-meta").text();
mHomeTeamRecord = game.select("td.home").select("div.record-container").select("p.record").text();
mAwayTeamRecord = game.select("td.away").select("div.record-container").select("p.record").text();
mGameStartTime = game.select("span.time").text();
Game newGameObj = new Game(mHomeTeam, mAwayTeam, mGameStartTime, mHomeTeamRecord, mAwayTeamRecord);
mGameList.add(newGameObj);
}
The team win-loss record data is loaded by Javascript in the page. Since Jsoup is an HTML parser this is why it's not displaying tags with the select() method.
However, it seems this data is located inside the page directly in a Javascript object called window.espn.scoreboardData.
Here is how to extract this data:
Document doc = Jsoup.connect("http://espn.go.com/nba/scoreboard/_/date/20160315").get();
for(Element script : doc.select("script")) {
String scriptData = script.html();
if (scriptData.contains("window.espn.scoreboardData")) {
// Parse scriptData to extract team win-loss record ...
}
}

how to search a name of text-file c# windows phone

I'm a newbie wp dev. I want to create a many text file name like 1.text 2.text 3.text ......1760.text and I want user to type the number in text box then click the button and the result is read that typed number.text. how can I do it ? please help
you can try this method:
1. put these txt-files into a path,like:TxtFiles/1.txt,2.txt...
2. when user type the number and click button, execute a method to combine file-path and read the file. and you should check the number first.
StreamResourceInfo resourceInfo = Application.GetResourceStream(new Uri(string.Format("yourFilePath/{0}.txt",userTypedNumber), UriKind.Relative));
using (StreamReader reader = new StreamReader(resourceInfo.Stream))
{
yourContentControl.Text = reader.ReadToEnd();
reader.Close();
}

innerHTML call to receive a url

I am trying to make a call so that when a title of a video is clicked on in my playlist, it will call back a particular videos url to be shown in the metadata field box that I have created.
So far I am getting results but the function below that I am using is giving me rmtp url's like this:
(rtmp://brightcove.fcod.llnwd.net/a500/d16/&mp4:media/1978114949001/1978114949001_2073371902001_How-to-Fish-the-Ice-Worm.mp4&1358870400000&7b1c5b2e65a7c051419c7f50bd712b1b
)
Brightcove has said to use (FLVURL&media_delivery=http).
I have tried every way I know of to put a media delivery in my function but always come up with nothing but the rmtp or a blank.
Can you please help with the small amount of code I have shown. If I need to show more that is not a problem. Thanks
function showMetaData(idx) {
$("tr.select").removeClass("select");
$("#tbData>tr:eq("+idx+")").addClass("select");
var v = oCurrentVideoList[idx];
//URL Metadata
document.getElementById('divMeta.FLVURL').innerHTML = v.FLVURL;
Here is my Population call for my list.
//For PlayList by ID
function buildMAinVideoList() {
//Wipe out the old results
$("#tbData").empty();
console.log(oCurrentMainVideoList);
oCurrentVideoList = oCurrentMainVideoList;
// Display video count
document.getElementById('divVideoCount').innerHTML = oCurrentMainVideoList.length + " videos";
document.getElementById('nameCol').innerHTML = "Video Name";
//document.getElementById('headTitle').innerHTML = title;
document.getElementById('search').value = "Search Videos";
document.getElementById('tdMeta').style.display = "block";
document.getElementById('searchDiv').style.display = "inline";
document.getElementById('checkToggle').style.display = "inline";
$("span[name=buttonRow]").show();
$(":button[name=delFromPlstButton]").hide();
//For each retrieved video, add a row to the table
var modDate = new Date();
$.each(oCurrentMainVideoList, function(i,n){
modDate.setTime(n.lastModifiedDate);
$("#tbData").append(
"<tr style=\"cursor:pointer;\" id=\""+(i)+"\"> \
<td>\
<input type=\"checkbox\" value=\""+(i)+"\" id=\""+(i)+"\" onclick=\"checkCheck()\">\
</td><td>"
+n.name +
"</td><td>"
+(modDate.getMonth()+1)+"/"+modDate.getDate()+"/"+modDate.getFullYear()+"\
</td><td>"
+n.id+
"</td><td>"
+((n.referenceId)?n.referenceId:'')+
"</td></tr>"
).children("tr").bind('click', function(){
showMetaData(this.id);
})
});
//Zebra stripe the table
$("#tbData>tr:even").addClass("oddLine");
//And add a hover effect
$("#tbData>tr").hover(function(){
$(this).addClass("hover");
}, function(){
$(this).removeClass("hover");
});
//if there are videos, show the metadata window, else hide it
if(oCurrentMainVideoList.length > 1){showMetaData(0);}
else{closeBox("tdMeta");}
}
If looking for HTTP paths, when the API call to Brightcove is correct you won't see the rtmp:// urls.
Since you're getting the rtmp URLs, this verifies you're using an API token with URL access, which is good. A request like this should return the playlist and the http URLs (insert your token and playlist ID).
http://api.brightcove.com/services/library?command=find_playlist_by_id&token={yourToken}&playlist_id={yourPlaylist}&video_fields=FLVURL&media_delivery=http
This API test tool can help build the queries for you, and show the expected results:
http://opensource.brightcove.com/tool/api-test-tool
I'm not seeing what would be wrong in your code, but in case you haven't tried this already, debugging in the browser can help you confirm the API results being returned, without having to access it via code. This help you root out any issues with the code you're using to access the values, vs problems with the values themselves. This is an overview on step-debugging in Chrome if you haven't used this before:
https://developers.google.com/chrome-developer-tools/docs/scripts-breakpoints