Skip to content

Commit

Permalink
added viewership rate statistic to uptime command under the variable …
Browse files Browse the repository at this point in the history
…#viewrate-current bot users need to update the uptime output message to utilize it; adjusted the conditions for PubSub start button to be enabled when using the auth code token method-the prior checks only included the manual token method and disabled PubSub unless using 'turn on when stream is online' method.
  • Loading branch information
WrithemTwine committed Jan 9, 2024
1 parent 670d33d commit 4b0023a
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 7 deletions.
7 changes: 4 additions & 3 deletions StreamerBot/StreamerBot.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -723,9 +723,10 @@ private void CheckFocus()
&& OptionFlags.TwitchAuthStreamerClientSecret != ""
&& OptionFlags.TwitchAuthStreamerAuthCode == "";

Radio_Twitch_PubSubBotStart.IsEnabled = OptionFlags.TwitchStreamerUseToken ?
(OptionFlags.TwitchStreamOauthToken != "" && OptionFlags.TwitchStreamerValidToken)
: OptionFlags.TwitchBotAccessToken != "";
Radio_Twitch_PubSubBotStart.IsEnabled = OptionFlags.TwitchTokenUseAuth ?
(OptionFlags.TwitchStreamerUseToken ? OptionFlags.TwitchAuthStreamerAccessToken != "" : OptionFlags.TwitchAuthBotAccessToken != "") :
OptionFlags.TwitchStreamerUseToken ?
(OptionFlags.TwitchStreamOauthToken != "" && OptionFlags.TwitchStreamerValidToken) : OptionFlags.TwitchBotAccessToken != "";

// Twitch

Expand Down
5 changes: 4 additions & 1 deletion StreamerBotLib/Culture/Msgs.resx
Original file line number Diff line number Diff line change
Expand Up @@ -405,6 +405,9 @@
<data name="Helpviewers" xml:space="preserve">
<value>display the number of viewers</value>
</data>
<data name="Helpviewrate" xml:space="preserve">
<value>Shows the current viewers / current followers percentage for the current live stream.</value>
</data>
<data name="Helpwinner" xml:space="preserve">
<value>display winner of Giveaway event</value>
</data>
Expand Down Expand Up @@ -662,7 +665,7 @@
<value>#user has returned. Welcome back!</value>
</data>
<data name="Msguptime" xml:space="preserve">
<value>#user has been streaming for #uptime, with #viewers (#deltaviewers).</value>
<value>#user has been streaming for #uptime, now with #viewers (#deltaviewers). The current viewer to follower rate is #viewrate, note, all viewers may not be followers.</value>
<comment>leave #(variable) intact, the message otherwise can be re-arranged/translated as necessary. also used as default message to build data table</comment>
</data>
<data name="Msgusage" xml:space="preserve">
Expand Down
9 changes: 9 additions & 0 deletions StreamerBotLib/Data/DataManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1120,6 +1120,15 @@ public string GetNewestFollower()
return ((FollowersRow)GetRows(_DataSource.Followers, null, $"{_DataSource.Followers.FollowedDateColumn.ColumnName} DESC").FirstOrDefault()).UserName;
}

/// <summary>
/// Query the Follower table to count the current active channel followers.
/// </summary>
/// <returns>The count of the current follower list.</returns>
public int? GetFollowerCount()
{
return (GetRows(_DataSource.Followers, $"{_DataSource.Followers.IsFollowerColumn}='true'"))?.Length ?? null;
}

/// <summary>
/// Clear all user watchtimes
/// </summary>
Expand Down
3 changes: 2 additions & 1 deletion StreamerBotLib/Enums/MsgVars.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ public enum MsgVars
quote,
Pluralquote,
Pluralbe,
be
be,
viewrate
}
}
8 changes: 8 additions & 0 deletions StreamerBotLib/StreamerBotLib.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@
<Copyright>2024</Copyright>
</PropertyGroup>

<ItemGroup>
<None Remove="Overlay\img\seconds.png" />
</ItemGroup>

<ItemGroup>
<Folder Include="MultiLive\Culture\" />
</ItemGroup>
Expand All @@ -36,6 +40,10 @@
<PackageReference Include="TwitchLib.PubSub" Version="3.2.6" />
</ItemGroup>

<ItemGroup>
<Resource Include="Overlay\img\seconds.png" />
</ItemGroup>

<ItemGroup>
<Compile Update="Data\DataSource.Designer.cs">
<DesignTime>True</DesignTime>
Expand Down
8 changes: 6 additions & 2 deletions StreamerBotLib/Systems/CommandSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -612,12 +612,16 @@ private string ParseCommand(string command, LiveUser User, List<string> arglist,
{
int DeltaViewers = Convert.ToInt32(arglist[0]) - LastLiveViewerCount;

result = VariableParser.ParseReplace(OptionFlags.IsStreamOnline ? (DataManage.GetCommand(command).Message ?? LocalizedMsgSystem.GetDefaultComMsg(DefaultCommand.uptime)) : LocalizedMsgSystem.GetVar(Msg.Msgstreamoffline), VariableParser.BuildDictionary(new Tuple<MsgVars, string>[]
result = VariableParser.ParseReplace(OptionFlags.IsStreamOnline ?
(DataManage.GetCommand(command).Message ?? LocalizedMsgSystem.GetDefaultComMsg(DefaultCommand.uptime)) :
LocalizedMsgSystem.GetVar(Msg.Msgstreamoffline),
VariableParser.BuildDictionary(new Tuple<MsgVars, string>[]
{
new( MsgVars.user, ChannelName ),
new( MsgVars.uptime, FormatData.FormatTimes(GetCurrentStreamStart) ),
new( MsgVars.viewers, FormatData.Plurality(arglist.Count > 0 ? arglist[0] : "", MsgVars.Pluralviewers) ),
new( MsgVars.deltaviewers, $"{(DeltaViewers>0?'+':"")}{DeltaViewers}" )
new( MsgVars.deltaviewers, $"{(DeltaViewers>0?'+':"")}{DeltaViewers}" ),
new( MsgVars.viewrate, arglist.Count > 0 ? (Convert.ToDouble(arglist[0])/(DataManage.GetFollowerCount() ?? 1)).ToString("{P2}") : "0")
}));

LastLiveViewerCount = Convert.ToInt32(arglist[0]);
Expand Down

0 comments on commit 4b0023a

Please sign in to comment.