Compare commits
No commits in common. "master" and "main" have entirely different histories.
5 changed files with 124 additions and 25 deletions
21
LICENSE
Normal file
21
LICENSE
Normal 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
39
README.md
Normal 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
|
|
@ -1,9 +1,13 @@
|
||||||
name: twitch-irc-crystal
|
name: twitch-irc-crystal
|
||||||
version: 0.1.0
|
version: 0.1.0
|
||||||
|
|
||||||
|
targets:
|
||||||
|
twitch-irc-crystal:
|
||||||
|
main: src/twitch-irc-crystal.cr
|
||||||
|
|
||||||
authors:
|
authors:
|
||||||
- Fijxu <fijxu@nadeko.net>
|
- Fijxu <fijxu@nadeko.net>
|
||||||
|
|
||||||
crystal: '>= 1.13.0'
|
crystal: '>= 1.14.0'
|
||||||
|
|
||||||
license: MIT
|
license: MIT
|
||||||
|
|
15
src/config.cr
Normal file
15
src/config.cr
Normal 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
|
|
@ -1,38 +1,58 @@
|
||||||
|
require "./config"
|
||||||
require "socket"
|
require "socket"
|
||||||
|
CONFIG = Config.load
|
||||||
|
|
||||||
module TwitchIRC
|
module TwitchIRC
|
||||||
struct Client
|
class Client
|
||||||
@ip_addr : String
|
|
||||||
@port : String
|
|
||||||
@ssl : Bool | Nil
|
|
||||||
@client : TCPSocket
|
@client : TCPSocket
|
||||||
def initialize(@ip_addr, @port, @ssl)
|
|
||||||
@client = TCPSocket.new(@ip_addr, @port)
|
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
|
end
|
||||||
|
|
||||||
def listen
|
def listen
|
||||||
spawn do
|
spawn do
|
||||||
loop do
|
loop do
|
||||||
puts @client.gets
|
begin
|
||||||
|
puts @client.gets
|
||||||
|
rescue ex
|
||||||
|
puts ex
|
||||||
|
end
|
||||||
|
Fiber.yield
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
sleep
|
|
||||||
end
|
|
||||||
|
|
||||||
def send_raw(msg : String)
|
|
||||||
@client << "#{msg}"
|
|
||||||
end
|
|
||||||
|
|
||||||
def send(msg : String)
|
|
||||||
@client << "#{msg}\n"
|
|
||||||
end
|
|
||||||
|
|
||||||
def send_privmsg(msg : String, channel : String)
|
|
||||||
@client << "PRIVMSG ##{channel} :#{msg}\n"
|
|
||||||
end
|
|
||||||
|
|
||||||
def capabilities
|
|
||||||
self.send("CAP REQ :twitch.tv/membership twitch.tv/tags twitch.tv/commands")
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
asd = TwitchIRC::Client.new(CONFIG.nick, CONFIG.oauth_token)
|
||||||
|
asd.listen
|
||||||
|
asd.join("fijxu")
|
||||||
|
asd.sendmsg("retardcrystaltest", "fijxu")
|
||||||
|
|
||||||
|
sleep
|
Loading…
Add table
Reference in a new issue