本文整理匯總了C#中SteamKit2.SteamFriends.SendChatMessage方法的典型用法代碼示例。如果您正苦於以下問題:C# SteamFriends.SendChatMessage方法的具體用法?C# SteamFriends.SendChatMessage怎麽用?C# SteamFriends.SendChatMessage使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類SteamKit2.SteamFriends
的用法示例。
在下文中一共展示了SteamFriends.SendChatMessage方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: Main
//.........這裏部分代碼省略.........
#region Steam Login Handler
//Logged in (or not)
msg.Handle<SteamUser.LoggedOnCallback>( callback =>
{
printConsole("Logged on callback: "+callback.Result, ConsoleColor.Cyan);
if(callback.Result != EResult.OK){
printConsole("Login Failed!",ConsoleColor.Red);
}else{
printConsole("Successfulyl Logged In!\nWelcome "+steamUser.SteamID,ConsoleColor.Green);
//Set community status
steamFriends.SetPersonaName(BotPersonaName);
steamFriends.SetPersonaState(BotPersonaState);
}
});
#endregion
#region Steam Trade Start
/**
*
* Steam Trading Handler
*
*/
msg.Handle<SteamTrading.TradeStartSessionCallback>(call =>
{
//Trading
trade = null;
trade = new TradeSystem();
trade.initTrade(steamUser.SteamID,call.Other,WebCookies);
});
#endregion
#region Trade Requested Handler
//Don't modify this
msg.Handle<SteamTrading.TradeProposedCallback>( thing =>
{
//Trade Callback
printConsole ("Trade Proposed Callback. Other: "+thing.Other+"\n");
//Accept It
steamTrade.RequestTrade(thing.Other);
});
#endregion
msg.Handle<SteamFriends.PersonaStateCallback>(callback =>
{
if (callback.FriendID == steamUser.SteamID)
return;
EFriendRelationship relationship = steamFriends.GetFriendRelationship(callback.FriendID);
if (!(relationship == EFriendRelationship.RequestRecipient))
return;
if(steamFriends.GetFriendRelationship(callback.FriendID)==EFriendRelationship.PendingInvitee){
printConsole("[Friend] Friend Request Pending: " + callback.FriendID + "(" + steamFriends.GetFriendPersonaName(callback.FriendID) + ") - Accepted", ConsoleColor.Yellow);
steamFriends.AddFriend(callback.FriendID);
}
});
#region Steam Chat Handler
/**
*
* Steam Chat Handler
*
*/
msg.Handle<SteamFriends.FriendMsgCallback>(callback =>
{
//Type (emote or chat)
EChatEntryType type = callback.EntryType;
if(type == EChatEntryType.ChatMsg){
//Message is a chat message
//Reply with the same message
steamFriends.SendChatMessage(callback.Sender,EChatEntryType.ChatMsg,callback.Message);
//Chat API coming soon
}else if(type == EChatEntryType.Emote){
//Message is emote
//Do nothing yet
}
});
#endregion
} //end while loop
} //end Main method
示例2: Main
static void Main(string[] args)
{
Console.ForegroundColor = ConsoleColor.DarkCyan;
System.Console.Title = "TradeBot";
System.Console.WriteLine("Welcome to TradeBot!\nCreated by Jessecar.\nTurn of Steam Guard before loggin in!\n\n");
Console.ForegroundColor = ConsoleColor.White;
printConsole("Steam Username:");
String username = "jessecar96"; //Console.ReadLine();
System.Console.WriteLine("Steam Password: ");
//heckey
Console.ForegroundColor = Console.BackgroundColor;
String password = Console.ReadLine();
Console.ForegroundColor = ConsoleColor.White;
SteamClient steamClient = new SteamClient(); // initialize our client
SteamUser steamUser = steamClient.GetHandler<SteamUser>();
steamFriends = steamClient.GetHandler<SteamFriends>();
SteamTrading trade = steamClient.GetHandler<SteamTrading>();
steamClient.Connect(); // connect to the steam network
while (true)
{
if (Console.KeyAvailable)
{
printConsole(Console.ReadLine(), ConsoleColor.Yellow);
}
CallbackMsg msg = steamClient.WaitForCallback(true); // block and wait until a callback is posted
//Print out callbacks
//printConsole(msg.ToString());
//Steam Connection
msg.Handle<SteamClient.ConnectedCallback>(callback =>
{
if (callback.Result != EResult.OK)
{
printConsole("Sorry, could not connect to Steam.");
}
steamUser.LogOn(new SteamUser.LogOnDetails
{
Username = username,
Password = password,
});
});
//Login Callback
msg.Handle<SteamUser.LoggedOnCallback>(callback =>
{
if (callback.Result != EResult.OK)
{
printConsole("Incorrect username or Password. Make sure you have disabled steam guard!");
}
else
{
printConsole("Connected to Steam!\nWelcome "+steamUser.SteamID);
steamFriends.SetPersonaName("ChatBot Beta (Say hi)");
steamFriends.SetPersonaState((EPersonaState)6);
}
});
//Chat Messages
msg.Handle<SteamFriends.FriendMsgCallback>(callback =>
{
EChatEntryType type = callback.EntryType;
if (type == EChatEntryType.ChatMsg)
{
SteamID sid = callback.Sender;
if (!clients.Contains(callback.Sender))
{
printConsole("[New Client]" + callback.Sender, ConsoleColor.Magenta);
clients.Add(callback.Sender);
steamFriends.SendChatMessage(callback.Sender, EChatEntryType.ChatMsg, "Welcome to TradeBot created by Jessecar. To see a list of commands type /help");
}
if (callback.Message.StartsWith("/"))
{
string message = callback.Message.Replace("/", "");
//.........這裏部分代碼省略.........
示例3: Bot
public Bot(Configuration.BotInfo config, string apiKey, UserHandlerCreator handlerCreator, bool debug = false)
{
logOnDetails = new SteamUser.LogOnDetails
{
Username = config.Username,
Password = config.Password
};
DisplayName = config.DisplayName;
ChatResponse = config.ChatResponse;
MaximumTradeTime = config.MaximumTradeTime;
MaximiumActionGap = config.MaximumActionGap;
DisplayNamePrefix = config.DisplayNamePrefix;
TradePollingInterval = config.TradePollingInterval <= 100 ? 800 : config.TradePollingInterval;
hatBuyPrice= config.HatBuyPrice;
hatSellPrice= config.HatSellPrice;
maxRequestTime= config.MaxRequestTime;
craftHatSellPrice = config.CraftHatSellPrice;
Admins = config.Admins;
this.apiKey = apiKey;
try
{
LogLevel = (Log.LogLevel)Enum.Parse(typeof(Log.LogLevel), config.LogLevel, true);
}
catch (ArgumentException)
{
Console.WriteLine("Invalid LogLevel provided in configuration. Defaulting to 'INFO'");
LogLevel = Log.LogLevel.Info;
}
log = new Log (config.LogFile, this.DisplayName, LogLevel);
CreateHandler = handlerCreator;
BotControlClass = config.BotControlClass;
// Hacking around https
ServicePointManager.ServerCertificateValidationCallback += SteamWeb.ValidateRemoteCertificate;
log.Debug ("Initializing Steam Bot...");
SteamClient = new SteamClient();
SteamTrade = SteamClient.GetHandler<SteamTrading>();
SteamUser = SteamClient.GetHandler<SteamUser>();
SteamFriends = SteamClient.GetHandler<SteamFriends>();
log.Info ("Connecting...");
SteamClient.Connect();
Thread CallbackThread = new Thread(() => // Callback Handling
{
while (true)
{
CallbackMsg msg = SteamClient.WaitForCallback (true);
HandleSteamMessage (msg);
}
});
new Thread(() =>
{
while (true)
{
Thread.Sleep(1000);
if (currentRequest.User != null)
{
DateTime RequestTimeout = RequestTime.AddSeconds(maxRequestTime);
int untilTradeTimeout = (int)Math.Round((RequestTimeout - DateTime.Now).TotalSeconds);
if (untilTradeTimeout <= 0 && (MySQL.getItem().User != null))
{
SteamFriends.SendChatMessage(currentRequest.User, EChatEntryType.ChatMsg, "Sorry, but your request took too long");
NewRequest(MySQL.RequestStatus.Timedout);
log.Warn("Request timedout");
}
}
}
}).Start();
CallbackThread.Start();
log.Success ("Done Loading Bot!");
CallbackThread.Join();
}