public async Task CallTransactionMadeEventAsync(IDiscordGuildChannel m, User receiver, User giver, int amount) { try { TransactionPacket p = new TransactionPacket(); p.discordChannel = m; p.discordUser = await m.GetUserAsync(receiver.Id.FromDbLong()); if (giver != null) { p.giver = giver; } p.receiver = receiver; p.amount = amount; if (OnTransaction != null) { await OnTransaction?.Invoke(p); } } catch (Exception e) { Log.Warning($"Achievement check failed: {e.ToString()}"); } }
public TransactionHub() { Console.WriteLine("Starting Transaction hub connection..."); connection = new HubConnectionBuilder() .WithUrl("https://spookvooper.com/transactionHub") .WithAutomaticReconnect(new RetryPolicy()) .Build(); connection.Closed += OnClosed; connection.On("NotifyTransaction", (string message) => { long timestamp = DateTimeOffset.UtcNow.ToUnixTimeSeconds(); Transaction transaction = transaction = JsonSerializer.Deserialize <Transaction>(message); transaction.Timestamp = timestamp; OnTransaction?.Invoke(transaction); }); try { connection.StartAsync(); } catch (Exception e) { Console.WriteLine("An error occured while opening the SignalR for the Transaction hub"); Console.WriteLine(e); } }
public async Task CallTransactionMadeEventAsync(IDiscordMessageChannel m, User receiver, User giver, int amount) { try { TransactionPacket p = new TransactionPacket(); p.discordChannel = m; p.discordUser = new RuntimeUser(Bot.instance.Client.GetUser(receiver.Id.FromDbLong())); if (giver != null) { p.giver = giver; } p.receiver = receiver; p.amount = amount; if (OnTransaction != null) { await OnTransaction?.Invoke(p); } } catch (Exception e) { await MeruUtils.ReportErrorAsync(e); Log.WarningAt("achievement check failed", e.ToString()); } }
public TransactionHub() { Console.WriteLine("Starting Transaction hub connection..."); connection = new HubConnectionBuilder() .WithUrl("https://spookvooper.com/transactionHub") .WithAutomaticReconnect() .Build(); connection.Closed += OnClosed; connection.On("NotifyTransaction", (string message) => { Transaction transaction = JsonConvert.DeserializeObject <Transaction>(message); OnTransaction?.Invoke(transaction); }); try { connection.StartAsync(); } catch (System.Exception e) { Console.WriteLine("An error occured while opening the SignalR for the Transaction hub"); Console.WriteLine(e.Message); } }
public AchievementManager(MikiApp bot) { this.bot = bot; AccountManager.Instance.OnLocalLevelUp += async(u, c, l) => { using (var db = new MikiContext()) { if (await provider.IsEnabled(MikiApp.Instance.GetService <ICacheClient>(), db, c.Id)) { LevelPacket p = new LevelPacket() { discordUser = await(c as IDiscordGuildChannel).GetUserAsync(u.Id), discordChannel = c, level = l, }; await OnLevelGained?.Invoke(p); } } }; AccountManager.Instance.OnTransactionMade += async(msg, u1, u2, amount) => { using (var db = new MikiContext()) { if (await provider.IsEnabled(MikiApp.Instance.GetService <ICacheClient>(), db, msg.ChannelId)) { TransactionPacket p = new TransactionPacket() { discordUser = msg.Author, discordChannel = await msg.GetChannelAsync(), giver = u1, receiver = u2, amount = amount }; await OnTransaction?.Invoke(p); } } }; bot.GetService <EventSystem>().GetCommandHandler <SimpleCommandHandler>().OnMessageProcessed += async(e, m, t) => { CommandPacket p = new CommandPacket() { discordUser = m.Author, discordChannel = await m.GetChannelAsync(), message = m, command = e, success = true }; await OnCommandUsed?.Invoke(p); }; }
public AchievementManager(IBot bot) { this.bot = bot; AccountManager.Instance.OnGlobalLevelUp += async(u, c, l) => { if (await provider.IsEnabled(c.Id)) { LevelPacket p = new LevelPacket() { discordUser = await c.Guild.GetUserAsync(u.Id), discordChannel = c, level = l, }; await OnLevelGained?.Invoke(p); } }; AccountManager.Instance.OnTransactionMade += async(msg, u1, u2, amount) => { if (await provider.IsEnabled(msg.Channel.Id)) { TransactionPacket p = new TransactionPacket() { discordUser = msg.Author, discordChannel = msg.Channel, giver = u1, receiver = u2, amount = amount }; await OnTransaction?.Invoke(p); } }; EventSystem.Instance.AddCommandDoneEvent(x => { x.Name = "--achievement-manager-command"; x.processEvent = async(m, e, s, t) => { CommandPacket p = new CommandPacket() { discordUser = m.Author, discordChannel = m.Channel, message = m, command = e, success = s }; await OnCommandUsed?.Invoke(p); }; }); }
public AchievementManager(Bot bot) { this.bot = bot; AccountManager.Instance.OnGlobalLevelUp += async(u, c, l) => { if (await provider.IsEnabled(Global.RedisClient, c.Id)) { LevelPacket p = new LevelPacket() { discordUser = await(c as IDiscordGuildChannel).GetUserAsync(u.Id), discordChannel = c, level = l, }; await OnLevelGained?.Invoke(p); } }; AccountManager.Instance.OnTransactionMade += async(msg, u1, u2, amount) => { if (await provider.IsEnabled(Global.RedisClient, msg.ChannelId)) { TransactionPacket p = new TransactionPacket() { discordUser = msg.Author, discordChannel = await msg.GetChannelAsync(), giver = u1, receiver = u2, amount = amount }; await OnTransaction?.Invoke(p); } }; bot.GetAttachedObject <EventSystem>().GetCommandHandler <SimpleCommandHandler>().OnMessageProcessed += async(e, m, t) => { CommandPacket p = new CommandPacket() { discordUser = m.Author, discordChannel = await m.GetChannelAsync(), message = m, command = e, success = true }; await OnCommandUsed?.Invoke(p); }; }
public AchievementManager(Bot bot) { this.bot = bot; AccountManager.Instance.OnGlobalLevelUp += async(u, c, l) => { if (await provider.IsEnabled(c.Id)) { LevelPacket p = new LevelPacket() { discordUser = await(c as IGuildChannel).GetUserAsync(u.Id), discordChannel = c, level = l, }; await OnLevelGained?.Invoke(p); } }; AccountManager.Instance.OnTransactionMade += async(msg, u1, u2, amount) => { if (await provider.IsEnabled(msg.Channel.Id)) { TransactionPacket p = new TransactionPacket() { discordUser = msg.Author, discordChannel = msg.Channel, giver = u1, receiver = u2, amount = amount }; await OnTransaction?.Invoke(p); } }; bot.GetAttachedObject <EventSystem>().OnCommandDone += async(ex, e, m, t) => { CommandPacket p = new CommandPacket() { discordUser = m.Author, discordChannel = m.Channel, message = m, command = e, success = ex == null }; await OnCommandUsed?.Invoke(p); }; }
private AchievementManager(Bot bot) { this.bot = bot; AccountManager.Instance.OnGlobalLevelUp += async(u, c, l) => { LevelPacket p = new LevelPacket() { discordUser = await c.Guild.GetUserAsync(u.Id.FromDbLong()), discordChannel = c, account = u, level = l, }; await OnLevelGained?.Invoke(p); }; AccountManager.Instance.OnTransactionMade += async(msg, u1, u2, amount) => { TransactionPacket p = new TransactionPacket() { discordUser = msg.Author, discordChannel = msg.Channel, giver = u1, receiver = u2, amount = amount }; await OnTransaction?.Invoke(p); }; bot.Client.MessageReceived += async(e) => { if (OnMessageReceived == null) { return; } MessageEventPacket p = new MessageEventPacket() { message = new RuntimeMessage(e), discordUser = new RuntimeUser(e.Author), discordChannel = new RuntimeMessageChannel(e.Channel) }; await OnMessageReceived?.Invoke(p); }; bot.Client.UserUpdated += async(ub, ua) => { UserUpdatePacket p = new UserUpdatePacket() { discordUser = new RuntimeUser(ub), userNew = new RuntimeUser(ua) }; await OnUserUpdate?.Invoke(p); }; bot.Events.AddCommandDoneEvent(x => { x.Name = "--achievement-manager-command"; x.processEvent = async(m, e, s) => { CommandPacket p = new CommandPacket() { discordUser = m.Author, discordChannel = m.Channel, message = m, command = e, success = s }; await OnCommandUsed?.Invoke(p); }; }); }
public void OnTransactionUpdated(UM_iTransaction transaction) { PrintTransactionInfo(transaction); OnTransaction.Invoke(transaction); }
private async Task <Message> WireDecodeMessage(UInt32 magic) { var command = DataDecoder.DecodeFixedString(await ReceiveExactly(12)); var payloadSize = DataDecoder.DecodeUInt32(await ReceiveExactly(4)); var payloadChecksum = DataDecoder.DecodeUInt32(await ReceiveExactly(4)); var payload = await ReceiveExactly(payloadSize.ToIntChecked()); if (!Messaging.VerifyPayloadChecksum(payloadChecksum, payload)) { throw new Exception($"Checksum failed for {command}"); } var message = new Message ( Magic: magic, Command: command, PayloadSize: payloadSize, PayloadChecksum: payloadChecksum, Payload: payload.ToImmutableArray() ); switch (message.Command) { case "addr": { var addressPayload = NetworkEncoder.DecodeAddressPayload(payload); OnReceivedAddresses?.Invoke(owner, addressPayload.NetworkAddresses); } break; case "alert": { var alertPayload = NetworkEncoder.DecodeAlertPayload(payload); } break; case "block": { var block = DataDecoder.DecodeBlock(null, payload); OnBlock?.Invoke(owner, block); } break; case "getblocks": { var getBlocksPayload = NetworkEncoder.DecodeGetBlocksPayload(payload); OnGetBlocks?.Invoke(owner, getBlocksPayload); } break; case "getheaders": { var getHeadersPayload = NetworkEncoder.DecodeGetBlocksPayload(payload); OnGetHeaders?.Invoke(owner, getHeadersPayload); } break; case "getdata": { var invPayload = NetworkEncoder.DecodeInventoryPayload(payload); OnGetData?.Invoke(owner, invPayload); } break; case "headers": { var blockHeaders = ImmutableList.CreateBuilder <BlockHeader>(); var offset = 0; var headerCount = payload.ReadVarInt(ref offset).ToIntChecked(); for (var i = 0; i < headerCount; i++) { var blockHeader = DataDecoder.DecodeBlockHeader(null, payload, ref offset); // ignore tx count var int payload.ReadVarInt(ref offset); blockHeaders.Add(blockHeader); } OnBlockHeaders?.Invoke(owner, blockHeaders.ToImmutable()); } break; case "inv": { var invPayload = NetworkEncoder.DecodeInventoryPayload(payload); OnInventoryVectors?.Invoke(owner, invPayload.InventoryVectors); } break; case "notfound": { var invPayload = NetworkEncoder.DecodeInventoryPayload(payload); OnNotFound?.Invoke(owner, invPayload.InventoryVectors); } break; case "ping": { OnPing?.Invoke(owner, payload.ToImmutableArray()); } break; case "tx": { var tx = DataDecoder.DecodeEncodedTx(null, payload); OnTransaction?.Invoke(owner, tx); } break; case "version": { var versionPayload = NetworkEncoder.DecodeVersionPayload(payload, payload.Length); OnVersion?.Invoke(owner, versionPayload); } break; case "verack": { OnVersionAcknowledged?.Invoke(owner); } break; default: { logger.Warn($"Unhandled incoming message: {message.Command}"); } break; } //TODO //if (payloadStream.Position != payloadStream.Length) //{ // var exMessage = $"Wrong number of bytes read for {message.Command}, parser error: read {payloadStream.Position} bytes from a {payloadStream.Length} byte payload"; // Debug.WriteLine(exMessage); // throw new Exception(exMessage); //} return(message); }