@@ -0,0 +1,3030 @@
+package pl.mkrystek.mkbot.pl.mkrystek.mkbot.database;%0A%0Aimport static com.google.common.collect.Lists.newArrayList;%0A%0Aimport java.sql.Connection;%0Aimport java.sql.PreparedStatement;%0Aimport java.sql.ResultSet;%0Aimport java.sql.SQLException;%0Aimport java.util.List;%0Aimport java.util.Properties;%0Aimport org.sqlite.JDBC;%0Aimport pl.mkrystek.mkbot.pl.mkrystek.mkbot.BotProperties;%0A%0Apublic class SkypeDatabase %7B%0A%0A    private Connection databaseConnection;%0A    private List%3CString%3E chatParticipants;%0A    private Integer conversationId;%0A    private int lastMessageId;%0A%0A    public SkypeDatabase() %7B%0A        try %7B%0A            databaseConnection = JDBC.createConnection(JDBC.PREFIX + BotProperties.getSkypeDbPath(), new Properties());%0A            extractProperties();%0A            updateLastMessageId();%0A        %7D catch (SQLException e) %7B%0A            e.printStackTrace();%0A        %7D%0A    %7D%0A%0A    private void extractProperties() throws SQLException %7B%0A        PreparedStatement ps = databaseConnection.prepareStatement(%22SELECT participants, conv_dbid FROM Chats WHERE topic = ?%22);%0A        ps.setString(1, BotProperties.getChatName());%0A        ResultSet rs = ps.executeQuery();%0A        if (rs.next()) %7B%0A            String participants = rs.getString(%22participants%22);%0A            chatParticipants = newArrayList(participants.split(%22 %22));%0A            conversationId = rs.getInt(%22conv_dbid%22);%0A        %7D else %7B%0A            //chat name is not a group conversation%0A            //TODO handle direct conversations later%0A        %7D%0A        ps.close();%0A        rs.close();%0A    %7D%0A%0A    private void updateLastMessageId() throws SQLException %7B%0A        PreparedStatement ps = databaseConnection.prepareStatement(%22SELECT inbox_message_id FROM Conversations WHERE displayname = ?%22);%0A        ps.setString(1, BotProperties.getChatName());%0A        ResultSet rs = ps.executeQuery();%0A        if (rs.next()) %7B%0A            lastMessageId = rs.getInt(%22inbox_message_id%22);%0A        %7D%0A        ps.close();%0A        rs.close();%0A    %7D%0A%0A    public List%3CString%3E getNewMessages() %7B%0A        List%3CString%3E newMessages = newArrayList();%0A        try %7B%0A            PreparedStatement ps = databaseConnection%0A                .prepareStatement(%22SELECT from_dispname, body_xml FROM Messages WHERE convo_id = ? AND id %3E ?%22);%0A            ps.setInt(1, conversationId);%0A            ps.setInt(2, lastMessageId);%0A            ResultSet rs = ps.executeQuery();%0A            while (rs.next()) %7B%0A                newMessages.add(String.format(%22%25s - %25s%22, rs.getString(%22from_dispname%22), rs.getString(%22body_xml%22)));%0A            %7D%0A            ps.close();%0A            rs.close();%0A            updateLastMessageId();%0A        %7D catch (SQLException e) %7B%0A            //do nothing, happens%0A        %7D%0A%0A        return newMessages;%0A    %7D%0A%0A    public void close() %7B%0A        try %7B%0A            if (databaseConnection != null) %7B%0A                databaseConnection.close();%0A            %7D%0A        %7D catch (SQLException e) %7B%0A%0A        %7D%0A    %7D%0A%0A    public List%3CString%3E getChatParticipants() %7B%0A        return chatParticipants;%0A    %7D%0A%7D%0A

Introduce SkypeDatabase class for skype messages handling