PageSourceSearch

https://yagpdb-cc.github.io/assets/js/26899c3e.da74369c.js

js yagpdb-cc.github.io collected 2026-10-03 10:13:46 UTC 14,639 bytes, 1 lines download raw bytes

1"use strict";(self.webpackChunkwebsite=self.webpackChunkwebsite||[]).push([[7254],{5680:(e,n,t)=>{t.d(n,{xA:()=>d,yg:()=>u});var r=t(6540);function i(e,n,t){return n in e?Object.defineProperty(e,n,{value:t,enumerable:!0,configurable:!0,writable:!0}):e[n]=t,e}function s(e,n){var t=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);n&&(r=r.filter((function(n){return Object.getOwnPropertyDescriptor(e,n).enumerable}))),t.push.apply(t,r)}return t}function a(e){for(var n=1;n<arguments.length;n++){var t=null!=arguments[n]?arguments[n]:{};n%2?s(Object(t),!0).forEach((function(n){i(e,n,t[n])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(t)):s(Object(t)).forEach((function(n){Object.defineProperty(e,n,Object.getOwnPropertyDescriptor(t,n))}))}return e}function o(e,n){if(null==e)return{};var t,r,i=function(e,n){if(null==e)return{};var t,r,i={},s=Object.keys(e);for(r=0;r<s.length;r++)t=s[r],n.indexOf(t)>=0||(i[t]=e[t]);return i}(e,n);if(Object.getOwnPropertySymbols){var s=Object.getOwnPropertySymbols(e);for(r=0;r<s.length;r++)t=s[r],n.indexOf(t)>=0||Object.prototype.propertyIsEnumerable.call(e,t)&&(i[t]=e[t])}return i}var l=r.createContext({}),c=function(e){var n=r.useContext(l),t=n;return e&&(t="function"==typeof e?e(n):a(a({},n),e)),t},d=function(e){var n=c(e.components);return r.createElement(l.Provider,{value:n},e.children)},g="mdxType",m={inlineCode:"code",wrapper:function(e){var n=e.children;return r.createElement(r.Fragment,{},n)}},p=r.forwardRef((function(e,n){var t=e.components,i=e.mdxType,s=e.originalType,l=e.parentName,d=o(e,["components","mdxType","originalType","parentName"]),g=c(t),p=i,u=g["".concat(l,".").concat(p)]||g[p]||m[p]||s;return t?r.createElement(u,a(a({ref:n},d),{},{components:t})):r.createElement(u,a({ref:n},d))}));function u(e,n){var t=arguments,i=n&&n.mdxType;if("string"==typeof e||i){var s=t.length,a=new Array(s);a[0]=p;var o={};for(var l in n)hasOwnProperty.call(n,l)&&(o[l]=n[l]);o.originalType=e,o[g]="string"==typeof e?e:i,a[1]=o;for(var c=2;c<s;c++)a[c]=t[c];return r.createElement.apply(null,a)}return r.createElement.apply(null,t)}p.displayName="MDXCreateElement"},1895:(e,n,t)=>{t.r(n),t.d(n,{assets:()=>l,contentTitle:()=>a,default:()=>m,frontMatter:()=>s,metadata:()=>o,toc:()=>c});var r=t(8168),i=(t(6540),t(5680));const s={title:"Custom Command to File"},a=void 0,o={unversionedId:"utilities/cc2file",id:"utilities/cc2file",title:"Custom Command to File",description:'This command sends your custom command code(s) as a text file, rather than "plain" Discord messages, preserving tabs, markdown, etc.',source:"@site/docs/utilities/cc2file.md",sourceDirName:"utilities",slug:"/utilities/cc2file",permalink:"/utilities/cc2file",draft:!1,editUrl:"https://github.com/yagpdb-cc/yagpdb-cc/edit/master/website/docs/utilities/cc2file.md",tags:[],version:"current",frontMatter:{title:"Custom Command to File"},sidebar:"sidebar",previous:{title:"Bookmark Message",permalink:"/utilities/bookmark"},next:{title:"Preview Color",permalink:"/utilities/color-preview"}},l={},c=[{value:"Trigger",id:"trigger",level:2},{value:"Usage",id:"usage",level:2},{value:"Example",id:"example",level:3},{value:"Configuration",id:"configuration",level:2},{value:"Code",id:"code",level:2},{value:"Author",id:"author",level:2}],d={toc:c},g="wrapper";
1function m(e){let{components:n,...t}=e;return(0,i.yg)(g,(0,r.A)({},d,t,{components:n,mdxType:"MDXLayout"}),(0,i.yg)("p",null,'This command sends your custom command code(s) as a text file, rather than "plain" Discord messages, preserving tabs, markdown, etc.'),(0,i.yg)("p",null,"You can specify more than one ID or trigger, and the bot will generate one file per input parameter. If none are provided, output will be the entire CC list."),(0,i.yg)("admonition",{type:"note"},(0,i.yg)("p",{parentName:"admonition"},"The built-in ",(0,i.yg)("inlineCode",{parentName:"p"},"cc")," command can send CC responses as files with the ",(0,i.yg)("inlineCode",{parentName:"p"},"-file")," switch, however it does not support showing multiple custom commands.\nThere is a ",(0,i.yg)("a",{parentName:"p",href:"export-ccs"},"dedicated CC")," to send ",(0,i.yg)("em",{parentName:"p"},"all")," server custom commands as files, this CC instead allows specifying up to 5 to send.")),(0,i.yg)("h2",{id:"trigger"},"Trigger"),(0,i.yg)("p",null,(0,i.yg)("strong",{parentName:"p"},"Type:")," ",(0,i.yg)("inlineCode",{parentName:"p"},"Command"),(0,i.yg)("br",null),"\n",(0,i.yg)("strong",{parentName:"p"},"Trigger:")," ",(0,i.yg)("inlineCode",{parentName:"p"},"cc2file")),(0,i.yg)("h2",{id:"usage"},"Usage"),(0,i.yg)("ul",null,(0,i.yg)("li",{parentName:"ul"},(0,i.yg)("inlineCode",{parentName:"li"},"-cc2file <id_or_trigger...>")," - Sends the custom command codes of all the custom commands provided.")),(0,i.yg)("h3",{id:"example"},"Example"),(0,i.yg)("pre",null,(0,i.yg)("code",{parentName:"pre"},'-cc2file 10 "te st" 23\n')),(0,i.yg)("p",null,"Sends the code for the custom command with the ID 10, the custom command with the trigger ",(0,i.yg)("inlineCode",{parentName:"p"},"te st"),", and the custom command with the ID 23."),(0,i.yg)("h2",{id:"configuration"},"Configuration"),(0,i.yg)("ul",null,(0,i.yg)("li",{parentName:"ul"},(0,i.yg)("p",{parentName:"li"},(0,i.yg)("inlineCode",{parentName:"p"},"$limitTo5CCs"),(0,i.yg)("br",null),"\nWhether or not to limit the output to five custom commands, to prevent spam.")),(0,i.yg)("li",{parentName:"ul"},(0,i.yg)("p",{parentName:"li"},(0,i.yg)("inlineCode",{parentName:"p"},"$CCInfo_MessageContent"),(0,i.yg)("br",null),"\nWhether or not the info for each custom command should be included in the message content.")),(0,i.yg)("li",{parentName:"ul"},(0,i.yg)("p",{parentName:"li"},(0,i.yg)("inlineCode",{parentName:"p"},"$CCInfo_Attachment"),(0,i.yg)("br",null),"\nWhether or not the info for each custom command should be included in the attached file.")),(0,i.yg)("li",{parentName:"ul"},(0,i.yg)("p",{parentName:"li"},(0,i.yg)("inlineCode",{parentName:"p"},"$blacklisted_CCIDs"),(0,i.yg)("br",null),"\nList of CCs to disallow showing code for using this command."))),(0,i.yg)("h2",{id:"code"},"Code"),(0,i.yg)("pre",null,(0,i.yg)("code",{parentName:"pre",className:"language-gotmpl",metastring:"file=../../../src/utilities/cc2file.go.tmpl",file:"../../../src/utilities/cc2file.go.tmpl"},'{{/*\n    Sends your custom command code as a text file on Discord. Supports showing more than one CC at a time.\n    See <https://yagpdb-cc.github.io/utilities/cc2file> for more information.\n    \n    Author: MatiasMFM2001 <https://github.com/MatiasMFM2001>\n*/}}\n\n{{/* Configurable values */}}\n{{$limitTo5CCs:= true}}\n{{$CCInfo_MessageContent:= true}}\n{{$CCInfo_Attachment:= false}}\n{{$blacklisted_CCIDs:= cslice 1234 5678}}\n{{$hideBlacklistedCCs:= false}}\n{{/* End of configurable values */}}\n\n{{/*\n    sendLongMessage is able to split a long text and send them in individual messages (of 2000 chars long max)\n\n    INPUT (arguments) is an SDICT with keys:\n        [String/Int/nil] "channelID" = Channel ID/Name/nil where message(s) will be sent\n        [String] "text" = The content itself you want to send\n        [String] "separator" = This will define when a \'word\' starts or ends\n*/}}\n{{define "sendLongMessage"}}\n    {{$outStr:= ""}}\n\n    {{/*If separator is not found on the text, fallback to a default empty string*/}}\n    {{if not (in .text .separator)}}\n        {{.Set "separator" ""}}\n    {{end}}\n\n    {{/*Split text in \'words\' and iterate over them*/}}\n    {{range (split .text .separator)}}\n        {{/*Keep appending words while length is under the limit. Then, send the message and "reset" the content for a new message*/}}\n        {{- if gt (add (len $outStr) (len .)) 2000}}\n            {{- sendMessage $.channelID $outStr}}\n            {{- $outStr = .}}\n        {{- else}}\n            {{- $outStr = joinStr $.separator $outStr .}}\n        {{- end -}}\n    {{end}}\n\n    {{/*Send the last message, that was left when range loop ended*/}}\n    {{sendMessage .channelID $outStr}}\n{{end}}\n\n{{/*\n    parseCC executes "-cc .argument" and extracts all possible information from it\n\n    INPUT is an SDICT with keys:\n        [String] "argument" = The CC ID or Trigger to parse\n\n    OUTPUT is the same SDICT with keys:\n        [String] "error" = If there are errors, they will be returned here (as a string)\n        [Int] "CCID" = The ID of processed CC\n        [String] "triggerType" = The type of the trigger this CC has (i.e. "None", "Command", "Regex", etc)\n        [String] "trigger" = The trigger itself this CC has (i.e. "cc2file", ".*", etc)\n        [Bool] "caseSensitive" = If lowercase and uppercase characters, are not considered equal\n        [String] "group" = CC group, this CC belongs to\n        [String] "code" = Executable source code of this CC\n*/}}\n{{define "parseCC"}}\n    {{/*EXECute "-cc" and extract stuff from its output*/}}\n    {{$answer:= exec "cc" .argument}}\n    {{$answerLines:= split $answer "\\n"}}\n    {{$extractedCode:= slice $answerLines 2 (sub (len $answerLines) 1)}}\n    {{$firstLine:= index $answerLines 0}}\n\n    {{/*Check if Answer\'s $firstLine is actually an error message*/}}\n    {{- if in $firstLine "here is a list of"}}\n        {{.Set "error" (printf "\u274c CC `%s` not found" .argument)}}\n    {{- else if in $firstLine "More than 1 matched command"}}\n        {{/*Insert argument in message output, and if it\'s empty, replace it with "<Empty trigger specified>"*/}}\n        {{.Set "error" (reReplace "``" (printf "`%s`: %s" .argument $answer) "`<Empty trigger specified>`")}}\n    {{end}}\n\n    {{/*If not, extract info from the CC*/}}\n    {{if not .error}}\n        {{/*Modified copy of TheHDCrafter\'s Regex expression. Licensed under MIT*/}}\n        {{$parsedFirstLine:= reFindAllSubmatches `^#\\s*(\\d+) - ((.*)(?:(?:: \\x60(.*)\\x60 - Case sensitive trigger: \\x60(.+)\\x60)|\\b))? - Group: \\x60(.+)\\x60$` $firstLine}}\n\n        {{.Set "CCID" (index $parsedFirstLine 0 1 | toInt)}}\n        {{.Set "triggerType" (or (index $parsedFirstLine 0 3) "None")}}\n        {{.Set "trigger" (index $parsedFirstLine 0 4)}}\n        {{.Set "caseSensitive" (index $parsedFirstLine 0 5 | eq "true")}}\n        {{.Set "group" (index $parsedFirstLine 0 6)}}\n\n        {{.Set "code" (joinStr "\\n" $extractedCode)}}\n    {{end}}\n{{end}}\n\n{{/*EXECUTION STARTS HERE*/}}\n{{/*If CC was called via execCC/scheduleUniqueCC, use .ExecData as the $args. If not, use .CmdArgs*/}}\n{{$args:= cslice}}\n{{with .ExecData}}\n    {{$args = .}}\n{{else}}\n    {{/*Delete duplicated $args*/}}\n    {{range .CmdArgs}}\n        {{- if not (in $args .)}}\n            {{- $args = $args.Append .}}\n        {{- end}}\n    {{- end}}\n{{end}}\n{{$numArgs:= len $args}}\n\n{{/*Exec can be called 5 times max, so $selectedArgs will have up to 5 $args to be processed*/}}\n{{$selectedArgs:= cslice}}\n{{if gt $numArgs 5}}\n    {{$selectedArgs = slice $args 0 5}}\n\n    {{if $limitTo5CCs}}\n        {{sendMessage nil "\u26a0\ufe0f WARNING: Only first 5 CCs will be processed"}}\n    {{end}}\n{{else}}\n    {{$selectedArgs = $args}}\n{{end}}\n\n{{/*Process each selected argument in this execution*/}}\n{{range $selectedArgs}}\n    {{- $params:= sdict "argument" .}}\n    {{- template "parseCC" $params}}\n\n    {{/*Check if that CC was $blacklisted*/}}\n    {{- if $params.error}}\n        {{- sendMessage nil $params.error}}\n    {{- else if in $blacklisted_CCIDs $params.CCID}}\n        {{- sendMessage nil (printf "\ud83d\udeab CC `%s` is blacklisted" .)}}\n    {{- else}}\n        {{/*No error message, so send CC\'s code and info*/}}\n        {{- $content:= ""}}\n        {{- $attachment:= $params.code}}\n\n        {{/*If $CCInfo_MessageContent flag is set, the info will be sent as message content*/}}\n        {{- if $CCInfo_MessageContent}}\n            {{- $content = printf "#%d - %s: `%s` - Case sensitive trigger: `%t` - Group: `%s`" $params.CCID $params.triggerType $params.trigger $params.caseSensitive $params.group}}\n        {{- end}}\n\n        {{/*If $CCInfo_Attachment flag is set, the info will be a comment in message\'s attachment*/}}\n        {{- if $CCInfo_Attachment}}\n            {{/*Generate the $leadingComment*/}}\n            {{- $leadingComment:= printf "{{/*\\n\\tDescription:\\n\\n\\tUsage:\\n"}}\n\n            {{- range reFindAllSubmatches `parseArgs\\s+\\d+\\s+"(.+)"` $params.code}}\n                {{- $leadingComment = printf "%s\\t\\t\\"%s\\"\\n" $leadingComment (index . 1)}}\n            {{- end}}\n\n            {{- $leadingComment = printf "%s\\n\\tRecomended trigger: \\"%s\\"\\n\\tTrigger type: %s\\n\\n\\tCredits:\\n*/}}" $leadingComment $params.trigger $params.triggerType}}\n\n            {{- $attachment = printf "%s\\n\\n%s" $leadingComment $attachment}}\n        {{- end}}\n\n        {{- sendMessage nil (complexMessage\n            "content" $content\n            "file" $attachment\n        )}}\n    {{- end}}\n\n    {{- sleep 1}}\n{{else}}\n    {{/*If there are 0 args, send full CC list*/}}\n    {{$answerLines:= split (exec "cc") "\\n"}}\n\n    {{/*Save the first line, and the rest of them, in different variables*/}}\n    {{$newMessage:= index $answerLines 0}}\n    {{$answerLines:= slice $answerLines 1 (sub (len $answerLines) 1) | cslice.AppendSlice}}\n\n    {{/*For each CC, if It\'s blacklisted, strikethrough whole line*/}}\n    {{range $index, $content:= $answerLines}}\n        {{- $CCID:= index (reFindAllSubmatches `^\\x60#([0-9 ]{3})` $content) 0 1 | toInt}}\n\n        {{- if in $blacklisted_CCIDs $CCID}}\n            {{- if $hideBlacklistedCCs}}\n                {{- $answerLines.Set $index ""}}\n            {{- else}}\n                {{- $answerLines.Set $index (printf "~~%s~~" $content)}}\n            {{- end}}\n        {{- end}}\n    {{end}}\n\n    {{/*A DIY "joinStr `\\n` $answerLines"*/}}\n    {{range $answerLines}}\n        {{- $newMessage = printf "%s\\n%s" $newMessage .}}\n    {{end}}\n\n    {{template "sendLongMessage" (sdict "channelID" nil "text" $newMessage "separator" "\\n")}}\n{{end}}\n\n{{/*If $limitTo5CCs flag is not set, and there are still arguments left, execute CC again to process them*/}}\n{{if and (not $limitTo5CCs) (gt $numArgs 5)}}\n    {{scheduleUniqueCC .CCID nil 1 "cc2file - remaining args" (slice $args 5 $numArgs)}}\n{{end}}\n')),(0,i.yg)("h2",{id:"author"},"Author"),(0,i.yg)("p",null,"This custom command was written by ",(0,i.yg)("a",{parentName:"p",href:"https://github.com/MatiasMFM2001"},"@MatiasMFM2001"),"."))}m.isMDXComponent=!0}}]);

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.