Module:NewCharacter

-- Lua module for function to create new article from data. -- Report bugs to User:BeardWizard

local p = {}

local months = { ["January"] = 1, ["February"] = 2, ["March"] = 3, ["April"] = 4, ["May"] = 5, ["June"] = 6, ["July"] = 7, ["August"] = 8, ["September"] = 9, ["October"] = 10, ["November"] = 11, ["December"] = 12, ["Jan"] = 1, ["Feb"] = 2, ["Mar"] = 3, ["Apr"] = 4, ["May"] = 5, ["Jun"] = 6, ["Jul"] = 7, ["Aug"] = 8, ["Sep"] = 9, ["Oct"] = 10, ["Nov"] = 11, ["Dec"] = 12, ["1"] = 1, ["2"] = 2, ["3"] = 3, ["4"] = 4, ["5"] = 5, ["6"] = 6, ["7"] = 7, ["8"] = 8, ["9"] = 9, ["01"] = 1, ["02"] = 2, ["03"] = 3, ["04"] = 4, ["05"] = 5, ["06"] = 6, ["07"] = 7, ["08"] = 8, ["09"] = 9, ["10"] = 10, ["11"] = 11, ["12"] = 12}

local months_numeric = {[1]="January", [2]="February", [3]="March", [4]="April", [5]="May", [6]="June", [7]="July", [8]="August", [9]="September", [10]="October", [11]="November", [12]="December"}

local function Zodiac(month,day) -- Note: Sources conflict on the exact boundaries for zodiac dates. -- Thankfully, we can rely on a trustworthy expert source: -- British TV astrologist Mystic Meg -- source: https://www.thesun.co.uk/fabulous/horoscopes/3900637/star-sign-zodiac-symbols-meaning-horoscope/ month = tonumber(month) month = months_numeric[month] day = tonumber(day) local sign = ""

if (month=="December" and day>=22) or (month=="January" and day<=20) then sign="Capricorn" elseif (month=="January" and day>=21) or (month=="February" and day<=18) then sign="Aquarius" elseif (month=="February" and day>=19) or (month=="March" and day<=20) then sign="Pisces" elseif (month=="March" and day>=21) or (month=="April" and day<=20) then sign="Aries" elseif (month=="April" and day>=21) or (month=="May" and day<=21) then sign="Taurus" elseif (month=="May" and day>=22) or (month=="June" and day<=21) then sign="Gemini" elseif (month=="June" and day>=22) or (month=="July" and day<=22) then sign="Cancer" elseif (month=="July" and day>=23) or (month=="August" and day<=23) then sign="Leo" elseif (month=="August" and day>=24) or (month=="September" and day<=22) then sign="Virgo" elseif (month=="September" and day>=23) or (month=="October" and day<=23) then sign="Libra" elseif (month=="October" and day>=24) or (month=="November" and day<=22) then sign="Scorpio" elseif (month=="November" and day>=23) or (month=="December" and day<=21) then sign="Sagittarius" end

return sign end

local function cm_to_imperial(cm) local measurements = {["ft"]=0,["in"]=0} local inches = cm / 2.54 measurements["ft"] = math.floor(inches / 12) measurements["in"] = math.floor((inches % 12)+0.5) -- round return measurements end local function imperial_to_cm(feet,inches) return (inches*2.54 + (feet*12*2.54)) end local function kg_to_lbs(kg) return kg*2.205 end local function lbs_to_kg(lb) return lb*0.454 end

function p.NewCharacter (frame) local affiliation = frame.args["affiliation"] or "Independent" local age = frame.args["age"] or "" local birth_month = frame.args["birth_month"] or "" local birth_day = frame.args["birth_day"] or "" local blood_type = frame.args["blood_type"] or "" local character_illustrator = frame.args["character_illustrator"] or "" local character_modeller = frame.args["character_modeller"] or "" local debut_day = frame.args["debut_day"] or "" local debut_month = frame.args["debut_month"] or "" local debut_year = frame.args["debut_year"] or "" local dimensions = frame.args["dimensions"] or "" local emoji = frame.args["emoji"] or "" local fan_name = frame.args["fan_name"] or "" local full_name = frame.args["full_name"] or "" local gender = frame.args["gender"] or "" local gender_voice = frame.args["gender_voice"] or gender local hashtag_art = frame.args["hashtag_art"] or "" local hashtag_general = frame.args["hashtag_general"] or "" local height_cm = frame.args["height_cm"] or "" local height_ft = frame.args["height_ft"] or "" local height_in = frame.args["height_in"] or "" local language = frame.args["language"] or "" local nick_name = frame.args["nick_name"] or "" local official_website_url = frame.args["official_website_url"] or "" local official_website_name = frame.args["official_website_name"] or "Website" local original_name = frame.args["original_name"] or "" local short_name = frame.args["short_name"] or fullname local twitch = frame.args["twitch"] or "" local twitter = frame.args["twitter"] or "" local weight_kg = frame.args["weight_kg"] or "" local weight_lbs = frame.args["weight_lbs"] or "" local youtube_url = frame.args["youtube_url"] or "" local youtube_channelname = frame.args["youtube_channelname"] or "" local zodiac_sign = frame.args["zodiac_sign"] or ""

-- default values if official_website_url ~= "" and official_website_name == "" then official_website_name = "Website" end if full_name == "" then full_name = "" end if short_name == "" then short_name = full_name end if gender_voice == "" then if (gender == "Male" or gender == "male") then gender_voice = "Male" elseif (gender == "Female" or gender == "female") then gender_voice = "Female" end end if affiliation == "" then affiliation = "Independent" end

-- derived values local main platform = "" local debut_string = "" local channel_string = "" if youtube_url ~= "" and youtube_channelname == "" then youtube_channelname = full_name end if debut_month ~= "" then debut_month = months[debut_month] -- convert to integer end

if tonumber(debut_year) then if tonumber(debut_year) < 100 then debut_year = ("20" .. debut_year) -- account for two-digit year end debut_string = debut_year if tonumber(debut_month) then debut_string = string.format("%s/%s",debut_string,debut_month) if tonumber(debut_day) then debut_string = string.format("%s/%s",debut_string,debut_day) end end end

local main_platform = "" if youtube_url ~= "" and twitch == "" then main_platform = "YouTube" debut_string = string.format("YouTube: %s", debut_string) channel_string = string.format("YouTube: [%s %s]", youtube_url, youtube_channelname) elseif twitch ~= "" and youtube_url == "" then main_platform = "Twitch" debut_string = string.format("Twitch: %s", debut_string) channel_string = string.format("Twitch: %s", twitch, twitch) elseif twitch ~= "" and youtube_url ~= "" then main_platform = "Twitch" -- assume they mainly stream on Twitch unless otherwise specified debut_string = string.format("Twitch/YouTube(?): %s", debut_string) channel_string = string.format("Twitch: %s", twitch, twitch) channel_string = string.format("%s YouTube: [%s %s]", channel_string, youtube_url, youtube_channelname) end

local pronouns = "" if gender == "male" or gender == "Male" then gender = "Male" pronouns = {"He","Him"} elseif gender == "female" or gender =="Female" then gender = "Female" pronouns = {"She","Her"} else pronouns = {"They","Their"} end local affiliation_string = affiliation if affiliation_string ~= "Independent" then affiliation_string = string.format("%s", affiliation) end

local social_media_string = "" if twitter ~= "" then social_media_string = string.format("Twitter: @%s", twitter, twitter) end local website_string = "" if official_website_url ~= "" then website_string = string.format("[%s %s]", official_website_url, official_website_name) end local character_designer = "" if character_illustrator ~= "" and character_modeller ~= "" then character_designer = string.format("Illustration: %s Modelling: %s", character_illustrator, character_modeller) elseif character_illustrator ~= "" then character_designer = string.format("Illustration: %s", character_illustrator) elseif character_modeler ~= "" then character_designer = string.format("Modelling: %s", character_modeller) end

hashtag_general = string.gsub(hashtag_general,"#","") hashtag_art = string.gsub(hashtag_art,"#","")

local birthday = "" if birth_month ~= "" then birth_month = months[birth_month] -- convert to integer birthday = string.format ("%s %s", birth_day, months_numeric[birth_month]) end if (zodiac_sign == "" and birth_month ~= "" and birth_day ~= "") then zodiac_sign = Zodiac(birth_month, birth_day) end if tonumber(age) then age = string.format("%s years old", age) end

if tonumber(height_cm) and (height_ft == "" or height_in == "") then height_ft = cm_to_imperial(height_cm)["ft"] height_in = cm_to_imperial(height_cm)["in"] elseif height_cm == "" and tonumber(height_ft) and tonumber(height_in) then height_cm = math.floor(imperial_to_cm(height_ft, height_in)+0.5) end

if weight_kg == "" and tonumber(weight_lbs) then weight_kg = math.floor(lbs_to_kg(weight_lbs)+0.5) elseif tonumber(weight_kg) and weight_lbs == "" then weight_lbs = math.floor(kg_to_lbs(weight_kg)+0.5) end

local height_string = "" if height_cm ~= "" then height_string = string.format("%s cm (%s'%s\")", height_cm, height_ft, height_in) end  local weight_string = ""  if weight_kg ~= "" then    weight_string = string.format("%s kg (%s lbs)", weight_kg, weight_lbs)  end

local temp = ""

-- build string local o = "" temp = [=[

%s is ]=]

o = string.format(temp,short_name, full_name, full_name, original_name, nick_name, debut_string, character_designer, affiliation_string, channel_string, social_media_string, website_string, gender, age, birthday, height_string, weight_string, zodiac_sign, emoji, blood_type, full_name)

vowels = {["a"]="a",["e"]="e",["i"]="i",["o"]="o",["u"]="u",["A"]="A",["E"]="E",["I"]="I",["O"]="O",["U"]="U"} temp = "" if affiliation == "Independent" then if language == "" then temp = "an independent VTuber." else temp = string.format("an independent %s-language VTuber.",language) end elseif language ~= "" then if vowels[string.sub(language,1,1)] then temp = string.format("an %s language VTuber affiliated with %s.",language, affiliation) else temp = string.format("a %s language VTuber affiliated with %s.",language, affiliation) end else temp = string.format("a VTuber affiliated with %s.", affiliation) end

local s = "" if gender == "Male" or gender == "Female" then s = "s" end if main_platform ~= "" then temp = temp .. string.format(" %s stream%s on %s.", pronouns[1], s, main_platform) end

o = o .. temp

temp = [=[

Appearance
]=]

o = o .. string.format(temp, short_name)

if affiliation ~= "Independent" then o = o .. "\n== Official profile ==\n\n\n" end

o = o .. [=[

Background
]=]

if tonumber(debut_year) then if tonumber(debut_month) and tonumber(debut_day) then o = o .. string.format("%s debuted on %d %s %d.\n\n", short_name, debut_day, months_numeric[debut_month], debut_year) else o = o .. string.format("%s debuted in %d.\n\n", short_name, debut_year) end

for n=tonumber(debut_year),tonumber(os.date("%Y")) do     o = o .. string.format("=== %d ===\n\n\n", n)   end end

o = o .. [=[

Fans
]=]

if fan_name ~= "" then o = o .. string.format("* %s's fans are known as \"%s\".",short_name, fan_name) end

o = o .. [=[

Media
]=]

if youtube_url ~= "" then o = o .. string.format("* [%s %s] - YouTube Channel\n", youtube_url, youtube_channelname) end if twitch ~= "" then o = o .. string.format("* %s - Twitch Channel\n", twitch, twitch) end if twitter ~= "" then o = o .. string.format("* @%s - Twitter account\n", twitter, twitter) end if official_website_url ~= "" then o = o .. string.format("* [%s %s] - Official website\n", official_website_url, official_website_name) end

if hashtag_general ~= "" or hashtag_art ~= "" then o = o .. "\n=== Twitter hashtags ===\n\n" if hashtag_general ~= "" then o = o .. string.format("* #%s - Stream tag\n", hashtag_general, hashtag_general) end if hashtag_art~= "" then o = o .. string.format("* #%s - Fan art\n", hashtag_art, hashtag_art) end end if twitch ~= "" then o = o .. "\n=== Statistics ===\n\n" o = o .. string.format("* %s - TwitchTracker stats\n", twitch, twitch) o = o .. string.format("* %s - SullyGnome Twitch stats\n", twitch, twitch) o = o .. string.format("* %s - Social Blade Twitch stats\n", twitch, twitch) end

if string.find(affiliation,"ololive") then o = o .. "\n\n" elseif string.find(affiliation,"ijisanji") then o = o .. "\n\n" end

o = o .. [=[