BigBrotherBot

Advanced Users => Plugin Developers => Topic started by: st0rm on October 30, 2016, 11:39:05 PM

Title: Kick Event Issue
Post by: st0rm on October 30, 2016, 11:39:05 PM
Hey,

I am kinda working on making a discord bot that post when people get kicked, banned into a discord server. I found some code from mamba of his twitter banned and modified to my needs. I can't seem to get the admin that kicked/banned or the reason for the penalty. Code break when this gets called.
Code: [Select]
 admin = b3.clients.getByCID(p.adminId)

this is the error
161030 17:32:17 ERROR    "Handler DiscordbanPlugin could not handle event Client Kicked: AttributeError: 'module' object has no attribute 'getByCID' [('C:\\\\Games\\\\Cod4HNS\\\\b3\\\\b3\\\\parser.py', 1412, 'handleEvents', 'hfunc.parseEvent(event)'), ('C:\\\\Games\\\\Cod4HNS\\\\b3\\\\b3\\\\plugin.py', 479, 'parseEvent', 'func(event)'), ('C:\\\\Games\\\\Cod4HNS\\\\b3\\\\b3\\\\extplugins\\\\discordban.py', 77, 'onEvent', 'admin = b3.clients.getByCID(p.adminId)')]"


action = ''

    if event.type == b3.events.EVT_CLIENT_KICK:
   action = 'kicked'

    if event.type == b3.events.EVT_CLIENT_BAN_TEMP:
   action = 'banned'

    if event.type == b3.events.EVT_CLIENT_BAN:
   action = 'banned'

    p = self.getLastBanKick(event.client)
    clientName = event.client.name
    admin = b3.clients.getByCID(p.adminId)
    self.debug('Posting Update to discord: %s' % admin.admin)
    text = '%s %s %s' % (self.removeColors(admin.name), action, clientName)
    self.debug('Posting Update to discord: %s' % text)
    text = '%s: for %s' % (text, self.removeColors(p.reason))

  def getLastBanKick(self, client):
    q = "select * from `penalties` where client_id = %i and type in ('Ban', 'TempBan', 'Kick') order by time_add desc limit 1 " % client.id
    self.debug(q)
    cursor = self.console.storage.query(q)
    g = cursor.getOneRow()
    self.debug(q)
    if not g:
      self.debug('Nothing found')
    return None
    self.debug('Found at least one row: %s' % (str(g)))

    penalty = b3.clients.Penalty()
    penalty.id = int(g['id'])
    penalty.type = g['type']
    penalty.keyword = g['keyword']
    penalty.reason = g['reason']
    penalty.data = g['data']
    penalty.duration = g['duration']
    penalty.inactive = int(g['inactive'])
    penalty.timeAdd  = int(g['time_add'])
    penalty.timeEdit = int(g['time_edit'])
    penalty.timeExpire = int(g['time_expire'])
    penalty.clientId = int(g['client_id'])
    penalty.adminId = int(g['admin_id'])

    return penalty

Any idea how to fix this?
Title: Re: Kick Event Issue
Post by: 82ndAB.Bravo17 on October 31, 2016, 12:27:49 AM
Try:

self.plugin.console.clients.getByCID(cid)
Title: Re: Kick Event Issue
Post by: Fenix on November 02, 2016, 11:41:46 AM
Try:

self.plugin.console.clients.getByCID(cid)
I suggest self.console.clients.getByCID(cid), since he's already referring to the parser using self.console :)
Title: Re: Kick Event Issue
Post by: st0rm on July 09, 2017, 03:09:11 AM
Hi

I ended up getting this to work and now i have a new issue trying to pass an kick event from a plugin.

this is my error
Code: [Select]
170708 20:53:45 ERROR    'Handler DiscordbanPlugin could not handle event Client Kicked: AttributeError: \'str\' object has no attribute \'name\' [(\'C:\\\\Servers\\\\B3Bots\\\\b3test\\\\b3\\\\parser.py\', 1412, \'handleEvents\', \'hfunc.parseEvent(event)\'), (\'C:\\\\Servers\\\\B3Bots\\\\b3test\\\\b3\\\\plugin.py\', 479, \'parseEvent\', \'func(event)\'), (\'C:\\\\Servers\\\\B3Bots\\\\b3test\\\\b3\\\\extplugins\\\\discordban.py\', 134, \'onKick\', \'"description": \\\'**%s** Kicked **%s**\\\' % (admin.name, client.name),\')]'


This is the trigger i am using to queue and event.
Code: [Select]
self.console.queueEvent(b3.events.Event(b3.events.EVT_CLIENT_KICK, {'reason': reason, 'admin': client.exactName}, sclient))

And that is the error I above any idea how to fix it.
Title: Re: Kick Event Issue
Post by: Fenix on July 10, 2017, 11:12:45 AM
Either admin or client (or both) is a string already, and no .name attribute for strings is defined.
Maybe you already parsed the client name into the admin/client variable.

AttributeError: \'str\' object has no attribute \'name\' <------ ERROR
Title: Re: Kick Event Issue
Post by: st0rm on July 11, 2017, 06:09:59 AM
Either admin or client (or both) is a string already, and no .name attribute for strings is defined.
Maybe you already parsed the client name into the admin/client variable.

AttributeError: \'str\' object has no attribute \'name\' <------ ERROR

Thanks for the help got it working. Had to pass the client variable without .exactName part.