电子发烧友App

硬声App

0
  • 聊天消息
  • 系统消息
  • 评论与回复
登录后你可以
  • 下载海量资料
  • 学习在线课程
  • 观看技术视频
  • 写文章/发帖/加入社区
创作中心

完善资料让更多小伙伴认识你,还能领取20积分哦,立即完善>

3天内不再提示
电子发烧友网>电子资料下载>电子资料>支持Twitch的简单可穿戴设备

支持Twitch的简单可穿戴设备

2023-01-04 | zip | 0.07 MB | 次下载 | 免费

资料介绍

描述

描述

这是另一个支持 Twitch 的简单可穿戴设备。这一次是关于如何帮助流以某种小车的方式跟上大型聊天室的步伐。

让我们快速模仿我们最喜欢的紫色反派。

让我们变得真实。每个人都会从抽取中恢复过来,所以让我们暂停一半的聊天而不是全面禁止。

构建说明

步骤1

Snap 手套与 esp32 搭配起来相当简单。我把它连接到一个单细胞脂肪上以获得动力。Gpio 14是电容式触摸管脚,编码时称为T6。我将一根电线连接到 gpio 14 并将其焊接到银导电线上! 

*请记住保持您的触摸板小,以便它们具有良好的灵敏控制。太大的垫将导致没有触摸触发或持续触摸,具体取决于灵敏度的设置方式。

第2步

导电织物肯定很难焊接(如果你是我的话)。我发现让你的熨斗刚好热到足以熔化你的焊料,除此之外什么都不是你想要留下的地方。

通过将一些焊料熔化到电线上来给电线镀锡,将其放在导电织物上,并在 3 秒内用烙铁加热。每次爆裂后检查焊点,看看是否需要施加更多的热量,或者它是否有效。

慢慢来,不要害怕搞砸这一步。

步骤 3

我用普通线缝合了所有传感器垫,并缝合了一些电缆。这有助于反复弯曲焊点。

最靠近拇指的传感器是中指末端的位置,同时弹响。<

图>

第4步

此代码的文件托管在此项目的文件部分中。

让我们从导入套接字、时间、随机和数学库开始。

import cfg
import socket
import time
import random
import math

他们的 cfg 文件是使用您的用户名、密码和您要放入 twitch 频道的机器人的频道名称定制的。

现在让我们定义我们的超时命令将如何运行。

def timeout(sock, user, secs):
    """
    Time out a user for a set period of time.
    Keyword arguments:
    sock -- the socket over which to send the timeout command
    user -- the user to be timed out
    secs -- the length of the timeout in seconds (default 600)
    """
    chat(sock, "/timeout {}".format(user, secs))
    
def untimeout(sock,user):
    chat(sock,"/unban {}".format(user))

当你调用这个函数时,你需要指出你试图与哪个套接字进行通信,你超时的用户名,以及他们将被禁止多长时间。

我还包含了一个使用 Twitch 的 unban 功能的撤销超时命令。

s = socket.socket()
s.connect((cfg.HOST,cfg.PORT))
s.send("PASS {}\r\n".format(cfg.PASS).encode("utf-8"))
s.send("NICK {}\r\n".format(cfg.NICK).encode("utf-8"))
s.send("JOIN {}\r\n".format(cfg.CHAN).encode("utf-8"))
CHAT_MSG=re.compile(r"^:\w+!\w+@\w+.tmi.twitch.tv PRIVMSG #\w+ :")

这部分代码创建套接字,并传递在我前面提到的 cfg 文件中排序的信息它还为 twitch 消息创建编译器/反编译器。

让我们创建一些变量来存储用户名,甚至是每个人的聊天计数器。

vips = []
vrem = []
vipc = []
vipCount = 0

 现在让我们创建一个无限循环来运行,并等待来自 twitch(聊天)的消息。然后我们将检查它是否是 ping。如果我们的机器人要保持与 Twitch 的连接,则需要发送一个 pong。

while True:    
        response = s.recv(1024).decode("utf-8")
        if response == "PING :tmi.twitch.tv\r\n":
            s.send("PONG :tmi.twitch.tv\r\n".encode("utf-8")) 
            print('sent')

但是,如果它不是 ping,而是我们想要关注的实际聊天呢?我们会将消息和用户名从我们收到的信息中分离出来。

 else:
            username = re.search(r"\w+", response).group(0) # return the entire match
            message = CHAT_MSG.sub("", response)
            # s.send(s,username +" + " + message)
            print(username + ": " + message) 

有了这些信息,我们将开始收集聊天中的每个人,将他们放入列表中,并计算他们在聊天中发言的次数。

 if username in vips: # will need to edit out tvheadbot, atltvhead, tmi from the messages collected! before doing the thanos glove
                # if its tvhead bot do nothing
                ind = vips.index(username)
                vipCount = vipc[ind]
                vipCount = vipCount + 1
                vipc[ind] = vipCount
                print(vips)
                print(vipc)
                # print(username + " has spoken " + str(vipCount) + " times.")
                
            else:
                vips.append(username)
                vipc.append(1)

如果用户名不在列表 VIPS 中,它将把它们添加到列表中。它还将一个整数添加到另一个列表中以计算它们的交互。如果用户在列表中,它将添加到他们的整数中。

接下来让我们看看消息是否是我们的 SNAP 命令。Snap 命令将为那些将被随机超时的人创建一个新列表,不会重复。这个新列表被计算为所有在聊天中发言的人的一半,四舍五入。它还说明了所有聊天 tmi 和您的聊天机器人中的 twitch 实体。在我的例子中是 tvheadbot。

if message.strip() == "SNAP" and username == "tvheadbot":
                # these operations move half of the chat to a new list for removal
                oglength = len(vips)
                delenght = math.ceil((oglength-3)/2)
                while len(vrem) < delenght:
                    userToMove = random.choice(vips)
                    if userToMove == "tmi" or userToMove == "tvheadbot" or userToMove == "atltvhead":
                        # do nothing
                        print("Encountered either Tmi or tvheadbot or atltvhead")
                    else:
                        if userToMove in vrem:
                            print("User " + userToMove + " is already to be timed out.")
                        else:
                            vrem.append(userToMove)

 一旦我们将一半的聊天分类到删除列表中。是时候让他们超时了。

 # this is where I do the timeout
                for q in vrem:
                    # print(q)
                    timeout(s, q, 10)
                    time.sleep(1 / cfg.RATE)
                # remember to wipe out vrem  I want to unban / untimout
                
                
        time.sleep(1 / cfg.RATE)

将每个人都列在一个列表中,您也可以轻松取消对他们的封禁!

您的聊天机器人不能做的一些事情是超时版主并将您的聊天设置为仅表情模式。我希望我可以启用仅表情模式,但我必须使用主播用户名来实现。

步骤 5

我使用的是旧版本的 IRCClient,我对其进行了修改以用于 Twitch。如果您使用最新版本,它将开箱即可与 Twitch 一起使用。<>

首先要添加的是库,定义我们的 wifi 网络,以及传递给 twitch 的信息。

#include 
#include 
/*-----------------------------------------------------------------------------------*/
#define ssid1         "Wifi"
#define password1     "Password"
#define IRC_SERVER   "irc.chat.twitch.tv"
#define IRC_PORT     6667
#define IRC_NICK     "Bot_Name"
#define IRC_CHAN     "#Channel_Name"
#define IRC_PASS     "oauth:####"
WiFiClient wiFiClient;
IRCClient client(IRC_SERVER, IRC_PORT, wiFiClient);

我们在这里调用我们的 wificlient 和我们的 ircclients,并列出适当的 twitch 端口您的机器人、频道名称和密码都是您需要更改的内容。

让我们定义一些变量,这些变量将帮助我们在我们不想的时候不让人们超时。

boolean snapboo = false;
boolean emoteboo = false;

 下一部分代码用于 esp 32 中内置的触摸传感器。我们还创建了一个函数,该函数将在触发快照时调用。

int thresholdTwo = 60;
bool touch2detected = false;
byte touchCountTwo = 0;
unsigned long touchTimeTwo;
unsigned long oldTouchTimeTwo;
void gotTouch2(){
  //figure out calibration here!
//get time and incriment timer
touchTimeTwo = millis();
touchCountTwo++;
// if counter is above a certain # in a certain timeout decrease sensitivity (time is going to be half second)
if(touchCountTwo >=3 && (touchTimeTwo-oldTouchTimeTwo)<=400 && thresholdTwo > 20){
  thresholdTwo=thresholdTwo-1;
  // reset count
  touchCountTwo=0;
  }
// if counter is below a # and a certain timeout increase sensitivity (time is going to be 2 min?)
else if((touchTimeTwo-oldTouchTimeTwo)>=60000){ // touchCount<1 && probably doesn't need the <1 touch count. if it creates too sensitive of a sensor, it will be backed off imediatly after. it should jut create more triggers after the high five
  thresholdTwo++;
  // reset counter
  touchCountTwo=0;
  }
// if counter is below # and timer is between sensitivity triggers touch detected
else if(400<(touchTimeTwo-oldTouchTimeTwo) && (touchTimeTwo-oldTouchTimeTwo)<60000){
  touch2detected = true;
  delay(500);
  // reset counter
  }
// time saved to new variable and reset
oldTouchTimeTwo = touchTimeTwo;

每次触发快照时,它都会校准传感器,通过比较时间间隔和触发次数来检查它是否是真正的触摸。

 接下来让我们创建我们的设置循环并附加我们的中断。wifi 和客户端也将开始。

void setup() {
  WiFi.begin(ssid1, password1);
  client.setCallback(callback);
  client.setSentCallback(debugSentCallback);
  touchAttachInterrupt(T7,gotTouch2,thresholdTwo);
}

 现在,在我们的主循环中,我们将把我们的信息传递给 twitch,并一直传递它直到我们建立连接。

void loop() {
  // put your main code here, to run repeatedly:
    if (!client.connected()) {
    //Serial.println("Attempting IRC connection...");
    // Attempt to connect
    if (client.connect(IRC_NICK, IRC_CHAN, IRC_PASS)) {
    //Serial.println("connected");
      client.sendMessage(IRC_CHAN, "Hello everyone! I'm TvheadBot, a construct, assistant within the head of Atltvhead. If you have any questions type !help , and I'll post a link to all the channel commands. Let's Tune into Good Vibes! <3");
    } else {
      //Serial.println("failed... try again in 5 seconds");
      // Wait 5 seconds before retrying
      delay(5000);
    }
    return;
  }

 我们将调用我们的回调函数来检查 twitch 消息并将其分解为 ping/pong 交互、聊天消息和用户名。我们还将开始检查是否检测到快照,并查看我们的任何密钥是否已解锁。

client.loop();
  
  //Time Outs or Emote Only 
  if(touch2detected){
    touch2detected = false;
    if(snapboo){
      snapboo = false;
      client.sendMessage(IRC_CHAN,"SNAP");
      
    } else if(emoteboo){
      emoteboo = false;
      client.sendMessage(IRC_CHAN,"IT'S EMOTE TIME!");
    } else{
      client.sendMessage(IRC_CHAN,"High Five Mode Initiated");
    }
  }
}

 不幸的是,聊天机器人无法触发仅表情模式,真可惜。

这些命令被我们的 python 脚本识别以启动超时。

上面提到,我们分解了 twitch 消息,用于 ping/pong、用户名、消息。

如果一个特定的单词是由特定的用户名(用户名)写的,那么解锁快照或仅表情模式(我又很笨,聊天机器人无法触发)。

void callback(IRCMessage ircMessage) {
//Serial.println("In CallBack");
  // PRIVMSG ignoring CTCP messages
  if (ircMessage.command == "PRIVMSG" && ircMessage.text[0] != '\001') {
    //Serial.println("Passed private message.");
    String message("<" + ircMessage.nick + "> " + ircMessage.text);
    
    if(ircMessage.text == "sk" && ircMessage.nick == "username"){
      snapboo = true;
      client.sendMessage(IRC_CHAN,"The Snap has been unlocked!");
    }
    else if(ircMessage.text == "ek" && ircMessage.nick == "username"){
      emoteboo = true;
      client.sendMessage(IRC_CHAN,"Emote only ready!");
    }
    return;
  }
}

 最后,只需为客户端设置调试。

void debugSentCallback(String data) {
  //Serial.println("I am in debug");
  Serial.println(data);
}

步骤 6

如何关闭你的构建并捕捉你的聊天!

不要忘记切一个洞,这样你的手指就可以接触到传感器! 

文件

Snap_Glove.ino :ESP32 和 Arduino 的 Snap Glove 代码

 

Thanos Twitch Bot.py :一个基本的 Twitch 机器人,它收集聊天中的所有用户,将其中一半的用户分段以超时,并在特定人员发送特定消息时将其超时缺少用于与 twitch 通信的 cfg 文件(它的密码和其他)-> # cfg.pyHOST = "irc.twitch.tv" # Twitch IRC 服务器端口 = 6667 # 总是使用端口 6667!NICK = "twitch_username" # 你的 Twitch 用户名,小写 PASS = "oauth:xxxxxxxxxxxxxxxxxxxx " # 你的 Twitch OAuth tokenCHAN = "#channel" # 你想加入的频道

 

 


下载该资料的人也在下载 下载该资料的人还在阅读
更多 >

评论

查看更多

下载排行

本周

  1. 1山景DSP芯片AP8248A2数据手册
  2. 1.06 MB  |  532次下载  |  免费
  3. 2RK3399完整板原理图(支持平板,盒子VR)
  4. 3.28 MB  |  339次下载  |  免费
  5. 3TC358743XBG评估板参考手册
  6. 1.36 MB  |  330次下载  |  免费
  7. 4DFM软件使用教程
  8. 0.84 MB  |  295次下载  |  免费
  9. 5元宇宙深度解析—未来的未来-风口还是泡沫
  10. 6.40 MB  |  227次下载  |  免费
  11. 6迪文DGUS开发指南
  12. 31.67 MB  |  194次下载  |  免费
  13. 7元宇宙底层硬件系列报告
  14. 13.42 MB  |  182次下载  |  免费
  15. 8FP5207XR-G1中文应用手册
  16. 1.09 MB  |  178次下载  |  免费

本月

  1. 1OrCAD10.5下载OrCAD10.5中文版软件
  2. 0.00 MB  |  234315次下载  |  免费
  3. 2555集成电路应用800例(新编版)
  4. 0.00 MB  |  33566次下载  |  免费
  5. 3接口电路图大全
  6. 未知  |  30323次下载  |  免费
  7. 4开关电源设计实例指南
  8. 未知  |  21549次下载  |  免费
  9. 5电气工程师手册免费下载(新编第二版pdf电子书)
  10. 0.00 MB  |  15349次下载  |  免费
  11. 6数字电路基础pdf(下载)
  12. 未知  |  13750次下载  |  免费
  13. 7电子制作实例集锦 下载
  14. 未知  |  8113次下载  |  免费
  15. 8《LED驱动电路设计》 温德尔著
  16. 0.00 MB  |  6656次下载  |  免费

总榜

  1. 1matlab软件下载入口
  2. 未知  |  935054次下载  |  免费
  3. 2protel99se软件下载(可英文版转中文版)
  4. 78.1 MB  |  537798次下载  |  免费
  5. 3MATLAB 7.1 下载 (含软件介绍)
  6. 未知  |  420027次下载  |  免费
  7. 4OrCAD10.5下载OrCAD10.5中文版软件
  8. 0.00 MB  |  234315次下载  |  免费
  9. 5Altium DXP2002下载入口
  10. 未知  |  233046次下载  |  免费
  11. 6电路仿真软件multisim 10.0免费下载
  12. 340992  |  191187次下载  |  免费
  13. 7十天学会AVR单片机与C语言视频教程 下载
  14. 158M  |  183279次下载  |  免费
  15. 8proe5.0野火版下载(中文版免费下载)
  16. 未知  |  138040次下载  |  免费