· 2 years ago · Jul 09, 2023, 05:25 PM
1-- Usage: > twitch_chat.lua <channel1> <channel2> <channel3> ...
2
3local tmi = require("tmi") -- https://pastebin.com/nve0x72X
4
5local Client = tmi.connect({
6 -- identity = { -- Optional
7 -- username = "YourUserName",
8 -- password = "oauth:token"
9 -- },
10 channels = { ... }, -- List of channels to connect to
11})
12
13local function writeCol(dev, color, text)
14 dev.setTextColor(color)
15 dev.write(text)
16end
17
18-- Emitted when joining a chat
19Client.listen("ROOMSTATE", function(channel, modes, tags)
20 writeCol(term, colors.white, "Joined ")
21 writeCol(term, colors.magenta, channel)
22 writeCol(term, colors.white, "'s chat")
23 print()
24end)
25
26-- Emitted every chat message
27Client.listen("CHAT", function(channel, username, message, tags, isSelf)
28 if #Client.channels > 1 then
29 writeCol(term, colors.magenta, "#" .. channel)
30 writeCol(term, colors.white, " - ")
31 end
32 local monitor = peripheral.find("monitor")
33 monitor.setCursorPos(1, 1)
34 writeCol(term, colors.orange, username)
35 writeCol(term, colors.white, ": ")
36 monitor.write(username)
37 monitor.write(": ")
38 monitor.write(message)
39 print(message)
40end)
41
42while true do
43 local event, key = tmi.tick(os.pullEventRaw())
44 if event == "terminate" then
45 Client.disconnect()
46 break
47 end
48end
49
50-- List of event callbacks
51--- "ACTION" -> function(channel, username, actionMessage, tags, isSelf)
52--- "ANONGIFTPAIDUPGRADE" -> function(channel, username, tags)
53--- "ANONSUBGIFT" -> function(channel, streak, recipient, tier, tags)
54--- "ANONSUBMYSTERYGIFT" -> function(channel, giftSubCount, tier, tags)
55--- "BAN" -> function(channel, username, tags)
56--- "CHAT" -> function(channel, username, message, tags, isSelf)
57--- "CHEER" -> function(channel, username, bits, message, tags)
58--- "CLEARCHAT" -> function(channel, tags)
59--- "CLOSED" -> function(reason)
60--- "FAILURE" -> function(reason)
61--- "GIFTPAIDUPGRADE" -> function(channel, username, gifter, tags)
62--- "GLOBALUSERSTATE" -> function(username, tags)
63--- "HOST" -> function(channel, target, viewers)
64--- "HOSTED" -> function(channel, name, autohost)
65--- "MESSAGEDELETED" -> function(channel, username, message, tags)
66--- "NEWCHATTER" -> function(channel, username, message, tags)
67--- "NOTICE" -> function(channel, message, tags)
68--- "PING" -> function()
69--- "PRIMEPAIDUPGRADE" -> function(channel, username, tier, tags)
70--- "RAID" -> function(channel, username, viewers, tags)
71--- "RAW" -> function(line)
72--- "REDEEM" -> function(channel, username, reward_id, message, tags)
73--- "RESUB" -> function(channel, username, streak, tier, message, tags)
74--- "RITUAL" -> function(channel, ritualName, username, message, tags)
75--- "ROOMSTATE" -> function(channel, modes, tags)
76--- "SUB" -> function(channel, username, tier, message, tags)
77--- "SUBGIFT" -> function(channel, username, streak, recipient, tier, tags)
78--- "SUBMYSTERYGIFT" -> function(channel, username, giftSubCount, tier, tags)
79--- "TIMEOUT" -> function(channel, username, duration, tags)
80--- "UNHOST" -> function(channel, viewers)
81--- "USERNOTICE" -> function(channel, msgId, message, tags)
82--- "USERSTATE" -> function(channel, tags)
83--- "WHISPER" -> function(username, message, tags)