Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
initial commit
Browse files Browse the repository at this point in the history
skorpy2009 committed Dec 10, 2023
1 parent 9221bcf commit 0549f9d
Showing 6 changed files with 148 additions and 1 deletion.
26 changes: 26 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
---
name: "Lint"

# yamllint disable-line rule:truthy
on: [push, pull_request]

jobs:
lint-yaml:
name: "YAML"
runs-on: ubuntu-22.04
env:
YAML_FILES: |
.github/workflows/lint.yml
action.yml
steps:
- uses: actions/checkout@v4
- name: Install Dependencies
run: sudo apt-get update && sudo apt-get install -y yamllint
- name: Validate YAML Files
run: yamllint $YAML_FILES

lint-python:
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v4
- uses: chartboost/ruff-action@v1
20 changes: 20 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
---
# yamllint disable rule:line-length
name: "Tests"

# yamllint disable-line rule:truthy
on: [push, pull_request]

jobs:
run:
runs-on: ubuntu-22.04
steps:
- name: Checkout
uses: actions/checkout@v4
- name: run
uses: "./"
with:
irc-server: "irc.hackint.org"
irc-nickname: "workflow-test"
irc-target: "#ffda-github-irc"
message: "${{ github.head_ref }} ${{ github.sha }}"
7 changes: 7 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v2.3.0
hooks:
- id: check-yaml
- id: end-of-file-fixer
- id: trailing-whitespace
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1 @@
# action-irc-message
# action-irc-message
31 changes: 31 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
---
# yamllint disable rule:line-length

name: "Send message to IRC"
inputs:
irc-server:
required: true
irc-nickname:
required: true
irc-target:
description: 'nickname or channel'
required: true
irc-port:
default: 6697
message:
required: true

runs:
using: 'composite'
steps:
- name: Install Python
uses: actions/setup-python@v4
with:
python-version: '3.12'
- name: Install Dependencies
run: pip install irc
shell: bash
- name: Send message
run: |
python irc-message.py -p "${{ inputs.irc-port }}" "${{ inputs.irc-server }}" "${{ inputs.irc-nickname }}" "${{ inputs.irc-target }}" "${{ inputs.message }}"
shell: bash
63 changes: 63 additions & 0 deletions irc-message.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
#! /usr/bin/env python

import sys
import ssl
import argparse

import irc.client

target = None
"The nick or channel to which to send messages"
message = None

def on_connect(connection, event):
if irc.client.is_channel(target):
connection.join(target)
return

def on_join(connection, event):
connection.privmsg(target, message)
connection.quit("Bye")


def on_disconnect(connection, event):
raise SystemExit()


def get_args():
parser = argparse.ArgumentParser()
parser.add_argument('server')
parser.add_argument('nickname')
parser.add_argument('target', help="a nickname or channel")
parser.add_argument('message')
parser.add_argument('-p', '--port', default=6697, type=int)
return parser.parse_args()


def main():
global target
global message

args = get_args()
target = args.target
message = args.message

ssl_factory = irc.connection.Factory(wrapper=ssl.wrap_socket)
reactor = irc.client.Reactor()
try:
c = reactor.server().connect(
args.server, args.port, args.nickname, connect_factory=ssl_factory
)
except irc.client.ServerConnectionError:
print(sys.exc_info()[1])
raise SystemExit(1)

c.add_global_handler("welcome", on_connect)
c.add_global_handler("join", on_join)
c.add_global_handler("disconnect", on_disconnect)

reactor.process_forever()


if __name__ == '__main__':
main()

0 comments on commit 0549f9d

Please sign in to comment.