This repository has been archived by the owner on Oct 24, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 65
/
TwitchIntegration.cs
72 lines (65 loc) · 2.72 KB
/
TwitchIntegration.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Text;
using System.Windows.Forms;
using TwitchLib;
using TwitchLib.Client;
using TwitchLib.Client.Models;
using TwitchLib.Client.Events;
using TwitchLib.Client.Models;
using TwitchLib.Communication.Clients;
using TwitchLib.Communication.Models;
namespace ValorantStreamOverlay
{
class TwitchIntegration
{
private TwitchClient client;
public TwitchIntegration()
{
ConnectionCredentials credentials = new ConnectionCredentials(Properties.Settings.Default.twitchBotUsername, Properties.Settings.Default.twitchBotToken);
ClientOptions clientOptions = new ClientOptions
{
MessagesAllowedInPeriod = 700,
ThrottlingPeriod = TimeSpan.FromSeconds(30)
};
WebSocketClient soccketClient = new WebSocketClient(clientOptions);
client = new TwitchClient(soccketClient);
try
{
Trace.WriteLine("Client Initalizing");
client.Initialize(credentials, Properties.Settings.Default.twitchChannel);
}
catch (Exception e)
{
Properties.Settings.Default.twitchbotEnabled = false;
Properties.Settings.Default.Save();
MessageBox.Show("Error Connecting to twitch, make sure token and username of bot is correct!");
Environment.Exit(1);
}
client.OnConnected += Client_OnConnected;
client.OnMessageReceived += Client_OnMessageRecieved;
//Connect Client to twitch chat.
client.Connect();
}
void Client_OnConnected(object sender, OnConnectedArgs e)
{
client.SendMessage(e.AutoJoinChannel, "Valor Stream Overlay has Connected.");
}
void Client_OnMessageRecieved(object sender, OnMessageReceivedArgs e)
{
switch (e.ChatMessage.Message.ToLower())
{
case "!elo":
client.SendMessage(e.ChatMessage.Channel, $"{e.ChatMessage.Channel} currently has {LogicHandler.currentMMRorELO} Total Rank Rating");
break;
case "!overlay":
client.SendMessage(e.ChatMessage.Channel, $"Overlay and Bot were created by @Rumblemikee, you can find the program here: https://github.com/RumbleMike/ValorantStreamOverlay/releases/latest");
break;
case "!rp":
client.SendMessage(e.ChatMessage.Channel, $"{e.ChatMessage.Channel} currently has {LogicHandler.currentRankPoints} Rating in {RankDetection.rankName}");
break;
}
}
}
}