Skip to content

Commit eef9d48

Browse files
committed
init first commit
0 parents  commit eef9d48

File tree

2 files changed

+89
-0
lines changed

2 files changed

+89
-0
lines changed

tinytwitch.nim

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
import
2+
irc, times, terminal, random, strutils, os
3+
from rawsockets import Port
4+
5+
const
6+
CHAT_URL = "irc.chat.twitch.tv"
7+
CHAT_PORT = Port(6667)
8+
9+
# helper function to clean up some (messier than this) code
10+
proc colorPrint(s: string, c: ForegroundColor): void =
11+
setForegroundColor(c)
12+
echo(s)
13+
setForegroundColor(fgWhite)
14+
15+
# add a hash to the channel name if there isn't one there already
16+
proc addHash(s: string): string =
17+
var str = s
18+
if s.startsWith('#'):
19+
return str
20+
else:
21+
str = "#"&str
22+
return str
23+
24+
# anonymous account generation (justinfan + 14 random numbers)
25+
proc randomTwitchUser(): string=
26+
random.randomize(epochTime().int)
27+
var name = "justinfan"
28+
for i in 0..13:
29+
name &= strutils.intToStr(random.random(9))
30+
return name
31+
32+
var chans = newSeq[string](0)
33+
if paramCount() == 0:
34+
echo("Type the usernames of the channels to join, seperated by a space: ")
35+
var channel: string = readLine(stdin)
36+
for chan in splitWhitespace(channel):
37+
chans.add(addHash(chan))
38+
elif paramCount() >= 1:
39+
for param in commandLineParams():
40+
chans.add(addHash(param))
41+
42+
var username = randomTwitchUser()
43+
var t = irc.newIrc(CHAT_URL, CHAT_PORT , username, username,
44+
joinChans = chans)
45+
var curtime: string
46+
47+
t.connect()
48+
# this gives us things such as userlist, joins, parts and mod status:
49+
t.send("CAP REQ :twitch.tv/membership", false)
50+
51+
while true:
52+
var event: IrcEvent
53+
if t.poll(event):
54+
curtime = "["&getClockStr()&"] "
55+
case event.typ
56+
of EvConnected: echo(curtime & "- [INFO] Connected to server")
57+
of EvDisconnected:
58+
colorPrint(curtime & "- [ERR] Timeout, reconnecting...", fgRed)
59+
t.reconnect()
60+
of EvTimeout:
61+
colorPrint(curtime & "- [ERR] Timeout, reconnecting...", fgRed)
62+
t.reconnect()
63+
of EvMsg:
64+
case event.cmd
65+
of MPrivMsg:
66+
colorPrint(curtime & event.origin & " - [MSG] " & event.nick & ": " & event.params[1], fgWhite)
67+
of MJoin:
68+
colorPrint(curtime & event.origin & " - [JOIN] " & event.nick, fgYellow)
69+
of MPart:
70+
colorPrint(curtime & event.origin & " - [PART] " & event.nick, fgYellow)
71+
of MMode:
72+
if event.params[1] == "+o":
73+
colorPrint(curtime & event.origin & " - [+MOD] " & event.params[2], fgCyan)
74+
elif event.params[1] == "-o":
75+
colorPrint(curtime & event.origin & " - [-MOD] " & event.params[2], fgCyan)
76+
else:
77+
discard

tinytwitch.nimble

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# Package
2+
3+
version = "0.1.0"
4+
author = "smt"
5+
description = "Very simple, very lightweight Twitch.tv chat viewer"
6+
license = "MIT"
7+
bin = @["tinytwitch"]
8+
9+
# Dependencies
10+
11+
requires "nim >= 0.16.0"
12+
requires "irc"

0 commit comments

Comments
 (0)