当前位置: 首页>>代码示例>>C#>>正文


C# SteamFriends.SendChatMessage方法代码示例

本文整理汇总了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
开发者ID:ampped101,项目名称:SteamBot,代码行数:101,代码来源:Main.cs

示例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("/", "");
//.........这里部分代码省略.........
开发者ID:ampped101,项目名称:SteamBot,代码行数:101,代码来源:Program.cs

示例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();
        }
开发者ID:norgalyn,项目名称:SteamBot,代码行数:74,代码来源:Bot.cs


注:本文中的SteamKit2.SteamFriends.SendChatMessage方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。