├── .dockerignore ├── .drone.yml ├── .github ├── issue_template.md ├── pull_request_template.md └── settings.yml ├── .gitignore ├── LICENSE ├── README.md ├── docker ├── Dockerfile.linux.amd64 ├── Dockerfile.linux.arm64 ├── Dockerfile.windows.1809 ├── Dockerfile.windows.ltsc2022 └── manifest.tmpl ├── go.mod ├── go.sum ├── main.go └── plugin.go /.dockerignore: -------------------------------------------------------------------------------- 1 | * 2 | !release/ 3 | -------------------------------------------------------------------------------- /.drone.yml: -------------------------------------------------------------------------------- 1 | kind: pipeline 2 | type: vm 3 | name: testing 4 | platform: 5 | os: linux 6 | arch: amd64 7 | pool: 8 | use: ubuntu 9 | 10 | steps: 11 | - name: lint 12 | image: golang:1.19 13 | pull: always 14 | commands: 15 | - go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest 16 | - golangci-lint version 17 | - golangci-lint run 18 | volumes: 19 | - name: gopath 20 | path: "/go" 21 | - name: test 22 | image: golang:1.19 23 | commands: 24 | - go test -cover ./... 25 | volumes: 26 | - name: gopath 27 | path: "/go" 28 | volumes: 29 | - name: gopath 30 | temp: {} 31 | trigger: 32 | ref: 33 | - refs/heads/master 34 | - refs/tags/** 35 | - refs/pull/** 36 | 37 | --- 38 | kind: pipeline 39 | type: vm 40 | name: linux-amd64 41 | platform: 42 | os: linux 43 | arch: amd64 44 | pool: 45 | use: ubuntu 46 | 47 | steps: 48 | - name: environment 49 | image: golang:1.19 50 | pull: always 51 | environment: 52 | CGO_ENABLED: "0" 53 | commands: 54 | - go version 55 | - go env 56 | - name: build 57 | image: golang:1.19 58 | environment: 59 | CGO_ENABLED: "0" 60 | commands: 61 | - go build -v -ldflags "-X main.version=" -a -tags netgo -o release/linux/amd64/drone-irc . 62 | - name: docker 63 | image: plugins/docker 64 | settings: 65 | dockerfile: docker/Dockerfile.linux.amd64 66 | repo: plugins/irc 67 | username: 68 | from_secret: docker_username 69 | password: 70 | from_secret: docker_password 71 | auto_tag: true 72 | auto_tag_suffix: linux-amd64 73 | depends_on: 74 | - testing 75 | trigger: 76 | ref: 77 | - refs/heads/master 78 | - refs/tags/** 79 | - refs/pull/** 80 | 81 | --- 82 | kind: pipeline 83 | type: vm 84 | name: linux-arm64 85 | platform: 86 | os: linux 87 | arch: arm64 88 | pool: 89 | use: ubuntu_arm64 90 | 91 | steps: 92 | - name: environment 93 | image: golang:1.19 94 | pull: always 95 | environment: 96 | CGO_ENABLED: "0" 97 | commands: 98 | - go version 99 | - go env 100 | - name: build 101 | image: golang:1.19 102 | environment: 103 | CGO_ENABLED: "0" 104 | commands: 105 | - go build -v -ldflags "-X main.version=" -a -tags netgo -o release/linux/arm64/drone-irc . 106 | - name: docker 107 | image: plugins/docker 108 | settings: 109 | dockerfile: docker/Dockerfile.linux.arm64 110 | repo: plugins/irc 111 | username: 112 | from_secret: docker_username 113 | password: 114 | from_secret: docker_password 115 | auto_tag: true 116 | auto_tag_suffix: linux-arm64 117 | depends_on: 118 | - testing 119 | trigger: 120 | ref: 121 | - refs/heads/master 122 | - refs/tags/** 123 | - refs/pull/** 124 | 125 | --- 126 | kind: pipeline 127 | type: vm 128 | name: windows-1809 129 | platform: 130 | os: windows 131 | arch: amd64 132 | pool: 133 | use: windows 134 | 135 | steps: 136 | - name: environment 137 | image: golang:1.19 138 | pull: always 139 | environment: 140 | CGO_ENABLED: "0" 141 | commands: 142 | - go version 143 | - go env 144 | - name: build 145 | image: golang:1.19 146 | environment: 147 | CGO_ENABLED: "0" 148 | commands: 149 | - go build -v -ldflags "-X main.version=" -a -tags netgo -o release/windows/amd64/drone-irc.exe . 150 | - name: docker 151 | image: plugins/docker 152 | settings: 153 | dockerfile: docker/Dockerfile.windows.1809 154 | repo: plugins/irc 155 | username: 156 | from_secret: docker_username 157 | password: 158 | from_secret: docker_password 159 | auto_tag: true 160 | auto_tag_suffix: windows-1809-amd64 161 | daemon_off: true 162 | purge: false 163 | when: 164 | ref: 165 | - refs/heads/master 166 | - refs/tags/** 167 | depends_on: 168 | - testing 169 | trigger: 170 | ref: 171 | - refs/heads/master 172 | - refs/tags/** 173 | - refs/pull/** 174 | 175 | --- 176 | kind: pipeline 177 | type: vm 178 | name: windows-ltsc2022 179 | platform: 180 | os: windows 181 | arch: amd64 182 | pool: 183 | use: windows-2022 184 | 185 | steps: 186 | - name: environment 187 | image: golang:1.19 188 | pull: always 189 | environment: 190 | CGO_ENABLED: "0" 191 | commands: 192 | - go version 193 | - go env 194 | - name: build 195 | image: golang:1.19 196 | environment: 197 | CGO_ENABLED: "0" 198 | commands: 199 | - go build -v -ldflags "-X main.version=" -a -tags netgo -o release/windows/amd64/drone-irc.exe . 200 | - name: docker 201 | image: plugins/docker 202 | settings: 203 | dockerfile: docker/Dockerfile.windows.ltsc2022 204 | repo: plugins/irc 205 | username: 206 | from_secret: docker_username 207 | password: 208 | from_secret: docker_password 209 | auto_tag: true 210 | auto_tag_suffix: windows-ltsc2022-amd64 211 | daemon_off: true 212 | purge: false 213 | when: 214 | ref: 215 | - refs/heads/master 216 | - refs/tags/** 217 | depends_on: 218 | - testing 219 | trigger: 220 | ref: 221 | - refs/heads/master 222 | - refs/tags/** 223 | - refs/pull/** 224 | 225 | --- 226 | kind: pipeline 227 | type: vm 228 | name: manifest 229 | platform: 230 | os: linux 231 | arch: amd64 232 | pool: 233 | use: ubuntu 234 | 235 | steps: 236 | - name: manifest 237 | image: plugins/manifest 238 | settings: 239 | auto_tag: "true" 240 | username: 241 | from_secret: docker_username 242 | password: 243 | from_secret: docker_password 244 | spec: docker/manifest.tmpl 245 | ignore_missing: true 246 | depends_on: 247 | - linux-amd64 248 | - linux-arm64 249 | - windows-1809 250 | - windows-ltsc2022 251 | trigger: 252 | ref: 253 | - refs/heads/master 254 | - refs/tags/** 255 | -------------------------------------------------------------------------------- /.github/issue_template.md: -------------------------------------------------------------------------------- 1 | 10 | -------------------------------------------------------------------------------- /.github/pull_request_template.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/drone-plugins/drone-irc/9a8b4487ec4db1cceb56e05b6ac230d527d8ae5c/.github/pull_request_template.md -------------------------------------------------------------------------------- /.github/settings.yml: -------------------------------------------------------------------------------- 1 | repository: 2 | name: drone-irc 3 | description: Drone plugin for sending IRC messages 4 | homepage: http://plugins.drone.io/drone-plugins/drone-irc 5 | topics: drone, drone-plugin 6 | 7 | private: false 8 | has_issues: true 9 | has_wiki: false 10 | has_downloads: false 11 | 12 | default_branch: master 13 | 14 | allow_squash_merge: true 15 | allow_merge_commit: true 16 | allow_rebase_merge: true 17 | 18 | labels: 19 | - name: bug 20 | color: d73a4a 21 | description: Something isn't working 22 | - name: duplicate 23 | color: cfd3d7 24 | description: This issue or pull request already exists 25 | - name: enhancement 26 | color: a2eeef 27 | description: New feature or request 28 | - name: good first issue 29 | color: 7057ff 30 | description: Good for newcomers 31 | - name: help wanted 32 | color: 008672 33 | description: Extra attention is needed 34 | - name: invalid 35 | color: e4e669 36 | description: This doesn't seem right 37 | - name: question 38 | color: d876e3 39 | description: Further information is requested 40 | - name: renovate 41 | color: e99695 42 | description: Automated action from Renovate 43 | - name: wontfix 44 | color: ffffff 45 | description: This will not be worked on 46 | 47 | teams: 48 | - name: Admins 49 | permission: admin 50 | - name: Captain 51 | permission: admin 52 | - name: Maintainers 53 | permission: push 54 | 55 | branches: 56 | - name: master 57 | protection: 58 | required_pull_request_reviews: 59 | required_approving_review_count: 1 60 | dismiss_stale_reviews: false 61 | require_code_owner_reviews: false 62 | dismissal_restrictions: 63 | teams: 64 | - Admins 65 | - Captain 66 | required_status_checks: 67 | strict: true 68 | contexts: 69 | - continuous-integration/drone/pr 70 | enforce_admins: false 71 | restrictions: 72 | users: [] 73 | teams: [] 74 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Compiled Object files, Static and Dynamic libs (Shared Objects) 2 | *.o 3 | *.a 4 | *.so 5 | 6 | # Folders 7 | _obj 8 | _test 9 | 10 | # Architecture specific extensions/prefixes 11 | *.[568vq] 12 | [568vq].out 13 | 14 | *.cgo1.go 15 | *.cgo2.c 16 | _cgo_defun.c 17 | _cgo_gotypes.go 18 | _cgo_export.* 19 | 20 | _testmain.go 21 | 22 | *.exe 23 | *.test 24 | *.prof 25 | 26 | release/ 27 | vendor/ 28 | 29 | coverage.out 30 | drone-irc 31 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "{}" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright {yyyy} {name of copyright owner} 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # drone-irc 2 | 3 | [![Build Status](http://cloud.drone.io/api/badges/drone-plugins/drone-irc/status.svg)](http://cloud.drone.io/drone-plugins/drone-irc) 4 | [![Gitter chat](https://badges.gitter.im/drone/drone.png)](https://gitter.im/drone/drone) 5 | [![Join the discussion at https://discourse.drone.io](https://img.shields.io/badge/discourse-forum-orange.svg)](https://discourse.drone.io) 6 | [![Drone questions at https://stackoverflow.com](https://img.shields.io/badge/drone-stackoverflow-orange.svg)](https://stackoverflow.com/questions/tagged/drone.io) 7 | [![](https://images.microbadger.com/badges/image/plugins/irc.svg)](https://microbadger.com/images/plugins/irc "Get your own image badge on microbadger.com") 8 | [![Go Doc](https://godoc.org/github.com/drone-plugins/drone-irc?status.svg)](http://godoc.org/github.com/drone-plugins/drone-irc) 9 | [![Go Report](https://goreportcard.com/badge/github.com/drone-plugins/drone-irc)](https://goreportcard.com/report/github.com/drone-plugins/drone-irc) 10 | 11 | Drone plugin to send build status notifications via IRC. For the usage information and a listing of the available options please take a look at [the docs](http://plugins.drone.io/drone-plugins/drone-irc/). 12 | 13 | ## Build 14 | 15 | Build the binary with the following command: 16 | 17 | ```console 18 | export GOOS=linux 19 | export GOARCH=amd64 20 | export CGO_ENABLED=0 21 | export GO111MODULE=on 22 | 23 | go build -v -a -tags netgo -o release/linux/amd64/drone-irc 24 | ``` 25 | 26 | ## Docker 27 | 28 | Build the Docker image with the following command: 29 | 30 | ```console 31 | docker build \ 32 | --label org.label-schema.build-date=$(date -u +"%Y-%m-%dT%H:%M:%SZ") \ 33 | --label org.label-schema.vcs-ref=$(git rev-parse --short HEAD) \ 34 | --file docker/Dockerfile.linux.amd64 --tag plugins/irc . 35 | ``` 36 | 37 | ## Usage 38 | 39 | ```console 40 | docker run --rm \ 41 | -e PLUGIN_HOST=irc.someserver.com \ 42 | -e PLUGIN_NICK="test-drone" \ 43 | -e PLUGIN_PASSWORD=password \ 44 | -e PLUGIN_ENABLE_TLS=true \ 45 | -e DRONE_REPO_OWNER=octocat \ 46 | -e DRONE_REPO_NAME=hello-world \ 47 | -e DRONE_COMMIT_SHA=7fd1a60b01f91b314f59955a4e4d4e80d8edf11d \ 48 | -e DRONE_COMMIT_BRANCH=master \ 49 | -e DRONE_COMMIT_AUTHOR=octocat \ 50 | -e DRONE_BUILD_NUMBER=1 \ 51 | -e DRONE_BUILD_STATUS=success \ 52 | -e DRONE_BUILD_LINK=http://github.com/octocat/hello-world \ 53 | -e DRONE_TAG=1.0.0 \ 54 | -v $(pwd):$(pwd) \ 55 | -w $(pwd) \ 56 | plugins/webhook 57 | ``` 58 | -------------------------------------------------------------------------------- /docker/Dockerfile.linux.amd64: -------------------------------------------------------------------------------- 1 | FROM plugins/base:multiarch 2 | 3 | LABEL maintainer="Drone.IO Community " \ 4 | org.label-schema.name="Drone IRC" \ 5 | org.label-schema.vendor="Drone.IO Community" \ 6 | org.label-schema.schema-version="1.0" 7 | 8 | ADD release/linux/amd64/drone-irc /bin/ 9 | ENTRYPOINT ["/bin/drone-irc"] 10 | -------------------------------------------------------------------------------- /docker/Dockerfile.linux.arm64: -------------------------------------------------------------------------------- 1 | FROM plugins/base:multiarch 2 | 3 | LABEL maintainer="Drone.IO Community " \ 4 | org.label-schema.name="Drone IRC" \ 5 | org.label-schema.vendor="Drone.IO Community" \ 6 | org.label-schema.schema-version="1.0" 7 | 8 | ADD release/linux/arm64/drone-irc /bin/ 9 | ENTRYPOINT ["/bin/drone-irc"] 10 | -------------------------------------------------------------------------------- /docker/Dockerfile.windows.1809: -------------------------------------------------------------------------------- 1 | # escape=` 2 | FROM plugins/base:windows-1809-amd64 3 | 4 | LABEL maintainer="Drone.IO Community " ` 5 | org.label-schema.name="Drone IRC" ` 6 | org.label-schema.vendor="Drone.IO Community" ` 7 | org.label-schema.schema-version="1.0" 8 | 9 | ADD release/windows/amd64/drone-irc.exe C:/bin/drone-irc.exe 10 | ENTRYPOINT [ "C:\\bin\\drone-irc.exe" ] 11 | -------------------------------------------------------------------------------- /docker/Dockerfile.windows.ltsc2022: -------------------------------------------------------------------------------- 1 | # escape=` 2 | FROM plugins/base:windows-ltsc2022-amd64 3 | 4 | LABEL maintainer="Drone.IO Community " ` 5 | org.label-schema.name="Drone IRC" ` 6 | org.label-schema.vendor="Drone.IO Community" ` 7 | org.label-schema.schema-version="1.0" 8 | 9 | ADD release/windows/amd64/drone-irc.exe C:/bin/drone-irc.exe 10 | ENTRYPOINT [ "C:\\bin\\drone-irc.exe" ] 11 | -------------------------------------------------------------------------------- /docker/manifest.tmpl: -------------------------------------------------------------------------------- 1 | image: plugins/irc:{{#if build.tag}}{{trimPrefix "v" build.tag}}{{else}}latest{{/if}} 2 | {{#if build.tags}} 3 | tags: 4 | {{#each build.tags}} 5 | - {{this}} 6 | {{/each}} 7 | {{/if}} 8 | manifests: 9 | - 10 | image: plugins/irc:{{#if build.tag}}{{trimPrefix "v" build.tag}}-{{/if}}linux-amd64 11 | platform: 12 | architecture: amd64 13 | os: linux 14 | - 15 | image: plugins/irc:{{#if build.tag}}{{trimPrefix "v" build.tag}}-{{/if}}linux-arm64 16 | platform: 17 | architecture: arm64 18 | os: linux 19 | variant: v8 20 | - 21 | image: plugins/irc:{{#if build.tag}}{{trimPrefix "v" build.tag}}-{{/if}}windows-1809 22 | platform: 23 | architecture: amd64 24 | os: windows 25 | version: 1809 26 | - 27 | image: plugins/irc:{{#if build.tag}}{{trimPrefix "v" build.tag}}-{{/if}}windows-ltsc2022-amd64 28 | platform: 29 | architecture: amd64 30 | os: windows 31 | version: ltsc2022 -------------------------------------------------------------------------------- /go.mod: -------------------------------------------------------------------------------- 1 | module github.com/drone-plugins/drone-irc 2 | 3 | go 1.19 4 | 5 | require ( 6 | github.com/drone/drone-template-lib v1.0.0 7 | github.com/pkg/errors v0.9.1 8 | github.com/thoj/go-ircevent v0.0.0-20210723090443-73e444401d64 9 | github.com/urfave/cli v1.22.10 10 | ) 11 | 12 | require ( 13 | bou.ke/monkey v1.0.2 // indirect 14 | github.com/Masterminds/goutils v1.1.0 // indirect 15 | github.com/Masterminds/semver v1.4.2 // indirect 16 | github.com/Masterminds/sprig v2.18.0+incompatible // indirect 17 | github.com/aymerick/raymond v2.0.2+incompatible // indirect 18 | github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d // indirect 19 | github.com/google/uuid v1.1.0 // indirect 20 | github.com/huandu/xstrings v1.2.0 // indirect 21 | github.com/imdario/mergo v0.3.7 // indirect 22 | github.com/russross/blackfriday/v2 v2.0.1 // indirect 23 | github.com/shurcooL/sanitized_anchor_name v1.0.0 // indirect 24 | github.com/stretchr/testify v1.8.1 // indirect 25 | github.com/tkuchiki/faketime v0.1.1 // indirect 26 | golang.org/x/crypto v0.0.0-20190211182817-74369b46fc67 // indirect 27 | golang.org/x/net v0.0.0-20210614182718-04defd469f4e // indirect 28 | golang.org/x/text v0.3.6 // indirect 29 | gopkg.in/yaml.v2 v2.4.0 // indirect 30 | ) 31 | -------------------------------------------------------------------------------- /go.sum: -------------------------------------------------------------------------------- 1 | bou.ke/monkey v1.0.2 h1:kWcnsrCNUatbxncxR/ThdYqbytgOIArtYWqcQLQzKLI= 2 | bou.ke/monkey v1.0.2/go.mod h1:OqickVX3tNx6t33n1xvtTtu85YN5s6cKwVug+oHMaIA= 3 | github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= 4 | github.com/Masterminds/goutils v1.1.0 h1:zukEsf/1JZwCMgHiK3GZftabmxiCw4apj3a28RPBiVg= 5 | github.com/Masterminds/goutils v1.1.0/go.mod h1:8cTjp+g8YejhMuvIA5y2vz3BpJxksy863GQaJW2MFNU= 6 | github.com/Masterminds/semver v1.4.2 h1:WBLTQ37jOCzSLtXNdoo8bNM8876KhNqOKvrlGITgsTc= 7 | github.com/Masterminds/semver v1.4.2/go.mod h1:MB6lktGJrhw8PrUyiEoblNEGEQ+RzHPF078ddwwvV3Y= 8 | github.com/Masterminds/sprig v2.18.0+incompatible h1:QoGhlbC6pter1jxKnjMFxT8EqsLuDE6FEcNbWEpw+lI= 9 | github.com/Masterminds/sprig v2.18.0+incompatible/go.mod h1:y6hNFY5UBTIWBxnzTeuNhlNS5hqE0NB0E6fgfo2Br3o= 10 | github.com/aymerick/raymond v2.0.2+incompatible h1:VEp3GpgdAnv9B2GFyTvqgcKvY+mfKMjPOA3SbKLtnU0= 11 | github.com/aymerick/raymond v2.0.2+incompatible/go.mod h1:osfaiScAUVup+UC9Nfq76eWqDhXlp+4UYaA8uhTBO6g= 12 | github.com/bouk/monkey v1.0.0/go.mod h1:PG/63f4XEUlVyW1ttIeOJmJhhe1+t9EC/je3eTjvFhE= 13 | github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d h1:U+s90UTSYgptZMwQh2aRr3LuazLJIa+Pg3Kc1ylSYVY= 14 | github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU= 15 | github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= 16 | github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= 17 | github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= 18 | github.com/drone/drone-template-lib v1.0.0 h1:PNBBfUhifRnrPCoWBlTitk3jipXdv8u8WLbIf7h7j00= 19 | github.com/drone/drone-template-lib v1.0.0/go.mod h1:Hqy1tgqPH5mtbFOZmow19l4jOkZvp+WZ00cB4W3MJhg= 20 | github.com/google/uuid v1.1.0 h1:Jf4mxPC/ziBnoPIdpQdPJ9OeiomAUHLvxmPRSPH9m4s= 21 | github.com/google/uuid v1.1.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= 22 | github.com/huandu/xstrings v1.2.0 h1:yPeWdRnmynF7p+lLYz0H2tthW9lqhMJrQV/U7yy4wX0= 23 | github.com/huandu/xstrings v1.2.0/go.mod h1:DvyZB1rfVYsBIigL8HwpZgxHwXozlTgGqn63UyNX5k4= 24 | github.com/imdario/mergo v0.3.7 h1:Y+UAYTZ7gDEuOfhxKWy+dvb5dRQ6rJjFSdX2HZY1/gI= 25 | github.com/imdario/mergo v0.3.7/go.mod h1:2EnlNZ0deacrJVfApfmtdGgDfMuh/nq6Ok1EcJh5FfA= 26 | github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= 27 | github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= 28 | github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= 29 | github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= 30 | github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= 31 | github.com/russross/blackfriday/v2 v2.0.1 h1:lPqVAte+HuHNfhJ/0LC98ESWRz8afy9tM/0RK8m9o+Q= 32 | github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= 33 | github.com/shurcooL/sanitized_anchor_name v1.0.0 h1:PdmoCO6wvbs+7yrJyMORt4/BmY5IYyJwS/kOiWx8mHo= 34 | github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc= 35 | github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= 36 | github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw= 37 | github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo= 38 | github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= 39 | github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= 40 | github.com/stretchr/testify v1.8.1 h1:w7B6lhMri9wdJUVmEZPGGhZzrYTPvgJArz7wNPgYKsk= 41 | github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4= 42 | github.com/thoj/go-ircevent v0.0.0-20210723090443-73e444401d64 h1:l/T7dYuJEQZOwVOpjIXr1180aM9PZL/d1MnMVIxefX4= 43 | github.com/thoj/go-ircevent v0.0.0-20210723090443-73e444401d64/go.mod h1:Q1NAJOuRdQCqN/VIWdnaaEhV8LpeO2rtlBP7/iDJNII= 44 | github.com/tkuchiki/faketime v0.0.0-20170607100027-a4500a4f4643/go.mod h1:RXY/TXAwGGL36IKDjrHFMcjpUrEiyWSEtLhFPw3UWF0= 45 | github.com/tkuchiki/faketime v0.1.1 h1:UZjBlktFAi23wo+jWuHuNoHUpLnB0j/5B62bl5nCPls= 46 | github.com/tkuchiki/faketime v0.1.1/go.mod h1:RXY/TXAwGGL36IKDjrHFMcjpUrEiyWSEtLhFPw3UWF0= 47 | github.com/urfave/cli v1.22.10 h1:p8Fspmz3iTctJstry1PYS3HVdllxnEzTEsgIgtxTrCk= 48 | github.com/urfave/cli v1.22.10/go.mod h1:Gos4lmkARVdJ6EkW0WaNv/tZAAMe9V7XWyB60NtXRu0= 49 | golang.org/x/crypto v0.0.0-20190211182817-74369b46fc67 h1:ng3VDlRp5/DHpSWl02R4rM9I+8M2rhmsuLwAMmkLQWE= 50 | golang.org/x/crypto v0.0.0-20190211182817-74369b46fc67/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= 51 | golang.org/x/net v0.0.0-20210614182718-04defd469f4e h1:XpT3nA5TvE525Ne3hInMh6+GETgn27Zfm9dxsThnX2Q= 52 | golang.org/x/net v0.0.0-20210614182718-04defd469f4e/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= 53 | golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 54 | golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 55 | golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= 56 | golang.org/x/text v0.3.6 h1:aRYxNxv6iGQlyVaZmk6ZgYEDa+Jg18DxebPSrd6bg1M= 57 | golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= 58 | golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= 59 | gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= 60 | gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= 61 | gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY= 62 | gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ= 63 | gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= 64 | gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= 65 | gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= 66 | -------------------------------------------------------------------------------- /main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "log" 5 | "os" 6 | 7 | "github.com/urfave/cli" 8 | ) 9 | 10 | var ( 11 | version = "unknown" 12 | ) 13 | 14 | func main() { 15 | app := cli.NewApp() 16 | app.Name = "irc plugin" 17 | app.Usage = "irc plugin" 18 | app.Action = run 19 | app.Version = version 20 | app.Flags = []cli.Flag{ 21 | cli.StringFlag{ 22 | Name: "prefix", 23 | Usage: "prefix for notification", 24 | EnvVar: "PLUGIN_PREFIX", 25 | Value: "build", 26 | }, 27 | cli.StringFlag{ 28 | Name: "nick", 29 | Usage: "nickname used by bot", 30 | EnvVar: "PLUGIN_NICK", 31 | }, 32 | cli.StringFlag{ 33 | Name: "channel", 34 | Usage: "channel to post message in", 35 | EnvVar: "PLUGIN_CHANNEL", 36 | }, 37 | cli.StringFlag{ 38 | Name: "recipient", 39 | Usage: "recipient", 40 | EnvVar: "PLUGIN_RECIPIENT", 41 | }, 42 | cli.StringFlag{ 43 | Name: "host", 44 | Usage: "host", 45 | EnvVar: "PLUGIN_HOST", 46 | }, 47 | cli.IntFlag{ 48 | Name: "port", 49 | Usage: "port", 50 | EnvVar: "PLUGIN_PORT", 51 | Value: 6667, 52 | }, 53 | cli.StringFlag{ 54 | Name: "password", 55 | Usage: "password", 56 | EnvVar: "PLUGIN_PASSWORD,IRC_PASSWORD", 57 | }, 58 | cli.StringFlag{ 59 | Name: "sasl-password", 60 | Usage: "sasl-password", 61 | EnvVar: "PLUGIN_SASL_PASSWORD,IRC_SASL_PASSWORD", 62 | }, 63 | cli.BoolFlag{ 64 | Name: "enable-tls", 65 | Usage: "enable-tls", 66 | EnvVar: "PLUGIN_ENABLE_TLS", 67 | }, 68 | cli.BoolFlag{ 69 | Name: "use-sasl", 70 | Usage: "use-sasl", 71 | EnvVar: "PLUGIN_USE_SASL", 72 | }, 73 | cli.BoolFlag{ 74 | Name: "debug", 75 | Usage: "debug", 76 | EnvVar: "PLUGIN_DEBUG", 77 | }, 78 | cli.StringFlag{ 79 | Name: "template", 80 | Usage: "template", 81 | EnvVar: "PLUGIN_TEMPLATE", 82 | Value: "*{{build.status}}* <{{build.link}}|{{repo.owner}}/{{repo.name}}#{{truncate build.commit 8}} ({{build.branch}}) by {{build.author}}", 83 | }, 84 | cli.StringFlag{ 85 | Name: "repo.owner", 86 | Usage: "repository owner", 87 | EnvVar: "DRONE_REPO_OWNER", 88 | }, 89 | cli.StringFlag{ 90 | Name: "repo.name", 91 | Usage: "repository name", 92 | EnvVar: "DRONE_REPO_NAME", 93 | }, 94 | cli.StringFlag{ 95 | Name: "commit.sha", 96 | Usage: "git commit sha", 97 | EnvVar: "DRONE_COMMIT_SHA", 98 | }, 99 | cli.StringFlag{ 100 | Name: "commit.ref", 101 | Value: "refs/heads/master", 102 | Usage: "git commit ref", 103 | EnvVar: "DRONE_COMMIT_REF", 104 | }, 105 | cli.StringFlag{ 106 | Name: "commit.branch", 107 | Value: "master", 108 | Usage: "git commit branch", 109 | EnvVar: "DRONE_COMMIT_BRANCH", 110 | }, 111 | cli.StringFlag{ 112 | Name: "commit.author", 113 | Usage: "git author name", 114 | EnvVar: "DRONE_COMMIT_AUTHOR", 115 | }, 116 | cli.StringFlag{ 117 | Name: "commit.message", 118 | Usage: "commit message", 119 | EnvVar: "DRONE_COMMIT_MESSAGE", 120 | }, 121 | cli.StringFlag{ 122 | Name: "build.event", 123 | Value: "push", 124 | Usage: "build event", 125 | EnvVar: "DRONE_BUILD_EVENT", 126 | }, 127 | cli.IntFlag{ 128 | Name: "build.number", 129 | Usage: "build number", 130 | EnvVar: "DRONE_BUILD_NUMBER", 131 | }, 132 | cli.StringFlag{ 133 | Name: "build.status", 134 | Usage: "build status", 135 | Value: "success", 136 | EnvVar: "DRONE_BUILD_STATUS", 137 | }, 138 | cli.StringFlag{ 139 | Name: "build.link", 140 | Usage: "build link", 141 | EnvVar: "DRONE_BUILD_LINK", 142 | }, 143 | cli.Int64Flag{ 144 | Name: "build.started", 145 | Usage: "build started", 146 | EnvVar: "DRONE_BUILD_STARTED", 147 | }, 148 | cli.Int64Flag{ 149 | Name: "build.created", 150 | Usage: "build created", 151 | EnvVar: "DRONE_BUILD_CREATED", 152 | }, 153 | cli.StringFlag{ 154 | Name: "build.tag", 155 | Usage: "build tag", 156 | EnvVar: "DRONE_TAG", 157 | }, 158 | cli.Int64Flag{ 159 | Name: "job.started", 160 | Usage: "job started", 161 | EnvVar: "DRONE_JOB_STARTED", 162 | }, 163 | } 164 | 165 | if err := app.Run(os.Args); err != nil { 166 | log.Fatal(err) 167 | } 168 | } 169 | 170 | func run(c *cli.Context) error { 171 | plugin := Plugin{ 172 | Repo: Repo{ 173 | Owner: c.String("repo.owner"), 174 | Name: c.String("repo.name"), 175 | }, 176 | Build: Build{ 177 | Tag: c.String("build.tag"), 178 | Number: c.Int("build.number"), 179 | Event: c.String("build.event"), 180 | Status: c.String("build.status"), 181 | Commit: c.String("commit.sha"), 182 | Ref: c.String("commit.ref"), 183 | Branch: c.String("commit.branch"), 184 | Author: c.String("commit.author"), 185 | Message: c.String("commit.message"), 186 | Link: c.String("build.link"), 187 | Started: c.Int64("build.started"), 188 | Created: c.Int64("build.created"), 189 | }, 190 | Job: Job{ 191 | Started: c.Int64("job.started"), 192 | }, 193 | Config: Config{ 194 | Prefix: c.String("prefix"), 195 | Nick: c.String("nick"), 196 | Channel: c.String("channel"), 197 | Recipient: c.String("recipient"), 198 | IRCHost: c.String("host"), 199 | IRCPort: c.Int("port"), 200 | IRCPassword: c.String("password"), 201 | SASLPassword: c.String("sasl-password"), 202 | IRCEnableTLS: c.Bool("enable-tls"), 203 | IRCDebug: c.Bool("debug"), 204 | IRCSASL: c.Bool("use-sasl"), 205 | Template: c.String("template"), 206 | }, 207 | } 208 | 209 | return plugin.Exec() 210 | } 211 | -------------------------------------------------------------------------------- /plugin.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | "math/rand" 6 | "net" 7 | "os" 8 | "strconv" 9 | "strings" 10 | 11 | "github.com/drone/drone-template-lib/template" 12 | "github.com/pkg/errors" 13 | irc "github.com/thoj/go-ircevent" 14 | ) 15 | 16 | type ( 17 | Repo struct { 18 | Owner string 19 | Name string 20 | } 21 | 22 | Build struct { 23 | Tag string 24 | Event string 25 | Number int 26 | Commit string 27 | Ref string 28 | Branch string 29 | Author string 30 | Message string 31 | Status string 32 | Link string 33 | Started int64 34 | Created int64 35 | } 36 | 37 | Config struct { 38 | Prefix string 39 | Nick string 40 | Channel string 41 | Recipient string 42 | IRCHost string 43 | IRCPort int 44 | IRCPassword string 45 | IRCEnableTLS bool 46 | IRCDebug bool 47 | IRCSASL bool 48 | SASLPassword string 49 | Template string 50 | } 51 | 52 | Job struct { 53 | Started int64 54 | } 55 | 56 | Plugin struct { 57 | Repo Repo 58 | Build Build 59 | Config Config 60 | Job Job 61 | } 62 | ) 63 | 64 | func (p Plugin) Exec() error { 65 | if len(p.Config.Channel) == 0 && len(p.Config.Recipient) == 0 { 66 | return errors.New("Please provide a channel or recipient") 67 | } 68 | 69 | if len(p.Config.Nick) == 0 { 70 | r := rand.New(rand.NewSource(99)) 71 | p.Config.Nick = fmt.Sprintf("drone%d", r.Int31()) 72 | } 73 | 74 | client := irc.IRC(p.Config.Nick, p.Config.Nick) 75 | 76 | if client == nil { 77 | return errors.New("Failed to create IRC Client: Invalid nick?") 78 | } 79 | 80 | client.Password = p.Config.IRCPassword 81 | client.UseTLS = p.Config.IRCEnableTLS 82 | client.Debug = p.Config.IRCDebug 83 | client.UseSASL = p.Config.IRCSASL 84 | 85 | if p.Config.IRCSASL { 86 | client.SASLLogin = p.Config.Nick 87 | client.SASLPassword = p.Config.SASLPassword 88 | } 89 | 90 | err := client.Connect(net.JoinHostPort(p.Config.IRCHost, strconv.Itoa(p.Config.IRCPort))) 91 | 92 | if err != nil { 93 | return errors.Wrap(err, "failed to connect to server") 94 | } 95 | 96 | go func() { 97 | if err := <-client.ErrorChan(); err != nil { 98 | _ = errors.Wrap(err, "received an error from server") 99 | 100 | os.Exit(1) 101 | return 102 | } 103 | }() 104 | 105 | client.AddCallback("001", func(event *irc.Event) { 106 | var destination string 107 | 108 | if len(p.Config.Recipient) != 0 { 109 | destination = p.Config.Recipient 110 | } else { 111 | if strings.HasPrefix(p.Config.Channel, "#") { 112 | destination = p.Config.Channel 113 | } else { 114 | destination = "#" + p.Config.Channel 115 | } 116 | } 117 | 118 | if strings.HasPrefix(destination, "#") { 119 | client.Join(destination) 120 | } 121 | 122 | txt, err := template.RenderTrim(p.Config.Template, p) 123 | 124 | if err != nil { 125 | _ = errors.Wrap(err, "failed to render template") 126 | 127 | os.Exit(1) 128 | return 129 | } 130 | 131 | client.Privmsg(destination, txt) 132 | 133 | if strings.HasPrefix(destination, "#") { 134 | client.Part(destination) 135 | } 136 | 137 | client.Quit() 138 | }) 139 | 140 | client.Loop() 141 | 142 | return nil 143 | } 144 | --------------------------------------------------------------------------------