tmijs / tmi.js

💬 Javascript library for the Twitch Messaging Interface. (Twitch.tv)
https://tmijs.com
MIT License
1.55k stars 215 forks source link

tmi does not support cyrillic (or even unicode) symbols. #323

Closed sviatoslav-vilkovych closed 5 years ago

sviatoslav-vilkovych commented 5 years ago

I was trying to apply simple tutorial from twitch documentation and it seems that tmi does not support cyrillic (or even any unicode) symbols.

Actual behaviour: username �� ������ 2

Expected behaviour: username ти вкинув 2

Error log: No error logged.

Server configuration

const tmi = require('tmi.js');
var BOT_USERNAME = "bot_name";
var OAUTH_TOKEN = "oauth:token";
var CHANNEL_NAME = "channel_name";

// Define configuration options
const opts = {
  identity: {
    username: BOT_USERNAME,
    password: OAUTH_TOKEN
  },
  channels: [
    CHANNEL_NAME
  ]
};

// Create a client with our options
const client = new tmi.client(opts);

// Register our event handlers (defined below)
client.on('message', onMessageHandler);
client.on('connected', onConnectedHandler);

// Connect to Twitch:
client.connect();

// Called every time a message comes in
function onMessageHandler (target, context, msg, self) {
  if (self) { return; } // Ignore messages from the bot

  // Remove whitespace from chat message
  const commandName = msg.trim();

  // If the command is known, let's execute it
  if (commandName === '!dice') {
    const num = rollDice();
    client.say(target, `${target} ти вкинув ${num}`);
    console.log(`* Executed ${commandName} command`);
  } else {
    console.log(`* Unknown command ${commandName}`);
  }
}

// Function called when the "dice" command is issued
function rollDice () {
  const sides = 6;
  return Math.floor(Math.random() * sides) + 1;
}

// Called every time the bot connects to Twitch chat
function onConnectedHandler (addr, port) {
  console.log(`* Connected to ${addr}:${port}`);
}
AlcaDesign commented 5 years ago

Do you have a user ID for that name? (or somewhere where they or someone with a similar name are chatting)

sviatoslav-vilkovych commented 5 years ago

@AlcaDesign sure. https://www.twitch.tv/bigdriftermen here. Type !dice to see the output.

sviatoslav-vilkovych commented 5 years ago

The reason was file encoding. Thank you @AlcaDesign for the quick response.