commit 52cec570f1edf283349391d6a3265a98d514365b Author: Fijxu Date: Sun Nov 10 03:02:39 2024 -0300 asd diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..86b560e --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2024 Fijxu + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/README.md b/README.md new file mode 100644 index 0000000..cfbd976 --- /dev/null +++ b/README.md @@ -0,0 +1,39 @@ +# twitch-irc-crystal + +TODO: Write a description here + +## Installation + +1. Add the dependency to your `shard.yml`: + + ```yaml + dependencies: + twitch-irc-crystal: + github: your-github-user/twitch-irc-crystal + ``` + +2. Run `shards install` + +## Usage + +```crystal +require "twitch-irc-crystal" +``` + +TODO: Write usage instructions here + +## Development + +TODO: Write development instructions here + +## Contributing + +1. Fork it () +2. Create your feature branch (`git checkout -b my-new-feature`) +3. Commit your changes (`git commit -am 'Add some feature'`) +4. Push to the branch (`git push origin my-new-feature`) +5. Create a new Pull Request + +## Contributors + +- [Fijxu](https://github.com/your-github-user) - creator and maintainer diff --git a/shard.yml b/shard.yml new file mode 100644 index 0000000..3fb9322 --- /dev/null +++ b/shard.yml @@ -0,0 +1,13 @@ +name: twitch-irc-crystal +version: 0.1.0 + +targets: + twitch-irc-crystal: + main: src/twitch-irc-crystal.cr + +authors: + - Fijxu + +crystal: '>= 1.14.0' + +license: MIT diff --git a/spec/spec_helper.cr b/spec/spec_helper.cr new file mode 100644 index 0000000..844827d --- /dev/null +++ b/spec/spec_helper.cr @@ -0,0 +1,2 @@ +require "spec" +require "../src/twitch-irc-crystal" diff --git a/spec/twitch-irc-crystal_spec.cr b/spec/twitch-irc-crystal_spec.cr new file mode 100644 index 0000000..9e11415 --- /dev/null +++ b/spec/twitch-irc-crystal_spec.cr @@ -0,0 +1,9 @@ +require "./spec_helper" + +describe Twitch::Irc::Crystal do + # TODO: Write tests + + it "works" do + false.should eq(true) + end +end diff --git a/src/config.cr b/src/config.cr new file mode 100644 index 0000000..d6da1d3 --- /dev/null +++ b/src/config.cr @@ -0,0 +1,15 @@ +require "yaml" + +class Config + include YAML::Serializable + + property nick : String + property oauth_token : String + + def self.load + config_file = "config.yml" + config_yaml = File.read(config_file) + config = Config.from_yaml(config_yaml) + config + end +end diff --git a/src/twitch-irc-crystal.cr b/src/twitch-irc-crystal.cr new file mode 100644 index 0000000..03c35c2 --- /dev/null +++ b/src/twitch-irc-crystal.cr @@ -0,0 +1,58 @@ +require "./config" +require "socket" +CONFIG = Config.load + +module TwitchIRC + class Client + @client : TCPSocket + + def initialize(username : String, oauth_token : String) + begin + @client = TCPSocket.new("irc.chat.twitch.tv", 6667) + sendraw("CAP REQ :twitch.tv/membership twitch.tv/tags twitch.tv/commands") + sendraw("PASS #{oauth_token}") + sendraw("NICK #{username}") + rescue ex + puts ex + end + end + + def join(channel : String | Array(String)) + if channel.is_a?(Array) + channel.each do |c| + sendraw("JOIN ##{c}") + end + else + sendraw("JOIN ##{channel}") + end + end + + def sendraw(message : String) + @client << "#{message}\n" + end + + def sendmsg(message : String, channel : String) + sendraw("PRIVMSG ##{channel} :#{message}") + end + + def listen + spawn do + loop do + begin + puts @client.gets + rescue ex + puts ex + end + Fiber.yield + end + end + end + end +end + +asd = TwitchIRC::Client.new(CONFIG.nick, CONFIG.oauth_token) +asd.listen +asd.join("fijxu") +asd.sendmsg("retardcrystaltest", "fijxu") + +sleep \ No newline at end of file