置顶公告:【置顶】关于临时开启评论区所有功能的公告(2022.10.22) | 【置顶】关于本站Widget恢复使用的公告
  • 你好~!欢迎来到萌娘百科镜像站!如需查看或编辑,请联系本站管理员注册账号。
  • 本镜像站和其他萌娘百科的镜像站无关,请注意分别。

Module:TodayBirthday

贴贴♀百科,万娘皆可贴的百科全书!转载请标注来源页面的网页链接,并声明引自贴贴百科。内容不可商用。
跳到导航 跳到搜索
Template-info.svg 模块文档  [查看] [编辑] [历史] [刷新]

这是一个用于显示某个主题中在今天以及近期过生日的角色的模块,其封装模板为{{TodayBirthday}}。

调用方法

使用{{#invoke:TodayBirthday|main|数据模块名|角色称呼|最近生日天数|设置当前时间}}即可调用模块,各参数说明如下:

  • 数据模块名:存放在Module:TodayBirthday/data/下的数据模块名称,不需要写前缀。
  • 角色称呼:输出语句中对角色的称呼,可省略,默认为“角色”。
  • 最近生日天数:设置显示最近多少天内过生日的角色,设为0为不显示,默认为0。
  • 设置当前时间:给定计算生日的“当天”时间,测试用,在封装模板中不提供此参数,默认为今天。

示例

  • 调用{{#invoke:TodayBirthday|main|赛马娘|赛马娘|7}}将显示:

真机伶菱钻奇宝西沙里奥生日快乐!7天内过生日的赛马娘有:目白麦昆(4月3日)成田路(4月4日)伏特加(4月4日)醒目飞鹰(4月4日)莱茵力量(4月4日)中山庆典(4月5日)气槽(4月6日)鹤丸刚志(4月6日)千明代表(4月7日)

  • 调用{{#invoke:TodayBirthday|main|赛马娘|赛马娘|7|2021-5-1}}将显示:

无声铃鹿狂怒乐章生日快乐!7天内过生日的赛马娘有:特别周(5月2日)骏川手纲(5月2日)成田白仁(5月3日)谷野美酒(5月4日)目白多伯(5月6日)稻荷一(5月7日)待兼诗歌剧(5月7日)森林宝穴(5月7日)樱花桂冠(5月8日)

使用更多数据

模块通过变量扩展和{{array}}输出了更多可用的数据,可以用于更多定制功能(以下所有示例均为上面{{#invoke:TodayBirthday|main|赛马娘|赛马娘|7|2021-5-1}}的输出结果):

  • {{#var:tbirth_today_raw}}(不带描述信息的今天过生日的角色列表):无声铃鹿狂怒乐章
  • {{#var:tbirth_recent_raw}}(不带描述信息的最近过生日的角色列表):特别周(5月2日)骏川手纲(5月2日)成田白仁(5月3日)谷野美酒(5月4日)目白多伯(5月6日)稻荷一(5月7日)待兼诗歌剧(5月7日)森林宝穴(5月7日)樱花桂冠(5月8日)
  • {{#var:tbirth_count}}(今天和最近过生日的角色总数):11
  • {{#var:tbirth_count_today}}(今天过生日人数):2
  • {{#var:tbirth_count_recent}}(最近过生日人数):9


  • {{array|get|tbirth_today|1}}(今天过生日角色数组):无声铃鹿
  • {{array|get|tbirth_recent|1}}(最近过生日角色数组):特别周

使用方法

使用以下按钮创建一个主题的角色数据模块:

以下为目前已创建的角色数据模块,请注意不要重复创建(点击展开):

数据填写说明

使用以上方式创建新模块后会有如下代码:

  1. local p = {}
  2. p.data={
  3. {
  4. "",--填写显示名称
  5. "",--填写内部链接
  6. 1,1--填写生日,形式:月,日
  7. },
  8. {--以同样格式添加下一个数据
  9. "",
  10. "",
  11. 1,1
  12. },
  13. }
  14. return p

需要填写的是使用--注释的三行(即5-7行),说明如下:

  • 在第一行填写角色显示名称,支持html,但建议将第一行的字符串改为用单引号'包裹,或者将双引号"使用反斜杠\转义,写为\";并且如果这么做第二行必须要填写内部链接。
  • 显示图片:受wiki内链生成机制限制,图片不能以[[File:]]的形式插入,请使用<img />语法插入图片
  • 第二行填写内部链接,若与显示名称相同则可省略,不需要写[[]]
  • 第三行填写生日,以月,日的形式。注意分隔符为半角逗号,

填写示例:

  1. {
  2. "特别周",
  3. "",
  4. 5,2
  5. },

使用html的填写示例:

  1. {
  2. '<span style="color:#EE6ECB">特别周</span>',
  3. "特别周",
  4. 5,2
  5. },

然后在下一行填写新的角色数据即可。

  1. local p = {}
  2. local array = require("Module:Var-array") --调用array
  3. local config = {
  4. name = "角色",
  5. recent = 0,
  6. }
  7. local data = {}
  8. --接近生日排序函数
  9. function birth_comp(a,b)
  10. return a[2]<b[2]
  11. end
  12. --frame.args[1]:数据模块名称
  13. --frame.args[2]:角色称呼
  14. --frame.args[3]:最近生日天数
  15. --frame.args[4]:指定当前日期
  16. function p.main( frame )
  17. --变量定义
  18. local lang = mw.language.new("zh") --语言库
  19. local today = {} --今天过生日
  20. local recent = {} --最近过生日
  21. local recent_aout = {}
  22. local today_out = ""
  23. local recent_out = ""
  24. local year = os.date("%Y") --年份
  25. local now ="" -- 当前时间
  26. local count_today = 0 --今天过生日人数
  27. local count_recent = 0 --最近过生日人数
  28. -- 处理参数和默认值
  29. if frame.args[1] then
  30. local data_module = require( "Module:TodayBirthday/data/" .. frame.args[1] )
  31. data = data_module.data
  32. else
  33. return "<span class=\"scribunto-error\">请指定数据模块名!</span>"
  34. end
  35. if frame.args[2] then
  36. config.name = frame.args[2]
  37. end
  38. if tonumber(frame.args[3]) then
  39. config.recent = tonumber(frame.args[3])
  40. end
  41. if frame.args[4] then
  42. now = lang:formatDate("U",frame.args[4],true)
  43. year = lang:formatDate("Y",frame.args[4],true)
  44. else
  45. now = lang:formatDate("U","",true)
  46. end
  47. --计算是否达到/接近生日
  48. for k,v in ipairs(data) do
  49. local birth = lang:formatDate("U", year .. "-" .. v[3] .. "-" .. v[4] .. "-8hour", true)
  50. local birth_next = lang:formatDate("U", year .. "-" .. v[3] .. "-" .. v[4] .. "-8hour+1 year", true)
  51. local link = ""
  52. if v[2] == "" then
  53. link="[[" .. v[1] .."]]"
  54. else
  55. link="[[" ..v[2] .. "|" .. v[1] .. "]]"
  56. end
  57. if (now-birth>=0 and now-birth<86400) or (now-birth_next>=0 and now-birth_next<86400) then
  58. table.insert(today,link)
  59. count_today = count_today + 1
  60. end
  61. if config.recent > 0 then
  62. if birth-now>0 and birth-now<=86400*config.recent then
  63. table.insert(recent,{link,birth-now,v[3],v[4]})
  64. table.insert(recent_aout,link)
  65. elseif birth_next-now>0 and birth_next-now<=86400*config.recent then
  66. table.insert(recent,{link,birth_next-now,v[3],v[4]})
  67. table.insert(recent_aout,link)
  68. end
  69. end
  70. end
  71. --生成今天生日字符串
  72. for k,v in ipairs(today) do
  73. if today_out == "" then
  74. today_out = v
  75. else
  76. today_out = today_out .. "、" ..v
  77. end
  78. end
  79. --处理接近生日顺序
  80. if config.recent > 0 then
  81. table.sort(recent,birth_comp)
  82. for k,v in ipairs(recent) do
  83. if recent_out == "" then
  84. recent_out = v[1] .. "<small>(" .. v[3] .. "月" .. v[4] .. "日)</small>"
  85. else
  86. recent_out = recent_out .. "、" ..v[1] .. "<small>(" .. v[3] .. "月" .. v[4] .. "日)</small>"
  87. end
  88. count_recent = count_recent + 1
  89. end
  90. end
  91. --通过变量扩展输出信息
  92. frame:callParserFunction("#vardefine:tbirth_today_raw",today_out)
  93. frame:callParserFunction("#vardefine:tbirth_recent_raw",recent_out)
  94. frame:callParserFunction("#vardefine:tbirth_count",count_recent+count_today)
  95. frame:callParserFunction("#vardefine:tbirth_count_today",count_today)
  96. frame:callParserFunction("#vardefine:tbirth_count_recent",count_recent)
  97. --通过array输出信息
  98. array.new("tbirth_today",today)
  99. array.new("tbirth_recent",recent_aout)
  100. --处理输出
  101. local out =""
  102. if count_today == 0 then
  103. out = ""
  104. else
  105. out = "祝" .. today_out .. "生日快乐!"
  106. end
  107. if config.recent > 0 then
  108. if recent_out == "" then
  109. out = out .. config.recent .. "天内没有" .. config.name .. "过生日。"
  110. else
  111. out = out .. config.recent .. "天内过生日的" .. config.name .. "有:" .. recent_out .. "。"
  112. end
  113. else
  114. out = out .. "。"
  115. end
  116. return out
  117. end
  118. return p