Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using FcCore.Engine;
- using FcCore.Subspace;
- using FcCore.Subspace.Modules;
- using DevoPoint.Framework.Extensions.BingTranslator;
- namespace FcCore.Fc.Modules
- {
- public class BingTranslator : IFcEngineModule
- {
- IChat chat;
- bool IFcEngineModule.OnLoad(IFcEngineHook engineHook)
- {
- BingTranslationExtension.BingAppID = "5BAAD00980E0BA6E487729CADD42478D9CA4D596";
- if (engineHook.AttachModule<IChat>(out chat))
- {
- chat.MessageRecieved += new MessageRecievedHandle(chat_MessageRecieved);
- return true;
- }
- return false;
- }
- bool IFcEngineModule.OnUnload(IFcEngineHook enghineHook)
- {
- return true;
- }
- void chat_MessageRecieved(object sender, MessageInfo mi)
- {
- if (mi.ChatType == ChatType.TeamBroadcast
- || mi.ChatType == ChatType.TeamMessage
- || mi.ChatType == ChatType.PrivateMessage)
- {
- BingLanguage language = BingLanguage.None;
- String translatedText = String.Empty;
- try
- {
- language = mi.Message.DetectLanguage();
- if (language != BingLanguage.English && language != BingLanguage.None)
- {
- translatedText = mi.Message.BingTranslate(BingLanguage.English);
- //Make sure the translated string is not the same as the original string
- if ((String.Compare(mi.Message, translatedText, true) != 0))
- {
- String output = String.Format("{0} -> English: {1}> {2}", language.ToString(), mi.SenderPlayerName, translatedText);
- chat.Send(mi.ChatType, mi.SenderPlayerId, output, SoundType.None);
- }
- }
- }
- catch (Exception e)
- {
- Console.WriteLine(e.Message);
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement