Skip to content

Instantly share code, notes, and snippets.

@rondhi
Last active June 7, 2024 17:43
Show Gist options
  • Save rondhi/aa5e8c3b7d1277d1c93dd7f486b596fe to your computer and use it in GitHub Desktop.
Save rondhi/aa5e8c3b7d1277d1c93dd7f486b596fe to your computer and use it in GitHub Desktop.
Tutorial for Writing Streamer.bot C# code with linting in Visual Studio Code

Writing Streamer.bot C# code with linting in Visual Studio Code

Description

This tutorial provides a general step-by-step guide on setting up Visual Studio Code (VS Code) for writing C# code for Streamer.bot. By following these instructions, you'll be able to write code with linting, which will help you catch errors early and ensure your code compiles before copying into Streamer.bot

Install VS Code

  1. Download VS Code
  2. Install VS Code

Install VS Code Extensions

  1. Launch VS Code
  2. Open Extensions
    1. Keyboard Shortcut: Ctrl+Shift+X
    2. Menu Bar: View > Extensions
  3. Install IntelliCode for C# Dev Kit

image

  1. This will also install the following Extension dependencies:
    1. C#
    2. C# Dev Kit
    3. .NET Install Tool

Sign into Visual Studio Account

  1. Open Command Palette with
    1. Keyboard Shortcut: Ctrl+Shift+P
    2. Menu Bar: View > Command Palette
  2. Type .NET: Sign into Visual Studio account and select it

image

  1. Select Allow and it will open your web browser for you to log in with your Microsoft Account

image

  1. Proceed to log in with Microsoft Account

Create new .NET Project

  1. Command Palette
    1. Keyboard Shortcut: Ctrl+Shift+P
    2. Menu Bar: View > Command Palette
  2. Type .NET: New Project and select it

image

  1. Select Console App

image

  1. Select a folder to save the new project folder into

  2. Write a name for the project and hit enter

image

  1. Press enter or select Create Project

image

Configure new project

  1. Open the Explorer
    1. Keyboard Shortcut: Ctrl+Shift+E
    2. Menu Bar: View > Explorer
  2. Navigate inside the open the .csproj file
  3. Replace with this template in the code block below
  4. Save and close the .csproj file
<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>net472</TargetFramework>
    <ImplicitUsings>enable</ImplicitUsings>
  </PropertyGroup>

  <ItemGroup>
    <!-- Include all DLLs in a specific directory in the build output -->
    <Reference Include="C:\Windows\Microsoft.NET\Framework64\v4.0.30319\System.dll" />
    <Reference Include="C:\Windows\Microsoft.NET\Framework64\v4.0.30319\System.Core.dll" />
    <Reference Include="C:\Windows\Microsoft.NET\Framework64\v4.0.30319\System.Net.dll" />
    <Reference Include="C:\Windows\Microsoft.NET\Framework64\v4.0.30319\System.Net.Http.dll" />
    <Reference Include="C:\Windows\Microsoft.NET\Framework64\v4.0.30319\netstandard.dll" />
    <Reference Include="C:\Windows\Microsoft.NET\Framework64\v4.0.30319\System.Windows.Forms.dll" />
    <Reference Include="C:\Windows\Microsoft.NET\Framework64\v4.0.30319\System.Drawing.dll" />
    <Reference Include="C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Microsoft.VisualBasic.dll" />
    <Reference Include="D:\overlays\streamerbot\Streamer.bot.Plugin.Interface.dll" />
    <Reference Include="D:\overlays\streamerbot\Streamer.bot.Common.dll" />
    <Reference Include="D:\overlays\streamerbot\Streamer.bot.Auth.dll" />
    <Reference Include="D:\overlays\streamerbot\Streamer.bot.EmoteHandlers.dll" />
    <Reference Include="D:\overlays\streamerbot\NAudio.dll" />
    <Reference Include="D:\overlays\streamerbot\NAudio.Core.dll" />
    <Reference Include="D:\overlays\streamerbot\Newtonsoft.Json.dll" />
    <Reference Include="D:\overlays\streamerbot\Twitch.Common.dll" />
    <Reference Include="D:\overlays\streamerbot\websocket-sharp.dll" />
    <Reference Include="D:\overlays\streamerbot\dlls\NCrontab.dll" />
  </ItemGroup>

  <PropertyGroup>
    <LangVersion>latest</LangVersion>
    <NoWarn>CS0114</NoWarn> <!-- Ignore CS114 errors -->
  </PropertyGroup>

</Project>

.csproj Notes

  • This file configures the project as a .NET Framework 4.7.2 project
  • I've added some basic assembly references that are used frequently
  • To point to your own Streamer.bot dlls, replace the directory with your own Streamer.bot directory and Streamer.bot dlls directory

Template for the .cs file

  1. Open the Explorer
    1. Keyboard Shortcut: Ctrl+Shift+E
    2. Menu Bar: View > Explorer
  2. Navigate inside the open the .cs file
  3. Replace your cs file with this template:
using Streamer.bot.Plugin.Interface;
using Streamer.bot.Plugin.Interface.Enums;
using Streamer.bot.Plugin.Interface.Model;
using System;

public class CPHInline : CPHInlineBase
{
    public bool Execute()
    {
        return true;
    }
}

.cs Notes

  • This is similar to the default code found in the Execute C# Code subaction
  • The first three lines are required in VS Code, but are used by default in Streamer.bot
  • Adding : CPHInlineBase after public class CPHInline seems to be the magic that gets VS Code to recognize the CPH methods

You can now write code with assistance from IntelliCode

  • You can type CPH. and it will automatically give you the available CPH methods
    • This uses the Streamer.bot.Plugin.Interface.dll of your Streamer.bot folder
    • The advantage of this is that you will have a current list of methods available

image

  • Open Problems
    • Keyboard Shortcut: Ctrl+Shift+M
    • Menu bar: View > Problems
  • The Problems view will show you if there will be any compile errors
    • Look for any red error icons

image

- These errors will be compiler errors
  • You may notice some yellow warning icons
    • Most of the time, this is caused by having these three methods
      • public void Init()
      • public void Dispose()
      • public bool Execute()

image

- These warnings can be safely ignored

Copying code to Streamer.bot

  • Feel free to exclude the first using statements from your code as they are automatically included in Streamer.bot's Execute C# Code subaction
  • After copying and pasting your code into the Execute C# Code subaction dialog, remember to remove:
: CPHInlineBase

from

public class CPHInline : CPHInlineBase
  • Make sure the code compiles successfully by clicking Compile
  • Click Save and Compile
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment