Hypixel SkyBlock Wiki
No edit summary
No edit summary
Line 1: Line 1:
 
--Get Required Modules
 
--Get Required Modules
 
local getArgs = require('Module:Arguments').getArgs
 
local getArgs = require('Module:Arguments').getArgs
  +
local yesno = require('Module:Yesno')
 
local string = require('Module:String')
 
local string = require('Module:String')
 
local lu = require('Module:LibraryUtil')
 
local lu = require('Module:LibraryUtil')

Revision as of 18:52, 19 September 2020

This module provides functions for providing report and content-management templates.

Methods

All methods are available below as fields under the required object name.

.buildLinks

.buildLinks(<user>(string)<isIp>(booleanNR))
This method returns the links for <user>. If <isIP> is true, it will add some links for IP address checking.

._main

Invoked By: {{Report}}

._main(<user>(string)<reporter>(string)<timestamp>(string)<reason>(string))
This method returns a report for use in the Administrator's Noticeboard for reporting users/vandals.

._delete

._delete(<page>(string)<reporter>(string)<timestamp>(string)<reason>(string)<comments>(string))
This method returns a page deletion request (not in use yet) similar to ._main().

._afPage

(not written yet)Module:Report/doc

Module Code

--Get Required Modules
local getArgs = require('Module:Arguments').getArgs
local yesno = require('Module:Yesno')
local string = require('Module:String')
local lu = require('Module:LibraryUtil')
 
local checkType = lu.checkType
local checkTypeMulti = lu.checkTypeMulti

local sep = ' <b>•</b> ' 

--Begin Exports
local p = {}

--Helper Functions
local function trimWhitespace(s)
    checkType('trimWhitespace', 1, s, 'string')
    
    return s:match( "^%s*(.-)%s*$" )
end

local function gsubMulti(s, t, lim)
    checkType('gsubMulti', 1, s, 'string')
    checkType('gsubMulti', 2, t, 'table')
    checkTypeMulti('gsubMulti', 3, lim, {'number', 'string', 'nil'})
    
    for k, v in pairs(t) do
        s = s:gsub(k, v or '', tonumber(lim))
    end
    return s
end

function p._trimUser(frame)
    local args = getArgs(frame)
        
    return p.trimUser(args[1], yesno(args[2], false))
end

function p.trimUser(s, link)
    checkType('trimUser', 1, s, 'string')
    
    local s = trimWhitespace(s)
    
    local matches = {
            {
                ['^.-(%[%[.-%]%]).*$']='%1';
                ['%[%[.-%:(.-)%|.*%]%]']='%1';
                ['Contribu?t?i?o?n?s%/']='';
            },
            {
                ['^.-%{%{.+%:(.-)%/.+%|?.*%}%}.+$']='%1';
            },
            {
                ['^.-%[?https?%:/%/%S-%/wiki%/.-%:(.+) ?.-%]?.*$']='%1';
                ['^AbuseLog%?wpSearchUser=(.+)$']='%1';
                ['Contribu?t?i?o?n?s%/']='';
                ['^(.-)%?.+$']='%1';
                [' .-%]$']='';
            }
        }
        
    
    if s:match('^.-(%[%[.-%]%]).*$') then
        s = gsubMulti(s, matches[1])
        
    elseif s:match('^.-%{%{.+%:(.-)%/.+%|?.*%}%}.+$') then
        s = gsubMulti(s, matches[2])
        
    elseif s:match('^.-%[?https?%:/%/%S-%/wiki%/.-%:(.+) ?.-%]?.*$') then
        s = gsubMulti(s, matches[3])
        
    end
    
    return link and table.concat{ '[[User:', s, '|', s, ']]' } or s 
end

local function isIp(ip)
    if ip == nil or type(ip) ~= "string" then
        return false
    end
 
    -- Check IPv4
    local chunks = {ip:match("(%d+)%.(%d+)%.(%d+)%.(%d+)")}
    if (#chunks == 4) then
        for _,v in pairs(chunks) do
            if (tonumber(v) < 0 or tonumber(v) > 255) then
                return false
            end
        end
        return true
    end
 
    -- Check IPv6
    local _, chunks = ip:gsub("%:", "")
    if chunks == 7 then
        return true
    end
 
    -- Otherwise
    return false
end
 
local function buildLinks(user, isIp)
    checkType('buildIpLinks', 1, user, 'string')
    checkTypeMulti('buildIpLinks', 2, isIp, { 'boolean', 'nil' })
    
    return table.concat{
        string.wrapLink({ 'User:', user }, user),
        '&nbsp;',
        string.wrapHtml{
            {
                '(',
                string.wrapLink({ 'Message_wall:', user }, 'wall'),
                sep,
                string.wrapLink({ 'Special:Contributions/', user }, 'contribs'),
                sep,
                string.wrapLink({ 'Special:DeletedContributions/', user }, 'DelContribs'),
                sep,
                string.wrapLink({ 'Special:Log/', user }, 'logs'),
                sep,
                string.fullUrl( 'Special:Log/block', { ['page']=user }, 'block log'),
                sep,
                string.fullUrl('Special:AbuseLog', { ['wpSearchUser']=user }, 'abuse log'),
                sep,
                string.wrapLink({ 'Special:Block/', user }, 'Block'),
                sep,
                string.fullUrl('Special:BlankPage', { ['blankspecial']='nuke', ['nukeuser']=user }, 'Nuke'),
                isIp and sep or '',
                isIp and string.externalUrl({ 'https://cleantalk.org/whois/', user }, nil, 'WHOIS') or '',
                isIp and sep or '',
                isIp and string.externalUrl({ 'https://www.ipqualityscore.com/free-ip-lookup-proxy-vpn-test/lookup/', user }, nil, 'Proxy check') or '',
                isIp and sep or '',
                isIp and string.externalUrl({ 'https://cleantalk.org/blacklists/', user }, nil, 'Spam BL check') or '',
                ')',
            },
            '<span>',
            {
                style="font-size: 10px"
            }
        }
    }
end
 
---------------------------------------------------------------------------------
-- Template: Report
-- 
-- Generates a Report about a user
---------------------------------------------------------------------------------
function p.main(frame)
    local args = getArgs(frame)
    local user = args["reported_user"] or args["ru"] or args["user"] or args["u"] or args[1]
    local reporter = args["reporter"] or args["r"] or args[2]
    local timestamp = args["timestamp"] or args["ts"] or args[3]
    local reason = args["reason"] or args["res"] or args[4]
    
    if not user then
        return string.error('Please provide a username to report!')
        
    elseif not reporter then
        return string.error('Please provide your signature!')
        
    elseif not reason then
        return string.error('Please provide a reason why you are reporting %s!', trimUser(user))
    end
 
    return string.pcall(p._main, user, reporter, timestamp, reason)
end
 
---------------------------------------------------------------------------------
-- Template: Report Module access point
---------------------------------------------------------------------------------
function p._main(user, reporter, timestamp, reason)
    checkType('_main', 1, user, 'string')
    checkType('_main', 2, reporter, 'string')
    checkType('_main', 3, timestamp, 'string')
    checkType('_main', 4, reason, 'string')
    
    local isIp = isIp(user)
    local user = p.trimUser(user)
    
    local links = buildLinks(user, isIp)
    local reporter = p.trimUser(reporter)
 
    return tostring(
        mw.html.create('ul')
            :tag('li')
                :wikitext(table.concat{
                    '<b>Reported User: </b>',
                    links,
                })
            :done()
            :tag('li')
                :wikitext(table.concat{ 
                    '<b>Signature: </b>&nbsp;', 
                    string.wrapLink({ 'User:', reporter }, reporter),
                    '&nbsp;',
                    string.wrapHtml{
                        {
                            '(',
                            string.wrapLink({ 'User_talk:', reporter }, 'wall'),
                            sep,
                            string.wrapLink({ 'Special:Contributions/', reporter }, 'contribs'),
                            ')',
                        },
                        '<span>',
                        {
                            style="font-size: 10px"
                        }
                    },
                })
            :done()
            :tag('li')
                :wikitext(table.concat{
                    '<b>Timestamp:</b>&nbsp;',
                    timestamp,
                })
            :done()
            :tag('li')
                :wikitext(table.concat{
                    '<b>Reason:</b>&nbsp;',
                    reason,
                })
            :done()
        :done()
    )
end
 
--Finish Module/Exports
return p