User:Theleekycauldron/Scripts/PSHAW/dependencies/Hook.js: Difference between revisions

Content deleted Content added
more code
def capitalize
 
(31 intermediate revisions by the same user not shown)
Line 12:
copies or substantial portions of the Software.
*/
function capitalize(string) {
return string.charAt(0).toUpperCase() + string.slice(1);
}
class Hook {
constructor(id,content,credits){
Line 17 ⟶ 20:
this.content = content;
this.articles = []
for (let m of this.content.matchAll(/'''[^']*?\[\[(.*?[^\]\|]+)[^\]].*\]\][^']*?'''|\[\[.*'''(.*?[^']+)'''\]\]/g)){
this.articles.push(capitalize(m[1]))
}
this.credits = credits
Line 36 ⟶ 39:
}
async subpage(){ //returns as Nomination object
give_credits(){
if (this.credits.length>0){
let nomination = await Nomination.create(`Template:Did you know nominations/${this.credits[0].subpage}`);
return nomination;
}
return null
}
give_credit(credit){
let res;
for console.log(let credit of credits){
if (credit.make){
res = `{{subst:Template:DYKmake/DYKmakecredit
|article=${credit.article}
|optional=
|nompage=Template:Did you know nominations/${credit.subpage}
|hook=${this.hookcontent}
}} ~~~~`
} else {
res = `{{subst:DYKnom/DYKnomcredit
|article=${credit.article}
|optional=${credit.subpage}
|nompage=Template:Did you know nominations/${thiscredit.hooksubpage}
}} ~~~~`
}
}
var params = {
action: 'edit',
title: `User talk:${credit.user}`,
sectiontitlesummary: `DYKGiving credit for ${credit.article}`+tag,
section: 'new',
sectiontitle: `DYK for ${credit.article}`,
text: res,
format: 'json'
}
return api.postWithToken( 'csrf', params );
}
tag_talk(article,file){
let res;
let today = new Date()
today = `${today.getUTCDate()} ${["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"][today.getUTCMonth()]} ${today.getUTCFullYear()}`
res = `{{DYK talk|${{subst:TODAY}today}|entry=${this.hookcontent}|${file}}}`
get_section(`Talk:${article}`,0).then((talk) => {
console.log(talk)
let talktext = talk.wikitext + `\n${res}`
console.log(talktext)
var params = {
action: 'edit',
title: this.title`Talk:${article}`,
summary: `GivingArticle creditappeared foron [[WP:DYK|DYK]] on ${credit.articletoday}, adding {{[[Template:DYK talk|DYK talk]]}}`+tag,
section: 'new0',
text: talktext,
sectiontitle: `DYK for ${credit.article}`,
text: res,
format: 'json'
}
return api.postWithToken( 'csrf', params );
})
}
tag_talk(file){
let res;
for (let credit of credits){
res = `{{DYK talk|{{subst:TODAY}}|entry=${this.hook}|${file}}}`
}
}
}
// </nowiki>