Skip to content

Commit

Permalink
Initial implementation of Issue #3, "Count Kicks"
Browse files Browse the repository at this point in the history
  • Loading branch information
kms70847 committed Jul 29, 2016
1 parent 60e216c commit b1cd14f
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
35 changes: 35 additions & 0 deletions dbmodel.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import sqlalchemy
from sqlalchemy import create_engine
engine = create_engine(config.database_connection_string)
from sqlalchemy.ext.declarative import declarative_base
Base = declarative_base()

from sqlalchemy import Column, Integer, String, Boolean
class User(Base):
__tablename__ = 'users'

surrogate_id = Column(Integer, primary_key=True)
so_user_id = Column(Integer, index=True, unique=True)
is_banned = Column(Boolean)
kick_count = Column(Integer)
trash_count = Column(Integer)
flag_count = Column(Integer)
notes = Column(String)

def __repr__(self):
names = "id is_banned kick_count trash_count flag_count notes".split()
return "<User(so_user_id={}, is_banned={}, kick_count={}, trash_count={}, flag_count={}, notes={})>".format(self.so_user_id, self.is_banned, self.kick_count, self.trash_count, self.flag_count, self.notes)

Base.metadata.create_all(engine)

def get_or_create_user(so_user_id):
user = session.query(User).filter(User.so_user_id == so_user_id).one_or_none()
if user is None:
return User(so_user_id=so_user_id, is_banned=False, kick_count=0, trash_count=0, flag_count=0, notes="")
else:
return user


from sqlalchemy.orm import sessionmaker
Session = sessionmaker(bind=engine)
session = Session()
6 changes: 6 additions & 0 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import json
import html
from queue import Queue
from dbmodel import User, get_or_create_user, session

PERSONAL_SANDBOX_ROOMID = 118024
ROTATING_KNIVES_ROOMID = 71097
Expand Down Expand Up @@ -88,6 +89,11 @@ def onMessage(self, payload):
elif event_type in (3,4): #user entered/left
action = {3:"entered", 4:"left"}[event_type]
print("user {} {} room {}".format(repr(event["user_name"]), action, repr(event["room_name"])))
elif event_type == 15: #account level changed
if event["content"] == "priv 1815 created": #kicked
user = get_or_create_user(event["user_id"])
user.kick_count += 1
session.commit()
else:
print(event_type_names[event_type])

Expand Down

0 comments on commit b1cd14f

Please sign in to comment.