This commit is contained in:
Fijxu 2024-11-10 03:02:39 -03:00
commit 52cec570f1
Signed by: Fijxu
GPG key ID: 32C1DDF333EDA6A4
7 changed files with 157 additions and 0 deletions

21
LICENSE Normal file
View file

@ -0,0 +1,21 @@
MIT License
Copyright (c) 2024 Fijxu <fijxu@nadeko.net>
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.

39
README.md Normal file
View file

@ -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 (<https://github.com/your-github-user/twitch-irc-crystal/fork>)
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

13
shard.yml Normal file
View file

@ -0,0 +1,13 @@
name: twitch-irc-crystal
version: 0.1.0
targets:
twitch-irc-crystal:
main: src/twitch-irc-crystal.cr
authors:
- Fijxu <fijxu@nadeko.net>
crystal: '>= 1.14.0'
license: MIT

2
spec/spec_helper.cr Normal file
View file

@ -0,0 +1,2 @@
require "spec"
require "../src/twitch-irc-crystal"

View file

@ -0,0 +1,9 @@
require "./spec_helper"
describe Twitch::Irc::Crystal do
# TODO: Write tests
it "works" do
false.should eq(true)
end
end

15
src/config.cr Normal file
View file

@ -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

58
src/twitch-irc-crystal.cr Normal file
View file

@ -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