Skip to content

Instantly share code, notes, and snippets.

@Yonom

Yonom/Form1.cs Secret

Last active August 29, 2015 14:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Yonom/75e5c83937ea8a167d9d to your computer and use it in GitHub Desktop.
Save Yonom/75e5c83937ea8a167d9d to your computer and use it in GitHub Desktop.
Speedrun Bot
using System;
using System.Threading.Tasks;
using System.Windows.Forms;
using BotBits;
using BotBits.Events;
using PlayerIOClient;
using Rabbit;
using Rabbit.EE;
namespace SpeedRun
{
public partial class Form1 : Form
{
public static BotBitsClient bot = new BotBitsClient();
public Form1()
{
InitializeComponent();
EventLoader.Of(bot).Load(this);
}
[EventListener]
void OnJoin(JoinEvent e)
{
this.Write("{0}: Press any arrow key to start the timer.", e.Player.ChatName);
}
[EventListener]
void OnMove(MoveEvent e)
{
if (e.Player.Get<DateTime>("StartTime") == default(DateTime))
{
e.Player.Set("StartTime", DateTime.UtcNow);
this.Write("{0}: Timer started, go go go!", e.Player.ChatName);
}
}
[EventListener]
void OnSilverCrown(SilverCrownEvent e)
{
var startTime = e.Player.Get<DateTime>("StartTime");
if (startTime != default(DateTime))
{
this.Write("{0}: You won! Time: {1:g}", e.Player.ChatName, DateTime.UtcNow - startTime);
}
}
private async void button1_Click(object sender, EventArgs e)
{
button1.Text = "Connecting...";
button1.Enabled = false;
try
{
var username = textBox1.Text == "guest" ? "guest@lol.dk" : textBox1.Text;
Client client = null;
await Task.Run(() =>
client = new RabbitAuth().LogOn(EERabbitAuth.GameId, username, textBox2.Text));
await ConnectionManager
.Of(bot)
.WithClient(client)
.JoinRoomAsync(textBox3.Text);
this.Hide();
}
catch (PlayerIOError ex)
{
MessageBox.Show("Error! " + ex.Message);
button1.Text = "Login";
button1.Enabled = true;
}
}
void Write(string message, params object[] args)
{
Chat.Of(bot).Say(message, args);
Console.WriteLine(message, args);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment