Add warn to comm_manager if send message > 250

-- Copyright (c) 2014 by Adam Hellberg <sharparam@sharparam.com>.
--
-- Permission is hereby granted, free of charge, to any person obtaining a copy
-- of this software and associated documentation files (the "Software"), to deal
-- in the Software without restriction, including without limitation the rights
-- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-- copies of the Software, and to permit persons to whom the Software is
-- furnished to do so, subject to the following conditions:
--
-- The above copyright notice and this permission notice shall be included in
-- all copies or substantial portions of the Software.
--
-- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
-- THE SOFTWARE.

NAME, T = ...

DELIMITER = '\t'
DELIMITER_MATCH = '[^' .. DELIMITER .. ']+'

MAX_MESSAGE_LENGTH = 250

local comm, log, misc

{
    :SendAddonMessage
    :wipe
    :UnitName
    :RegisterAddonMessagePrefix
} = _G

T.comm_manager =
    prefix: NAME\upper!
    handlers: {}

    handle: (message, channel, sender) =>
        return unless message
        message = message\trim!
        return if message == ''
        di = message\find DELIMITER
        kind = di and message\sub 1, di - 1 or message
        kind = kind\lower!

        return unless @handlers[kind]

        args = {}
        if di
            arg = message\sub di + 1
            for token in arg\gmatch DELIMITER_MATCH
                args[#args + 1] = token

        for _, handler in pairs @handlers[kind]
            handler channel, sender, unpack args

    send: (channel, target, kind, ...) =>
        if channel != 'WHISPER' and channel != 'CHANNEL' and target
            return @send channel, nil, target, kind, ...

        message = kind
        for v in *{...}
            message ..= DELIMITER .. v

        if message\len! > MAX_MESSAGE_LENGTH
            log\warn 'comm_manager\send: (%s) message length > %d', kind, MAX_MESSAGE_LENGTH

        SendAddonMessage @prefix, message, channel, target

    add: (kind, handler) =>
        kind = kind\lower!
        @handlers[kind] = {} unless @handlers[kind]
        @handlers[kind][#@handlers[kind] + 1] = handler

    remove: (kind, handler) =>
        kind = kind\lower!
        return unless @handlers[kind]
        for i = #@handlers[kind], 1, -1
            h = @handlers[kind][i]
            @handlers[kind][i] = nil if h == handler

    remove_all: (kind) =>
        kind = kind\lower!
        return unless @handlers[kind]
        wipe @handlers[kind]

{comm_manager: comm, :log, :misc} = T

T.CHAT_MSG_ADDON = (prefix, message, channel, sender) =>
    return if prefix != comm.prefix or channel != 'PARTY'
    fixed_sender = misc.fix_name sender
    player = misc.fix_name UnitName 'player'
    return if fixed_sender == player
    comm\handle message, channel, sender

T.SHAREXP_LOADED = =>
    RegisterAddonMessagePrefix comm.prefix
    log\debug 'Registered addon message prefix: %s', comm.prefix

-- Copyright (c) 2014 by Adam Hellberg <sharparam@sharparam.com>.
--
-- Permission is hereby granted, free of charge, to any person obtaining a copy
-- of this software and associated documentation files (the "Software"), to deal
-- in the Software without restriction, including without limitation the rights
-- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-- copies of the Software, and to permit persons to whom the Software is
-- furnished to do so, subject to the following conditions:
--
-- The above copyright notice and this permission notice shall be included in
-- all copies or substantial portions of the Software.
--
-- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
-- THE SOFTWARE.

NAME, T = ...

DELIMITER = '\t'
DELIMITER_MATCH = '[^' .. DELIMITER .. ']+'

local comm, log, misc

{
    :SendAddonMessage
    :wipe
    :UnitName
    :RegisterAddonMessagePrefix
} = _G

T.comm_manager =
    prefix: NAME\upper!
    handlers: {}

    handle: (message, channel, sender) =>
        return unless message
        message = message\trim!
        return if message == ''
        di = message\find DELIMITER
        kind = di and message\sub 1, di - 1 or message
        kind = kind\lower!

        return unless @handlers[kind]

        args = {}
        if di
            arg = message\sub di + 1
            for token in arg\gmatch DELIMITER_MATCH
                args[#args + 1] = token

        for _, handler in pairs @handlers[kind]
            handler channel, sender, unpack args

    send: (channel, target, kind, ...) =>
        if channel != 'WHISPER' and channel != 'CHANNEL' and target
            return @send channel, nil, target, kind, ...

        message = kind
        for v in *{...}
            message ..= DELIMITER .. v

        SendAddonMessage @prefix, message, channel, target

    add: (kind, handler) =>
        kind = kind\lower!
        @handlers[kind] = {} unless @handlers[kind]
        @handlers[kind][#@handlers[kind] + 1] = handler

    remove: (kind, handler) =>
        kind = kind\lower!
        return unless @handlers[kind]
        for i = #@handlers[kind], 1, -1
            h = @handlers[kind][i]
            @handlers[kind][i] = nil if h == handler

    remove_all: (kind) =>
        kind = kind\lower!
        return unless @handlers[kind]
        wipe @handlers[kind]

{comm_manager: comm, :log, :misc} = T

T.CHAT_MSG_ADDON = (prefix, message, channel, sender) =>
    return if prefix != comm.prefix or channel != 'PARTY'
    fixed_sender = misc.fix_name sender
    player = misc.fix_name UnitName 'player'
    return if fixed_sender == player
    comm\handle message, channel, sender

T.SHAREXP_LOADED = =>
    RegisterAddonMessagePrefix comm.prefix
    log\debug 'Registered addon message prefix: %s', comm.prefix


emoji: em8ball

emoji: em8ball

Former-commit-id: 59549e219fa48ab477b14a193ecf962008aba911 [formerly 10aba4963c0e6ee5ce04eaec64e4a2d5c9f7b459]
Former-commit-id: ca1dff9fda7c768c7f6abcd4b4245ad8d017a1ad

util = require 'util'
emojis =
  emoticons:'😀😁😂😃😄😅😆😇😈😉😊😋😌😍😎😏
    😐😑😒😓😔😕😖😗😘😙😚😛😜😝😞😟
    😠😡😢😣😤😥😦😧😨😩😪😫😬😭😮😯
    😰😱😲😳😴😵😶😷😸😹😺😻😼😽😾😿
    🙀🙅🙆🙇🙈🙉🙊🙋🙌🙍🙎🙏',
  transport:'🚀🚁🚂🚃🚄🚅🚆🚇🚈🚉🚊🚋🚌🚍🚎🚏
    🚐🚑🚒🚓🚔🚕🚖🚗🚘🚙🚚🚛🚜🚝🚞🚟
    🚠🚡🚢🚣🚤🚥🚦🚧🚨🚩🚪🚫🚬🚭🚮🚯
    🚰🚱🚲🚳🚴🚵🚶🚷🚸🚹🚺🚻🚼🚽🚾🚿
    🛀🛁🛂🛃🛄🛅',
  symbol:'☀☁☂☃☄★☆☇☈☉☊☋☌☍☎☏
    ☐☑☒☓☔☕☖☗☘☙☚☛☜☝☞☟
    ☠☡☢☣☤☥☦☧☨☩☪☫☬☭☮☯
    ☰☱☲☳☴☵☶☷☸☹☺☻☼☽☾☿
    ♀♁♂♃♄♅♆♇♈♉♊♋♌♍♎♏
    ♐♑♒♓♔♕♖♗♘♙♚♛♜♝♞♟
    ♠♡♢♣♤♥♦♧♨♩♪♫♬♭♮♯
    ♰♱♲♳♴♵♶♷♸♹♺♻♼♽♾♿
    ⚀⚁⚂⚃⚄⚅⚆⚇⚈⚉⚊⚋⚌⚍⚎⚏
    ⚐⚑⚒⚓⚔⚕⚖⚗⚘⚙⚚⚛⚜⚝⚞⚟
    ⚠⚡⚢⚣⚤⚥⚦⚧⚨⚩⚪⚫⚬⚭⚮⚯
    ⚰⚱⚲⚳⚴⚵⚶⚷⚸⚹⚺⚻⚼⚽⚾⚿
    ⛀⛁⛂⛃⛄⛅⛆⛇⛈⛉⛊⛋⛌⛍⛎⛏
    ⛐⛑⛒⛓⛔⛕⛖⛗⛘⛙⛚⛛⛜⛝⛞⛟
    ⛠⛡⛢⛣⛤⛥⛦⛧⛨⛩⛪⛫⛬⛭⛮⛯
    ⛰⛱⛲⛳⛴⛵⛶⛷⛸⛹⛺⛻⛼⛽⛾⛿',
  misc:'🌀🌁🌂🌃🌄🌅🌆🌇🌈🌉🌊🌋🌌🌍🌎🌏
    🌐🌑🌒🌓🌔🌕🌖🌗🌘🌙🌚🌛🌜🌝🌞🌟
    🌠
    🌰🌱🌲🌳🌴🌵🌷🌸🌹🌺🌻🌼🌽🌾🌿
    🍀🍁🍂🍃🍄🍅🍆🍇🍈🍉🍊🍋🍌🍍🍎🍏
    🍐🍑🍒🍓🍔🍕🍖🍗🍘🍙🍚🍛🍜🍝🍞🍟
    🍠🍡🍢🍣🍤🍥🍦🍧🍨🍩🍪🍫🍬🍭🍮🍯
    🍰🍱🍲🍳🍴🍵🍶🍷🍸🍹🍺🍻🍼
    🎀🎁🎂🎃🎄🎅🎆🎇🎈🎉🎊🎋🎌🎍🎎🎏
    🎐🎑🎒🎓
    🎠🎡🎢🎣🎤🎥🎦🎧🎨🎩🎪🎫🎬🎭🎮🎯
    🎰🎱🎲🎳🎴🎵🎶🎷🎸🎹🎺🎻🎼🎽🎾🎿
    🏀🏁🏂🏃🏄🏆🏇🏈🏉🏊

    🏠🏡🏢🏣🏤🏥🏦🏧🏨🏩🏪🏫🏬🏭🏮🏯
    🏰
    🐀🐁🐂🐃🐄🐅🐆🐇🐈🐉🐊🐋🐌🐍🐎🐏
    🐐🐑🐒🐓🐔🐕🐖🐗🐘🐙🐚🐛🐜🐝🐞🐟
    🐠🐡🐢🐣🐤🐥🐦🐧🐨🐩🐪🐫🐬🐭🐮🐯
    🐰🐱🐲🐳🐴🐵🐶🐷🐸🐹🐺🐻🐼🐽🐾
    👀👂👃👄👅👆👇👈👉👊👋👌👍👎👏
    👐👑👒👓👔👕👖👗👘👙👚👛👜👝👞👟
    👠👡👢👣👤👥👦👧👨👩👪👫👬👭👮👯
    👰👱👲👳👴👵👶👷👸👹👺👻👼👽👾👿
    💀💁💂💃💄💅💆💇💈💉💊💋💌💍💎💏
    💐💑💒💓💔💕💖💗💘💙💚💛💜💝💞💟
    💠💡💢💣💤💥💦💧💨💩💪💫💬💭💮💯
    💰💱💲💳💴💵💶💷💸💹💺💻💼💽💾💿
    📀📁📂📃📄📅📆📇📈📉📊📋📌📍📎📏
    📐📑📒📓📔📕📖📗📘📙📚📛📜📝📞📟
    📠📡📢📣📤📥📦📧📨📩📪📫📬📭📮📯
    📰📱📲📳📴📵📶📷📹📺📻📼
    🔀🔁🔂🔃🔄🔅🔆🔇🔈🔉🔊🔋🔌🔍🔎🔏
    🔐🔑🔒🔓🔔🔕🔖🔗🔘🔙🔚🔛🔜🔝🔞🔟
    🔠🔡🔢🔣🔤🔥🔦🔧🔨🔩🔪🔫🔬🔭🔮🔯
    🔰🔱🔲🔳🔴🔵🔶🔷🔸🔹🔺🔻🔼🔽
    🕀🕁🕂🕃
    🕐🕑🕒🕓🕔🕕🕖🕗🕘🕙🕚🕛🕜🕝🕞🕟
    🕠🕡🕢🕣🕤🕥🕦🕧
    🗻🗼🗽🗾🗿'

for cat, str in pairs emojis
  str, n = str\gsub('%s', '')
  emojis[cat] = str

PRIVMSG:
  '^%pemoji all$': (source, dest, arg) =>
    out = {}
    for cat, str in pairs emojis
      table.insert out, str
    say table.concat out
  '^%pemoji$': (source, dest, arg) =>
    out = {}
    for cat, str in pairs emojis
      table.insert out, cat
    say table.concat(out, ', ')
  '^%pemoji (.+)$': (source, dest, cat) =>
    say emojis[cat]
  '^%pem8ball(.+)$': (source, dest, arg) =>
    out = {}
    for cat, str in pairs emojis
      for uchar in util.utf8.chars(str)
        table.insert out, uchar
    choice = math.random(1, #out)
    say out[choice]


Update Tween tests for previous commit

Update Tween tests for previous commit

* Subclass Tween to make update behave like Tweener\updateTweens

require "busted"
require "tests.mock_love"

require "LunoPunk.Tween"

-- This is how the Tweener updates
class tween extends Tween
	update: =>
		super!
		@finish! if @__finish

describe "Tween", ->
	setup ->
		-- We used fixed time for testing
		LP.fixed = true

	it "construct", ->
		assert.has.errors -> tween!
		twn = tween 500
		assert.is.False twn.active
		assert.is.Nil twn.ease
		assert.are.equal TweenType.Persist, twn.type
		assert.are.equal 0, twn.t

	it "update (persist)", ->
		twn = tween 5
		twn\start!
		assert.is.True twn.active
		twn\update!
		assert.are.equal 1/5, twn.t
		twn\update!
		assert.are.equal 2/5, twn.t
		-- Finish up the twn
		twn\update!
		twn\update!
		twn\update!
		-- t loops back to 0 to start again
		assert.are.equal 0, twn.t
		assert.is.False twn.active

		twn = tween 2, TweenType.Persist, nil, (t) => t + 1
		twn\update!
		assert.is.False twn.active

	it "update (looping)", ->
		twn = tween 2, TweenType.Looping
		twn\start!
		for i=1, 33
			assert.is.True twn.active
			assert.are.equal (i-1)%2/2, twn.t
			twn\update!

	it "update (oneshot)", ->
		twn = tween 2, TweenType.OneShot
		twn\start!

		assert.is.True twn.active
		assert.are.equal 0, twn.t
		twn\update!

		assert.is.True twn.active
		assert.are.equal 1/2, twn.t
		twn\update!

		assert.is.False twn.active

	it "complete callback", ->

	it "cancel", ->

require "busted"
require "tests.mock_love"

require "LunoPunk.Tween"

describe "Tween", ->
	setup ->
		-- We used fixed time for testing
		LP.fixed = true

	it "construct", ->
		assert.has.errors -> Tween!
		tween = Tween 500
		assert.is.False tween.active
		assert.is.Nil tween.ease
		assert.are.equal TweenType.Persist, tween.type
		assert.are.equal 0, tween.t

	it "update (persist)", ->
		tween = Tween 5
		tween\start!
		assert.is.True tween.active
		tween\update!
		assert.are.equal 1/5, tween.t
		tween\update!
		assert.are.equal 2/5, tween.t
		-- Finish up the tween
		tween\update!
		tween\update!
		tween\update!
		-- t loops back to 0 to start again
		assert.are.equal 0, tween.t
		assert.is.False tween.active

		tween = Tween 2, TweenType.Persist, nil, (t) => t + 1
		tween\update!
		assert.is.False tween.active

	it "update (looping)", ->
		tween = Tween 2, TweenType.Looping
		tween\start!
		for i=1, 33
			assert.is.True tween.active
			assert.are.equal (i-1)%2/2, tween.t
			tween\update!

	it "update (oneshot)", ->
		tween = Tween 2, TweenType.OneShot
		tween\start!

		assert.is.True tween.active
		assert.are.equal 0, tween.t
		tween\update!

		assert.is.True tween.active
		assert.are.equal 1/2, tween.t
		tween\update!

		assert.is.False tween.active

	it "complete callback", ->

	it "cancel", ->